2020-08-23 17:14:54 +00:00
|
|
|
#pragma once
|
2020-08-19 22:21:35 +00:00
|
|
|
|
|
|
|
#include "CNProtocol.hpp"
|
2020-08-20 21:43:48 +00:00
|
|
|
#include "PlayerManager.hpp"
|
|
|
|
#include "NPC.hpp"
|
2020-08-19 22:21:35 +00:00
|
|
|
|
2020-09-24 22:36:25 +00:00
|
|
|
#include "contrib/JSON.hpp"
|
|
|
|
|
2020-08-19 22:21:35 +00:00
|
|
|
#include <map>
|
2020-10-24 19:48:55 +00:00
|
|
|
#include <unordered_map>
|
2020-08-25 01:34:53 +00:00
|
|
|
#include <vector>
|
2020-08-19 22:21:35 +00:00
|
|
|
|
2020-08-25 01:34:53 +00:00
|
|
|
#define RESURRECT_HEIGHT 400
|
|
|
|
|
2020-12-15 22:16:18 +00:00
|
|
|
// placeholder; there's only one trigger type right now
|
|
|
|
enum Trigger {
|
|
|
|
ON_KILLED
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef void (*NPCEventHandler)(CNSocket*, BaseNPC*);
|
|
|
|
|
|
|
|
struct NPCEvent {
|
|
|
|
int32_t npcType;
|
|
|
|
int trigger;
|
|
|
|
NPCEventHandler handler;
|
|
|
|
|
|
|
|
NPCEvent(int32_t t, int tr, NPCEventHandler hndlr)
|
|
|
|
: npcType(t), trigger(tr), handler(hndlr) {}
|
|
|
|
};
|
|
|
|
|
2020-08-25 01:34:53 +00:00
|
|
|
// this should really be called vec3 or something...
|
2020-08-23 16:26:25 +00:00
|
|
|
struct WarpLocation {
|
2020-10-02 20:17:24 +00:00
|
|
|
int x, y, z, instanceID, isInstance, limitTaskID, npcID;
|
2020-08-23 16:26:25 +00:00
|
|
|
};
|
|
|
|
|
2020-10-24 19:48:55 +00:00
|
|
|
struct Egg : public BaseNPC {
|
|
|
|
bool summoned;
|
|
|
|
bool dead = false;
|
|
|
|
time_t deadUntil;
|
|
|
|
|
|
|
|
Egg(int x, int y, int z, uint64_t iID, int type, int32_t id, bool summon)
|
|
|
|
: BaseNPC(x, y, z, 0, iID, type, id) {
|
|
|
|
summoned = summon;
|
|
|
|
npcClass = NPCClass::NPC_EGG;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct EggType {
|
|
|
|
int dropCrateId;
|
|
|
|
int effectId;
|
|
|
|
int duration;
|
|
|
|
int regen;
|
|
|
|
};
|
|
|
|
|
2020-08-19 22:21:35 +00:00
|
|
|
namespace NPCManager {
|
2020-09-16 23:43:48 +00:00
|
|
|
extern std::map<int32_t, BaseNPC*> NPCs;
|
2020-08-23 16:26:25 +00:00
|
|
|
extern std::map<int32_t, WarpLocation> Warps;
|
2020-10-24 19:48:55 +00:00
|
|
|
extern std::vector<WarpLocation> RespawnPoints;
|
2020-12-15 22:16:18 +00:00
|
|
|
extern std::vector<NPCEvent> NPCEvents;
|
2020-10-24 19:48:55 +00:00
|
|
|
extern std::unordered_map<int, Egg*> Eggs;
|
2020-10-22 09:09:50 +00:00
|
|
|
extern std::map<std::pair<CNSocket*, int32_t>, time_t> EggBuffs;
|
2020-10-24 19:48:55 +00:00
|
|
|
extern std::unordered_map<int, EggType> EggTypes;
|
2020-09-24 22:36:25 +00:00
|
|
|
extern nlohmann::json NPCData;
|
|
|
|
extern int32_t nextId;
|
2020-08-19 22:21:35 +00:00
|
|
|
void init();
|
|
|
|
|
2020-09-25 01:58:20 +00:00
|
|
|
void destroyNPC(int32_t);
|
2020-11-18 00:07:04 +00:00
|
|
|
void updateNPCPosition(int32_t, int X, int Y, int Z, uint64_t I, int angle);
|
2020-09-17 22:45:43 +00:00
|
|
|
|
2020-09-25 00:00:26 +00:00
|
|
|
void sendToViewable(BaseNPC* npc, void* buf, uint32_t type, size_t size);
|
|
|
|
|
2020-08-29 11:14:21 +00:00
|
|
|
void npcBarkHandler(CNSocket* sock, CNPacketData* data);
|
2020-08-25 02:28:42 +00:00
|
|
|
void npcSummonHandler(CNSocket* sock, CNPacketData* data);
|
2020-09-18 21:24:15 +00:00
|
|
|
void npcUnsummonHandler(CNSocket* sock, CNPacketData* data);
|
2020-08-29 11:14:21 +00:00
|
|
|
void npcWarpHandler(CNSocket* sock, CNPacketData* data);
|
2020-09-25 05:35:27 +00:00
|
|
|
void npcWarpTimeMachine(CNSocket* sock, CNPacketData* data);
|
2020-08-29 11:14:21 +00:00
|
|
|
|
2020-09-09 01:15:25 +00:00
|
|
|
void npcVendorStart(CNSocket* sock, CNPacketData* data);
|
|
|
|
void npcVendorTable(CNSocket* sock, CNPacketData* data);
|
|
|
|
void npcVendorBuy(CNSocket* sock, CNPacketData* data);
|
2020-09-12 02:04:23 +00:00
|
|
|
void npcVendorSell(CNSocket* sock, CNPacketData* data);
|
2020-09-14 14:27:52 +00:00
|
|
|
void npcVendorBuyback(CNSocket* sock, CNPacketData* data);
|
|
|
|
void npcVendorBuyBattery(CNSocket* sock, CNPacketData* data);
|
2020-09-16 00:30:01 +00:00
|
|
|
void npcCombineItems(CNSocket* sock, CNPacketData* data);
|
2020-09-25 05:35:27 +00:00
|
|
|
|
|
|
|
void handleWarp(CNSocket* sock, int32_t warpId);
|
2020-12-15 22:15:39 +00:00
|
|
|
BaseNPC *summonNPC(int x, int y, int z, uint64_t instance, int type, bool respawn=false, bool baseInstance=false);
|
2020-10-11 03:12:12 +00:00
|
|
|
|
2020-11-23 00:14:46 +00:00
|
|
|
BaseNPC* getNearestNPC(std::set<Chunk*>* chunks, int X, int Y, int Z);
|
2020-10-22 08:23:12 +00:00
|
|
|
|
|
|
|
/// returns -1 on fail
|
|
|
|
int eggBuffPlayer(CNSocket* sock, int skillId, int duration);
|
2020-10-24 19:48:55 +00:00
|
|
|
void eggStep(CNServer* serv, time_t currTime);
|
|
|
|
void npcDataToEggData(sNPCAppearanceData* npc, sShinyAppearanceData* egg);
|
|
|
|
void eggPickup(CNSocket* sock, CNPacketData* data);
|
2020-08-19 22:21:35 +00:00
|
|
|
}
|