populated NPCManager

This commit is contained in:
2020-08-21 17:14:11 -05:00
parent caaffcbe3d
commit f289c72f6f
7 changed files with 25491 additions and 6 deletions

View File

@@ -4,14 +4,47 @@
#include <cmath>
#include <algorithm>
#include <list>
#include <fstream>
#include "JSON.hpp"
std::map<int32_t, BaseNPC> NPCManager::NPCs;
#define CHECKNPC(x) if (NPC.value().find(x) == NPC.value().end()) { \
std::cout << "[WARN] Malformed NPC.json file! failed to find " << x << std::endl; \
return; \
}
void NPCManager::init() {
/* BaseNPC test(settings::SPAWN_X, settings::SPAWN_Y, settings::SPAWN_Z, 727);
NPCs[test.appearanceData.iNPC_ID] = test; */
// load NPCs from NPCs.json into our NPC manager
std::ifstream inFile("NPCs.json");
nlohmann::json jsonData;
// read file into jsonData
inFile >> jsonData;
for (auto& NPC : jsonData.items()) {
std::string name = NPC.key();
// sanity checks
CHECKNPC("id")
CHECKNPC("x")
CHECKNPC("y")
CHECKNPC("z")
int x = (int)(jsonData[NPC.key()]["x"]);
int y = (int)(jsonData[NPC.key()]["y"]);
int z = (int)(jsonData[NPC.key()]["z"]);
BaseNPC tmp(x, y, z, jsonData[NPC.key()]["id"]);
NPCManager::NPCs[tmp.appearanceData.iNPC_ID] = tmp;
}
std::cout << "populated " << NPCs.size() << " NPCs" << std::endl;
}
#undef CHECKNPC
void NPCManager::updatePlayerNPCS(CNSocket* sock, PlayerView& view) {
std::list<int32_t> yesView;
std::list<int32_t> noView;