mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-22 05:20:05 +00:00
Clean up /path command handler
This commit is contained in:
parent
2d7aa3c536
commit
32daa68458
@ -58,6 +58,18 @@ bool CustomCommands::runCmd(std::string full, CNSocket* sock) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
static void updatePathMarkers(CNSocket* sock) {
|
||||
Player* plr = PlayerManager::getPlayer(sock);
|
||||
if (TableData::RunningNPCPaths.find(plr->iID) != TableData::RunningNPCPaths.end()) {
|
||||
for (BaseNPC* marker : TableData::RunningNPCPaths[plr->iID].second)
|
||||
marker->enterIntoViewOf(sock);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
static void helpCommand(std::string full, std::vector<std::string>& args, CNSocket* sock) {
|
||||
Chat::sendServerMessage(sock, "Commands available to you:");
|
||||
Player *plr = PlayerManager::getPlayer(sock);
|
||||
@ -948,7 +960,8 @@ static void pathCommand(std::string full, std::vector<std::string>& args, CNSock
|
||||
if (args.size() < 2) {
|
||||
Chat::sendServerMessage(sock, "[PATH] Too few arguments");
|
||||
Chat::sendServerMessage(sock, "[PATH] Usage: /path <start/kf/undo/here/test/cancel/end>");
|
||||
goto update;
|
||||
updatePathMarkers(sock);
|
||||
return;
|
||||
}
|
||||
|
||||
// /path start
|
||||
@ -957,14 +970,15 @@ static void pathCommand(std::string full, std::vector<std::string>& args, CNSock
|
||||
if (TableData::RunningNPCPaths.find(plr->iID) != TableData::RunningNPCPaths.end()) {
|
||||
Chat::sendServerMessage(sock, "[PATH] An NPC is already following you");
|
||||
Chat::sendServerMessage(sock, "[PATH] Run '/path end' first, if you're done");
|
||||
goto update;
|
||||
updatePathMarkers(sock);
|
||||
return;
|
||||
}
|
||||
|
||||
// find nearest NPC
|
||||
BaseNPC* npc = NPCManager::getNearestNPC(&plr->viewableChunks, plr->x, plr->y, plr->z);
|
||||
if (npc == nullptr) {
|
||||
Chat::sendServerMessage(sock, "[PATH] No NPCs found nearby");
|
||||
goto update;
|
||||
return;
|
||||
}
|
||||
|
||||
// add first point at NPC's current location
|
||||
@ -974,13 +988,15 @@ static void pathCommand(std::string full, std::vector<std::string>& args, CNSock
|
||||
// map from player
|
||||
TableData::RunningNPCPaths[plr->iID] = std::make_pair(npc, pathPoints);
|
||||
Chat::sendServerMessage(sock, "[PATH] NPC " + std::to_string(npc->appearanceData.iNPC_ID) + " is now following you");
|
||||
goto update;
|
||||
} else {
|
||||
updatePathMarkers(sock);
|
||||
return;
|
||||
}
|
||||
|
||||
// make sure the player has a follower
|
||||
if (TableData::RunningNPCPaths.find(plr->iID) == TableData::RunningNPCPaths.end()) {
|
||||
Chat::sendServerMessage(sock, "[PATH] No NPC is currently following you");
|
||||
Chat::sendServerMessage(sock, "[PATH] Run '/path start' near an NPC first");
|
||||
goto update;
|
||||
return;
|
||||
}
|
||||
|
||||
std::pair<BaseNPC*, std::vector<BaseNPC*>>* entry = &TableData::RunningNPCPaths[plr->iID];
|
||||
@ -991,7 +1007,8 @@ static void pathCommand(std::string full, std::vector<std::string>& args, CNSock
|
||||
BaseNPC* marker = new BaseNPC(npc->x, npc->y, npc->z, 0, plr->instanceID, 1386, NPCManager::nextId--);
|
||||
entry->second.push_back(marker);
|
||||
Chat::sendServerMessage(sock, "[PATH] Added keyframe");
|
||||
goto update;
|
||||
updatePathMarkers(sock);
|
||||
return;
|
||||
}
|
||||
|
||||
// /path here
|
||||
@ -1002,14 +1019,14 @@ static void pathCommand(std::string full, std::vector<std::string>& args, CNSock
|
||||
npc->disappearFromViewOf(sock);
|
||||
npc->enterIntoViewOf(sock);
|
||||
Chat::sendServerMessage(sock, "[PATH] Come here");
|
||||
goto update;
|
||||
return;
|
||||
}
|
||||
|
||||
// /path undo
|
||||
if (args[1] == "undo") {
|
||||
if (entry->second.size() == 1) {
|
||||
Chat::sendServerMessage(sock, "[PATH] Nothing to undo");
|
||||
goto update;
|
||||
return;
|
||||
}
|
||||
|
||||
BaseNPC* marker = entry->second.back();
|
||||
@ -1018,7 +1035,8 @@ static void pathCommand(std::string full, std::vector<std::string>& args, CNSock
|
||||
|
||||
entry->second.pop_back(); // remove from the vector
|
||||
Chat::sendServerMessage(sock, "[PATH] Undid last keyframe");
|
||||
goto update;
|
||||
updatePathMarkers(sock);
|
||||
return;
|
||||
}
|
||||
|
||||
// /path test
|
||||
@ -1030,7 +1048,7 @@ static void pathCommand(std::string full, std::vector<std::string>& args, CNSock
|
||||
int speedArg = std::strtol(args[2].c_str(), &buf, 10);
|
||||
if (*buf) {
|
||||
Chat::sendServerMessage(sock, "[PATH] Invalid speed " + args[2]);
|
||||
goto update;
|
||||
return;
|
||||
}
|
||||
speed = speedArg;
|
||||
}
|
||||
@ -1057,7 +1075,7 @@ static void pathCommand(std::string full, std::vector<std::string>& args, CNSock
|
||||
entry->second.pop_back(); // remove temp end point
|
||||
|
||||
Chat::sendServerMessage(sock, "[PATH] Testing NPC path");
|
||||
goto update;
|
||||
return;
|
||||
}
|
||||
|
||||
// /path cancel
|
||||
@ -1076,7 +1094,7 @@ static void pathCommand(std::string full, std::vector<std::string>& args, CNSock
|
||||
// unmap
|
||||
TableData::RunningNPCPaths.erase(plr->iID);
|
||||
Chat::sendServerMessage(sock, "[PATH] NPC " + std::to_string(npc->appearanceData.iNPC_ID) + " is no longer following you");
|
||||
goto update;
|
||||
return;
|
||||
}
|
||||
|
||||
// /path end
|
||||
@ -1084,7 +1102,7 @@ static void pathCommand(std::string full, std::vector<std::string>& args, CNSock
|
||||
if (args.size() < 2) {
|
||||
Chat::sendServerMessage(sock, "[PATH] Too few arguments");
|
||||
Chat::sendServerMessage(sock, "[PATH] Usage: /path end [speed] [a/r]");
|
||||
goto update;
|
||||
return;
|
||||
}
|
||||
|
||||
int speed = NPC_DEFAULT_SPEED;
|
||||
@ -1094,7 +1112,7 @@ static void pathCommand(std::string full, std::vector<std::string>& args, CNSock
|
||||
int speedArg = std::strtol(args[2].c_str(), &buf, 10);
|
||||
if (*buf) {
|
||||
Chat::sendServerMessage(sock, "[PATH] Invalid speed " + args[2]);
|
||||
goto update;
|
||||
return;
|
||||
}
|
||||
speed = speedArg;
|
||||
}
|
||||
@ -1162,18 +1180,11 @@ static void pathCommand(std::string full, std::vector<std::string>& args, CNSock
|
||||
|
||||
TableData::flush();
|
||||
Chat::sendServerMessage(sock, "[PATH] Path saved to gruntwork");
|
||||
goto update;
|
||||
return;
|
||||
}
|
||||
|
||||
// /path ???
|
||||
Chat::sendServerMessage(sock, "[PATH] Unknown argument '" + args[1] + "'");
|
||||
}
|
||||
|
||||
update:
|
||||
if (TableData::RunningNPCPaths.find(plr->iID) != TableData::RunningNPCPaths.end()) {
|
||||
for (BaseNPC* marker : TableData::RunningNPCPaths[plr->iID].second)
|
||||
marker->enterIntoViewOf(sock);
|
||||
}
|
||||
}
|
||||
|
||||
static void registerCommand(std::string cmd, int requiredLevel, CommandHandler handlr, std::string help) {
|
||||
|
Loading…
Reference in New Issue
Block a user