diff --git a/config.ini b/config.ini index 6260221..8568fba 100644 --- a/config.ini +++ b/config.ini @@ -41,6 +41,8 @@ xdtdata=tdata/xdt.json npcdata=tdata/NPCs.json # mob json mobdata=tdata/mobs.json +# academy mobs & npcs json +academydata=tdata/academy.json # path json pathdata=tdata/paths.json # drop json diff --git a/src/TableData.cpp b/src/TableData.cpp index 61bad6b..0a2270b 100644 --- a/src/TableData.cpp +++ b/src/TableData.cpp @@ -319,6 +319,40 @@ void TableData::init() { exit(1); } +#ifdef ACADEMY + // load Academy NPCs from academy.json + try { + std::ifstream inFile(settings::ACADEMYJSON); + nlohmann::json npcData; + + // read file into json + inFile >> npcData; + npcData = npcData["NPCs"]; + for (nlohmann::json::iterator _npc = npcData.begin(); _npc != npcData.end(); _npc++) { + auto npc = _npc.value(); + int instanceID = npc.find("iMapNum") == npc.end() ? INSTANCE_OVERWORLD : (int)npc["iMapNum"]; + + int team = NPCManager::NPCData[(int)npc["iNPCType"]]["m_iTeam"]; + + if (team == 2) { + NPCManager::NPCs[nextId] = new Mob(npc["iX"], npc["iY"], npc["iZ"], npc["iAngle"], instanceID, npc["iNPCType"], NPCManager::NPCData[(int)npc["iNPCType"]], nextId); + MobManager::Mobs[nextId] = (Mob*)NPCManager::NPCs[nextId]; + } else + NPCManager::NPCs[nextId] = new BaseNPC(npc["iX"], npc["iY"], npc["iZ"], npc["iAngle"], instanceID, npc["iNPCType"], nextId); + + NPCManager::updateNPCPosition(nextId, npc["iX"], npc["iY"], npc["iZ"], instanceID, npc["iAngle"]); + nextId++; + + if (npc["iNPCType"] == 641 || npc["iNPCType"] == 642) + NPCManager::RespawnPoints.push_back({ npc["iX"], npc["iY"], ((int)npc["iZ"]) + RESURRECT_HEIGHT, instanceID }); + } + } + catch (const std::exception& err) { + std::cerr << "[FATAL] Malformed academy.json file! Reason:" << err.what() << std::endl; + exit(1); + } +#endif + loadDrops(); loadEggs(&nextId); diff --git a/src/settings.cpp b/src/settings.cpp index 1ca0e06..7e01ba9 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -31,6 +31,7 @@ int settings::SPAWN_ANGLE = 130; std::string settings::NPCJSON = "tdata/NPCs.json"; std::string settings::XDTJSON = "tdata/xdt.json"; std::string settings::MOBJSON = "tdata/mobs.json"; +std::string settings::ACADEMYJSON = "tdata/academy.json"; std::string settings::PATHJSON = "tdata/paths.json"; std::string settings::DROPSJSON = "tdata/drops.json"; std::string settings::EGGSJSON = "tdata/eggs.json"; @@ -77,6 +78,7 @@ void settings::init() { NPCJSON = reader.Get("shard", "npcdata", NPCJSON); XDTJSON = reader.Get("shard", "xdtdata", XDTJSON); MOBJSON = reader.Get("shard", "mobdata", MOBJSON); + ACADEMYJSON = reader.Get("shard", "academydata", ACADEMYJSON); DROPSJSON = reader.Get("shard", "dropdata", DROPSJSON); EGGSJSON = reader.Get("shard", "eggdata", EGGSJSON); PATHJSON = reader.Get("shard", "pathdata", PATHJSON); diff --git a/src/settings.hpp b/src/settings.hpp index 1150eb1..9836668 100644 --- a/src/settings.hpp +++ b/src/settings.hpp @@ -19,6 +19,7 @@ namespace settings { extern std::string NPCJSON; extern std::string XDTJSON; extern std::string MOBJSON; + extern std::string ACADEMYJSON; extern std::string PATHJSON; extern std::string DROPSJSON; extern std::string EGGSJSON;