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 {
|
2020-09-24 01:18:41 +00:00
|
|
|
// general
|
2020-09-16 23:43:48 +00:00
|
|
|
MobState state;
|
2020-09-24 22:36:25 +00:00
|
|
|
int maxHealth;
|
2020-09-22 18:33:10 +00:00
|
|
|
int spawnX;
|
|
|
|
int spawnY;
|
|
|
|
int spawnZ;
|
|
|
|
|
2020-09-24 01:18:41 +00:00
|
|
|
// dead
|
|
|
|
time_t killedTime = 0;
|
2020-09-24 20:55:33 +00:00
|
|
|
time_t regenTime;
|
2020-09-24 22:36:25 +00:00
|
|
|
bool summoned = false;
|
2020-09-24 01:18:41 +00:00
|
|
|
bool despawned = false; // for the sake of death animations
|
|
|
|
|
|
|
|
// roaming
|
|
|
|
int idleRange;
|
2020-09-22 18:33:10 +00:00
|
|
|
time_t nextMovement = 0;
|
|
|
|
|
2020-09-24 01:18:41 +00:00
|
|
|
// combat
|
|
|
|
CNSocket *target = nullptr;
|
|
|
|
time_t nextAttack = 0;
|
|
|
|
|
2020-09-22 18:33:10 +00:00
|
|
|
// temporary; until we're sure what's what
|
|
|
|
nlohmann::json data;
|
|
|
|
|
2020-09-24 22:36:25 +00:00
|
|
|
Mob(int x, int y, int z, int type, int hp, int angle, nlohmann::json d, int32_t id)
|
|
|
|
: BaseNPC(x, y, z, type, id), maxHealth(hp) {
|
2020-09-16 23:43:48 +00:00
|
|
|
state = MobState::ROAMING;
|
|
|
|
|
2020-09-24 01:18:41 +00:00
|
|
|
data = d;
|
|
|
|
|
|
|
|
regenTime = data["m_iRegenTime"];
|
|
|
|
idleRange = data["m_iIdleRange"];
|
|
|
|
|
2020-09-26 01:48:45 +00:00
|
|
|
// XXX: temporarily force respawns for Fusions until we implement instancing
|
|
|
|
if (regenTime >= 300000000)
|
|
|
|
regenTime = 1500;
|
|
|
|
|
2020-09-22 18:33:10 +00:00
|
|
|
spawnX = appearanceData.iX;
|
|
|
|
spawnY = appearanceData.iY;
|
|
|
|
spawnZ = appearanceData.iZ;
|
|
|
|
|
2020-09-22 20:22:10 +00:00
|
|
|
appearanceData.iConditionBitFlag = 0;
|
|
|
|
|
2020-09-16 23:43:48 +00:00
|
|
|
// NOTE: there appear to be discrepancies in the dump
|
|
|
|
appearanceData.iHP = maxHealth;
|
2020-09-24 22:36:25 +00:00
|
|
|
|
|
|
|
npcClass = NPC_MOB;
|
|
|
|
}
|
|
|
|
|
|
|
|
// constructor for /summon
|
|
|
|
Mob(int x, int y, int z, int type, nlohmann::json d, int32_t id)
|
|
|
|
: Mob(x, y, z, type, 0, 0, d, id) {
|
|
|
|
summoned = true; // will be despawned and deallocated when killed
|
|
|
|
appearanceData.iHP = maxHealth = d["m_iHP"];
|
2020-09-16 23:43:48 +00:00
|
|
|
}
|
2020-09-24 22:36:25 +00:00
|
|
|
|
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-22 19:31:08 +00:00
|
|
|
void step(CNServer*, time_t);
|
2020-09-16 23:43:48 +00:00
|
|
|
|
|
|
|
void deadStep(Mob*, time_t);
|
2020-09-24 01:18:41 +00:00
|
|
|
void combatStep(Mob*, time_t);
|
|
|
|
void retreatStep(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-24 01:18:41 +00:00
|
|
|
void npcAttackPc(Mob *mob);
|
2020-09-25 00:00:26 +00:00
|
|
|
int hitMob(CNSocket *sock, Mob *mob, int damage);
|
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);
|
2020-09-24 20:55:33 +00:00
|
|
|
std::pair<int,int> lerp(int, int, int, int, int);
|
2020-08-27 20:16:52 +00:00
|
|
|
}
|