2020-08-19 22:21:35 +00:00
|
|
|
#include "NPCManager.hpp"
|
2022-07-16 23:19:40 +00:00
|
|
|
|
|
|
|
#include "servers/CNShardServer.hpp"
|
|
|
|
|
|
|
|
#include "PlayerManager.hpp"
|
2021-03-16 22:29:13 +00:00
|
|
|
#include "Items.hpp"
|
2020-08-20 21:43:48 +00:00
|
|
|
#include "settings.hpp"
|
2021-03-13 22:55:16 +00:00
|
|
|
#include "Combat.hpp"
|
2021-03-16 22:29:13 +00:00
|
|
|
#include "Missions.hpp"
|
|
|
|
#include "Chunking.hpp"
|
|
|
|
#include "Nanos.hpp"
|
2020-11-08 08:42:49 +00:00
|
|
|
#include "TableData.hpp"
|
2021-03-16 22:29:13 +00:00
|
|
|
#include "Groups.hpp"
|
|
|
|
#include "Racing.hpp"
|
2021-04-16 17:28:59 +00:00
|
|
|
#include "Vendors.hpp"
|
2021-03-13 20:22:29 +00:00
|
|
|
#include "Abilities.hpp"
|
2021-03-28 20:57:43 +00:00
|
|
|
#include "Rand.hpp"
|
2020-08-20 21:43:48 +00:00
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <list>
|
2020-08-21 22:14:11 +00:00
|
|
|
#include <fstream>
|
2020-08-25 01:34:53 +00:00
|
|
|
#include <vector>
|
2020-09-24 22:36:25 +00:00
|
|
|
#include <assert.h>
|
2020-10-11 03:12:12 +00:00
|
|
|
#include <limits.h>
|
2020-08-21 22:14:11 +00:00
|
|
|
|
2021-03-16 21:06:10 +00:00
|
|
|
using namespace NPCManager;
|
|
|
|
|
2021-03-31 19:05:49 +00:00
|
|
|
std::unordered_map<int32_t, BaseNPC*> NPCManager::NPCs;
|
2020-08-23 16:26:25 +00:00
|
|
|
std::map<int32_t, WarpLocation> NPCManager::Warps;
|
2020-08-25 01:34:53 +00:00
|
|
|
std::vector<WarpLocation> NPCManager::RespawnPoints;
|
2020-09-24 22:36:25 +00:00
|
|
|
nlohmann::json NPCManager::NPCData;
|
2020-08-19 22:21:35 +00:00
|
|
|
|
2021-03-31 19:05:49 +00:00
|
|
|
static std::queue<int32_t> RemovalQueue;
|
|
|
|
|
2020-09-24 22:36:25 +00:00
|
|
|
/*
|
|
|
|
* Initialized at the end of TableData::init().
|
|
|
|
* This allows us to summon and kill mobs in arbitrary order without
|
|
|
|
* NPC ID collisions.
|
|
|
|
*/
|
|
|
|
int32_t NPCManager::nextId;
|
2020-09-18 21:24:15 +00:00
|
|
|
|
2020-09-25 01:58:20 +00:00
|
|
|
void NPCManager::destroyNPC(int32_t id) {
|
2020-09-18 21:24:15 +00:00
|
|
|
// sanity check
|
|
|
|
if (NPCs.find(id) == NPCs.end()) {
|
2020-10-20 22:55:58 +00:00
|
|
|
std::cout << "npc not found: " << id << std::endl;
|
2020-09-18 21:24:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
BaseNPC* entity = NPCs[id];
|
|
|
|
|
|
|
|
// sanity check
|
2021-03-16 22:29:13 +00:00
|
|
|
if (!Chunking::chunkExists(entity->chunkPos)) {
|
2020-09-18 21:24:15 +00:00
|
|
|
std::cout << "chunk not found!" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove NPC from the chunk
|
2021-03-21 01:42:45 +00:00
|
|
|
EntityRef ref = {id};
|
|
|
|
Chunking::untrackEntity(entity->chunkPos, ref);
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-09-25 01:58:20 +00:00
|
|
|
// remove from viewable chunks
|
2021-03-21 01:42:45 +00:00
|
|
|
Chunking::removeEntityFromChunks(Chunking::getViewableChunks(entity->chunkPos), ref);
|
2020-09-23 04:08:51 +00:00
|
|
|
|
2020-09-18 21:24:15 +00:00
|
|
|
// finally, remove it from the map and free it
|
|
|
|
NPCs.erase(id);
|
|
|
|
delete entity;
|
2020-09-17 22:45:43 +00:00
|
|
|
}
|
|
|
|
|
2020-11-18 00:07:04 +00:00
|
|
|
void NPCManager::updateNPCPosition(int32_t id, int X, int Y, int Z, uint64_t I, int angle) {
|
2020-09-23 14:53:06 +00:00
|
|
|
BaseNPC* npc = NPCs[id];
|
2021-06-20 18:37:37 +00:00
|
|
|
npc->angle = angle;
|
2020-11-19 01:37:58 +00:00
|
|
|
ChunkPos oldChunk = npc->chunkPos;
|
2021-03-16 22:29:13 +00:00
|
|
|
ChunkPos newChunk = Chunking::chunkPosAt(X, Y, I);
|
2021-04-14 00:57:24 +00:00
|
|
|
npc->x = X;
|
|
|
|
npc->y = Y;
|
|
|
|
npc->z = Z;
|
2020-11-18 00:07:04 +00:00
|
|
|
npc->instanceID = I;
|
|
|
|
if (oldChunk == newChunk)
|
|
|
|
return; // didn't change chunks
|
2021-03-21 01:42:45 +00:00
|
|
|
Chunking::updateEntityChunk({id}, oldChunk, newChunk);
|
2020-10-02 20:17:24 +00:00
|
|
|
}
|
|
|
|
|
2022-07-17 06:33:57 +00:00
|
|
|
void NPCManager::sendToViewable(Entity *npc, void *buf, uint32_t type, size_t size) {
|
2021-03-20 01:23:53 +00:00
|
|
|
for (auto it = npc->viewableChunks.begin(); it != npc->viewableChunks.end(); it++) {
|
2020-11-19 22:19:46 +00:00
|
|
|
Chunk* chunk = *it;
|
2021-03-21 02:54:24 +00:00
|
|
|
for (const EntityRef& ref : chunk->entities) {
|
2022-04-13 19:09:43 +00:00
|
|
|
if (ref.kind == EntityKind::PLAYER)
|
2021-03-21 02:54:24 +00:00
|
|
|
ref.sock->sendPacket(buf, type, size);
|
2020-09-25 00:00:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-16 21:06:10 +00:00
|
|
|
static void npcBarkHandler(CNSocket* sock, CNPacketData* data) {
|
2020-12-15 23:42:22 +00:00
|
|
|
sP_CL2FE_REQ_BARKER* req = (sP_CL2FE_REQ_BARKER*)data->buf;
|
|
|
|
|
2023-12-09 03:49:26 +00:00
|
|
|
int taskID = req->iMissionTaskID;
|
|
|
|
int npcID = req->iNPC_ID;
|
|
|
|
|
|
|
|
if (Missions::Tasks.find(taskID) == Missions::Tasks.end()) {
|
|
|
|
std::cout << "mission task not found: " << taskID << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (npcID < 0 || npcID >= NPCData.size()) {
|
|
|
|
std::cout << "npc not found: " << npcID << std::endl;
|
|
|
|
return;
|
2020-12-15 23:42:22 +00:00
|
|
|
}
|
|
|
|
|
2023-12-09 03:49:26 +00:00
|
|
|
// get bark IDs from task data
|
|
|
|
TaskData* td = Missions::Tasks[taskID];
|
|
|
|
auto& barks = td->task["m_iHBarkerTextID"];
|
|
|
|
|
|
|
|
int barkType = NPCData[npcID]["m_iBarkerType"];
|
|
|
|
if (barkType < 1 || barkType > 4)
|
|
|
|
return; // no barks
|
|
|
|
|
|
|
|
int barkID = barks[barkType - 1];
|
|
|
|
if (barkID == 0)
|
2020-12-15 23:42:22 +00:00
|
|
|
return; // no barks
|
|
|
|
|
|
|
|
INITSTRUCT(sP_FE2CL_REP_BARKER, resp);
|
2023-12-09 03:49:26 +00:00
|
|
|
resp.iNPC_ID = npcID;
|
|
|
|
resp.iMissionStringID = barkID;
|
2021-03-20 23:50:57 +00:00
|
|
|
sock->sendPacket(resp, P_FE2CL_REP_BARKER);
|
2020-12-15 23:42:22 +00:00
|
|
|
}
|
2020-08-25 02:28:42 +00:00
|
|
|
|
2021-03-16 21:06:10 +00:00
|
|
|
static void npcUnsummonHandler(CNSocket* sock, CNPacketData* data) {
|
2020-09-28 18:11:13 +00:00
|
|
|
Player* plr = PlayerManager::getPlayer(sock);
|
|
|
|
|
2020-12-01 19:18:01 +00:00
|
|
|
if (plr->accountLevel > 30)
|
2020-09-18 21:24:15 +00:00
|
|
|
return;
|
2020-10-05 00:03:13 +00:00
|
|
|
|
2020-09-18 21:24:15 +00:00
|
|
|
sP_CL2FE_REQ_NPC_UNSUMMON* req = (sP_CL2FE_REQ_NPC_UNSUMMON*)data->buf;
|
2020-09-25 01:58:20 +00:00
|
|
|
NPCManager::destroyNPC(req->iNPC_ID);
|
2020-09-18 21:24:15 +00:00
|
|
|
}
|
|
|
|
|
2020-12-15 22:15:39 +00:00
|
|
|
// type must already be checked and updateNPCPosition() must be called on the result
|
2023-09-10 17:47:42 +00:00
|
|
|
BaseNPC *NPCManager::summonNPC(int spawnX, int spawnY, int spawnZ, uint64_t instance, int type, bool respawn, bool baseInstance) {
|
2020-12-15 22:15:39 +00:00
|
|
|
uint64_t inst = baseInstance ? MAPNUM(instance) : instance;
|
|
|
|
|
2021-04-26 17:50:51 +00:00
|
|
|
int id = nextId--;
|
2020-12-15 22:15:39 +00:00
|
|
|
int team = NPCData[type]["m_iTeam"];
|
|
|
|
BaseNPC *npc = nullptr;
|
|
|
|
|
|
|
|
if (team == 2) {
|
2023-09-10 17:47:42 +00:00
|
|
|
npc = new Mob(spawnX, spawnY, spawnZ, inst, type, NPCData[type], id);
|
2020-12-15 22:15:39 +00:00
|
|
|
|
|
|
|
// re-enable respawning, if desired
|
|
|
|
((Mob*)npc)->summoned = !respawn;
|
|
|
|
} else
|
2021-10-19 22:30:53 +00:00
|
|
|
npc = new BaseNPC(0, inst, type, id);
|
2020-12-15 22:15:39 +00:00
|
|
|
|
|
|
|
NPCs[id] = npc;
|
|
|
|
|
|
|
|
return npc;
|
|
|
|
}
|
|
|
|
|
2021-03-16 21:06:10 +00:00
|
|
|
static void npcSummonHandler(CNSocket* sock, CNPacketData* data) {
|
2021-03-20 23:50:57 +00:00
|
|
|
auto req = (sP_CL2FE_REQ_NPC_SUMMON*)data->buf;
|
2020-08-29 11:14:21 +00:00
|
|
|
Player* plr = PlayerManager::getPlayer(sock);
|
2020-08-25 02:28:42 +00:00
|
|
|
|
2020-12-21 00:57:56 +00:00
|
|
|
int limit = NPCData.back()["m_iNpcNumber"];
|
|
|
|
|
2020-08-25 02:28:42 +00:00
|
|
|
// permission & sanity check
|
2021-03-03 22:17:36 +00:00
|
|
|
if (plr->accountLevel > 30 || req->iNPCType > limit || req->iNPCCnt > 100)
|
2020-08-25 02:28:42 +00:00
|
|
|
return;
|
|
|
|
|
2020-10-13 19:50:14 +00:00
|
|
|
for (int i = 0; i < req->iNPCCnt; i++) {
|
2020-12-15 22:15:39 +00:00
|
|
|
BaseNPC *npc = summonNPC(plr->x, plr->y, plr->z, plr->instanceID, req->iNPCType);
|
2021-06-20 18:37:37 +00:00
|
|
|
updateNPCPosition(npc->id, plr->x, plr->y, plr->z, plr->instanceID, 0);
|
2020-10-13 19:50:14 +00:00
|
|
|
}
|
2020-08-25 02:28:42 +00:00
|
|
|
}
|
2020-08-29 11:14:21 +00:00
|
|
|
|
2021-03-16 21:06:10 +00:00
|
|
|
static void handleWarp(CNSocket* sock, int32_t warpId) {
|
2020-11-17 23:16:16 +00:00
|
|
|
Player* plr = PlayerManager::getPlayer(sock);
|
2020-08-29 11:14:21 +00:00
|
|
|
// sanity check
|
2020-09-25 05:35:27 +00:00
|
|
|
if (Warps.find(warpId) == Warps.end())
|
2020-08-29 11:14:21 +00:00
|
|
|
return;
|
|
|
|
|
2020-12-29 13:31:48 +00:00
|
|
|
if (plr->iPCState & 8) {
|
2020-12-28 16:39:08 +00:00
|
|
|
// remove the player's vehicle
|
|
|
|
plr->iPCState &= ~8;
|
|
|
|
|
|
|
|
// send to self
|
|
|
|
INITSTRUCT(sP_FE2CL_PC_VEHICLE_OFF_SUCC, off);
|
2021-03-20 23:50:57 +00:00
|
|
|
sock->sendPacket(off, P_FE2CL_PC_VEHICLE_OFF_SUCC);
|
2020-12-28 16:39:08 +00:00
|
|
|
|
|
|
|
// send to others
|
|
|
|
INITSTRUCT(sP_FE2CL_PC_STATE_CHANGE, chg);
|
|
|
|
chg.iPC_ID = plr->iID;
|
|
|
|
chg.iState = plr->iPCState;
|
2021-03-20 23:50:57 +00:00
|
|
|
PlayerManager::sendToViewable(sock, chg, P_FE2CL_PC_STATE_CHANGE);
|
2020-12-28 16:39:08 +00:00
|
|
|
}
|
2020-12-27 23:42:29 +00:00
|
|
|
|
2020-10-02 20:17:24 +00:00
|
|
|
// std::cerr << "Warped to Map Num:" << Warps[warpId].instanceID << " NPC ID " << Warps[warpId].npcID << std::endl;
|
2020-10-19 17:26:14 +00:00
|
|
|
if (Warps[warpId].isInstance) {
|
2020-10-12 16:55:41 +00:00
|
|
|
uint64_t instanceID = Warps[warpId].instanceID;
|
2020-10-20 22:55:58 +00:00
|
|
|
|
2022-04-23 01:13:00 +00:00
|
|
|
Player* leader = plr;
|
2022-04-24 20:50:03 +00:00
|
|
|
if (plr->group != nullptr) leader = PlayerManager::getPlayer(plr->group->filter(EntityKind::PLAYER)[0].sock);
|
2022-04-23 01:13:00 +00:00
|
|
|
|
2020-10-20 22:55:58 +00:00
|
|
|
// if warp requires you to be on a mission, it's gotta be a unique instance
|
|
|
|
if (Warps[warpId].limitTaskID != 0 || instanceID == 14) { // 14 is a special case for the Time Lab
|
2022-04-23 01:13:00 +00:00
|
|
|
instanceID += ((uint64_t)leader->iID << 32); // upper 32 bits are leader ID
|
2021-03-16 22:29:13 +00:00
|
|
|
Chunking::createInstance(instanceID);
|
2020-12-14 23:22:27 +00:00
|
|
|
|
|
|
|
// save Lair entrance coords as a pseudo-Resurrect 'Em
|
|
|
|
plr->recallX = Warps[warpId].x;
|
|
|
|
plr->recallY = Warps[warpId].y;
|
2020-12-15 22:11:10 +00:00
|
|
|
plr->recallZ = Warps[warpId].z + RESURRECT_HEIGHT;
|
|
|
|
plr->recallInstance = instanceID;
|
2020-10-12 16:55:41 +00:00
|
|
|
}
|
2020-10-19 17:26:14 +00:00
|
|
|
|
2022-04-23 01:13:00 +00:00
|
|
|
if (plr->group == nullptr)
|
2020-10-17 04:58:51 +00:00
|
|
|
PlayerManager::sendPlayerTo(sock, Warps[warpId].x, Warps[warpId].y, Warps[warpId].z, instanceID);
|
|
|
|
else {
|
2022-04-24 20:50:03 +00:00
|
|
|
auto players = plr->group->filter(EntityKind::PLAYER);
|
2022-04-23 01:13:00 +00:00
|
|
|
for (int i = 0; i < players.size(); i++) {
|
|
|
|
CNSocket* sockTo = players[i].sock;
|
|
|
|
Player* otherPlr = PlayerManager::getPlayer(sockTo);
|
2020-10-17 04:58:51 +00:00
|
|
|
|
|
|
|
if (otherPlr == nullptr || sockTo == nullptr)
|
|
|
|
continue;
|
|
|
|
|
2020-12-24 04:22:46 +00:00
|
|
|
// save Lair entrance coords for everyone else as well
|
|
|
|
otherPlr->recallX = Warps[warpId].x;
|
|
|
|
otherPlr->recallY = Warps[warpId].y;
|
|
|
|
otherPlr->recallZ = Warps[warpId].z + RESURRECT_HEIGHT;
|
|
|
|
otherPlr->recallInstance = instanceID;
|
|
|
|
|
2020-12-27 23:42:29 +00:00
|
|
|
// remove their vehicle if they're on one
|
2020-12-29 13:31:48 +00:00
|
|
|
if (otherPlr->iPCState & 8) {
|
2020-12-28 16:39:08 +00:00
|
|
|
// remove the player's vehicle
|
|
|
|
otherPlr->iPCState &= ~8;
|
|
|
|
|
|
|
|
// send to self
|
|
|
|
INITSTRUCT(sP_FE2CL_PC_VEHICLE_OFF_SUCC, off);
|
2021-03-20 23:50:57 +00:00
|
|
|
sockTo->sendPacket(off, P_FE2CL_PC_VEHICLE_OFF_SUCC);
|
2020-12-28 16:39:08 +00:00
|
|
|
|
|
|
|
// send to others
|
|
|
|
INITSTRUCT(sP_FE2CL_PC_STATE_CHANGE, chg);
|
|
|
|
chg.iPC_ID = otherPlr->iID;
|
|
|
|
chg.iState = otherPlr->iPCState;
|
2021-03-20 23:50:57 +00:00
|
|
|
PlayerManager::sendToViewable(sockTo, chg, P_FE2CL_PC_STATE_CHANGE);
|
2020-12-28 16:39:08 +00:00
|
|
|
}
|
2020-12-27 23:42:29 +00:00
|
|
|
|
2020-10-17 04:58:51 +00:00
|
|
|
PlayerManager::sendPlayerTo(sockTo, Warps[warpId].x, Warps[warpId].y, Warps[warpId].z, instanceID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-18 00:07:04 +00:00
|
|
|
INITSTRUCT(sP_FE2CL_REP_PC_WARP_USE_NPC_SUCC, resp); // Can only be used for exiting instances because it sets the instance flag to false
|
2020-10-02 20:17:24 +00:00
|
|
|
resp.iX = Warps[warpId].x;
|
|
|
|
resp.iY = Warps[warpId].y;
|
|
|
|
resp.iZ = Warps[warpId].z;
|
2020-11-17 23:16:16 +00:00
|
|
|
resp.iCandy = plr->money;
|
2020-10-02 20:17:24 +00:00
|
|
|
resp.eIL = 4; // do not take away any items
|
2020-12-31 02:31:46 +00:00
|
|
|
uint64_t fromInstance = plr->instanceID; // pre-warp instance, saved for post-warp
|
2020-11-17 23:16:16 +00:00
|
|
|
plr->instanceID = INSTANCE_OVERWORLD;
|
2021-03-16 22:29:13 +00:00
|
|
|
Missions::failInstancedMissions(sock); // fail any instanced missions
|
2021-03-20 23:50:57 +00:00
|
|
|
sock->sendPacket(resp, P_FE2CL_REP_PC_WARP_USE_NPC_SUCC);
|
2020-12-28 16:51:57 +00:00
|
|
|
|
2022-07-22 00:40:33 +00:00
|
|
|
PlayerManager::updatePlayerPositionForWarp(sock, resp.iX, resp.iY, resp.iZ, INSTANCE_OVERWORLD);
|
2020-12-28 16:51:57 +00:00
|
|
|
|
|
|
|
// remove the player's ongoing race, if any
|
2021-03-16 22:29:13 +00:00
|
|
|
if (Racing::EPRaces.find(sock) != Racing::EPRaces.end())
|
|
|
|
Racing::EPRaces.erase(sock);
|
2020-12-31 02:31:46 +00:00
|
|
|
|
|
|
|
// post-warp: check if the source instance has no more players in it and delete it if so
|
2021-03-16 22:29:13 +00:00
|
|
|
Chunking::destroyInstanceIfEmpty(fromInstance);
|
2020-10-02 20:17:24 +00:00
|
|
|
}
|
2020-09-07 20:12:53 +00:00
|
|
|
}
|
2020-10-11 03:12:12 +00:00
|
|
|
|
2021-03-16 21:06:10 +00:00
|
|
|
static void npcWarpHandler(CNSocket* sock, CNPacketData* data) {
|
2021-03-20 23:50:57 +00:00
|
|
|
auto warpNpc = (sP_CL2FE_REQ_PC_WARP_USE_NPC*)data->buf;
|
2021-03-16 21:06:10 +00:00
|
|
|
handleWarp(sock, warpNpc->iWarpID);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void npcWarpTimeMachine(CNSocket* sock, CNPacketData* data) {
|
|
|
|
// this is just a warp request
|
|
|
|
handleWarp(sock, 28);
|
|
|
|
}
|
|
|
|
|
2020-10-11 03:12:12 +00:00
|
|
|
/*
|
|
|
|
* Helper function to get NPC closest to coordinates in specified chunks
|
|
|
|
*/
|
2020-11-23 00:14:46 +00:00
|
|
|
BaseNPC* NPCManager::getNearestNPC(std::set<Chunk*>* chunks, int X, int Y, int Z) {
|
2020-10-11 03:12:12 +00:00
|
|
|
BaseNPC* npc = nullptr;
|
|
|
|
int lastDist = INT_MAX;
|
2020-11-23 00:14:46 +00:00
|
|
|
for (auto c = chunks->begin(); c != chunks->end(); c++) { // haha get it
|
2020-10-11 03:12:12 +00:00
|
|
|
Chunk* chunk = *c;
|
2021-03-21 02:54:24 +00:00
|
|
|
for (auto ent = chunk->entities.begin(); ent != chunk->entities.end(); ent++) {
|
2022-04-13 19:09:43 +00:00
|
|
|
if (ent->kind == EntityKind::PLAYER)
|
2021-03-21 02:54:24 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
BaseNPC* npcTemp = (BaseNPC*)ent->getEntity();
|
2021-04-14 00:57:24 +00:00
|
|
|
int distXY = std::hypot(X - npcTemp->x, Y - npcTemp->y);
|
|
|
|
int dist = std::hypot(distXY, Z - npcTemp->z);
|
2020-10-11 03:12:12 +00:00
|
|
|
if (dist < lastDist) {
|
|
|
|
npc = npcTemp;
|
|
|
|
lastDist = dist;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return npc;
|
|
|
|
}
|
2020-10-22 08:23:12 +00:00
|
|
|
|
2023-09-10 18:02:52 +00:00
|
|
|
// TODO: Move this to separate file in ai/ subdir when implementing more events
|
2020-12-15 22:16:18 +00:00
|
|
|
#pragma region NPCEvents
|
|
|
|
|
|
|
|
// summon right arm and stage 2 body
|
2023-09-10 18:02:52 +00:00
|
|
|
static void lordFuseStageTwo(CombatNPC *npc) {
|
2020-12-15 22:16:18 +00:00
|
|
|
Mob *oldbody = (Mob*)npc; // adaptium, stun
|
|
|
|
|
|
|
|
std::cout << "Lord Fuse stage two" << std::endl;
|
|
|
|
|
2021-10-19 22:33:21 +00:00
|
|
|
// Fuse doesn't move
|
2020-12-15 22:16:18 +00:00
|
|
|
// Blastons, Heal
|
2023-09-10 17:24:19 +00:00
|
|
|
Mob *newbody = (Mob*)NPCManager::summonNPC(oldbody->x, oldbody->y, oldbody->z, oldbody->instanceID, 2467);
|
2020-12-15 22:16:18 +00:00
|
|
|
|
2021-06-20 18:37:37 +00:00
|
|
|
newbody->angle = oldbody->angle;
|
2023-09-10 17:24:19 +00:00
|
|
|
NPCManager::updateNPCPosition(newbody->id, newbody->spawnX, newbody->spawnY, newbody->spawnZ,
|
|
|
|
oldbody->instanceID, oldbody->angle);
|
2020-12-15 22:16:18 +00:00
|
|
|
|
|
|
|
// right arm, Adaptium, Stun
|
2023-09-10 17:24:19 +00:00
|
|
|
Mob *arm = (Mob*)NPCManager::summonNPC(oldbody->x - 600, oldbody->y, oldbody->z, oldbody->instanceID, 2469);
|
2020-12-15 22:16:18 +00:00
|
|
|
|
2021-06-20 18:37:37 +00:00
|
|
|
arm->angle = oldbody->angle;
|
2023-09-10 17:24:19 +00:00
|
|
|
NPCManager::updateNPCPosition(arm->id, arm->spawnX, arm->spawnY, arm->spawnZ,
|
|
|
|
oldbody->instanceID, oldbody->angle);
|
2020-12-15 22:16:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// summon left arm and stage 3 body
|
2023-09-10 18:02:52 +00:00
|
|
|
static void lordFuseStageThree(CombatNPC *npc) {
|
2020-12-15 22:16:18 +00:00
|
|
|
Mob *oldbody = (Mob*)npc;
|
|
|
|
|
|
|
|
std::cout << "Lord Fuse stage three" << std::endl;
|
|
|
|
|
2021-01-17 21:50:49 +00:00
|
|
|
// Cosmix, Damage Point
|
2023-09-10 17:24:19 +00:00
|
|
|
Mob *newbody = (Mob*)NPCManager::summonNPC(oldbody->x, oldbody->y, oldbody->z, oldbody->instanceID, 2468);
|
2020-12-15 22:16:18 +00:00
|
|
|
|
2021-06-20 18:37:37 +00:00
|
|
|
newbody->angle = oldbody->angle;
|
2023-09-10 17:24:19 +00:00
|
|
|
NPCManager::updateNPCPosition(newbody->id, newbody->spawnX, newbody->spawnY, newbody->spawnZ,
|
|
|
|
newbody->instanceID, oldbody->angle);
|
2020-12-15 22:16:18 +00:00
|
|
|
|
|
|
|
// Blastons, Heal
|
2023-09-10 17:24:19 +00:00
|
|
|
Mob *arm = (Mob*)NPCManager::summonNPC(oldbody->x + 600, oldbody->y, oldbody->z, oldbody->instanceID, 2470);
|
2020-12-15 22:16:18 +00:00
|
|
|
|
2021-06-20 18:37:37 +00:00
|
|
|
arm->angle = oldbody->angle;
|
2023-09-10 17:24:19 +00:00
|
|
|
NPCManager::updateNPCPosition(arm->id, arm->spawnX, arm->spawnY, arm->spawnZ,
|
|
|
|
arm->instanceID, oldbody->angle);
|
2020-12-15 22:16:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<NPCEvent> NPCManager::NPCEvents = {
|
2023-09-10 18:02:52 +00:00
|
|
|
NPCEvent(2466, AIState::DEAD, lordFuseStageTwo),
|
|
|
|
NPCEvent(2467, AIState::DEAD, lordFuseStageThree),
|
2020-12-15 22:16:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#pragma endregion NPCEvents
|
2021-03-16 21:06:10 +00:00
|
|
|
|
2021-03-31 19:05:49 +00:00
|
|
|
void NPCManager::queueNPCRemoval(int32_t id) {
|
|
|
|
RemovalQueue.push(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void step(CNServer *serv, time_t currTime) {
|
|
|
|
for (auto& pair : NPCs) {
|
2022-04-13 19:09:43 +00:00
|
|
|
if (pair.second->kind != EntityKind::COMBAT_NPC && pair.second->kind != EntityKind::MOB)
|
2021-03-31 19:05:49 +00:00
|
|
|
continue;
|
|
|
|
auto npc = (CombatNPC*)pair.second;
|
|
|
|
|
2022-04-11 14:26:57 +00:00
|
|
|
npc->step(currTime);
|
2021-03-31 19:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// deallocate all NPCs queued for removal
|
|
|
|
while (RemovalQueue.size() > 0) {
|
|
|
|
NPCManager::destroyNPC(RemovalQueue.front());
|
|
|
|
RemovalQueue.pop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-16 21:06:10 +00:00
|
|
|
void NPCManager::init() {
|
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_WARP_USE_NPC, npcWarpHandler);
|
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_TIME_TO_GO_WARP, npcWarpTimeMachine);
|
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_NPC_SUMMON, npcSummonHandler);
|
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_NPC_UNSUMMON, npcUnsummonHandler);
|
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_BARKER, npcBarkHandler);
|
2021-03-31 19:05:49 +00:00
|
|
|
|
2023-07-25 17:49:40 +00:00
|
|
|
REGISTER_SHARD_TIMER(step, MS_PER_COMBAT_TICK);
|
2021-03-16 21:06:10 +00:00
|
|
|
}
|