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>
|
2020-10-17 17:26:09 +00:00
|
|
|
#include <unordered_map>
|
2020-10-01 14:36:16 +00:00
|
|
|
#include <queue>
|
2020-09-16 23:43:48 +00:00
|
|
|
|
|
|
|
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;
|
functional crates (no more plungers) (#133)
* FM, Taros and Boosts awards from killing mobs should be pretty
accurate now. A temporary formula for adjusting player/mob level gap is
implemented, but it will probably need to be adjusted in the future
* Mobs now drop correct crates
* Crates can be opened and give you correct items This includes
regular mob crates, world boss crates, mission crates, IZ race crates,
E.G.G.E.R.s, golden Eggs, and Event Crates. Keep in mind that neither
IZ races or golden Eggs are implemented, but if you spawn such a crate
it can be opened.
* All data is read from a json file, for which I'm going to release a
tool soon so it's easily adjustable
* There is a new setting for enabling events, which enables dropping
extra event crates These are Knishmas, Halloween and Easter
2020-10-10 17:18:47 +00:00
|
|
|
int level;
|
2020-09-22 18:33:10 +00:00
|
|
|
|
2020-10-17 17:26:09 +00:00
|
|
|
std::unordered_map<int32_t,time_t> unbuffTimes;
|
|
|
|
|
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-10-20 22:55:58 +00:00
|
|
|
const int sightRange;
|
2020-09-22 18:33:10 +00:00
|
|
|
time_t nextMovement = 0;
|
2020-10-12 19:03:18 +00:00
|
|
|
bool staticPath = false;
|
2020-10-17 17:26:09 +00:00
|
|
|
int roamX, roamY, roamZ;
|
2020-09-22 18:33:10 +00:00
|
|
|
|
2020-09-24 01:18:41 +00:00
|
|
|
// combat
|
|
|
|
CNSocket *target = nullptr;
|
|
|
|
time_t nextAttack = 0;
|
2020-10-28 21:05:01 +00:00
|
|
|
time_t lastDrainTime = 0;
|
2020-09-24 01:18:41 +00:00
|
|
|
|
2020-10-17 23:19:05 +00:00
|
|
|
// drop
|
functional crates (no more plungers) (#133)
* FM, Taros and Boosts awards from killing mobs should be pretty
accurate now. A temporary formula for adjusting player/mob level gap is
implemented, but it will probably need to be adjusted in the future
* Mobs now drop correct crates
* Crates can be opened and give you correct items This includes
regular mob crates, world boss crates, mission crates, IZ race crates,
E.G.G.E.R.s, golden Eggs, and Event Crates. Keep in mind that neither
IZ races or golden Eggs are implemented, but if you spawn such a crate
it can be opened.
* All data is read from a json file, for which I'm going to release a
tool soon so it's easily adjustable
* There is a new setting for enabling events, which enables dropping
extra event crates These are Knishmas, Halloween and Easter
2020-10-10 17:18:47 +00:00
|
|
|
int dropType;
|
|
|
|
|
2020-11-15 07:06:29 +00:00
|
|
|
// group
|
|
|
|
int groupLeader = 0;
|
|
|
|
int offsetX, offsetY;
|
|
|
|
int groupMember[4] = {0, 0, 0, 0};
|
|
|
|
|
2020-09-22 18:33:10 +00:00
|
|
|
// temporary; until we're sure what's what
|
|
|
|
nlohmann::json data;
|
|
|
|
|
2020-10-12 16:55:41 +00:00
|
|
|
Mob(int x, int y, int z, int angle, uint64_t iID, int type, int hp, nlohmann::json d, int32_t id)
|
2020-10-20 22:55:58 +00:00
|
|
|
: BaseNPC(x, y, z, angle, iID, type, id),
|
|
|
|
maxHealth(hp),
|
|
|
|
sightRange(d["m_iSightRange"]) {
|
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"];
|
2020-10-12 19:03:18 +00:00
|
|
|
idleRange = (int)data["m_iIdleRange"] * 2; // TODO: tuning?
|
functional crates (no more plungers) (#133)
* FM, Taros and Boosts awards from killing mobs should be pretty
accurate now. A temporary formula for adjusting player/mob level gap is
implemented, but it will probably need to be adjusted in the future
* Mobs now drop correct crates
* Crates can be opened and give you correct items This includes
regular mob crates, world boss crates, mission crates, IZ race crates,
E.G.G.E.R.s, golden Eggs, and Event Crates. Keep in mind that neither
IZ races or golden Eggs are implemented, but if you spawn such a crate
it can be opened.
* All data is read from a json file, for which I'm going to release a
tool soon so it's easily adjustable
* There is a new setting for enabling events, which enables dropping
extra event crates These are Knishmas, Halloween and Easter
2020-10-10 17:18:47 +00:00
|
|
|
dropType = data["m_iDropType"];
|
|
|
|
level = data["m_iNpcLevel"];
|
2020-09-24 01:18:41 +00:00
|
|
|
|
2020-10-13 19:44:43 +00:00
|
|
|
roamX = spawnX = appearanceData.iX;
|
|
|
|
roamY = spawnY = appearanceData.iY;
|
|
|
|
roamZ = spawnZ = appearanceData.iZ;
|
2020-09-22 18:33:10 +00:00
|
|
|
|
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
|
2020-10-12 16:55:41 +00:00
|
|
|
Mob(int x, int y, int z, uint64_t iID, int type, nlohmann::json d, int32_t id)
|
2020-10-14 00:30:54 +00:00
|
|
|
: Mob(x, y, z, 0, iID, type, 0, d, id) {
|
2020-09-24 22:36:25 +00:00
|
|
|
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
|
|
|
|
functional crates (no more plungers) (#133)
* FM, Taros and Boosts awards from killing mobs should be pretty
accurate now. A temporary formula for adjusting player/mob level gap is
implemented, but it will probably need to be adjusted in the future
* Mobs now drop correct crates
* Crates can be opened and give you correct items This includes
regular mob crates, world boss crates, mission crates, IZ race crates,
E.G.G.E.R.s, golden Eggs, and Event Crates. Keep in mind that neither
IZ races or golden Eggs are implemented, but if you spawn such a crate
it can be opened.
* All data is read from a json file, for which I'm going to release a
tool soon so it's easily adjustable
* There is a new setting for enabling events, which enables dropping
extra event crates These are Knishmas, Halloween and Easter
2020-10-10 17:18:47 +00:00
|
|
|
struct MobDropChance {
|
|
|
|
int dropChance;
|
|
|
|
std::vector<int> cratesRatio;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MobDrop {
|
|
|
|
std::vector<int> crateIDs;
|
|
|
|
int dropChanceType;
|
|
|
|
int taros;
|
|
|
|
int fm;
|
|
|
|
int boosts;
|
|
|
|
};
|
|
|
|
|
2020-11-12 00:46:53 +00:00
|
|
|
struct Bullet {
|
|
|
|
int pointDamage;
|
|
|
|
int groupDamage;
|
|
|
|
bool weaponBoost;
|
|
|
|
int bulletType;
|
|
|
|
};
|
|
|
|
|
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-10-01 14:36:16 +00:00
|
|
|
extern std::queue<int32_t> RemovalQueue;
|
functional crates (no more plungers) (#133)
* FM, Taros and Boosts awards from killing mobs should be pretty
accurate now. A temporary formula for adjusting player/mob level gap is
implemented, but it will probably need to be adjusted in the future
* Mobs now drop correct crates
* Crates can be opened and give you correct items This includes
regular mob crates, world boss crates, mission crates, IZ race crates,
E.G.G.E.R.s, golden Eggs, and Event Crates. Keep in mind that neither
IZ races or golden Eggs are implemented, but if you spawn such a crate
it can be opened.
* All data is read from a json file, for which I'm going to release a
tool soon so it's easily adjustable
* There is a new setting for enabling events, which enables dropping
extra event crates These are Knishmas, Halloween and Easter
2020-10-10 17:18:47 +00:00
|
|
|
extern std::map<int32_t, MobDropChance> MobDropChances;
|
|
|
|
extern std::map<int32_t, MobDrop> MobDrops;
|
2020-11-12 00:46:53 +00:00
|
|
|
extern std::map<int32_t, std::map<int8_t, Bullet>> Bullets;
|
2020-10-07 18:38:32 +00:00
|
|
|
extern bool simulateMobs;
|
2020-09-16 23:43:48 +00:00
|
|
|
|
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-26 22:16:15 +00:00
|
|
|
void playerTick(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-26 22:16:15 +00:00
|
|
|
void dealGooDamage(CNSocket *sock, int amount);
|
2020-08-27 20:16:52 +00:00
|
|
|
|
2020-10-04 23:54:08 +00:00
|
|
|
void npcAttackPc(Mob *mob, time_t currTime);
|
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);
|
functional crates (no more plungers) (#133)
* FM, Taros and Boosts awards from killing mobs should be pretty
accurate now. A temporary formula for adjusting player/mob level gap is
implemented, but it will probably need to be adjusted in the future
* Mobs now drop correct crates
* Crates can be opened and give you correct items This includes
regular mob crates, world boss crates, mission crates, IZ race crates,
E.G.G.E.R.s, golden Eggs, and Event Crates. Keep in mind that neither
IZ races or golden Eggs are implemented, but if you spawn such a crate
it can be opened.
* All data is read from a json file, for which I'm going to release a
tool soon so it's easily adjustable
* There is a new setting for enabling events, which enables dropping
extra event crates These are Knishmas, Halloween and Easter
2020-10-10 17:18:47 +00:00
|
|
|
void giveReward(CNSocket *sock, Mob *mob);
|
2020-10-17 23:19:05 +00:00
|
|
|
void getReward(sItemBase *reward, MobDrop *drop, MobDropChance *chance);
|
functional crates (no more plungers) (#133)
* FM, Taros and Boosts awards from killing mobs should be pretty
accurate now. A temporary formula for adjusting player/mob level gap is
implemented, but it will probably need to be adjusted in the future
* Mobs now drop correct crates
* Crates can be opened and give you correct items This includes
regular mob crates, world boss crates, mission crates, IZ race crates,
E.G.G.E.R.s, golden Eggs, and Event Crates. Keep in mind that neither
IZ races or golden Eggs are implemented, but if you spawn such a crate
it can be opened.
* All data is read from a json file, for which I'm going to release a
tool soon so it's easily adjustable
* There is a new setting for enabling events, which enables dropping
extra event crates These are Knishmas, Halloween and Easter
2020-10-10 17:18:47 +00:00
|
|
|
void giveEventReward(CNSocket* sock, Player* player);
|
|
|
|
|
2020-09-24 20:55:33 +00:00
|
|
|
std::pair<int,int> lerp(int, int, int, int, int);
|
2020-10-09 00:01:35 +00:00
|
|
|
std::pair<int,int> getDamage(int, int, bool, bool, int, int, int);
|
2020-09-22 15:30:49 +00:00
|
|
|
|
|
|
|
void pcAttackChars(CNSocket *sock, CNPacketData *data);
|
2020-10-21 05:24:51 +00:00
|
|
|
void drainMobHP(Mob *mob, int amount);
|
2020-10-12 19:03:18 +00:00
|
|
|
void incNextMovement(Mob *mob, time_t currTime=0);
|
2020-10-04 23:54:08 +00:00
|
|
|
bool aggroCheck(Mob *mob, time_t currTime);
|
2020-10-28 21:05:01 +00:00
|
|
|
void clearDebuff(Mob *mob);
|
2020-11-12 00:46:53 +00:00
|
|
|
|
|
|
|
void grenadeFire(CNSocket* sock, CNPacketData* data);
|
|
|
|
void rocketFire(CNSocket* sock, CNPacketData* data);
|
|
|
|
void projectileHit(CNSocket* sock, CNPacketData* data);
|
|
|
|
/// returns bullet id
|
|
|
|
int8_t addBullet(Player* plr, bool isGrenade);
|
|
|
|
|
2020-08-27 20:16:52 +00:00
|
|
|
}
|