mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2025-11-16 23:10:09 +00:00
populated NPCManager
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user