diff --git a/src/ChatManager.cpp b/src/ChatManager.cpp index 6262324..24ce155 100644 --- a/src/ChatManager.cpp +++ b/src/ChatManager.cpp @@ -263,8 +263,7 @@ void summonWCommand(std::string full, std::vector& args, CNSocket* void unsummonWCommand(std::string full, std::vector& args, CNSocket* sock) { Player* plr = PlayerManager::getPlayer(sock); - std::vector chunks; // TODO - BaseNPC* npc = NPCManager::getNearestNPC(chunks, plr->x, plr->y, plr->z); + BaseNPC* npc = NPCManager::getNearestNPC(plr->viewableChunks, plr->x, plr->y, plr->z); if (npc == nullptr) { ChatManager::sendServerMessage(sock, "/unsummonW: No NPCs found nearby"); @@ -286,11 +285,19 @@ void unsummonWCommand(std::string full, std::vector& args, CNSocket int leadId = ((Mob*)npc)->groupLeader; if (leadId != 0) { + if (MobManager::Mobs.find(leadId) == MobManager::Mobs.end()) { + std::cout << "[WARN] unsummonW: leader not found!" << std::endl; + } Mob* leadNpc = MobManager::Mobs[leadId]; for (int i = 0; i < 4; i++) { if (leadNpc->groupMember[i] == 0) break; + if (MobManager::Mobs.find(leadNpc->groupMember[i]) == MobManager::Mobs.end()) { + std::cout << "[WARN] unsommonW: leader can't find a group member!" << std::endl; + continue; + } + TableData::RunningMobs.erase(leadNpc->groupMember[i]); NPCManager::destroyNPC(leadNpc->groupMember[i]); } @@ -336,8 +343,7 @@ void toggleAiCommand(std::string full, std::vector& args, CNSocket* void npcRotateCommand(std::string full, std::vector& args, CNSocket* sock) { Player* plr = PlayerManager::getPlayer(sock); - std::vector chunks; // TODO - BaseNPC* npc = NPCManager::getNearestNPC(chunks, plr->x, plr->y, plr->z); + BaseNPC* npc = NPCManager::getNearestNPC(plr->viewableChunks, plr->x, plr->y, plr->z); if (npc == nullptr) { ChatManager::sendServerMessage(sock, "[NPCR] No NPCs found nearby"); @@ -407,8 +413,7 @@ void npcInstanceCommand(std::string full, std::vector& args, CNSock return; } - std::vector chunks; // TODO - BaseNPC* npc = NPCManager::getNearestNPC(chunks, plr->x, plr->y, plr->z); + BaseNPC* npc = NPCManager::getNearestNPC(plr->viewableChunks, plr->x, plr->y, plr->z); if (npc == nullptr) { ChatManager::sendServerMessage(sock, "[NPCI] No NPCs found nearby"); @@ -562,8 +567,10 @@ void summonGroupCommand(std::string full, std::vector& args, CNSock } // permission & sanity check - if (plr == nullptr || type >= 3314 || type2 >= 3314 || count > 5) + if (type >= 3314 || type2 >= 3314 || count > 5) { + ChatManager::sendServerMessage(sock, "Invalid parameters; double check types and count"); return; + } Mob* leadNpc = nullptr; @@ -571,7 +578,6 @@ void summonGroupCommand(std::string full, std::vector& args, CNSock int team = NPCManager::NPCData[type]["m_iTeam"]; assert(NPCManager::nextId < INT32_MAX); - #define EXTRA_HEIGHT 200 BaseNPC *npc = nullptr; int id = NPCManager::nextId++; @@ -613,7 +619,7 @@ void summonGroupCommand(std::string full, std::vector& args, CNSock npc->appearanceData.iAngle = (plr->angle + 180) % 360; NPCManager::NPCs[npc->appearanceData.iNPC_ID] = npc; - NPCManager::updateNPCPosition(npc->appearanceData.iNPC_ID, x, y, z); + NPCManager::updateNPCPosition(npc->appearanceData.iNPC_ID, x, y, z, plr->instanceID, npc->appearanceData.iAngle); // if we're in a lair, we need to spawn the NPC in both the private instance and the template if (PLAYERID(plr->instanceID) != 0) { @@ -640,7 +646,7 @@ void summonGroupCommand(std::string full, std::vector& args, CNSock npc->appearanceData.iAngle = (plr->angle + 180) % 360; NPCManager::NPCs[npc->appearanceData.iNPC_ID] = npc; - NPCManager::updateNPCPosition(npc->appearanceData.iNPC_ID, x, y, z); + NPCManager::updateNPCPosition(npc->appearanceData.iNPC_ID, x, y, z, plr->instanceID, npc->appearanceData.iAngle); } ChatManager::sendServerMessage(sock, "/summonGroup(W): placed mob with type: " + std::to_string(type) + diff --git a/src/NPCManager.cpp b/src/NPCManager.cpp index 4a11783..3358dfd 100644 --- a/src/NPCManager.cpp +++ b/src/NPCManager.cpp @@ -550,10 +550,10 @@ void NPCManager::handleWarp(CNSocket* sock, int32_t warpId) { /* * Helper function to get NPC closest to coordinates in specified chunks */ -BaseNPC* NPCManager::getNearestNPC(std::vector chunks, int X, int Y, int Z) { +BaseNPC* NPCManager::getNearestNPC(std::set* chunks, int X, int Y, int Z) { BaseNPC* npc = nullptr; int lastDist = INT_MAX; - for (auto c = chunks.begin(); c != chunks.end(); c++) { // haha get it + for (auto c = chunks->begin(); c != chunks->end(); c++) { // haha get it Chunk* chunk = *c; for (auto _npc = chunk->NPCs.begin(); _npc != chunk->NPCs.end(); _npc++) { BaseNPC* npcTemp = NPCs[*_npc]; diff --git a/src/NPCManager.hpp b/src/NPCManager.hpp index 521cf58..7aa22ed 100644 --- a/src/NPCManager.hpp +++ b/src/NPCManager.hpp @@ -68,7 +68,7 @@ namespace NPCManager { void handleWarp(CNSocket* sock, int32_t warpId); - BaseNPC* getNearestNPC(std::vector chunks, int X, int Y, int Z); + BaseNPC* getNearestNPC(std::set* chunks, int X, int Y, int Z); /// returns -1 on fail int eggBuffPlayer(CNSocket* sock, int skillId, int duration);