Began refactoring the server (read more)
* deleted the enemy and combat stubs * encapsulated the character and account stubs TODO: * The remaining managers should be singletons
This commit is contained in:
@@ -24,15 +24,35 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
struct AccountData {
|
||||
class AccountData {
|
||||
public:
|
||||
AccountData() = default;
|
||||
~AccountData() = default;
|
||||
|
||||
//accessors and mutators
|
||||
int SetClientIndex(int i) { return clientIndex = i; }
|
||||
int GetClientIndex() { return clientIndex; }
|
||||
|
||||
std::string SetUsername(std::string s) { return username = s; }
|
||||
std::string GetUsername() { return username; }
|
||||
|
||||
//database stuff
|
||||
bool GetBlackListed() { return blackListed; }
|
||||
bool GetWhiteListed() { return whiteListed; }
|
||||
bool GetModerator() { return mod; }
|
||||
bool GetAdministrator() { return admin; }
|
||||
|
||||
private:
|
||||
friend class AccountManager;
|
||||
|
||||
int clientIndex;
|
||||
std::string username;
|
||||
//TODO: password
|
||||
|
||||
bool blackListed = false;
|
||||
bool whiteListed = true;
|
||||
bool mod = false;
|
||||
bool admin = false;
|
||||
|
||||
int clientIndex;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -31,27 +31,41 @@
|
||||
#include <string>
|
||||
#include <cmath>
|
||||
|
||||
struct CharacterData {
|
||||
//metadata
|
||||
int owner;
|
||||
std::string handle;
|
||||
std::string avatar;
|
||||
class CharacterData {
|
||||
public:
|
||||
CharacterData();
|
||||
~CharacterData();
|
||||
|
||||
//location and movement
|
||||
int SetRoomIndex(int i) { return roomIndex = i; }
|
||||
Vector2 SetOrigin(Vector2 v) { return origin = v; }
|
||||
Vector2 SetMotion(Vector2 v) { return motion = v; }
|
||||
|
||||
int GetRoomIndex() { return roomIndex; }
|
||||
Vector2 GetOrigin() { return origin; }
|
||||
Vector2 GetMotion() { return motion; }
|
||||
|
||||
//accessors and mutators
|
||||
Statistics* GetBaseStats() { return &baseStats; }
|
||||
|
||||
//database stuff
|
||||
int GetOwner() { return owner; }
|
||||
std::string GetHandle() { return handle; }
|
||||
std::string GetAvatar() { return avatar; }
|
||||
|
||||
private:
|
||||
friend class CharacterManager;
|
||||
|
||||
//world position
|
||||
int roomIndex = 0;
|
||||
Vector2 origin = {0.0,0.0};
|
||||
Vector2 motion = {0.0,0.0};
|
||||
|
||||
//base statistics
|
||||
Statistics stats;
|
||||
Statistics baseStats;
|
||||
|
||||
//TODO: gameplay components: equipment, items, buffs, debuffs
|
||||
|
||||
//active gameplay members
|
||||
//NOTE: these are lost when unloaded
|
||||
bool inCombat = false;
|
||||
int atbGauge = 0;
|
||||
//TODO: stored command
|
||||
int owner;
|
||||
std::string handle;
|
||||
std::string avatar;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -58,7 +58,7 @@ static const char* DELETE_CHARACTER = "DELETE FROM Characters WHERE uid = ?;";
|
||||
//Define the methods
|
||||
//-------------------------
|
||||
|
||||
//NOTE: default stats as a parameter would be good for different beggining states or multiple classes
|
||||
//NOTE: default baseStats as a parameter would be good for different beggining states or multiple classes
|
||||
int CharacterManager::CreateCharacter(int owner, std::string handle, std::string avatar) {
|
||||
//Create the character, failing if it exists
|
||||
sqlite3_stmt* statement = nullptr;
|
||||
@@ -142,20 +142,20 @@ int CharacterManager::LoadCharacter(int owner, std::string handle, std::string a
|
||||
newChar.origin.y = (double)sqlite3_column_int(statement, 7);
|
||||
|
||||
//statistics
|
||||
newChar.stats.level = sqlite3_column_int(statement, 8);
|
||||
newChar.stats.exp = sqlite3_column_int(statement, 9);
|
||||
newChar.stats.maxHP = sqlite3_column_int(statement, 10);
|
||||
newChar.stats.health = sqlite3_column_int(statement, 11);
|
||||
newChar.stats.maxMP = sqlite3_column_int(statement, 12);
|
||||
newChar.stats.mana = sqlite3_column_int(statement, 13);
|
||||
newChar.stats.attack = sqlite3_column_int(statement, 14);
|
||||
newChar.stats.defence = sqlite3_column_int(statement, 15);
|
||||
newChar.stats.intelligence = sqlite3_column_int(statement, 16);
|
||||
newChar.stats.resistance = sqlite3_column_int(statement, 17);
|
||||
newChar.stats.speed = sqlite3_column_int(statement, 18);
|
||||
newChar.stats.accuracy = sqlite3_column_double(statement, 19);
|
||||
newChar.stats.evasion = sqlite3_column_double(statement, 20);
|
||||
newChar.stats.luck = sqlite3_column_double(statement, 21);
|
||||
newChar.baseStats.level = sqlite3_column_int(statement, 8);
|
||||
newChar.baseStats.exp = sqlite3_column_int(statement, 9);
|
||||
newChar.baseStats.maxHP = sqlite3_column_int(statement, 10);
|
||||
newChar.baseStats.health = sqlite3_column_int(statement, 11);
|
||||
newChar.baseStats.maxMP = sqlite3_column_int(statement, 12);
|
||||
newChar.baseStats.mana = sqlite3_column_int(statement, 13);
|
||||
newChar.baseStats.attack = sqlite3_column_int(statement, 14);
|
||||
newChar.baseStats.defence = sqlite3_column_int(statement, 15);
|
||||
newChar.baseStats.intelligence = sqlite3_column_int(statement, 16);
|
||||
newChar.baseStats.resistance = sqlite3_column_int(statement, 17);
|
||||
newChar.baseStats.speed = sqlite3_column_int(statement, 18);
|
||||
newChar.baseStats.accuracy = sqlite3_column_double(statement, 19);
|
||||
newChar.baseStats.evasion = sqlite3_column_double(statement, 20);
|
||||
newChar.baseStats.luck = sqlite3_column_double(statement, 21);
|
||||
|
||||
//TODO: gameplay components: equipment, items, buffs, debuffs
|
||||
|
||||
@@ -199,20 +199,20 @@ int CharacterManager::SaveCharacter(int uid) {
|
||||
ret |= sqlite3_bind_int(statement, 4, (int)character.origin.y) != SQLITE_OK;
|
||||
|
||||
//statistics
|
||||
ret |= sqlite3_bind_int(statement, 5, character.stats.level) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_int(statement, 6, character.stats.exp) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_int(statement, 7, character.stats.maxHP) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_int(statement, 8, character.stats.health) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_int(statement, 9, character.stats.maxMP) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_int(statement, 10, character.stats.mana) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_int(statement, 11, character.stats.attack) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_int(statement, 12, character.stats.defence) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_int(statement, 13, character.stats.intelligence) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_int(statement, 14, character.stats.resistance) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_int(statement, 15, character.stats.speed) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_double(statement, 16, character.stats.accuracy) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_double(statement, 17, character.stats.evasion) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_double(statement, 18, character.stats.luck) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_int(statement, 5, character.baseStats.level) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_int(statement, 6, character.baseStats.exp) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_int(statement, 7, character.baseStats.maxHP) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_int(statement, 8, character.baseStats.health) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_int(statement, 9, character.baseStats.maxMP) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_int(statement, 10, character.baseStats.mana) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_int(statement, 11, character.baseStats.attack) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_int(statement, 12, character.baseStats.defence) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_int(statement, 13, character.baseStats.intelligence) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_int(statement, 14, character.baseStats.resistance) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_int(statement, 15, character.baseStats.speed) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_double(statement, 16, character.baseStats.accuracy) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_double(statement, 17, character.baseStats.evasion) != SQLITE_OK;
|
||||
ret |= sqlite3_bind_double(statement, 18, character.baseStats.luck) != SQLITE_OK;
|
||||
|
||||
//TODO: gameplay components: equipment, items, buffs, debuffs
|
||||
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
/* Copyright: (c) Kayne Ruse 2014
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef COMBATDATA_HPP_
|
||||
#define COMBATDATA_HPP_
|
||||
|
||||
#include "vector2.hpp"
|
||||
#include "combat_defines.hpp"
|
||||
|
||||
//gameplay members
|
||||
#include "character_data.hpp"
|
||||
#include "enemy_data.hpp"
|
||||
|
||||
//std namespace
|
||||
#include <chrono>
|
||||
#include <array>
|
||||
#include <utility>
|
||||
|
||||
struct CombatData {
|
||||
typedef std::chrono::steady_clock Clock;
|
||||
|
||||
std::array<CharacterData, COMBAT_MAX_CHARACTERS> characterArray;
|
||||
std::array<EnemyData, COMBAT_MAX_ENEMIES> enemyArray;
|
||||
|
||||
//world interaction
|
||||
int mapIndex = 0;
|
||||
Vector2 origin = {0.0,0.0};
|
||||
Vector2 bounds = {0.0,0.0};
|
||||
|
||||
//time interval
|
||||
Clock::time_point lastTick = Clock::now();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,54 +0,0 @@
|
||||
/* Copyright: (c) Kayne Ruse 2014
|
||||
*
|
||||
* 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 "combat_manager.hpp"
|
||||
|
||||
//-------------------------
|
||||
//public access methods
|
||||
//-------------------------
|
||||
|
||||
//TODO
|
||||
|
||||
//-------------------------
|
||||
//accessors and mutators
|
||||
//-------------------------
|
||||
|
||||
CombatData* CombatManager::GetCombat(int uid) {
|
||||
std::map<int, CombatData>::iterator it = combatMap.find(uid);
|
||||
|
||||
if (it == combatMap.end()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return &it->second;
|
||||
}
|
||||
|
||||
std::map<int, CombatData>* CombatManager::GetContainer() {
|
||||
return &combatMap;
|
||||
}
|
||||
|
||||
lua_State* CombatManager::SetLuaState(lua_State* L) {
|
||||
return luaState = L;
|
||||
}
|
||||
|
||||
lua_State* CombatManager::GetLuaState() {
|
||||
return luaState;
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
/* Copyright: (c) Kayne Ruse 2014
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef COMBATMANAGER_HPP_
|
||||
#define COMBATMANAGER_HPP_
|
||||
|
||||
#include "combat_data.hpp"
|
||||
|
||||
#include "lua/lua.hpp"
|
||||
|
||||
#include <map>
|
||||
|
||||
class CombatManager {
|
||||
public:
|
||||
CombatManager() = default;
|
||||
~CombatManager() = default;
|
||||
|
||||
//public access methods
|
||||
//TODO
|
||||
|
||||
//accessors and mutators
|
||||
CombatData* GetCombat(int uid);
|
||||
std::map<int, CombatData>* GetContainer();
|
||||
|
||||
lua_State* SetLuaState(lua_State*);
|
||||
lua_State* GetLuaState();
|
||||
|
||||
private:
|
||||
std::map<int, CombatData> combatMap;
|
||||
lua_State* luaState = nullptr;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,37 +0,0 @@
|
||||
#config
|
||||
INCLUDES+=. ../../common/gameplay ../../common/utilities ../characters ../enemies
|
||||
LIBS+=
|
||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||
|
||||
#source
|
||||
CXXSRC=$(wildcard *.cpp)
|
||||
|
||||
#objects
|
||||
OBJDIR=obj
|
||||
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
||||
|
||||
#output
|
||||
OUTDIR=..
|
||||
OUT=$(addprefix $(OUTDIR)/,server.a)
|
||||
|
||||
#targets
|
||||
all: $(OBJ) $(OUT)
|
||||
ar -crs $(OUT) $(OBJ)
|
||||
|
||||
$(OBJ): | $(OBJDIR)
|
||||
|
||||
$(OUT): | $(OUTDIR)
|
||||
|
||||
$(OBJDIR):
|
||||
mkdir $(OBJDIR)
|
||||
|
||||
$(OUTDIR):
|
||||
mkdir $(OUTDIR)
|
||||
|
||||
$(OBJDIR)/%.o: %.cpp
|
||||
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||
|
||||
clean:
|
||||
$(RM) *.o *.a *.exe
|
||||
|
||||
rebuild: clean all
|
||||
@@ -1,47 +0,0 @@
|
||||
/* Copyright: (c) Kayne Ruse 2014
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef ENEMYDATA_HPP_
|
||||
#define ENEMYDATA_HPP_
|
||||
|
||||
#include "vector2.hpp"
|
||||
#include "statistics.hpp"
|
||||
|
||||
//std namespace
|
||||
#include <string>
|
||||
|
||||
struct EnemyData {
|
||||
//metadata
|
||||
std::string handle;
|
||||
std::string avatar;
|
||||
|
||||
//gameplay
|
||||
Statistics stats;
|
||||
|
||||
//TODO: gameplay components: equipment, items, buffs, debuffs, rewards
|
||||
|
||||
//active gameplay members
|
||||
//NOTE: these are lost when unloaded
|
||||
int tableIndex;
|
||||
int atbGauge = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,54 +0,0 @@
|
||||
/* Copyright: (c) Kayne Ruse 2014
|
||||
*
|
||||
* 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 "enemy_manager.hpp"
|
||||
|
||||
//-------------------------
|
||||
//public access methods
|
||||
//-------------------------
|
||||
|
||||
//TODO
|
||||
|
||||
//-------------------------
|
||||
//accessors and mutators
|
||||
//-------------------------
|
||||
|
||||
EnemyData* EnemyManager::GetEnemy(int uid) {
|
||||
std::map<int, EnemyData>::iterator it = enemyMap.find(uid);
|
||||
|
||||
if (it == enemyMap.end()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return &it->second;
|
||||
}
|
||||
|
||||
std::map<int, EnemyData>* EnemyManager::GetContainer() {
|
||||
return &enemyMap;
|
||||
}
|
||||
|
||||
lua_State* EnemyManager::SetLuaState(lua_State* L) {
|
||||
return luaState = L;
|
||||
}
|
||||
|
||||
lua_State* EnemyManager::GetLuaState() {
|
||||
return luaState;
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
/* Copyright: (c) Kayne Ruse 2014
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef ENEMYMANAGER_HPP_
|
||||
#define ENEMYMANAGER_HPP_
|
||||
|
||||
#include "enemy_data.hpp"
|
||||
|
||||
#include "lua/lua.hpp"
|
||||
|
||||
#include <map>
|
||||
|
||||
class EnemyManager {
|
||||
public:
|
||||
EnemyManager() = default;
|
||||
~EnemyManager() = default;
|
||||
|
||||
//public access methods
|
||||
//TODO
|
||||
|
||||
//accessors and mutators
|
||||
EnemyData* GetEnemy(int uid);
|
||||
std::map<int, EnemyData>* GetContainer();
|
||||
|
||||
lua_State* SetLuaState(lua_State*);
|
||||
lua_State* GetLuaState();
|
||||
|
||||
private:
|
||||
std::map<int, EnemyData> enemyMap;
|
||||
lua_State* luaState = nullptr;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,37 +0,0 @@
|
||||
#config
|
||||
INCLUDES+=. ../mapgen ../../common/gameplay ../../common/map ../../common/utilities
|
||||
LIBS+=
|
||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||
|
||||
#source
|
||||
CXXSRC=$(wildcard *.cpp)
|
||||
|
||||
#objects
|
||||
OBJDIR=obj
|
||||
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
||||
|
||||
#output
|
||||
OUTDIR=..
|
||||
OUT=$(addprefix $(OUTDIR)/,server.a)
|
||||
|
||||
#targets
|
||||
all: $(OBJ) $(OUT)
|
||||
ar -crs $(OUT) $(OBJ)
|
||||
|
||||
$(OBJ): | $(OBJDIR)
|
||||
|
||||
$(OUT): | $(OUTDIR)
|
||||
|
||||
$(OBJDIR):
|
||||
mkdir $(OBJDIR)
|
||||
|
||||
$(OUTDIR):
|
||||
mkdir $(OUTDIR)
|
||||
|
||||
$(OBJDIR)/%.o: %.cpp
|
||||
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||
|
||||
clean:
|
||||
$(RM) *.o *.a *.exe
|
||||
|
||||
rebuild: clean all
|
||||
Reference in New Issue
Block a user