Wrote some basic combat management code
This commit is contained in:
@@ -19,8 +19,8 @@
|
|||||||
* 3. This notice may not be removed or altered from any source
|
* 3. This notice may not be removed or altered from any source
|
||||||
* distribution.
|
* distribution.
|
||||||
*/
|
*/
|
||||||
#ifndef COMBATINSTANCE_HPP_
|
#ifndef COMBATDATA_HPP_
|
||||||
#define COMBATINSTACNE_HPP_
|
#define COMBATDATA_HPP_
|
||||||
|
|
||||||
#include "vector2.hpp"
|
#include "vector2.hpp"
|
||||||
#include "bbox.hpp"
|
#include "bbox.hpp"
|
||||||
@@ -31,7 +31,9 @@
|
|||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
struct CombatInstance {
|
struct CombatData {
|
||||||
|
typedef std::chrono::steady_clock Clock;
|
||||||
|
|
||||||
//combatants
|
//combatants
|
||||||
std::list<CharacterData*> characterList;
|
std::list<CharacterData*> characterList;
|
||||||
std::list<EnemyData> enemyList;
|
std::list<EnemyData> enemyList;
|
||||||
@@ -42,9 +44,9 @@ struct CombatInstance {
|
|||||||
BBox bbox = {0,0,0,0};
|
BBox bbox = {0,0,0,0};
|
||||||
|
|
||||||
//time interval
|
//time interval
|
||||||
std::chrono::time_point<std::chrono:steady_clock> lastTick;
|
Clock::time_point lastTick = Clock::now();
|
||||||
|
|
||||||
void Update();
|
static int uidCounter;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -21,4 +21,81 @@
|
|||||||
*/
|
*/
|
||||||
#include "server_application.hpp"
|
#include "server_application.hpp"
|
||||||
|
|
||||||
//TODO: method definitions
|
#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<int>(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<const int, CombatData>& 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
|
||||||
|
}
|
||||||
@@ -26,6 +26,7 @@
|
|||||||
#include "client_data.hpp"
|
#include "client_data.hpp"
|
||||||
#include "account_data.hpp"
|
#include "account_data.hpp"
|
||||||
#include "character_data.hpp"
|
#include "character_data.hpp"
|
||||||
|
#include "combat_data.hpp"
|
||||||
|
|
||||||
//maps
|
//maps
|
||||||
#include "map_allocator.hpp"
|
#include "map_allocator.hpp"
|
||||||
@@ -85,14 +86,19 @@ private:
|
|||||||
void UnloadUserAccount(int uid);
|
void UnloadUserAccount(int uid);
|
||||||
void DeleteUserAccount(int uid);
|
void DeleteUserAccount(int uid);
|
||||||
|
|
||||||
//TODO: character management
|
//character management
|
||||||
int CreateCharacter(int owner, std::string handle, std::string avatar);
|
int CreateCharacter(int owner, std::string handle, std::string avatar);
|
||||||
int LoadCharacter(int owner, std::string handle, std::string avatar);
|
int LoadCharacter(int owner, std::string handle, std::string avatar);
|
||||||
int SaveCharacter(int uid);
|
int SaveCharacter(int uid);
|
||||||
void UnloadCharacter(int uid);
|
void UnloadCharacter(int uid);
|
||||||
void DeleteCharacter(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
|
//APIs
|
||||||
UDPNetworkUtility network;
|
UDPNetworkUtility network;
|
||||||
@@ -103,6 +109,7 @@ private:
|
|||||||
std::map<int, ClientData> clientMap;
|
std::map<int, ClientData> clientMap;
|
||||||
std::map<int, AccountData> accountMap;
|
std::map<int, AccountData> accountMap;
|
||||||
std::map<int, CharacterData> characterMap;
|
std::map<int, CharacterData> characterMap;
|
||||||
|
std::map<int, CombatData> combatMap;
|
||||||
|
|
||||||
//maps
|
//maps
|
||||||
//TODO: I need to handle multiple map objects
|
//TODO: I need to handle multiple map objects
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
int ClientData::uidCounter = 0;
|
int ClientData::uidCounter = 0;
|
||||||
|
int CombatData::uidCounter = 0;
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//Define the public members
|
//Define the public members
|
||||||
|
|||||||
Reference in New Issue
Block a user