mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-12-23 03:40:05 +00:00
populated NPCManager
This commit is contained in:
parent
caaffcbe3d
commit
f289c72f6f
@ -15,6 +15,8 @@ ip=192.168.1.183
|
||||
view=20000
|
||||
# little message players see when they enter the game
|
||||
motd=Welcome to OpenFusion!
|
||||
# NPC json data
|
||||
npcdata=NPCs.json
|
||||
|
||||
# spawn coordinates (Z is height)
|
||||
# the supplied defaults are at City Hall
|
||||
|
25447
src/JSON.hpp
Normal file
25447
src/JSON.hpp
Normal file
File diff suppressed because it is too large
Load Diff
@ -19,7 +19,7 @@ public:
|
||||
appearanceData.iBarkerType = 0;
|
||||
|
||||
// hopefully no collisions happen :eyes:
|
||||
appearanceData.iNPC_ID = (int32_t)getTime();
|
||||
appearanceData.iNPC_ID = (int32_t)rand();
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -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;
|
||||
|
@ -15,7 +15,7 @@ int settings::SPAWN_X = 179213;
|
||||
int settings::SPAWN_Y = 268451;
|
||||
int settings::SPAWN_Z = -4210;
|
||||
std::string settings::GMPASS = "pass";
|
||||
|
||||
std::string settings::NPCJSON = "NPCs.json";
|
||||
std::string settings::MOTDSTRING = "Welcome to OpenFusion!";
|
||||
|
||||
void settings::init() {
|
||||
@ -38,7 +38,8 @@ void settings::init() {
|
||||
SPAWN_X = reader.GetInteger("shard", "spawnx", SPAWN_X);
|
||||
SPAWN_Y = reader.GetInteger("shard", "spawny", SPAWN_Y);
|
||||
SPAWN_Z = reader.GetInteger("shard", "spawnz", SPAWN_Z);
|
||||
MOTDSTRING = reader.Get("shard", "motd", "Welcome to OpenFusion!");
|
||||
GMPASS = reader.Get("login", "pass", "pass");
|
||||
GMPASS = reader.Get("login", "pass", GMPASS);
|
||||
NPCJSON = reader.Get("shard", "npcdata", NPCJSON);
|
||||
MOTDSTRING = reader.Get("shard", "motd", MOTDSTRING);
|
||||
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ namespace settings {
|
||||
extern int SPAWN_Y;
|
||||
extern int SPAWN_Z;
|
||||
extern std::string MOTDSTRING;
|
||||
extern std::string NPCJSON;
|
||||
extern std::string GMPASS;
|
||||
|
||||
void init();
|
||||
|
Loading…
Reference in New Issue
Block a user