switched to dumped XDT & moved to a submodule

This commit is contained in:
CPunch 2020-09-09 12:06:22 -05:00
parent 45a33758a5
commit eb1ad6bb37
13 changed files with 108 additions and 84 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "tdata"]
path = tdata
url = https://github.com/OpenFusionProject/tabledata.git

View File

@ -45,6 +45,7 @@ CXXSRC=\
src/PlayerManager.cpp\
src/settings.cpp\
src/TransportManager.cpp\
src/TableData.cpp\
# headers (for timestamp purposes)
CHDR=\
@ -79,6 +80,7 @@ CXXHDR=\
src/PlayerManager.hpp\
src/settings.hpp\
src/TransportManager.hpp\
src/TableData.hpp\
COBJ=$(CSRC:.c=.o)
CXXOBJ=$(CXXSRC:.cpp=.o)

View File

@ -25,11 +25,11 @@ npcdistance=16000
# little message players see when they enter the game
motd=Welcome to OpenFusion!
# NPC json data
npcdata=data/NPCs.json
# warp target json data
warpdata=data/warps.json
npcdata=tdata/NPCs.json
# xdt json data
xdtdata=tdata/xdt.json
# mob json
mobdata=data/mobs.json
mobdata=tdata/mobs.json
# is everyone a GM?
gm=true

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -14,80 +14,6 @@ std::map<int32_t, WarpLocation> NPCManager::Warps;
std::vector<WarpLocation> NPCManager::RespawnPoints;
void NPCManager::init() {
// load NPCs from NPCs.json into our NPC manager
// Temporary fix, IDs will be pulled from json later
int i = 0;
try {
std::ifstream inFile(settings::NPCJSON);
nlohmann::json npcData;
// read file into json
inFile >> npcData;
for (nlohmann::json::iterator npc = npcData.begin(); npc != npcData.end(); npc++) {
BaseNPC tmp(npc.value()["x"], npc.value()["y"], npc.value()["z"], npc.value()["id"]);
// Temporary fix, IDs will be pulled from json later
tmp.appearanceData.iNPC_ID = i;
i++;
NPCs[tmp.appearanceData.iNPC_ID] = tmp;
if (npc.value()["id"] == 641 || npc.value()["id"] == 642)
RespawnPoints.push_back({ npc.value()["x"], npc.value()["y"], ((int)npc.value()["z"]) + RESURRECT_HEIGHT });
}
}
catch (const std::exception& err) {
std::cerr << "[WARN] Malformed NPCs.json file! Reason:" << err.what() << std::endl;
}
// load temporary mob dump
try {
std::ifstream inFile(settings::MOBJSON); // not in settings, since it's temp
nlohmann::json npcData;
// read file into json
inFile >> npcData;
for (nlohmann::json::iterator npc = npcData.begin(); npc != npcData.end(); npc++) {
BaseNPC tmp(npc.value()["iX"], npc.value()["iY"], npc.value()["iZ"], npc.value()["iNPCType"],
npc.value()["iHP"], npc.value()["iConditionBitFlag"], npc.value()["iAngle"], npc.value()["iBarkerType"]);
// Temporary fix, IDs will be pulled from json later
tmp.appearanceData.iNPC_ID = i;
i++;
NPCs[tmp.appearanceData.iNPC_ID] = tmp;
}
std::cout << "[INFO] populated " << NPCs.size() << " NPCs" << std::endl;
}
catch (const std::exception& err) {
std::cerr << "[WARN] Malformed mobs.json file! Reason:" << err.what() << std::endl;
}
try {
std::ifstream infile(settings::WARPJSON);
nlohmann::json warpData;
// read file into json
infile >> warpData;
for (nlohmann::json::iterator warp = warpData.begin(); warp != warpData.end(); warp++) {
WarpLocation warpLoc = { warp.value()["m_iToX"], warp.value()["m_iToY"], warp.value()["m_iToZ"] };
int warpID = atoi(warp.key().c_str());
Warps[warpID] = warpLoc;
}
std::cout << "[INFO] populated " << Warps.size() << " Warps" << std::endl;
}
catch (const std::exception& err) {
std::cerr << "[WARN] Malformed warps.json file! Reason:" << err.what() << std::endl;
}
REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_WARP_USE_NPC, npcWarpHandler);
REGISTER_SHARD_PACKET(P_CL2FE_REQ_NPC_SUMMON, npcSummonHandler);
REGISTER_SHARD_PACKET(P_CL2FE_REQ_BARKER, npcBarkHandler);

87
src/TableData.cpp Normal file
View File

@ -0,0 +1,87 @@
#include "TableData.hpp"
#include "NPCManager.hpp"
#include "settings.hpp"
#include "contrib/JSON.hpp"
#include <fstream>
void TabledataManager::init() {
int i = 0;
// load NPCs from NPC.json
try {
std::ifstream inFile(settings::NPCJSON);
nlohmann::json npcData;
// read file into json
inFile >> npcData;
for (nlohmann::json::iterator npc = npcData.begin(); npc != npcData.end(); npc++) {
BaseNPC tmp(npc.value()["x"], npc.value()["y"], npc.value()["z"], npc.value()["id"]);
// Temporary fix, IDs will be pulled from json later
tmp.appearanceData.iNPC_ID = i;
i++;
NPCManager::NPCs[tmp.appearanceData.iNPC_ID] = tmp;
if (npc.value()["id"] == 641 || npc.value()["id"] == 642)
NPCManager::RespawnPoints.push_back({ npc.value()["x"], npc.value()["y"], ((int)npc.value()["z"]) + RESURRECT_HEIGHT });
}
}
catch (const std::exception& err) {
std::cerr << "[WARN] Malformed NPCs.json file! Reason:" << err.what() << std::endl;
}
// load temporary mob dump
try {
std::ifstream inFile(settings::MOBJSON); // not in settings, since it's temp
nlohmann::json npcData;
// read file into json
inFile >> npcData;
for (nlohmann::json::iterator npc = npcData.begin(); npc != npcData.end(); npc++) {
BaseNPC tmp(npc.value()["iX"], npc.value()["iY"], npc.value()["iZ"], npc.value()["iNPCType"],
npc.value()["iHP"], npc.value()["iConditionBitFlag"], npc.value()["iAngle"], npc.value()["iBarkerType"]);
// Temporary fix, IDs will be pulled from json later
tmp.appearanceData.iNPC_ID = i;
i++;
NPCManager::NPCs[tmp.appearanceData.iNPC_ID] = tmp;
}
std::cout << "[INFO] populated " << NPCManager::NPCs.size() << " NPCs" << std::endl;
}
catch (const std::exception& err) {
std::cerr << "[WARN] Malformed mobs.json file! Reason:" << err.what() << std::endl;
}
// load everything else from xdttable
try {
std::ifstream infile(settings::XDTJSON);
nlohmann::json xdtData;
// read file into json
infile >> xdtData;
// load warps from m_pInstanceTable.m_pWarpData
nlohmann::json warpData = xdtData["m_pInstanceTable"]["m_pWarpData"];
for (nlohmann::json::iterator warp = warpData.begin(); warp != warpData.end(); warp++) {
WarpLocation warpLoc = { warp.value()["m_iToX"], warp.value()["m_iToY"], warp.value()["m_iToZ"] };
int warpID = warp.value()["m_iWarpNumber"];
NPCManager::Warps[warpID] = warpLoc;
}
std::cout << "[INFO] populated " << NPCManager::Warps.size() << " Warps" << std::endl;
}
catch (const std::exception& err) {
std::cerr << "[WARN] Malformed xdt.json file! Reason:" << err.what() << std::endl;
}
}

6
src/TableData.hpp Normal file
View File

@ -0,0 +1,6 @@
#pragma once
#include <map>
namespace TabledataManager {
void init();
}

View File

@ -9,6 +9,7 @@
#include "NPCManager.hpp"
#include "TransportManager.hpp"
#include "Database.hpp"
#include "TableData.hpp"
#include "settings.hpp"
@ -70,6 +71,7 @@ int main() {
settings::init();
std::cout << "[INFO] Protocol version: " << PROTOCOL_VERSION << std::endl;
std::cout << "[INFO] Intializing Packet Managers..." << std::endl;
TabledataManager::init();
PlayerManager::init();
ChatManager::init();
CombatManager::init();

View File

@ -20,7 +20,7 @@ int settings::SPAWN_Y = 268451;
int settings::SPAWN_Z = -4210;
std::string settings::GMPASS = "pass";
std::string settings::NPCJSON = "data/NPCs.json";
std::string settings::WARPJSON = "data/warps.json";
std::string settings::XDTJSON = "data/xdt.json";
std::string settings::MOBJSON = "data/mobs.json";
std::string settings::MOTDSTRING = "Welcome to OpenFusion!";
bool settings::GM = false;
@ -50,7 +50,7 @@ void settings::init() {
SPAWN_Z = reader.GetInteger("shard", "spawnz", SPAWN_Z);
GMPASS = reader.Get("login", "pass", GMPASS);
NPCJSON = reader.Get("shard", "npcdata", NPCJSON);
WARPJSON = reader.Get("shard", "warpdata", WARPJSON);
XDTJSON = reader.Get("shard", "xdtdata", XDTJSON);
MOBJSON = reader.Get("shard", "mobdata", MOBJSON);
MOTDSTRING = reader.Get("shard", "motd", MOTDSTRING);
GM = reader.GetBoolean("shard", "gm", GM);

View File

@ -14,7 +14,7 @@ namespace settings {
extern int SPAWN_Z;
extern std::string MOTDSTRING;
extern std::string NPCJSON;
extern std::string WARPJSON;
extern std::string XDTJSON;
extern std::string MOBJSON;
extern std::string GMPASS;
extern bool GM;

1
tdata Submodule

@ -0,0 +1 @@
Subproject commit 19d9902331c94174785323d39daccc2cd23c5872