mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-22 13:30:06 +00:00
Make /npcr use the nearest NPC
This commit is contained in:
parent
42fc018097
commit
5ed332d836
@ -4,9 +4,11 @@
|
|||||||
#include "PlayerManager.hpp"
|
#include "PlayerManager.hpp"
|
||||||
#include "TransportManager.hpp"
|
#include "TransportManager.hpp"
|
||||||
#include "TableData.hpp"
|
#include "TableData.hpp"
|
||||||
|
#include "limits.h"
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
std::map<std::string, ChatCommand> ChatManager::commands;
|
std::map<std::string, ChatCommand> ChatManager::commands;
|
||||||
|
|
||||||
@ -186,41 +188,40 @@ void mssCommand(std::string full, std::vector<std::string>& args, CNSocket* sock
|
|||||||
}
|
}
|
||||||
|
|
||||||
void npcRotateCommand(std::string full, std::vector<std::string>& args, CNSocket* sock) {
|
void npcRotateCommand(std::string full, std::vector<std::string>& args, CNSocket* sock) {
|
||||||
|
|
||||||
|
PlayerView& plrv = PlayerManager::players[sock];
|
||||||
|
Player* plr = plrv.plr;
|
||||||
|
|
||||||
if (args.size() < 2) {
|
BaseNPC* npc = nullptr;
|
||||||
ChatManager::sendServerMessage(sock, "[NPCR] Too few arguments");
|
int lastDist = INT_MAX;
|
||||||
ChatManager::sendServerMessage(sock, "[NPCR] Usage: /npcr <NPC ID>");
|
for (auto c = plrv.currentChunks.begin(); c != plrv.currentChunks.end(); c++) { // haha get it
|
||||||
|
Chunk* chunk = *c;
|
||||||
|
for (auto _npc = chunk->NPCs.begin(); _npc != chunk->NPCs.end(); _npc++) {
|
||||||
|
BaseNPC* npcTemp = NPCManager::NPCs[*_npc];
|
||||||
|
int distXY = std::hypot(plr->x - npcTemp->appearanceData.iX, plr->y - npcTemp->appearanceData.iY);
|
||||||
|
int dist = std::hypot(distXY, plr->z - npcTemp->appearanceData.iZ);
|
||||||
|
if (dist < lastDist) {
|
||||||
|
npc = npcTemp;
|
||||||
|
lastDist = dist;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (npc == nullptr) {
|
||||||
|
ChatManager::sendServerMessage(sock, "[NPCR] No NPCs found nearby");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate NPC ID number
|
int angle = (plr->angle + 180) % 360;
|
||||||
char* npcIDC;
|
NPCManager::updateNPCPosition(npc->appearanceData.iNPC_ID, npc->appearanceData.iX, npc->appearanceData.iY, npc->appearanceData.iZ, angle);
|
||||||
int npcID = std::strtol(args[1].c_str(), &npcIDC, 10);
|
TableData::RunningNPCRotations[npc->appearanceData.iNPC_ID] = angle;
|
||||||
if (*npcIDC) {
|
|
||||||
// not an integer
|
// update rotation clientside
|
||||||
ChatManager::sendServerMessage(sock, "[NPCR] Invalid NPC ID '" + args[1] + "'");
|
INITSTRUCT(sP_FE2CL_NPC_ENTER, pkt);
|
||||||
return;
|
pkt.NPCAppearanceData = npc->appearanceData;
|
||||||
}
|
sock->sendPacket((void*)&pkt, P_FE2CL_NPC_ENTER, sizeof(sP_FE2CL_NPC_ENTER));
|
||||||
|
|
||||||
// Ensure NPC exists
|
ChatManager::sendServerMessage(sock, "[NPCR] Successfully set angle to " + std::to_string(angle) + " for NPC " + std::to_string(npc->appearanceData.iNPC_ID));
|
||||||
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 refreshCommand(std::string full, std::vector<std::string>& args, CNSocket* sock) {
|
void refreshCommand(std::string full, std::vector<std::string>& args, CNSocket* sock) {
|
||||||
|
Loading…
Reference in New Issue
Block a user