Implemented mob roaming.

Will likely need further tuning.
Mobs in vacant chunks are skipped.
This commit is contained in:
2020-09-22 20:33:10 +02:00
parent 94ab5b8b64
commit ac1fd1e5be
5 changed files with 75 additions and 3 deletions

View File

@@ -5,6 +5,8 @@
#include "CNShardServer.hpp"
#include "NPC.hpp"
#include "contrib/JSON.hpp"
#include <map>
enum class MobState {
@@ -22,14 +24,32 @@ struct Mob : public BaseNPC {
const int regenTime;
bool despawned = false; // for the sake of death animations
Mob(int x, int y, int z, int type, int hp, int angle, int rt)
: BaseNPC(x, y, z, type), maxHealth(hp), regenTime(rt) {
int spawnX;
int spawnY;
int spawnZ;
const int idleRange;
time_t nextMovement = 0;
// temporary; until we're sure what's what
nlohmann::json data;
Mob(int x, int y, int z, int type, int hp, int angle, nlohmann::json d)
: BaseNPC(x, y, z, type), maxHealth(hp), regenTime(d["m_iRegenTime"]), idleRange(d["m_iIdleRange"]), data(d) {
state = MobState::ROAMING;
spawnX = appearanceData.iX;
spawnY = appearanceData.iY;
spawnZ = appearanceData.iZ;
// NOTE: there appear to be discrepancies in the dump
appearanceData.iHP = maxHealth;
}
~Mob() {}
auto operator[](std::string s) {
return data[s];
}
};
namespace MobManager {
@@ -39,6 +59,7 @@ namespace MobManager {
void step(time_t);
void deadStep(Mob*, time_t);
void roamingStep(Mob*, time_t);
void pcAttackNpcs(CNSocket *sock, CNPacketData *data);
void combatBegin(CNSocket *sock, CNPacketData *data);