2020-08-27 20:16:52 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "CNProtocol.hpp"
|
|
|
|
#include "CNShared.hpp"
|
|
|
|
#include "CNShardServer.hpp"
|
2020-09-16 23:43:48 +00:00
|
|
|
#include "NPC.hpp"
|
|
|
|
|
2020-09-22 18:33:10 +00:00
|
|
|
#include "contrib/JSON.hpp"
|
|
|
|
|
2020-09-16 23:43:48 +00:00
|
|
|
#include <map>
|
|
|
|
|
|
|
|
enum class MobState {
|
|
|
|
INACTIVE,
|
|
|
|
ROAMING,
|
|
|
|
COMBAT,
|
|
|
|
RETREAT,
|
|
|
|
DEAD
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Mob : public BaseNPC {
|
|
|
|
MobState state;
|
|
|
|
const int maxHealth;
|
|
|
|
time_t killedTime = 0;
|
|
|
|
const int regenTime;
|
2020-09-21 22:21:43 +00:00
|
|
|
bool despawned = false; // for the sake of death animations
|
2020-09-16 23:43:48 +00:00
|
|
|
|
2020-09-22 18:33:10 +00:00
|
|
|
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) {
|
2020-09-16 23:43:48 +00:00
|
|
|
state = MobState::ROAMING;
|
|
|
|
|
2020-09-22 18:33:10 +00:00
|
|
|
spawnX = appearanceData.iX;
|
|
|
|
spawnY = appearanceData.iY;
|
|
|
|
spawnZ = appearanceData.iZ;
|
|
|
|
|
2020-09-16 23:43:48 +00:00
|
|
|
// NOTE: there appear to be discrepancies in the dump
|
|
|
|
appearanceData.iHP = maxHealth;
|
|
|
|
}
|
2020-09-18 21:24:15 +00:00
|
|
|
~Mob() {}
|
2020-09-22 18:33:10 +00:00
|
|
|
|
|
|
|
auto operator[](std::string s) {
|
|
|
|
return data[s];
|
|
|
|
}
|
2020-09-16 23:43:48 +00:00
|
|
|
};
|
2020-08-27 20:16:52 +00:00
|
|
|
|
2020-09-16 19:46:15 +00:00
|
|
|
namespace MobManager {
|
2020-09-16 23:43:48 +00:00
|
|
|
extern std::map<int32_t, Mob*> Mobs;
|
|
|
|
|
2020-08-27 20:16:52 +00:00
|
|
|
void init();
|
2020-09-16 23:43:48 +00:00
|
|
|
void step(time_t);
|
|
|
|
|
|
|
|
void deadStep(Mob*, time_t);
|
2020-09-22 18:33:10 +00:00
|
|
|
void roamingStep(Mob*, time_t);
|
2020-08-27 20:16:52 +00:00
|
|
|
|
|
|
|
void pcAttackNpcs(CNSocket *sock, CNPacketData *data);
|
|
|
|
void combatBegin(CNSocket *sock, CNPacketData *data);
|
|
|
|
void combatEnd(CNSocket *sock, CNPacketData *data);
|
|
|
|
void dotDamageOnOff(CNSocket *sock, CNPacketData *data);
|
|
|
|
|
2020-09-16 23:43:48 +00:00
|
|
|
void killMob(CNSocket *sock, Mob *mob);
|
2020-08-27 20:16:52 +00:00
|
|
|
void giveReward(CNSocket *sock);
|
|
|
|
}
|