mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-05 06:50:04 +00:00
Implemented saving gruntwork results to file.
* Monkey Skyway paths are now saved in a format compatible with paths.json * flush() is called on every periodic DB save in addition to the /flush and /mss N export commands * Monkeys now accept WIP routes
This commit is contained in:
parent
ce58411ff8
commit
d4d0f388c4
@ -37,6 +37,8 @@ xdtdata=tdata/xdt.json
|
||||
mobdata=tdata/mobs.json
|
||||
# path json
|
||||
pathdata=tdata/paths.json
|
||||
# gruntwork output (this is what you submit)
|
||||
gruntwork=tdata/gruntwork.json
|
||||
|
||||
# account permission level that will be set upon character creation
|
||||
# 1 = default, will allow *all* commands
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "CNShared.hpp"
|
||||
#include "settings.hpp"
|
||||
#include "Database.hpp"
|
||||
#include "TableData.hpp" // for flush()
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
@ -56,6 +57,7 @@ void CNShardServer::periodicSaveTimer(CNServer* serv, time_t currTime) {
|
||||
Database::updatePlayer(pair.second.plr);
|
||||
}
|
||||
|
||||
TableData::flush();
|
||||
std::cout << "[INFO] Done." << std::endl;
|
||||
}
|
||||
|
||||
|
@ -99,7 +99,7 @@ void mssCommand(std::string full, std::vector<std::string>& args, CNSocket* sock
|
||||
|
||||
if (args.size() < 3) {
|
||||
ChatManager::sendServerMessage(sock, "[MSS] Too few arguments");
|
||||
ChatManager::sendServerMessage(sock, "[MSS] Usage: /mss <route> <add/remove/goto/clear/test/export> <<height>>");
|
||||
ChatManager::sendServerMessage(sock, "[MSS] Usage: /mss <route> <add/remove/goto/clear/test> <<height>>");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -167,26 +167,16 @@ void mssCommand(std::string full, std::vector<std::string>& args, CNSocket* sock
|
||||
return;
|
||||
}
|
||||
|
||||
// IMPROMPTU LERP
|
||||
int speed = 1500; // TODO: make this adjustable
|
||||
std::queue<WarpLocation> path;
|
||||
WarpLocation last = route->front(); // start pos
|
||||
PlayerManager::sendPlayerTo(sock, last.x, last.y, last.z); // send the player to the start of the path
|
||||
for (int i = 1; i < route->size(); i++) {
|
||||
WarpLocation coords = route->at(i);
|
||||
TransportManager::lerp(&path, last, coords, speed);
|
||||
path.push(coords); // add keyframe to the queue
|
||||
last = coords; // update start pos
|
||||
}
|
||||
|
||||
TransportManager::SkywayQueues[sock] = path;
|
||||
WarpLocation pulled = route->front();
|
||||
PlayerManager::sendPlayerTo(sock, pulled.x, pulled.y, pulled.z);
|
||||
TransportManager::testMssRoute(sock, route);
|
||||
return;
|
||||
}
|
||||
|
||||
// mss <route> export
|
||||
// for compatibility: mss <route> export
|
||||
if (args[2] == "export") {
|
||||
ChatManager::sendServerMessage(sock, "[MSS] export on " + std::to_string(routeNum));
|
||||
// TODO: dump route to tdata
|
||||
TableData::flush();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -195,6 +185,11 @@ void mssCommand(std::string full, std::vector<std::string>& args, CNSocket* sock
|
||||
|
||||
}
|
||||
|
||||
void flushCommand(std::string full, std::vector<std::string>& args, CNSocket* sock) {
|
||||
ChatManager::sendServerMessage(sock, "Wrote gruntwork to " + settings::GRUNTWORKJSON);
|
||||
TableData::flush();
|
||||
}
|
||||
|
||||
void ChatManager::init() {
|
||||
REGISTER_SHARD_PACKET(P_CL2FE_REQ_SEND_FREECHAT_MESSAGE, chatHandler);
|
||||
REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_AVATAR_EMOTES_CHAT, emoteHandler);
|
||||
@ -204,6 +199,7 @@ void ChatManager::init() {
|
||||
registerCommand("access", 100, accessCommand);
|
||||
// TODO: add help command
|
||||
registerCommand("mss", 30, mssCommand);
|
||||
registerCommand("flush", 30, flushCommand);
|
||||
registerCommand("level", 50, levelCommand);
|
||||
registerCommand("population", 100, populationCommand);
|
||||
}
|
||||
|
@ -196,6 +196,8 @@ void TableData::init() {
|
||||
std::cerr << "[WARN] Malformed mobs.json file! Reason:" << err.what() << std::endl;
|
||||
}
|
||||
|
||||
loadGruntwork();
|
||||
|
||||
NPCManager::nextId = nextId;
|
||||
}
|
||||
|
||||
@ -290,7 +292,6 @@ void TableData::constructPathSkyway(nlohmann::json::iterator _pathData) {
|
||||
}
|
||||
|
||||
void TableData::constructPathSlider(nlohmann::json points, int rotations, int sliderID) {
|
||||
|
||||
std::queue<WarpLocation> route;
|
||||
std::rotate(points.begin(), points.begin() + rotations, points.end()); // rotate points
|
||||
nlohmann::json::iterator _point = points.begin(); // iterator
|
||||
@ -336,3 +337,64 @@ void TableData::constructPathNPC(nlohmann::json::iterator _pathData) {
|
||||
}
|
||||
TransportManager::NPCQueues[pathData["iNPCID"]] = points;
|
||||
}
|
||||
|
||||
// load gruntwork output; if it exists
|
||||
void TableData::loadGruntwork() {
|
||||
try {
|
||||
std::ifstream inFile(settings::GRUNTWORKJSON);
|
||||
nlohmann::json gruntwork;
|
||||
|
||||
// skip if there's no gruntwork to load
|
||||
if (inFile.fail())
|
||||
return;
|
||||
|
||||
inFile >> gruntwork;
|
||||
|
||||
// skyway paths
|
||||
auto skyway = gruntwork["skyway"];
|
||||
for (auto _route = skyway.begin(); _route != skyway.end(); _route++) {
|
||||
auto route = _route.value();
|
||||
std::vector<WarpLocation> points;
|
||||
|
||||
for (auto _point = route["points"].begin(); _point != route["points"].end(); _point++) {
|
||||
auto point = _point.value();
|
||||
points.push_back(WarpLocation{point["x"], point["y"], point["z"]});
|
||||
}
|
||||
|
||||
RunningSkywayRoutes[(int)route["iRouteID"]] = points;
|
||||
}
|
||||
|
||||
std::cout << "[INFO] Loaded gruntwork.json" << std::endl;
|
||||
}
|
||||
catch (const std::exception& err) {
|
||||
std::cerr << "[WARN] Malformed gruntwork.json file! Reason:" << err.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
// write gruntwork output to file
|
||||
void TableData::flush() {
|
||||
std::ofstream file(settings::GRUNTWORKJSON);
|
||||
nlohmann::json gruntwork;
|
||||
|
||||
for (auto& pair : RunningSkywayRoutes) {
|
||||
nlohmann::json route;
|
||||
|
||||
route["iRouteID"] = (int)pair.first;
|
||||
route["iMonkeySpeed"] = 1500; // TODO
|
||||
|
||||
std::cout << "serializing mss route " << (int)pair.first << std::endl;
|
||||
for (WarpLocation& point : pair.second) {
|
||||
nlohmann::json tmp;
|
||||
|
||||
tmp["x"] = point.x;
|
||||
tmp["y"] = point.y;
|
||||
tmp["z"] = point.z;
|
||||
|
||||
route["points"].push_back(tmp);
|
||||
}
|
||||
|
||||
gruntwork["skyway"].push_back(route);
|
||||
}
|
||||
|
||||
file << gruntwork << std::endl;
|
||||
}
|
||||
|
@ -9,6 +9,8 @@ namespace TableData {
|
||||
|
||||
void init();
|
||||
void cleanup();
|
||||
void loadGruntwork();
|
||||
void flush();
|
||||
|
||||
int getItemType(int);
|
||||
void loadPaths(int*);
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "PlayerManager.hpp"
|
||||
#include "NanoManager.hpp"
|
||||
#include "TransportManager.hpp"
|
||||
#include "TableData.hpp"
|
||||
|
||||
#include <unordered_map>
|
||||
#include <cmath>
|
||||
@ -157,6 +158,12 @@ void TransportManager::transportWarpHandler(CNSocket* sock, CNPacketData* data)
|
||||
NanoManager::summonNano(sock, -1); // make sure that no nano is active during the ride
|
||||
SkywayQueues[sock] = SkywayPaths[route.mssRouteNum]; // set socket point queue to route
|
||||
break;
|
||||
} else if (TableData::RunningSkywayRoutes.find(route.mssRouteNum) != TableData::RunningSkywayRoutes.end()) {
|
||||
std::vector<WarpLocation>* _route = &TableData::RunningSkywayRoutes[route.mssRouteNum];
|
||||
|
||||
NanoManager::summonNano(sock, -1);
|
||||
testMssRoute(sock, _route);
|
||||
break;
|
||||
}
|
||||
|
||||
// refund and send alert packet
|
||||
@ -184,6 +191,21 @@ void TransportManager::transportWarpHandler(CNSocket* sock, CNPacketData* data)
|
||||
sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_WARP_USE_TRANSPORTATION_SUCC, sizeof(sP_FE2CL_REP_PC_WARP_USE_TRANSPORTATION_SUCC));
|
||||
}
|
||||
|
||||
void TransportManager::testMssRoute(CNSocket *sock, std::vector<WarpLocation>* route) {
|
||||
int speed = 1500; // TODO: make this adjustable
|
||||
std::queue<WarpLocation> path;
|
||||
WarpLocation last = route->front(); // start pos
|
||||
|
||||
for (int i = 1; i < route->size(); i++) {
|
||||
WarpLocation coords = route->at(i);
|
||||
TransportManager::lerp(&path, last, coords, speed);
|
||||
path.push(coords); // add keyframe to the queue
|
||||
last = coords; // update start pos
|
||||
}
|
||||
|
||||
SkywayQueues[sock] = path;
|
||||
}
|
||||
|
||||
void TransportManager::tickTransportationSystem(CNServer* serv, time_t currTime) {
|
||||
stepNPCPathing();
|
||||
stepSkywaySystem();
|
||||
|
@ -30,6 +30,8 @@ namespace TransportManager {
|
||||
void transportRegisterLocationHandler(CNSocket*, CNPacketData*);
|
||||
void transportWarpHandler(CNSocket*, CNPacketData*);
|
||||
|
||||
void testMssRoute(CNSocket *sock, std::vector<WarpLocation>* route);
|
||||
|
||||
void tickTransportationSystem(CNServer*, time_t);
|
||||
void stepNPCPathing();
|
||||
void stepSkywaySystem();
|
||||
|
@ -24,6 +24,7 @@ std::string settings::NPCJSON = "tdata/NPCs.json";
|
||||
std::string settings::XDTJSON = "tdata/xdt.json";
|
||||
std::string settings::MOBJSON = "tdata/mobs.json";
|
||||
std::string settings::PATHJSON = "tdata/paths.json";
|
||||
std::string settings::GRUNTWORKJSON = "tdata/gruntwork.json";
|
||||
std::string settings::MOTDSTRING = "Welcome to OpenFusion!";
|
||||
int settings::ACCLEVEL = 1;
|
||||
|
||||
@ -56,6 +57,7 @@ void settings::init() {
|
||||
XDTJSON = reader.Get("shard", "xdtdata", XDTJSON);
|
||||
MOBJSON = reader.Get("shard", "mobdata", MOBJSON);
|
||||
PATHJSON = reader.Get("shard", "pathdata", PATHJSON);
|
||||
GRUNTWORKJSON = reader.Get("shard", "gruntwork", GRUNTWORKJSON);
|
||||
MOTDSTRING = reader.Get("shard", "motd", MOTDSTRING);
|
||||
ACCLEVEL = reader.GetInteger("shard", "accountlevel", ACCLEVEL);
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ namespace settings {
|
||||
extern std::string XDTJSON;
|
||||
extern std::string MOBJSON;
|
||||
extern std::string PATHJSON;
|
||||
extern std::string GRUNTWORKJSON;
|
||||
|
||||
void init();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user