From d102fabc2f8fc6046b2975ad17c8f528a65b6d81 Mon Sep 17 00:00:00 2001 From: Kamil Date: Sun, 8 Nov 2020 09:42:49 +0100 Subject: [PATCH] set up gruntwork --- src/ChatManager.cpp | 8 ++++++++ src/NPCManager.cpp | 14 +++++++++++--- src/TableData.cpp | 29 +++++++++++++++++++++++++++++ src/TableData.hpp | 1 + 4 files changed, 49 insertions(+), 3 deletions(-) diff --git a/src/ChatManager.cpp b/src/ChatManager.cpp index fe2b37e..86f2f76 100644 --- a/src/ChatManager.cpp +++ b/src/ChatManager.cpp @@ -270,6 +270,14 @@ void unsummonWCommand(std::string full, std::vector& args, CNSocket return; } + if (TableData::RunningEggs.find(npc->appearanceData.iNPC_ID) != TableData::RunningEggs.end()) { + ChatManager::sendServerMessage(sock, "/unsummonW: removed egg with type: " + std::to_string(npc->appearanceData.iNPCType) + + ", id: " + std::to_string(npc->appearanceData.iNPC_ID)); + TableData::RunningEggs.erase(npc->appearanceData.iNPC_ID); + NPCManager::destroyNPC(npc->appearanceData.iNPC_ID); + return; + } + if (TableData::RunningMobs.find(npc->appearanceData.iNPC_ID) == TableData::RunningMobs.end()) { ChatManager::sendServerMessage(sock, "/unsummonW: Closest NPC is not a gruntwork mob."); return; diff --git a/src/NPCManager.cpp b/src/NPCManager.cpp index f299340..df52e0f 100644 --- a/src/NPCManager.cpp +++ b/src/NPCManager.cpp @@ -5,6 +5,8 @@ #include "MissionManager.hpp" #include "ChunkManager.hpp" #include "NanoManager.hpp" +#include "TableData.hpp" +#include "ChatManager.hpp" #include #define M_PI 3.14159265358979323846 @@ -26,6 +28,8 @@ std::unordered_map NPCManager::EggTypes; std::unordered_map NPCManager::Eggs; nlohmann::json NPCManager::NPCData; + + /* * Initialized at the end of TableData::init(). * This allows us to summon and kill mobs in arbitrary order without @@ -182,6 +186,7 @@ void NPCManager::updateNPCPosition(int32_t id, int X, int Y, int Z) { npc->appearanceData.iX = X; npc->appearanceData.iY = Y; npc->appearanceData.iZ = Z; + std::tuple newPos = ChunkManager::grabChunk(X, Y, npc->instanceID); // nothing to be done (but we should also update currentChunks to add/remove stale chunks) @@ -876,14 +881,17 @@ void NPCManager::eggSummon(CNSocket* sock, CNPacketData* data) { * instead we're using some math to place the egg right in front of the player */ - int addX = -500.0f * sin(plr->angle / 180.0f * M_PI); - int addY = -500.0f * cos(plr->angle / 180.0f * M_PI); + // temporarly disabled for sake of gruntwork + int addX = 0; //-500.0f * sin(plr->angle / 180.0f * M_PI); + int addY = 0; //-500.0f * cos(plr->angle / 180.0f * M_PI); - Egg* egg = new Egg (plr->x + addX, plr->y + addY, plr->z, plr->instanceID, summon->iShinyType, id, true); + Egg* egg = new Egg (plr->x + addX, plr->y + addY, plr->z, plr->instanceID, summon->iShinyType, id, false); // change last arg to true after gruntwork NPCManager::NPCs[id] = egg; NPCManager::Eggs[id] = egg; NPCManager::updateNPCPosition(id, plr->x + addX, plr->y + addY, plr->z, plr->instanceID); + // add to template + TableData::RunningEggs[id] = egg; } void NPCManager::eggPickup(CNSocket* sock, CNPacketData* data) { diff --git a/src/TableData.cpp b/src/TableData.cpp index 0f4d0d8..bc9e4e6 100644 --- a/src/TableData.cpp +++ b/src/TableData.cpp @@ -16,6 +16,7 @@ std::map> TableData::RunningSkywayRoutes; std::map TableData::RunningNPCRotations; std::map TableData::RunningNPCMapNumbers; std::map TableData::RunningMobs; +std::map TableData::RunningEggs; class TableException : public std::exception { public: @@ -615,6 +616,19 @@ void TableData::loadGruntwork(int32_t *nextId) { NPCManager::updateNPCPosition(npc->appearanceData.iNPC_ID, mob["iX"], mob["iY"], mob["iZ"]); } + auto eggs = gruntwork["eggs"]; + for (auto _egg = eggs.begin(); _egg != eggs.end(); _egg++) { + auto egg = _egg.value(); + int id = (*nextId)++; + Egg* addEgg = new Egg(egg["iX"], egg["iY"], egg["iZ"], egg["iMapNum"], egg["iType"], id, false); + NPCManager::NPCs[id] = addEgg; + NPCManager::Eggs[id] = addEgg; + NPCManager::updateNPCPosition(id, egg["iX"], egg["iY"], egg["iZ"], egg["iMapNum"]); + TableData::RunningEggs[id] = addEgg; + std::cout << id << " " << addEgg->currentChunks.size() << std::endl; + } + + std::cout << "[INFO] Loaded gruntwork.json" << std::endl; } catch (const std::exception& err) { @@ -701,5 +715,20 @@ void TableData::flush() { gruntwork["mobs"].push_back(mob); } + for (auto& pair : RunningEggs) { + nlohmann::json egg; + BaseNPC* npc = pair.second; + + if (NPCManager::Eggs.find(pair.first) == NPCManager::Eggs.end()) + continue; + egg["iX"] = npc->appearanceData.iX; + egg["iY"] = npc->appearanceData.iY; + egg["iZ"] = npc->appearanceData.iZ; + egg["iMapNum"] = MAPNUM(npc->instanceID); + egg["iType"] = npc->appearanceData.iNPCType; + + gruntwork["eggs"].push_back(egg); + } + file << gruntwork << std::endl; } diff --git a/src/TableData.hpp b/src/TableData.hpp index 5710fef..437ffbc 100644 --- a/src/TableData.hpp +++ b/src/TableData.hpp @@ -9,6 +9,7 @@ namespace TableData { extern std::map RunningNPCRotations; extern std::map RunningNPCMapNumbers; extern std::map RunningMobs; + extern std::map RunningEggs; void init(); void cleanup();