Merge branch 'develop', read more
* moved network_api.*pp * Added copyright notices to scripts * Changed SQL table names (including hardcoded usage) * Added monster tables to the database * Made updates.sql (unneeded, and deleted) * Added ForEachMonster() to the room API (incomplete) * Created class MonsterData (incomplete) * Created class MonsterManager (incomplete) * Created MonsterManager API (incomplete)
This commit is contained in:
@@ -1,3 +1,29 @@
|
|||||||
|
--[[
|
||||||
|
/* Copyright: (c) Kayne Ruse 2013-2015
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
--]]
|
||||||
|
|
||||||
|
--DOCS: a placeholder door utility
|
||||||
|
|
||||||
local doorUtility = {}
|
local doorUtility = {}
|
||||||
|
|
||||||
roomAPI = require("room")
|
roomAPI = require("room")
|
||||||
|
|||||||
@@ -1,3 +1,29 @@
|
|||||||
|
--[[
|
||||||
|
/* Copyright: (c) Kayne Ruse 2013-2015
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
--]]
|
||||||
|
|
||||||
|
--DOCS: a placeholder map generator
|
||||||
|
|
||||||
local regionAPI = require("region")
|
local regionAPI = require("region")
|
||||||
|
|
||||||
local mapMaker = {}
|
local mapMaker = {}
|
||||||
|
|||||||
@@ -1,3 +1,27 @@
|
|||||||
|
--[[
|
||||||
|
/* Copyright: (c) Kayne Ruse 2013-2015
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
--]]
|
||||||
|
|
||||||
local region = require("region")
|
local region = require("region")
|
||||||
|
|
||||||
local mapSaver = {}
|
local mapSaver = {}
|
||||||
|
|||||||
@@ -1,3 +1,29 @@
|
|||||||
|
--[[
|
||||||
|
/* Copyright: (c) Kayne Ruse 2013-2015
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
--]]
|
||||||
|
|
||||||
|
--DOCS: This script is run by the server on startup
|
||||||
|
|
||||||
print("Lua script check")
|
print("Lua script check")
|
||||||
|
|
||||||
--requirements
|
--requirements
|
||||||
@@ -27,10 +53,9 @@ end)
|
|||||||
--NOTE: room 0 is the first that the client asks for, therefore it must exist
|
--NOTE: room 0 is the first that the client asks for, therefore it must exist
|
||||||
local overworld, uidOne = roomManagerAPI.CreateRoom("overworld", "overworld.bmp")
|
local overworld, uidOne = roomManagerAPI.CreateRoom("overworld", "overworld.bmp")
|
||||||
roomAPI.Initialize(overworld, mapSaver.Load, mapSaver.Save, mapMaker.DebugIsland, mapSaver.Save)
|
roomAPI.Initialize(overworld, mapSaver.Load, mapSaver.Save, mapMaker.DebugIsland, mapSaver.Save)
|
||||||
|
|
||||||
local underworld, uidTwo = roomManagerAPI.CreateRoom("underworld", "overworld.bmp")
|
local underworld, uidTwo = roomManagerAPI.CreateRoom("underworld", "overworld.bmp")
|
||||||
roomAPI.Initialize(underworld, mapSaver.Load, mapSaver.Save, mapMaker.DebugGrassland, mapSaver.Save)
|
roomAPI.Initialize(underworld, mapSaver.Load, mapSaver.Save, mapMaker.DebugGrassland, mapSaver.Save)
|
||||||
|
|
||||||
--call the monstrosity
|
--call the monstrosity
|
||||||
doorUtility.createDoorPair("pair 1", overworld, -64, -64, underworld, 64, 64)
|
doorUtility.createDoorPair("pair 1", overworld, -64, -64, underworld, 64, 64)
|
||||||
|
|
||||||
print("Finished the lua script")
|
|
||||||
|
|||||||
@@ -1,6 +1,26 @@
|
|||||||
--TODO: (3) An archive table of all dead characters
|
/* Copyright: (c) Kayne Ruse 2013-2015
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
|
||||||
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 +35,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,16 +51,45 @@ 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
|
CREATE TABLE IF NOT EXISTS DeadCharacters (
|
||||||
baseStats INTEGER REFERENCES StatisticSets(uid),
|
uid INTEGER PRIMARY KEY,
|
||||||
|
|
||||||
--equipment
|
--metadata
|
||||||
weapon INTEGER REFERENCES WornEquipment(uid),
|
owner INTEGER REFERENCES Accounts(uid),
|
||||||
helmet INTEGER REFERENCES WornEquipment(uid),
|
handle varchar(100),
|
||||||
armour INTEGER REFERENCES WornEquipment(uid)
|
avatar varchar(100),
|
||||||
--etc.
|
birth timestamp NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS LiveMonsters (
|
||||||
|
uid INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
|
||||||
|
--metadata
|
||||||
|
handle varchar(100) UNIQUE,
|
||||||
|
avatar varchar(100),
|
||||||
|
|
||||||
|
--actions
|
||||||
|
-- script
|
||||||
|
|
||||||
|
--physically exists in the world
|
||||||
|
roomIndex INTEGER DEFAULT 0,
|
||||||
|
originX INTEGER DEFAULT 0,
|
||||||
|
originY INTEGER DEFAULT 0,
|
||||||
|
boundsX INTEGER DEFAULT 0,
|
||||||
|
boundsY INTEGER DEFAULT 0,
|
||||||
|
boundsW INTEGER DEFAULT 0,
|
||||||
|
boundsH INTEGER DEFAULT 0
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS DeadMonsters (
|
||||||
|
uid INTEGER PRIMARY KEY,
|
||||||
|
|
||||||
|
--metadata
|
||||||
|
handle varchar(100) UNIQUE,
|
||||||
|
avatar varchar(100)
|
||||||
);
|
);
|
||||||
|
|
||||||
-------------------------
|
-------------------------
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -36,7 +36,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, "
|
||||||
@@ -58,9 +58,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, "
|
||||||
@@ -70,9 +70,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
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public:
|
|||||||
const char* GetType() const;
|
const char* GetType() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Entity(const char*);
|
Entity(const char* type);
|
||||||
virtual ~Entity() = default;
|
virtual ~Entity() = default;
|
||||||
|
|
||||||
int roomIndex = -1;
|
int roomIndex = -1;
|
||||||
|
|||||||
+4
-4
@@ -41,8 +41,8 @@
|
|||||||
#include "character_manager_api.hpp"
|
#include "character_manager_api.hpp"
|
||||||
#include "region_api.hpp"
|
#include "region_api.hpp"
|
||||||
#include "region_pager_api.hpp"
|
#include "region_pager_api.hpp"
|
||||||
#include "monster_api.hpp"
|
//#include "monster_api.hpp"
|
||||||
#include "monster_manager_api.hpp"
|
//#include "monster_manager_api.hpp"
|
||||||
#include "network_api.hpp"
|
#include "network_api.hpp"
|
||||||
#include "room_api.hpp"
|
#include "room_api.hpp"
|
||||||
#include "room_manager_api.hpp"
|
#include "room_manager_api.hpp"
|
||||||
@@ -70,8 +70,8 @@ static const luaL_Reg preloadedlibs[] = {
|
|||||||
{TORTUGA_ENTITY_API, openEntityAPI}, //required by derived classes
|
{TORTUGA_ENTITY_API, openEntityAPI}, //required by derived classes
|
||||||
{TORTUGA_CHARACTER_API, openCharacterAPI},
|
{TORTUGA_CHARACTER_API, openCharacterAPI},
|
||||||
{TORTUGA_CHARACTER_MANAGER_API, openCharacterManagerAPI},
|
{TORTUGA_CHARACTER_MANAGER_API, openCharacterManagerAPI},
|
||||||
{TORTUGA_MONSTER_API, openMonsterAPI},
|
// {TORTUGA_MONSTER_API, openMonsterAPI},
|
||||||
{TORTUGA_MONSTER_MANAGER_API, openMonsterManagerAPI},
|
// {TORTUGA_MONSTER_MANAGER_API, openMonsterManagerAPI},
|
||||||
{TORTUGA_NETWORK_API, openNetworkAPI},
|
{TORTUGA_NETWORK_API, openNetworkAPI},
|
||||||
{TORTUGA_REGION_API, openRegionAPI},
|
{TORTUGA_REGION_API, openRegionAPI},
|
||||||
{TORTUGA_REGION_PAGER_API, openRegionPagerAPI},
|
{TORTUGA_REGION_PAGER_API, openRegionPagerAPI},
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
#include directories
|
#include directories
|
||||||
INCLUDES+=SDL . accounts characters clients entities monsters rooms server_utilities triggers ../common/debugging ../common/gameplay ../common/map ../common/network ../common/network/packet_types ../common/utilities
|
INCLUDES+=SDL . accounts characters clients entities rooms server_utilities triggers ../common/debugging ../common/gameplay ../common/map ../common/network ../common/network/packet_types ../common/utilities
|
||||||
|
|
||||||
#libraries
|
#libraries
|
||||||
#the order of the $(LIBS) is important, at least for MinGW
|
#the order of the $(LIBS) is important, at least for MinGW
|
||||||
@@ -33,7 +33,7 @@ all: $(OBJ) $(OUT)
|
|||||||
$(MAKE) -C characters
|
$(MAKE) -C characters
|
||||||
$(MAKE) -C clients
|
$(MAKE) -C clients
|
||||||
$(MAKE) -C entities
|
$(MAKE) -C entities
|
||||||
$(MAKE) -C monsters
|
# $(MAKE) -C monsters
|
||||||
$(MAKE) -C rooms
|
$(MAKE) -C rooms
|
||||||
$(MAKE) -C server_utilities
|
$(MAKE) -C server_utilities
|
||||||
$(MAKE) -C triggers
|
$(MAKE) -C triggers
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,10 +21,23 @@
|
|||||||
*/
|
*/
|
||||||
#include "monster_data.hpp"
|
#include "monster_data.hpp"
|
||||||
|
|
||||||
MonsterData::MonsterData(): Entity("monster") {
|
MonsterData::MonsterData(std::string _avatar, int _scriptRef):
|
||||||
|
Entity("monster"),
|
||||||
|
avatar(_avatar),
|
||||||
|
scriptRef(_scriptRef)
|
||||||
|
{
|
||||||
//EMPTY
|
//EMPTY
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MonsterData::Update() {
|
||||||
|
Entity::Update();
|
||||||
|
//TODO: (0) call the script reference
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//accessors & mutators
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
std::string MonsterData::SetAvatar(std::string s) {
|
std::string MonsterData::SetAvatar(std::string s) {
|
||||||
return avatar = s;
|
return avatar = s;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,11 +28,22 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
/* DOCS: Monster attributes, read more
|
||||||
|
* species (avatar, script)
|
||||||
|
* level
|
||||||
|
* health/mana
|
||||||
|
* permadeath/respawn
|
||||||
|
*/
|
||||||
|
|
||||||
class MonsterData: public Entity {
|
class MonsterData: public Entity {
|
||||||
public:
|
public:
|
||||||
MonsterData();
|
MonsterData(std::string avatar, int scriptRef);
|
||||||
~MonsterData() = default;
|
~MonsterData() = default;
|
||||||
|
|
||||||
|
virtual void Update();
|
||||||
|
|
||||||
|
//accessors & mutators
|
||||||
|
|
||||||
std::string SetAvatar(std::string);
|
std::string SetAvatar(std::string);
|
||||||
std::string GetAvatar();
|
std::string GetAvatar();
|
||||||
|
|
||||||
|
|||||||
@@ -29,46 +29,66 @@ MonsterManager::~MonsterManager() {
|
|||||||
UnloadAll();
|
UnloadAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
int MonsterManager::Create(std::string) {
|
int MonsterManager::Create(std::string avatar, int scriptRef) {
|
||||||
//TODO: (9) MonsterManager::Create()
|
//implicitly create the new
|
||||||
|
elementMap.emplace(counter, MonsterData(avatar, scriptRef));
|
||||||
|
|
||||||
|
//TODO: do various things like saving to the database
|
||||||
|
return counter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: (1) monster load, save
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public:
|
|||||||
~MonsterManager();
|
~MonsterManager();
|
||||||
|
|
||||||
//common public methods
|
//common public methods
|
||||||
int Create(std::string);
|
int Create(std::string avatar, int scriptRef);
|
||||||
void Unload(int uid);
|
void Unload(int uid);
|
||||||
|
|
||||||
void UnloadAll();
|
void UnloadAll();
|
||||||
@@ -57,6 +57,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
//members
|
//members
|
||||||
std::map<int, MonsterData> elementMap;
|
std::map<int, MonsterData> elementMap;
|
||||||
|
int counter = 0;
|
||||||
lua_State* lua = nullptr;
|
lua_State* lua = nullptr;
|
||||||
sqlite3* database = nullptr;
|
sqlite3* database = nullptr;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -23,7 +23,54 @@
|
|||||||
|
|
||||||
#include "monster_manager.hpp"
|
#include "monster_manager.hpp"
|
||||||
|
|
||||||
|
static int create(lua_State* L) {
|
||||||
|
MonsterManager* mgr = static_cast<MonsterManager* const>(lua_touserdata(L, 1));
|
||||||
|
int index = mgr->Create(lua_tostring(L, 2), lua_tointeger(L, 3));
|
||||||
|
MonsterData* monster = mgr->Get(index);
|
||||||
|
lua_pushlightuserdata(L, static_cast<void*>(monster));
|
||||||
|
lua_pushinteger(L, index);
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
//TOOD: this needs to take the userdata as a parameter too
|
||||||
|
static int unload(lua_State* L) {
|
||||||
|
MonsterManager* mgr = static_cast<MonsterManager* const>(lua_touserdata(L, 1));
|
||||||
|
mgr->Unload(lua_tointeger(L, 2));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int unloadAll(lua_State* L) {
|
||||||
|
MonsterManager* mgr = static_cast<MonsterManager* const>(lua_touserdata(L, 1));
|
||||||
|
mgr->UnloadAll();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int unloadIf(lua_State* L) {
|
||||||
|
MonsterManager* mgr = static_cast<MonsterManager* const>(lua_touserdata(L, 1));
|
||||||
|
//TODO: unloadIf
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int get(lua_State* L) {
|
||||||
|
MonsterManager* mgr = static_cast<MonsterManager* const>(lua_touserdata(L, 1));
|
||||||
|
MonsterData* monster = mgr->Get(lua_tointeger(L, 2));
|
||||||
|
lua_pushlightuserdata(L, static_cast<void*>(monster));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int getLoadedCount(lua_State* L) {
|
||||||
|
MonsterManager* mgr = static_cast<MonsterManager* const>(lua_touserdata(L, 1));
|
||||||
|
lua_pushinteger(L, mgr->GetLoadedCount());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static const luaL_Reg monsterManagerLib[] = {
|
static const luaL_Reg monsterManagerLib[] = {
|
||||||
|
{"Create", create},
|
||||||
|
{"Unload", unload},
|
||||||
|
{"UnloadAll", unloadAll},
|
||||||
|
// {"UnloadIf", unloadIf},
|
||||||
|
{"Get", get},
|
||||||
|
{"GetLoadedCount", getLoadedCount},
|
||||||
{nullptr, nullptr}
|
{nullptr, nullptr}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -56,11 +56,13 @@ static int getPager(lua_State* L) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
static int getMonsterMgr(lua_State* L) {
|
static int getMonsterMgr(lua_State* L) {
|
||||||
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
||||||
lua_pushlightuserdata(L, reinterpret_cast<void*>(room->GetMonsterMgr()) );
|
lua_pushlightuserdata(L, reinterpret_cast<void*>(room->GetMonsterMgr()) );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
static int getTriggerMgr(lua_State* L) {
|
static int getTriggerMgr(lua_State* L) {
|
||||||
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
||||||
@@ -68,8 +70,6 @@ static int getTriggerMgr(lua_State* L) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: character list
|
|
||||||
|
|
||||||
static int forEachCharacter(lua_State* L) {
|
static int forEachCharacter(lua_State* L) {
|
||||||
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
||||||
//pass each character to the given function
|
//pass each character to the given function
|
||||||
@@ -87,6 +87,26 @@ static int forEachCharacter(lua_State* L) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
static int forEachMonster(lua_State* L) {
|
||||||
|
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
||||||
|
MonsterManager* monsterMgr = room->GetMonsterMgr();
|
||||||
|
//pass each monster to the given function
|
||||||
|
for (auto& it : *monsterMgr->GetContainer()) {
|
||||||
|
lua_pushvalue(L, -1);
|
||||||
|
lua_pushlightuserdata(L, static_cast<void*>(&it.second));
|
||||||
|
//call each iteration, throwing an exception if something happened
|
||||||
|
if (lua_pcall(L, 1, 0, 0) != LUA_OK) {
|
||||||
|
std::ostringstream os;
|
||||||
|
os << "Lua error: ";
|
||||||
|
os << lua_tostring(L, -1);
|
||||||
|
throw(std::runtime_error(os.str()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
static int setOnTick(lua_State* L) {
|
static int setOnTick(lua_State* L) {
|
||||||
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
||||||
luaL_unref(L, LUA_REGISTRYINDEX, room->GetTickReference());
|
luaL_unref(L, LUA_REGISTRYINDEX, room->GetTickReference());
|
||||||
@@ -120,10 +140,11 @@ static const luaL_Reg roomLib[] = {
|
|||||||
{"GetTileset", getTilesetName},
|
{"GetTileset", getTilesetName},
|
||||||
|
|
||||||
{"GetPager",getPager},
|
{"GetPager",getPager},
|
||||||
{"GetMonsterMgr",getMonsterMgr},
|
// {"GetMonsterMgr",getMonsterMgr},
|
||||||
{"GetTriggerMgr",getTriggerMgr},
|
{"GetTriggerMgr",getTriggerMgr},
|
||||||
|
|
||||||
{"ForEachCharacter", forEachCharacter},
|
{"ForEachCharacter", forEachCharacter},
|
||||||
|
// {"ForEachMonster", forEachMonster},
|
||||||
|
|
||||||
{"SetOnTick", setOnTick},
|
{"SetOnTick", setOnTick},
|
||||||
{"GetOnTick", getOnTick},
|
{"GetOnTick", getOnTick},
|
||||||
|
|||||||
@@ -122,10 +122,6 @@ RegionPagerLua* RoomData::GetPager() {
|
|||||||
return &pager;
|
return &pager;
|
||||||
}
|
}
|
||||||
|
|
||||||
MonsterManager* RoomData::GetMonsterMgr() {
|
|
||||||
return &monsterMgr;
|
|
||||||
}
|
|
||||||
|
|
||||||
TriggerManager* RoomData::GetTriggerMgr() {
|
TriggerManager* RoomData::GetTriggerMgr() {
|
||||||
return &triggerMgr;
|
return &triggerMgr;
|
||||||
}
|
}
|
||||||
@@ -137,7 +133,6 @@ std::list<CharacterData*>* RoomData::GetCharacterList() {
|
|||||||
lua_State* RoomData::SetLuaState(lua_State* L) {
|
lua_State* RoomData::SetLuaState(lua_State* L) {
|
||||||
lua = L;
|
lua = L;
|
||||||
pager.SetLuaState(lua);
|
pager.SetLuaState(lua);
|
||||||
monsterMgr.SetLuaState(lua);
|
|
||||||
triggerMgr.SetLuaState(lua);
|
triggerMgr.SetLuaState(lua);
|
||||||
return lua;
|
return lua;
|
||||||
}
|
}
|
||||||
@@ -148,7 +143,6 @@ lua_State* RoomData::GetLuaState() {
|
|||||||
|
|
||||||
sqlite3* RoomData::SetDatabase(sqlite3* db) {
|
sqlite3* RoomData::SetDatabase(sqlite3* db) {
|
||||||
database = db;
|
database = db;
|
||||||
monsterMgr.SetDatabase(database);
|
|
||||||
return database;
|
return database;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,11 +23,11 @@
|
|||||||
#define ROOMDATA_HPP_
|
#define ROOMDATA_HPP_
|
||||||
|
|
||||||
#include "character_data.hpp"
|
#include "character_data.hpp"
|
||||||
#include "monster_manager.hpp"
|
|
||||||
#include "region_pager_lua.hpp"
|
#include "region_pager_lua.hpp"
|
||||||
#include "trigger_manager.hpp"
|
#include "trigger_manager.hpp"
|
||||||
|
|
||||||
#include "lua.hpp"
|
#include "lua.hpp"
|
||||||
|
#include "sqlite3.h"
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -47,7 +47,6 @@ public:
|
|||||||
std::string GetTileset();
|
std::string GetTileset();
|
||||||
|
|
||||||
RegionPagerLua* GetPager();
|
RegionPagerLua* GetPager();
|
||||||
MonsterManager* GetMonsterMgr();
|
|
||||||
TriggerManager* GetTriggerMgr();
|
TriggerManager* GetTriggerMgr();
|
||||||
std::list<CharacterData*>* GetCharacterList();
|
std::list<CharacterData*>* GetCharacterList();
|
||||||
|
|
||||||
@@ -69,7 +68,6 @@ private:
|
|||||||
|
|
||||||
//members
|
//members
|
||||||
RegionPagerLua pager;
|
RegionPagerLua pager;
|
||||||
MonsterManager monsterMgr;
|
|
||||||
TriggerManager triggerMgr;
|
TriggerManager triggerMgr;
|
||||||
std::list<CharacterData*> characterList;
|
std::list<CharacterData*> characterList;
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,6 @@
|
|||||||
#include "account_manager.hpp"
|
#include "account_manager.hpp"
|
||||||
#include "character_manager.hpp"
|
#include "character_manager.hpp"
|
||||||
#include "client_manager.hpp"
|
#include "client_manager.hpp"
|
||||||
#include "monster_manager.hpp"
|
|
||||||
#include "room_manager.hpp"
|
#include "room_manager.hpp"
|
||||||
|
|
||||||
//utilities
|
//utilities
|
||||||
@@ -105,9 +104,6 @@ private:
|
|||||||
void hCharacterAttack(CharacterPacket* const);
|
void hCharacterAttack(CharacterPacket* const);
|
||||||
void hCharacterDamage(CharacterPacket* const);
|
void hCharacterDamage(CharacterPacket* const);
|
||||||
|
|
||||||
//character management
|
|
||||||
void hMonsterDamage(MonsterPacket* const);
|
|
||||||
|
|
||||||
//chat
|
//chat
|
||||||
void hTextBroadcast(TextPacket* const);
|
void hTextBroadcast(TextPacket* const);
|
||||||
void hTextSpeech(TextPacket* const);
|
void hTextSpeech(TextPacket* const);
|
||||||
|
|||||||
@@ -327,11 +327,6 @@ void ServerApplication::HandlePacket(SerialPacket* const argPacket) {
|
|||||||
hCharacterDamage(static_cast<CharacterPacket*>(argPacket));
|
hCharacterDamage(static_cast<CharacterPacket*>(argPacket));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
//monster management
|
|
||||||
case SerialPacketType::MONSTER_DAMAGE:
|
|
||||||
hMonsterDamage(static_cast<MonsterPacket*>(argPacket));
|
|
||||||
break;
|
|
||||||
|
|
||||||
//chat
|
//chat
|
||||||
case SerialPacketType::TEXT_BROADCAST:
|
case SerialPacketType::TEXT_BROADCAST:
|
||||||
hTextBroadcast(static_cast<TextPacket*>(argPacket));
|
hTextBroadcast(static_cast<TextPacket*>(argPacket));
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
|
||||||
*
|
|
||||||
* This software is provided 'as-is', without any express or implied
|
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
|
||||||
* arising from the use of this software.
|
|
||||||
*
|
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
|
||||||
* including commercial applications, and to alter it and redistribute it
|
|
||||||
* freely, subject to the following restrictions:
|
|
||||||
*
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
* claim that you wrote the original software. If you use this software
|
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
|
||||||
* appreciated but is not required.
|
|
||||||
*
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
* misrepresented as being the original software.
|
|
||||||
*
|
|
||||||
* 3. This notice may not be removed or altered from any source
|
|
||||||
* distribution.
|
|
||||||
*/
|
|
||||||
#include "server_application.hpp"
|
|
||||||
|
|
||||||
void ServerApplication::hMonsterDamage(MonsterPacket* const argPacket) {
|
|
||||||
//TODO: (9) ServerApplication::hMonsterDamage()
|
|
||||||
}
|
|
||||||
@@ -64,8 +64,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