set up gruntwork

This commit is contained in:
Kamil 2020-11-08 09:42:49 +01:00 committed by Gent
parent 6d4afd0c6a
commit d102fabc2f
4 changed files with 49 additions and 3 deletions

View File

@ -270,6 +270,14 @@ void unsummonWCommand(std::string full, std::vector<std::string>& args, CNSocket
return; 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()) { if (TableData::RunningMobs.find(npc->appearanceData.iNPC_ID) == TableData::RunningMobs.end()) {
ChatManager::sendServerMessage(sock, "/unsummonW: Closest NPC is not a gruntwork mob."); ChatManager::sendServerMessage(sock, "/unsummonW: Closest NPC is not a gruntwork mob.");
return; return;

View File

@ -5,6 +5,8 @@
#include "MissionManager.hpp" #include "MissionManager.hpp"
#include "ChunkManager.hpp" #include "ChunkManager.hpp"
#include "NanoManager.hpp" #include "NanoManager.hpp"
#include "TableData.hpp"
#include "ChatManager.hpp"
#include <cmath> #include <cmath>
#define M_PI 3.14159265358979323846 #define M_PI 3.14159265358979323846
@ -26,6 +28,8 @@ std::unordered_map<int, EggType> NPCManager::EggTypes;
std::unordered_map<int, Egg*> NPCManager::Eggs; std::unordered_map<int, Egg*> NPCManager::Eggs;
nlohmann::json NPCManager::NPCData; nlohmann::json NPCManager::NPCData;
/* /*
* Initialized at the end of TableData::init(). * Initialized at the end of TableData::init().
* This allows us to summon and kill mobs in arbitrary order without * 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.iX = X;
npc->appearanceData.iY = Y; npc->appearanceData.iY = Y;
npc->appearanceData.iZ = Z; npc->appearanceData.iZ = Z;
std::tuple<int, int, uint64_t> newPos = ChunkManager::grabChunk(X, Y, npc->instanceID); std::tuple<int, int, uint64_t> newPos = ChunkManager::grabChunk(X, Y, npc->instanceID);
// nothing to be done (but we should also update currentChunks to add/remove stale chunks) // 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 * 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); // temporarly disabled for sake of gruntwork
int addY = -500.0f * cos(plr->angle / 180.0f * M_PI); 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::NPCs[id] = egg;
NPCManager::Eggs[id] = egg; NPCManager::Eggs[id] = egg;
NPCManager::updateNPCPosition(id, plr->x + addX, plr->y + addY, plr->z, plr->instanceID); 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) { void NPCManager::eggPickup(CNSocket* sock, CNPacketData* data) {

View File

@ -16,6 +16,7 @@ std::map<int32_t, std::vector<WarpLocation>> TableData::RunningSkywayRoutes;
std::map<int32_t, int> TableData::RunningNPCRotations; std::map<int32_t, int> TableData::RunningNPCRotations;
std::map<int32_t, int> TableData::RunningNPCMapNumbers; std::map<int32_t, int> TableData::RunningNPCMapNumbers;
std::map<int32_t, BaseNPC*> TableData::RunningMobs; std::map<int32_t, BaseNPC*> TableData::RunningMobs;
std::map<int32_t, BaseNPC*> TableData::RunningEggs;
class TableException : public std::exception { class TableException : public std::exception {
public: public:
@ -615,6 +616,19 @@ void TableData::loadGruntwork(int32_t *nextId) {
NPCManager::updateNPCPosition(npc->appearanceData.iNPC_ID, mob["iX"], mob["iY"], mob["iZ"]); 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; std::cout << "[INFO] Loaded gruntwork.json" << std::endl;
} }
catch (const std::exception& err) { catch (const std::exception& err) {
@ -701,5 +715,20 @@ void TableData::flush() {
gruntwork["mobs"].push_back(mob); 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; file << gruntwork << std::endl;
} }

View File

@ -9,6 +9,7 @@ namespace TableData {
extern std::map<int32_t, int> RunningNPCRotations; extern std::map<int32_t, int> RunningNPCRotations;
extern std::map<int32_t, int> RunningNPCMapNumbers; extern std::map<int32_t, int> RunningNPCMapNumbers;
extern std::map<int32_t, BaseNPC*> RunningMobs; extern std::map<int32_t, BaseNPC*> RunningMobs;
extern std::map<int32_t, BaseNPC*> RunningEggs;
void init(); void init();
void cleanup(); void cleanup();