Began marking changes for monsters
These changes include storing monsters on shutdown, storing dead characters and monsters, etc. Also fleshed out the MonsterManager's internals a bit. (cherry picked from commit af982710f6de050c09ef503cf2f8e1c9fdd34979)
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
--TODO: (3) An archive table of all dead characters
|
--TODO: (3) An archive table of all dead characters
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS Accounts (
|
CREATE TABLE IF NOT EXISTS UserAccounts (
|
||||||
uid INTEGER PRIMARY KEY AUTOINCREMENT,
|
uid INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
username varchar(100) UNIQUE, --TODO: (3) Swap username for email address
|
username varchar(100) UNIQUE, --TODO: (3) Swap username for email address
|
||||||
|
|
||||||
@@ -15,7 +15,7 @@ CREATE TABLE IF NOT EXISTS Accounts (
|
|||||||
admin BIT DEFAULT 0
|
admin BIT DEFAULT 0
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS Characters (
|
CREATE TABLE IF NOT EXISTS LiveCharacters (
|
||||||
uid INTEGER PRIMARY KEY AUTOINCREMENT,
|
uid INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
|
||||||
--metadata
|
--metadata
|
||||||
@@ -31,18 +31,30 @@ CREATE TABLE IF NOT EXISTS Characters (
|
|||||||
boundsX INTEGER DEFAULT 0,
|
boundsX INTEGER DEFAULT 0,
|
||||||
boundsY INTEGER DEFAULT 0,
|
boundsY INTEGER DEFAULT 0,
|
||||||
boundsW INTEGER DEFAULT 0,
|
boundsW INTEGER DEFAULT 0,
|
||||||
boundsH INTEGER DEFAULT 0,
|
boundsH INTEGER DEFAULT 0
|
||||||
|
|
||||||
--statistics
|
--TODO: statistics
|
||||||
baseStats INTEGER REFERENCES StatisticSets(uid),
|
-- baseStats INTEGER REFERENCES StatisticSets(uid)
|
||||||
|
|
||||||
--equipment
|
--TODO: equipment
|
||||||
weapon INTEGER REFERENCES WornEquipment(uid),
|
-- weapon INTEGER REFERENCES WornEquipment(uid)
|
||||||
helmet INTEGER REFERENCES WornEquipment(uid),
|
-- helmet INTEGER REFERENCES WornEquipment(uid)
|
||||||
armour INTEGER REFERENCES WornEquipment(uid)
|
-- armour INTEGER REFERENCES WornEquipment(uid)
|
||||||
--etc.
|
--etc.
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS DeadCharacters (
|
||||||
|
uid INTEGER PRIMARY KEY AUTOINCREMENT
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS LiveMonsters (
|
||||||
|
uid INTEGER PRIMARY KEY AUTOINCREMENT
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS DeadMonsters (
|
||||||
|
uid INTEGER PRIMARY KEY AUTOINCREMENT
|
||||||
|
);
|
||||||
|
|
||||||
-------------------------
|
-------------------------
|
||||||
--Utility tables
|
--Utility tables
|
||||||
-------------------------
|
-------------------------
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
//Define the queries
|
//Define the queries
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
static const char* CREATE_USER_ACCOUNT = "INSERT INTO Accounts (username) VALUES (?);";
|
static const char* CREATE_USER_ACCOUNT = "INSERT INTO UserAccounts (username) VALUES (?);";
|
||||||
|
|
||||||
static const char* LOAD_USER_ACCOUNT = "SELECT "
|
static const char* LOAD_USER_ACCOUNT = "SELECT "
|
||||||
"uid, "
|
"uid, "
|
||||||
@@ -35,18 +35,18 @@ static const char* LOAD_USER_ACCOUNT = "SELECT "
|
|||||||
"whitelisted, "
|
"whitelisted, "
|
||||||
"mod, "
|
"mod, "
|
||||||
"admin "
|
"admin "
|
||||||
" FROM Accounts WHERE username = ?;";
|
" FROM UserAccounts WHERE username = ?;";
|
||||||
|
|
||||||
static const char* SAVE_USER_ACCOUNT = "UPDATE OR FAIL Accounts SET "
|
static const char* SAVE_USER_ACCOUNT = "UPDATE OR FAIL UserAccounts SET "
|
||||||
"blacklisted = ?2, "
|
"blacklisted = ?2, "
|
||||||
"whitelisted = ?3, "
|
"whitelisted = ?3, "
|
||||||
"mod = ?4, "
|
"mod = ?4, "
|
||||||
"admin = ?5 "
|
"admin = ?5 "
|
||||||
"WHERE uid = ?1;";
|
"WHERE uid = ?1;";
|
||||||
|
|
||||||
static const char* DELETE_USER_ACCOUNT = "DELETE FROM Accounts WHERE uid = ?;";
|
static const char* DELETE_USER_ACCOUNT = "DELETE FROM UserAccounts WHERE uid = ?;";
|
||||||
|
|
||||||
static const char* COUNT_USER_ACCOUNT_RECORDS = "SELECT COUNT(*) FROM Accounts;";
|
static const char* COUNT_USER_ACCOUNT_RECORDS = "SELECT COUNT(*) FROM UserAccounts;";
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//Define the public methods
|
//Define the public methods
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
//NOTE: Programmer set variables are NOT zero-indexed
|
//NOTE: Programmer set variables are NOT zero-indexed
|
||||||
//NOTE: SQLite3 returned variables (i.e. loading) ARE zero-indexed
|
//NOTE: SQLite3 returned variables (i.e. loading) ARE zero-indexed
|
||||||
|
|
||||||
static const char* CREATE_CHARACTER = "INSERT INTO Characters ("
|
static const char* CREATE_CHARACTER = "INSERT INTO LiveCharacters ("
|
||||||
"owner, "
|
"owner, "
|
||||||
"handle, "
|
"handle, "
|
||||||
"avatar, "
|
"avatar, "
|
||||||
@@ -57,9 +57,9 @@ static const char* LOAD_CHARACTER = "SELECT "
|
|||||||
"boundsY, "
|
"boundsY, "
|
||||||
"boundsW, "
|
"boundsW, "
|
||||||
"boundsH "
|
"boundsH "
|
||||||
"FROM Characters WHERE handle = ?;";
|
"FROM LiveCharacters WHERE handle = ?;";
|
||||||
|
|
||||||
static const char* SAVE_CHARACTER = "UPDATE OR FAIL Characters SET "
|
static const char* SAVE_CHARACTER = "UPDATE OR FAIL LiveCharacters SET "
|
||||||
"roomIndex = ?2, "
|
"roomIndex = ?2, "
|
||||||
"originX = ?3, "
|
"originX = ?3, "
|
||||||
"originY = ?4, "
|
"originY = ?4, "
|
||||||
@@ -69,9 +69,9 @@ static const char* SAVE_CHARACTER = "UPDATE OR FAIL Characters SET "
|
|||||||
"boundsH = ?8 "
|
"boundsH = ?8 "
|
||||||
"WHERE uid = ?1;";
|
"WHERE uid = ?1;";
|
||||||
|
|
||||||
static const char* DELETE_CHARACTER = "DELETE FROM Characters WHERE uid = ?;";
|
static const char* DELETE_CHARACTER = "DELETE FROM LiveCharacters WHERE uid = ?;";
|
||||||
|
|
||||||
static const char* COUNT_CHARACTER_RECORDS = "SELECT COUNT(*) FROM Characters;";
|
static const char* COUNT_CHARACTER_RECORDS = "SELECT COUNT(*) FROM LiveCharacters;";
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//Define the methods
|
//Define the methods
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
static int setAvatar(lua_State* L) {
|
static int setAvatar(lua_State* L) {
|
||||||
MonsterData* monster = static_cast<MonsterData*>(lua_touserdata(L, 1));
|
MonsterData* monster = static_cast<MonsterData*>(lua_touserdata(L, 1));
|
||||||
monster->SetAvatar(lua_tostring(L, 2));
|
monster->SetAvatar(lua_tostring(L, 2));
|
||||||
//TODO: send an update to the clients?
|
//TODO: (1) send an update to the clients?
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,46 +29,60 @@ MonsterManager::~MonsterManager() {
|
|||||||
UnloadAll();
|
UnloadAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
int MonsterManager::Create(std::string) {
|
int MonsterManager::Create(std::string s) {
|
||||||
//TODO: (9) MonsterManager::Create()
|
//TODO: (1) MonsterManager::Create()
|
||||||
}
|
}
|
||||||
|
|
||||||
void MonsterManager::Unload(int uid) {
|
void MonsterManager::Unload(int uid) {
|
||||||
//TODO: (9) MonsterManager::Unload()
|
elementMap.erase(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MonsterManager::UnloadAll() {
|
void MonsterManager::UnloadAll() {
|
||||||
//TODO: (9) MonsterManager::UnloadAll()
|
elementMap.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MonsterManager::UnloadIf(std::function<bool(std::pair<const int, MonsterData const&>)> fn) {
|
void MonsterManager::UnloadIf(std::function<bool(std::pair<const int, MonsterData const&>)> fn) {
|
||||||
//TODO: (9) MonsterManager::UnloadIf()
|
std::map<int, MonsterData>::iterator it = elementMap.begin();
|
||||||
|
while (it != elementMap.end()) {
|
||||||
|
if (fn(*it)) {
|
||||||
|
it = elementMap.erase(it);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MonsterData* MonsterManager::Get(int uid) {
|
MonsterData* MonsterManager::Get(int uid) {
|
||||||
//TODO: (9) MonsterManager::Get()
|
std::map<int, MonsterData>::iterator it = elementMap.find(uid);
|
||||||
|
|
||||||
|
if (it == elementMap.end()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return &it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MonsterManager::GetLoadedCount() {
|
int MonsterManager::GetLoadedCount() {
|
||||||
//TODO: (9) MonsterManager::GetLoadedCount()
|
return elementMap.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<int, MonsterData>* MonsterManager::GetContainer() {
|
std::map<int, MonsterData>* MonsterManager::GetContainer() {
|
||||||
//TODO: (9) MonsterManager::GetContainer()
|
return &elementMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
lua_State* MonsterManager::SetLuaState(lua_State* L) {
|
lua_State* MonsterManager::SetLuaState(lua_State* L) {
|
||||||
//TODO: (9) MonsterManager::SetLuaState()
|
return lua = L;
|
||||||
}
|
}
|
||||||
|
|
||||||
lua_State* MonsterManager::GetLuaState() {
|
lua_State* MonsterManager::GetLuaState() {
|
||||||
//TODO: (9) MonsterManager::GetLuaState()
|
return lua;
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlite3* MonsterManager::SetDatabase(sqlite3* db) {
|
sqlite3* MonsterManager::SetDatabase(sqlite3* db) {
|
||||||
//TODO: (9) MonsterManager::SetDatabase()
|
return database = db;
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlite3* MonsterManager::GetDatabase() {
|
sqlite3* MonsterManager::GetDatabase() {
|
||||||
//TODO: (9) MonsterManager::GetDatabase()
|
return database;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,8 +62,13 @@ static int pumpCharacterUpdate(lua_State* L) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int pumpMonsterUpdate(lua_State* L) {
|
||||||
|
//TODO: (0) send the info about a specific monster instance
|
||||||
|
}
|
||||||
|
|
||||||
static const luaL_Reg networkLib[] = {
|
static const luaL_Reg networkLib[] = {
|
||||||
{"PumpCharacterUpdate", pumpCharacterUpdate},
|
{"PumpCharacterUpdate", pumpCharacterUpdate},
|
||||||
|
{"PumpMonsterUpdate", pumpMonsterUpdate},
|
||||||
{nullptr, nullptr}
|
{nullptr, nullptr}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user