diff --git a/src/ChatManager.cpp b/src/ChatManager.cpp index 031d036..d486fa8 100644 --- a/src/ChatManager.cpp +++ b/src/ChatManager.cpp @@ -266,6 +266,19 @@ void unsummonWCommand(std::string full, std::vector& args, CNSocket NPCManager::destroyNPC(npc->appearanceData.iNPC_ID); } +void toggleAiCommand(std::string full, std::vector& args, CNSocket* sock) { + MobManager::simulateMobs = !MobManager::simulateMobs; + + if (MobManager::simulateMobs) + return; + + // return all mobs to their spawn points + for (auto& pair : MobManager::Mobs) { + pair.second->state = MobState::RETREAT; + pair.second->target = nullptr; + } +} + void npcRotateCommand(std::string full, std::vector& args, CNSocket* sock) { PlayerView& plrv = PlayerManager::players[sock]; Player* plr = plrv.plr; @@ -324,6 +337,7 @@ void ChatManager::init() { registerCommand("npcr", 30, npcRotateCommand); registerCommand("summonW", 30, summonWCommand); registerCommand("unsummonW", 30, unsummonWCommand); + registerCommand("toggleai", 30, toggleAiCommand); registerCommand("flush", 30, flushCommand); registerCommand("level", 50, levelCommand); registerCommand("population", 100, populationCommand); diff --git a/src/MobManager.cpp b/src/MobManager.cpp index 108df39..f73e940 100644 --- a/src/MobManager.cpp +++ b/src/MobManager.cpp @@ -12,6 +12,8 @@ std::map MobManager::Mobs; std::queue MobManager::RemovalQueue; +bool MobManager::simulateMobs; + void MobManager::init() { REGISTER_SHARD_TIMER(step, 200); REGISTER_SHARD_TIMER(playerTick, 2000); @@ -22,6 +24,8 @@ void MobManager::init() { REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_COMBAT_END, combatEnd); REGISTER_SHARD_PACKET(P_CL2FE_DOT_DAMAGE_ONOFF, dotDamageOnOff); REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_ATTACK_CHARs, pcAttackChars); + + simulateMobs = settings::SIMULATEMOBS; } void MobManager::pcAttackNpcs(CNSocket *sock, CNPacketData *data) { @@ -436,7 +440,8 @@ void MobManager::step(CNServer *serv, time_t currTime) { continue; // skip mob movement and combat if disabled - if (!settings::SIMULATEMOBS && pair.second->state != MobState::DEAD) + if (!simulateMobs && pair.second->state != MobState::DEAD + && pair.second->state != MobState::RETREAT) continue; // skip attack/move if stunned or asleep diff --git a/src/MobManager.hpp b/src/MobManager.hpp index 2d446cd..19d168d 100644 --- a/src/MobManager.hpp +++ b/src/MobManager.hpp @@ -85,6 +85,7 @@ struct Mob : public BaseNPC { namespace MobManager { extern std::map Mobs; extern std::queue RemovalQueue; + extern bool simulateMobs; void init(); void step(CNServer*, time_t);