From f0453375c465379c43b5a1e87077670261be3365 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Thu, 15 May 2014 23:59:24 +1000 Subject: [PATCH 1/7] Stating to implement the combat system --- server/character_data.hpp | 2 ++ server/combat_instance.hpp | 37 ++++++++++++++++++++++ server/combat_management.cpp | 24 ++++++++++++++ server/enemy_data.hpp | 50 ++++++++++++++++++++++++++++++ server/enemy_factory_generic.cpp | 34 ++++++++++++++++++++ server/enemy_factory_generic.hpp | 42 +++++++++++++++++++++++++ server/enemy_factory_interface.hpp | 40 ++++++++++++++++++++++++ server/server_application.hpp | 1 + todo.txt | 37 +++++++++++----------- 9 files changed, 249 insertions(+), 18 deletions(-) create mode 100644 server/combat_instance.hpp create mode 100644 server/combat_management.cpp create mode 100644 server/enemy_data.hpp create mode 100644 server/enemy_factory_generic.cpp create mode 100644 server/enemy_factory_generic.hpp create mode 100644 server/enemy_factory_interface.hpp diff --git a/server/character_data.hpp b/server/character_data.hpp index 0442483..df7aaf9 100644 --- a/server/character_data.hpp +++ b/server/character_data.hpp @@ -54,6 +54,8 @@ struct CharacterData { float accuracy = 0.0; float evasion = 0.0; float luck = 0.0; + + //TODO: equipment and items }; #endif diff --git a/server/combat_instance.hpp b/server/combat_instance.hpp new file mode 100644 index 0000000..78ba16c --- /dev/null +++ b/server/combat_instance.hpp @@ -0,0 +1,37 @@ +/* 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 COMBATINSTANCE_HPP_ +#define COMBATINSTACNE_HPP_ + +#include "character_data.hpp" +#include "enemy_data.hpp" + +#include + +struct CombatInstance { + std::list characterList; + std::list enemyList; + + //TODO: more? +}; + +#endif diff --git a/server/combat_management.cpp b/server/combat_management.cpp new file mode 100644 index 0000000..2c822a0 --- /dev/null +++ b/server/combat_management.cpp @@ -0,0 +1,24 @@ +/* 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 "server_application.hpp" + +//TODO: method definitions \ No newline at end of file diff --git a/server/enemy_data.hpp b/server/enemy_data.hpp new file mode 100644 index 0000000..1e90d68 --- /dev/null +++ b/server/enemy_data.hpp @@ -0,0 +1,50 @@ +/* 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 + +struct EnemyData { + //metadata + std::string handle; + std::string avatar; + + //TODO: attached lua scripts + + //statistics + int level = 0; + int exp = 0; + int maxHP = 0; + int health = 0; + int maxMP = 0; + int mana = 0; + int attack = 0; + int defence = 0; + int intelligence = 0; + int resistance = 0; + float accuracy = 0.0; + float evasion = 0.0; + float luck = 0.0; +}; + +#endif diff --git a/server/enemy_factory_generic.cpp b/server/enemy_factory_generic.cpp new file mode 100644 index 0000000..4c83281 --- /dev/null +++ b/server/enemy_factory_generic.cpp @@ -0,0 +1,34 @@ +/* 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_factory_generic.hpp" + +EnemyFactoryGeneric::EnemyFactoryGeneric() : EnemyFactoryInterface() { + // +} + +EnemyFactoryGeneric::~EnemyFactoryGeneric() noexcept { + // +} + +void EnemyFactoryGeneric::Generate(std::list* container) { + //TODO: fill out +} \ No newline at end of file diff --git a/server/enemy_factory_generic.hpp b/server/enemy_factory_generic.hpp new file mode 100644 index 0000000..5a63078 --- /dev/null +++ b/server/enemy_factory_generic.hpp @@ -0,0 +1,42 @@ +/* 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 ENEMYFACTORYGENERIC_HPP_ +#define ENEMYFACTORYGENERIC_HPP_ + +#include "enemy_factory_interface.hpp" + +#include "enemy_data.hpp" + +#include + +//DOCS: Not really intended for use, but rather for copying and tweaking +class EnemyFactoryGeneric : public EnemyFactoryInterface { +public: + EnemyFactoryGeneric(); + ~EnemyFactoryGeneric() noexcept override; + + void Generate(std::list* container) override; +private: + //TODO: hold the parameters specified by the room +}; + +#endif diff --git a/server/enemy_factory_interface.hpp b/server/enemy_factory_interface.hpp new file mode 100644 index 0000000..6582145 --- /dev/null +++ b/server/enemy_factory_interface.hpp @@ -0,0 +1,40 @@ +/* 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 ENEMYFACTORYINTERFACE_HPP_ +#define ENEMYFACTORYINTERFACE_HPP_ + +#include "enemy_data.hpp" + +#include + +//NOTE: Based on biome, world difficulty, etc. +class EnemyFactoryInterface { +public: + EnemyFactoryInterface() = default; + virtual ~EnemyFactoryInterface() = default; + + virtual void Generate(std::list* container) = 0; +private: + //TODO: hold the parameters here? +}; + +#endif diff --git a/server/server_application.hpp b/server/server_application.hpp index 0b93372..3953a30 100644 --- a/server/server_application.hpp +++ b/server/server_application.hpp @@ -51,6 +51,7 @@ #include //The main application class +//TODO: modulate this god class class ServerApplication { public: //standard functions diff --git a/todo.txt b/todo.txt index c37d3e4..a3d260d 100644 --- a/todo.txt +++ b/todo.txt @@ -16,24 +16,25 @@ I may also need to rewrite some variable names. --ServerApplication's methods-- -These interact with the database file, making the server a persistent system. - -* CreateUserAccount -* LoadUserAccount -* SaveUserAccount -* UnloadUserAccount -* DeleteUserAccount - -* CreateCharacter -* LoadCharacter -* SaveCharacter -* UnloadCharacter -* DeleteCharacter +//NOTE: I honestly don't know what I'm doing +CreateCombatInstance(roomIndex) +PushCharacterToCombat(charIndex, combatIndex) +UpdateCombatInstances() //handles all combat --Battle System-- -CombatPortal: - x, y - list - list - //... \ No newline at end of file +CharacterData: + --stats + +EnemyData + --stats + +CombatInstance + list + list + +Room: + RegionPager pager + EnemyFactory enemyFactory --this takes information on the room's data early in the room's construction + list + From b1d6e5a314a74ff6259e331b6e52a6a0ce519549 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Fri, 16 May 2014 02:05:52 +1000 Subject: [PATCH 2/7] Mostly planning --- server/character_data.hpp | 15 ++++++++++--- server/combat_instance.hpp | 7 ++++++ server/enemy_data.hpp | 12 ++++++++-- todo.txt | 45 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 74 insertions(+), 5 deletions(-) diff --git a/server/character_data.hpp b/server/character_data.hpp index df7aaf9..3a49689 100644 --- a/server/character_data.hpp +++ b/server/character_data.hpp @@ -38,9 +38,8 @@ struct CharacterData { int mapIndex = 0; Vector2 position = {0.0,0.0}; Vector2 motion = {0.0,0.0}; - BBox bbox = {0,0,0,0}; - //statistics + //base statistics int level = 0; int exp = 0; int maxHP = 0; @@ -55,7 +54,17 @@ struct CharacterData { float evasion = 0.0; float luck = 0.0; - //TODO: equipment and items + //TODO: equipment + //TODO: items + //TODO: buffs + //TODO: debuffs + + //active gameplay members + //NOTE: these are lost when unloaded + BBox bbox = {0,0,0,0}; + bool inCombat = false; + int atbGauge = 0; + //TODO: stored command }; #endif diff --git a/server/combat_instance.hpp b/server/combat_instance.hpp index 78ba16c..2507bb3 100644 --- a/server/combat_instance.hpp +++ b/server/combat_instance.hpp @@ -28,6 +28,13 @@ #include struct CombatInstance { + //TODO: metadata + + //world position + int mapIndex = 0; + Vector2 position = {0.0,0.0}; + Vector2 motion = {0.0,0.0}; + std::list characterList; std::list enemyList; diff --git a/server/enemy_data.hpp b/server/enemy_data.hpp index 1e90d68..0045444 100644 --- a/server/enemy_data.hpp +++ b/server/enemy_data.hpp @@ -29,8 +29,6 @@ struct EnemyData { std::string handle; std::string avatar; - //TODO: attached lua scripts - //statistics int level = 0; int exp = 0; @@ -45,6 +43,16 @@ struct EnemyData { float accuracy = 0.0; float evasion = 0.0; float luck = 0.0; + + //TODO: equipment + //TODO: items + //TODO: buffs + //TODO: debuffs + + //active gameplay members + //NOTE: these are lost when unloaded + int tableIndex; + int atbGauge = 0; }; #endif diff --git a/todo.txt b/todo.txt index a3d260d..8237afa 100644 --- a/todo.txt +++ b/todo.txt @@ -1,6 +1,7 @@ * I need to keep the documentation up to date. Namely, the GDD is getting out of date. * How many lookups is the map system using? * Add the serial packet to the network utility +* I completely forgot about status ailments --Naming conventions-- @@ -38,3 +39,47 @@ Room: EnemyFactory enemyFactory --this takes information on the room's data early in the room's construction list +--Requirements-- + +The enemies need AI scripts +The scripts need to be able to generate other enemies (frog king). +The characters need a flag to show if they're in a combat instance or not, to signify of they should be unloaded client-side +On each game loop, the server should envoke each combat instance's update function + Each combat instance invokes each enemy's and character's update functions + These update functions increase the ATB guagues + if an ATB guage is full + than the stored command is executed + the players issue their commands during the build up + if there isn't a command ready, then the player is still choosing + for the enemies, the stored commands are driven by scripts, so when the enemies need to attack, their attached scripts are called. + after the commands are called, the ATB is reset to 0. + etc... + +--Enemy Tables-- + +enemyTables: The global store of enemy tables. Only accessed by C++ code (unless you want to break something). + +table.logic: the AI logic. If null, simply attack +table.ref: reference to the enemy itself, for use by API functions, set by constructor? + + + + + + + +--NOTE: useful for copying tables +function deepcopy(orig) + local orig_type = type(orig) + local copy + if orig_type == 'table' then + copy = {} + for orig_key, orig_value in next, orig, nil do + copy[deepcopy(orig_key)] = deepcopy(orig_value) + end + setmetatable(copy, deepcopy(getmetatable(orig))) + else -- number, string, boolean, etc + copy = orig + end + return copy +end \ No newline at end of file From 873715b28cdefcae2aa59cf1c274450a18a860c2 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Fri, 16 May 2014 17:56:40 +1000 Subject: [PATCH 3/7] Added the "speed" statistic --- rsc/scripts/setup_server.sql | 1 + server/character_data.hpp | 1 + server/character_management.cpp | 7 ++++--- server/enemy_data.hpp | 1 + 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/rsc/scripts/setup_server.sql b/rsc/scripts/setup_server.sql index 7a84df0..1167c3c 100644 --- a/rsc/scripts/setup_server.sql +++ b/rsc/scripts/setup_server.sql @@ -71,6 +71,7 @@ CREATE TABLE IF NOT EXISTS PlayerCharacters ( defence INTEGER DEFAULT 0, intelligence INTEGER DEFAULT 0, resistance INTEGER DEFAULT 0, + speed INTEGER DEFAULT 0, accuracy REAL DEFAULT 0.0, evasion REAL DEFAULT 0.0, luck REAL DEFAULT 0.0, diff --git a/server/character_data.hpp b/server/character_data.hpp index 3a49689..2db2bb0 100644 --- a/server/character_data.hpp +++ b/server/character_data.hpp @@ -50,6 +50,7 @@ struct CharacterData { int defence = 0; int intelligence = 0; int resistance = 0; + int speed = 0; float accuracy = 0.0; float evasion = 0.0; float luck = 0.0; diff --git a/server/character_management.cpp b/server/character_management.cpp index 74209bf..58fb6b2 100644 --- a/server/character_management.cpp +++ b/server/character_management.cpp @@ -131,9 +131,10 @@ int ServerApplication::LoadCharacter(int owner, std::string handle, std::string newChar.defence = sqlite3_column_int(statement, 15); newChar.intelligence = sqlite3_column_int(statement, 16); newChar.resistance = sqlite3_column_int(statement, 17); - newChar.accuracy = sqlite3_column_double(statement, 18); - newChar.evasion = sqlite3_column_double(statement, 19); - newChar.luck = sqlite3_column_double(statement, 20); + newChar.speed = sqlite3_column_int(statement, 18); + newChar.accuracy = sqlite3_column_double(statement, 19); + newChar.evasion = sqlite3_column_double(statement, 20); + newChar.luck = sqlite3_column_double(statement, 21); //TODO: equipment diff --git a/server/enemy_data.hpp b/server/enemy_data.hpp index 0045444..4d562fb 100644 --- a/server/enemy_data.hpp +++ b/server/enemy_data.hpp @@ -40,6 +40,7 @@ struct EnemyData { int defence = 0; int intelligence = 0; int resistance = 0; + int speed = 0; float accuracy = 0.0; float evasion = 0.0; float luck = 0.0; From e7403be508490aad516dbc1c24bb5fa986690dfa Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sat, 17 May 2014 02:33:02 +1000 Subject: [PATCH 4/7] Minor tweak to CombatInstance --- server/combat_instance.hpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/server/combat_instance.hpp b/server/combat_instance.hpp index 2507bb3..30257ca 100644 --- a/server/combat_instance.hpp +++ b/server/combat_instance.hpp @@ -22,23 +22,29 @@ #ifndef COMBATINSTANCE_HPP_ #define COMBATINSTACNE_HPP_ +#include "vector2.hpp" +#include "bbox.hpp" + #include "character_data.hpp" #include "enemy_data.hpp" +#include #include struct CombatInstance { - //TODO: metadata - - //world position - int mapIndex = 0; - Vector2 position = {0.0,0.0}; - Vector2 motion = {0.0,0.0}; - + //combatants std::list characterList; std::list enemyList; - //TODO: more? + //world interaction + int mapIndex = 0; + Vector2 position = {0.0,0.0}; + BBox bbox = {0,0,0,0}; + + //time interval + std::chrono::time_point lastTick; + + void Update(); }; #endif From f7df4fba6c4966a68fa3b7dc46df1837bf3cbd9a Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sun, 18 May 2014 01:48:22 +1000 Subject: [PATCH 5/7] Wrote some basic combat management code --- .../{combat_instance.hpp => combat_data.hpp} | 12 +-- server/combat_management.cpp | 79 ++++++++++++++++++- server/server_application.hpp | 11 ++- server/server_internals.cpp | 1 + 4 files changed, 95 insertions(+), 8 deletions(-) rename server/{combat_instance.hpp => combat_data.hpp} (87%) diff --git a/server/combat_instance.hpp b/server/combat_data.hpp similarity index 87% rename from server/combat_instance.hpp rename to server/combat_data.hpp index 30257ca..df75325 100644 --- a/server/combat_instance.hpp +++ b/server/combat_data.hpp @@ -19,8 +19,8 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef COMBATINSTANCE_HPP_ -#define COMBATINSTACNE_HPP_ +#ifndef COMBATDATA_HPP_ +#define COMBATDATA_HPP_ #include "vector2.hpp" #include "bbox.hpp" @@ -31,7 +31,9 @@ #include #include -struct CombatInstance { +struct CombatData { + typedef std::chrono::steady_clock Clock; + //combatants std::list characterList; std::list enemyList; @@ -42,9 +44,9 @@ struct CombatInstance { BBox bbox = {0,0,0,0}; //time interval - std::chrono::time_point lastTick; + Clock::time_point lastTick = Clock::now(); - void Update(); + static int uidCounter; }; #endif diff --git a/server/combat_management.cpp b/server/combat_management.cpp index 2c822a0..7376f5a 100644 --- a/server/combat_management.cpp +++ b/server/combat_management.cpp @@ -21,4 +21,81 @@ */ #include "server_application.hpp" -//TODO: method definitions \ No newline at end of file +#include "utility.hpp" + +int ServerApplication::CreateCombatInstance(int mapIndex, int x, int y) { + CombatData& combat = combatMap[CombatData::uidCounter]; + + combat.mapIndex = mapIndex; + combat.position.x = x; + combat.position.y = y; + + //explicitly postfix + return CombatData::uidCounter++; +} + +void ServerApplication::UnloadCombatInstance(int uid) { + for (auto& it : combatMap[uid].characterList) { + it->inCombat = false; + } + combatMap.erase(uid); +} + +void ServerApplication::UpdateCombat() { + for (auto& combat : combatMap) { + //prune characters that have left + erase_if(combat.second.characterList, [](CharacterData* it) -> bool { + return !it->inCombat; + }); + + //TODO: prune dead enemies + + //update the instance once per second + if (CombatData::Clock::now() - combat.second.lastTick > std::chrono::duration(1)) { + //increase the ATB gauges + for (auto& it : combat.second.characterList) { + it->atbGauge += it->speed; + } + for (auto& it : combat.second.enemyList) { + it.atbGauge += it.speed; + } + combat.second.lastTick = CombatData::Clock::now(); + + //execute the combat commands + for (auto& it : combat.second.characterList) { + if (it->atbGauge >= 100 && /* TODO: Check that there is something stored... */ true ) { + it->atbGauge = 0; + //TODO: EXECUTE STORED COMMAND + } + } + for (auto& it : combat.second.enemyList) { + if (it.atbGauge >= 100) { + it.atbGauge = 0; + //TODO: EXECUTE AI SCRIPT + } + } + } + } + + //Erase instances with no enemies left + erase_if(combatMap, [](std::pair& combat) -> bool { + if (combat.second.enemyList.size() == 0) { + //kick the characters out + for (auto& it : combat.second.characterList) { + it->inCombat = false; + } + return true; + } + return false; + }); + + //TODO: reset instances with no players? +} + +void ServerApplication::PushCharacterToCombat() { + //TODO +} + +void ServerApplication::PopCharacterFromCombat() { + //TODO +} \ No newline at end of file diff --git a/server/server_application.hpp b/server/server_application.hpp index 3953a30..4dd50ea 100644 --- a/server/server_application.hpp +++ b/server/server_application.hpp @@ -26,6 +26,7 @@ #include "client_data.hpp" #include "account_data.hpp" #include "character_data.hpp" +#include "combat_data.hpp" //maps #include "map_allocator.hpp" @@ -85,14 +86,19 @@ private: void UnloadUserAccount(int uid); void DeleteUserAccount(int uid); - //TODO: character management + //character management int CreateCharacter(int owner, std::string handle, std::string avatar); int LoadCharacter(int owner, std::string handle, std::string avatar); int SaveCharacter(int uid); void UnloadCharacter(int uid); void DeleteCharacter(int uid); - //TODO: combat systems + //TODO: combat management + int CreateCombatInstance(int mapIndex, int x, int y); + void UnloadCombatInstance(int uid); + void UpdateCombat(); + void PushCharacterToCombat(); + void PopCharacterFromCombat(); //APIs UDPNetworkUtility network; @@ -103,6 +109,7 @@ private: std::map clientMap; std::map accountMap; std::map characterMap; + std::map combatMap; //maps //TODO: I need to handle multiple map objects diff --git a/server/server_internals.cpp b/server/server_internals.cpp index c2b83c1..abd16e8 100644 --- a/server/server_internals.cpp +++ b/server/server_internals.cpp @@ -32,6 +32,7 @@ //------------------------- int ClientData::uidCounter = 0; +int CombatData::uidCounter = 0; //------------------------- //Define the public members From bb6e248583a9d57cb0617afbd05318bacdc93614 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sun, 18 May 2014 03:45:36 +1000 Subject: [PATCH 6/7] Implemented EnemyFactory, still empty --- server/combat_management.cpp | 39 +++++++++++++++++++++++++++--- server/enemy_factory_generic.cpp | 6 ++--- server/enemy_factory_interface.hpp | 20 +++++++++++++-- server/server_application.hpp | 6 +++-- server/server_internals.cpp | 2 ++ 5 files changed, 62 insertions(+), 11 deletions(-) diff --git a/server/combat_management.cpp b/server/combat_management.cpp index 7376f5a..43a87bd 100644 --- a/server/combat_management.cpp +++ b/server/combat_management.cpp @@ -30,6 +30,8 @@ int ServerApplication::CreateCombatInstance(int mapIndex, int x, int y) { combat.position.x = x; combat.position.y = y; + enemyFactory.Generate(&combat.enemyList); + //explicitly postfix return CombatData::uidCounter++; } @@ -49,6 +51,10 @@ void ServerApplication::UpdateCombat() { }); //TODO: prune dead enemies + //NOTE: This needs to invoke some sort of on death script +// erase_if(combat.second.enemyList, [](EnemyData* it) -> bool { +// return it.health <= 0; +// }); //update the instance once per second if (CombatData::Clock::now() - combat.second.lastTick > std::chrono::duration(1)) { @@ -92,10 +98,35 @@ void ServerApplication::UpdateCombat() { //TODO: reset instances with no players? } -void ServerApplication::PushCharacterToCombat() { - //TODO +int ServerApplication::PushCharacterToCombat(int characterIndex, int combatIndex) { + CombatData& combat = combatMap[combatIndex]; + CharacterData& character = characterMap[characterIndex]; + + //prevent duplicate entries + for (auto& it : combat.characterList) { + if (it == &character) { + //skip out + return -1; + } + } + + combat.characterList.push_back(&character); + + return 0; } -void ServerApplication::PopCharacterFromCombat() { - //TODO +int ServerApplication::PopCharacterFromCombat(int characterIndex, int combatIndex) { + CombatData& combat = combatMap[combatIndex]; + CharacterData& character = characterMap[characterIndex]; + + //derpy + //TODO: should the list point to the std::pair? + for (auto it = combat.characterList.begin(); it != combat.characterList.end(); it++) { + if (*it == &character) { + combat.characterList.erase(it); + return 0; + } + } + + return -1; } \ No newline at end of file diff --git a/server/enemy_factory_generic.cpp b/server/enemy_factory_generic.cpp index 4c83281..e8dd647 100644 --- a/server/enemy_factory_generic.cpp +++ b/server/enemy_factory_generic.cpp @@ -22,13 +22,13 @@ #include "enemy_factory_generic.hpp" EnemyFactoryGeneric::EnemyFactoryGeneric() : EnemyFactoryInterface() { - // + //EMPTY } EnemyFactoryGeneric::~EnemyFactoryGeneric() noexcept { - // + //EMPTY } void EnemyFactoryGeneric::Generate(std::list* container) { - //TODO: fill out + //TODO: fill this out } \ No newline at end of file diff --git a/server/enemy_factory_interface.hpp b/server/enemy_factory_interface.hpp index 6582145..a1c141b 100644 --- a/server/enemy_factory_interface.hpp +++ b/server/enemy_factory_interface.hpp @@ -26,6 +26,15 @@ #include +//TODO: move this elsewhere +enum RoomType { + OVERWORLD, + RUINS, + TOWERS, + FORESTS, + CAVES, +}; + //NOTE: Based on biome, world difficulty, etc. class EnemyFactoryInterface { public: @@ -33,8 +42,15 @@ public: virtual ~EnemyFactoryInterface() = default; virtual void Generate(std::list* container) = 0; -private: - //TODO: hold the parameters here? + + //control the difficulty of the room + RoomType SetType(RoomType t) { return type = t; } + int SetDifficulty(int d) { return difficulty = d; } + RoomType GetType() { return type; } + int GetDifficulty() { return difficulty; } +protected: + RoomType type = RoomType::OVERWORLD; + int difficulty = 0; }; #endif diff --git a/server/server_application.hpp b/server/server_application.hpp index 4dd50ea..a05ab9b 100644 --- a/server/server_application.hpp +++ b/server/server_application.hpp @@ -27,6 +27,7 @@ #include "account_data.hpp" #include "character_data.hpp" #include "combat_data.hpp" +#include "enemy_factory_generic.hpp" //maps #include "map_allocator.hpp" @@ -97,8 +98,8 @@ private: int CreateCombatInstance(int mapIndex, int x, int y); void UnloadCombatInstance(int uid); void UpdateCombat(); - void PushCharacterToCombat(); - void PopCharacterFromCombat(); + int PushCharacterToCombat(int characterIndex, int combatIndex); + int PopCharacterFromCombat(int characterIndex, int combatIndex); //APIs UDPNetworkUtility network; @@ -115,6 +116,7 @@ private: //TODO: I need to handle multiple map objects //TODO: Unload regions that are distant from any characters RegionPager regionPager; + EnemyFactoryGeneric enemyFactory; //misc bool running = true; diff --git a/server/server_internals.cpp b/server/server_internals.cpp index abd16e8..7fed732 100644 --- a/server/server_internals.cpp +++ b/server/server_internals.cpp @@ -136,6 +136,8 @@ void ServerApplication::Proc() { } //update the internals //TODO: update the internals i.e. player positions + + UpdateCombat(); //give the computer a break SDL_Delay(10); } From 6a6e7f7125cd675741b1190e6e742705cf1f185d Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Mon, 19 May 2014 20:04:17 +1000 Subject: [PATCH 7/7] Adjusted the README and tweaked some notes --- README.md | 16 +++++---- rsc/scripts/setup_server.lua | 15 ++++++-- todo.txt | 68 ++++++------------------------------ 3 files changed, 32 insertions(+), 67 deletions(-) diff --git a/README.md b/README.md index ab16447..a215a4e 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,14 @@ -The most recent stable windows build can be found [here](https://dl.dropboxusercontent.com/u/46669050/Tortuga.rar). +The most recent stable build for Windows can be found [here](https://dl.dropboxusercontent.com/u/46669050/Tortuga.rar). -Tortuga is an open source 2D multiplayer role playing game featuring permadeath (deletion of a character upon death). The emphasis of this game is on multiplayer cooperation, competition, exploration and customization. The game runs on customizable server software that can support up to 150 simultaneous players or more. +Tortuga is a 2D multiplayer JRPG featuring permadeath (deletion of a character upon death). The emphasis of this game is on multiplayer cooperation, exploration and customization. The game runs on customizable server software that can support up to 150 simultaneous players or more. This game is inspired by classic 2D RPGs, as well as more modern sandbox MMOs. This project is currently independently created and funded, with the goal of creating a game that will engage user's imagination and inspire a large modding community. +## Documentation + +Tortuga's full documentation can be found in a separate branch, see [Tortuga/docs](https://github.com/Ratstail91/Tortuga/tree/docs). +For Tortuga's primary documentation, please read the [Tortuga Game Design Document](https://github.com/Ratstail91/Tortuga/blob/docs/Tortuga%20Game%20Design%20Document.docx?raw=true). + ## External Dependencies * [SDL 1.2](http://www.libsdl.org/) - Simple DirectMedia Layer API @@ -11,13 +16,10 @@ This game is inspired by classic 2D RPGs, as well as more modern sandbox MMOs. T * [lua 5.2](http://www.lua.org/) - The lua programming language * [SQLite3](http://www.sqlite.org/) - A lightweight SQL database engine -## Documentation - -[Tortuga Game Design Document](https://github.com/Ratstail91/Tortuga/blob/docs/design%20doc.docx?raw=true) -[Tortuga Technical Document](https://github.com/Ratstail91/Tortuga/blob/docs/technical%20doc.docx?raw=true) - ## Copyright +(Future versions (to be determined) may be released under a modified version of the [Uplink Developer's License](http://www.introversion.co.uk/uplink/developer/license.html).) + The current version of Tortuga is released under the [zlib license](http://en.wikipedia.org/wiki/Zlib_License). Copyright (c) 2013, 2014 Kayne Ruse diff --git a/rsc/scripts/setup_server.lua b/rsc/scripts/setup_server.lua index 16b7627..8629320 100644 --- a/rsc/scripts/setup_server.lua +++ b/rsc/scripts/setup_server.lua @@ -1,4 +1,8 @@ -print("Lua script check OK (./rsc)") +print("Lua script check (./rsc)") + +------------------------- +--Map API overrides +------------------------- function map.create(region) for i = 1, map.getregionwidth() do @@ -16,12 +20,17 @@ function map.unload(region) -- end ---return true if file loaded, otherwise return false function map.load(region, dir) - -- + --return true if file loaded, otherwise return false return false end function map.save(region, dir) -- end + +------------------------- +--Enemy API +------------------------- + +--TODO \ No newline at end of file diff --git a/todo.txt b/todo.txt index 8237afa..8182392 100644 --- a/todo.txt +++ b/todo.txt @@ -1,43 +1,11 @@ * I need to keep the documentation up to date. Namely, the GDD is getting out of date. * How many lookups is the map system using? -* Add the serial packet to the network utility +* Hook the serial packet to the network utility * I completely forgot about status ailments ---Naming conventions-- - -I need to define the differences between several different terms i.e. naming conventions. -I may also need to rewrite some variable names. - -* User: This is the individual who is playing the game -* Player: A synonym for a user -* Character: This is the actual player character in the game -* Username: This is the name of the player; ususally kept private -* Handle: This is the name of a character -* Avatar: This is the name of the sprite used by a character - ---ServerApplication's methods-- - -//NOTE: I honestly don't know what I'm doing -CreateCombatInstance(roomIndex) -PushCharacterToCombat(charIndex, combatIndex) -UpdateCombatInstances() //handles all combat - --Battle System-- -CharacterData: - --stats - -EnemyData - --stats - -CombatInstance - list - list - -Room: - RegionPager pager - EnemyFactory enemyFactory --this takes information on the room's data early in the room's construction - list +TODO --Requirements-- @@ -55,31 +23,17 @@ On each game loop, the server should envoke each combat instance's update functi after the commands are called, the ATB is reset to 0. etc... ---Enemy Tables-- +--Enemy API-- -enemyTables: The global store of enemy tables. Only accessed by C++ code (unless you want to break something). +enemyTables -- The global store of enemy tables. Only accessed by C++ code (unless you want to break something). -table.logic: the AI logic. If null, simply attack +enemy.new(parameters) -- return a new enemy object + +table.logic: the AI logic. If null, do nothing table.ref: reference to the enemy itself, for use by API functions, set by constructor? +combat -- the combat API +combat.new(mapIndex, x, y) -- return combat instance's index +combat.pushenemy(c, enemy) -- return the enemy's position +combat.popenemy(c, position) -- - - - - - ---NOTE: useful for copying tables -function deepcopy(orig) - local orig_type = type(orig) - local copy - if orig_type == 'table' then - copy = {} - for orig_key, orig_value in next, orig, nil do - copy[deepcopy(orig_key)] = deepcopy(orig_value) - end - setmetatable(copy, deepcopy(getmetatable(orig))) - else -- number, string, boolean, etc - copy = orig - end - return copy -end \ No newline at end of file