Add NPC rotation command /npcr

This commit is contained in:
Gent 2020-10-06 17:59:33 -04:00
parent 5009fe1994
commit 1b68b5e2e2

View File

@ -160,7 +160,7 @@ void mssCommand(std::string full, std::vector<std::string>& args, CNSocket* sock
return; return;
} }
// mss <route> reload // mss <route> test
if (args[2] == "test") { if (args[2] == "test") {
if (route->empty()) { if (route->empty()) {
ChatManager::sendServerMessage(sock, "[MSS] Route " + std::to_string(routeNum) + " is empty"); ChatManager::sendServerMessage(sock, "[MSS] Route " + std::to_string(routeNum) + " is empty");
@ -175,7 +175,7 @@ void mssCommand(std::string full, std::vector<std::string>& args, CNSocket* sock
// for compatibility: mss <route> export // for compatibility: mss <route> export
if (args[2] == "export") { if (args[2] == "export") {
ChatManager::sendServerMessage(sock, "[MSS] export on " + std::to_string(routeNum)); ChatManager::sendServerMessage(sock, "Wrote gruntwork to " + settings::GRUNTWORKJSON);
TableData::flush(); TableData::flush();
return; return;
} }
@ -185,6 +185,44 @@ void mssCommand(std::string full, std::vector<std::string>& args, CNSocket* sock
} }
void npcRotateCommand(std::string full, std::vector<std::string>& args, CNSocket* sock) {
if (args.size() < 2) {
ChatManager::sendServerMessage(sock, "[NPCR] Too few arguments");
ChatManager::sendServerMessage(sock, "[NPCR] Usage: /npcr <NPC ID>");
return;
}
// Validate NPC ID number
char* npcIDC;
int npcID = std::strtol(args[1].c_str(), &npcIDC, 10);
if (*npcIDC) {
// not an integer
ChatManager::sendServerMessage(sock, "[NPCR] Invalid NPC ID '" + args[1] + "'");
return;
}
// Ensure NPC exists
if (NPCManager::NPCs.find(npcID) == NPCManager::NPCs.end()) {
// doesn't exist
ChatManager::sendServerMessage(sock, "[NPCR] Can't find NPC with ID " + args[1]);
return;
}
Player* plr = PlayerManager::getPlayer(sock);
BaseNPC* npc = NPCManager::NPCs[npcID];
int angle = plr->angle + 180;
// normalize angle
while (angle >= 360)
angle -= 360;
while (angle < 0)
angle += 360;
NPCManager::updateNPCPosition(npcID, npc->appearanceData.iX, npc->appearanceData.iY, npc->appearanceData.iZ, angle);
TableData::RunningNPCRotations[npcID] = angle;
PlayerManager::sendPlayerTo(sock, plr->x, plr->y, plr->z);
ChatManager::sendServerMessage(sock, "[NPCR] Successfully set angle to " + std::to_string(angle) + " for NPC " + args[1]);
}
void flushCommand(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); ChatManager::sendServerMessage(sock, "Wrote gruntwork to " + settings::GRUNTWORKJSON);
TableData::flush(); TableData::flush();
@ -199,6 +237,7 @@ void ChatManager::init() {
registerCommand("access", 100, accessCommand); registerCommand("access", 100, accessCommand);
// TODO: add help command // TODO: add help command
registerCommand("mss", 30, mssCommand); registerCommand("mss", 30, mssCommand);
registerCommand("npcr", 30, npcRotateCommand);
registerCommand("flush", 30, flushCommand); registerCommand("flush", 30, flushCommand);
registerCommand("level", 50, levelCommand); registerCommand("level", 50, levelCommand);
registerCommand("population", 100, populationCommand); registerCommand("population", 100, populationCommand);