From 591a8562cc43eed69c48617b9bee8c2d64f4836b Mon Sep 17 00:00:00 2001 From: trickerer Date: Sun, 24 Nov 2024 16:59:55 +0700 Subject: [PATCH] NPCBots: Output more info in `.npcbot fix` command and apply harsher measures to perform the fix. Now only in GM mode (cherry picked from commit 7f913891901b843c78e2ee676041cf38e0e963a2) --- src/server/game/AI/NpcBots/bot_ai.cpp | 73 +++++++++++++++++++--- src/server/game/AI/NpcBots/botcommands.cpp | 4 +- 2 files changed, 68 insertions(+), 9 deletions(-) diff --git a/src/server/game/AI/NpcBots/bot_ai.cpp b/src/server/game/AI/NpcBots/bot_ai.cpp index c7865a2b169086..cd0dddc7611212 100644 --- a/src/server/game/AI/NpcBots/bot_ai.cpp +++ b/src/server/game/AI/NpcBots/bot_ai.cpp @@ -3476,20 +3476,79 @@ void bot_ai::ReceiveEmote(Player* player, uint32 emote) break; case TEXT_EMOTE_TICKLE: { - if (master != player && !player->IsGameMaster()) + if (!player->IsGameMaster()) break; std::ostringstream report; - report << "Problems:"; + report << "Bot " << me->GetName() << " (" << me->GetEntry() << "), " + << "ai owner: " << _ownerGuid << ", data owner: " << _botData->owner << ", master guid: " << master->GetGUID().ToString() << ", " + << "command states: " << _botCommandState << ", await states: " << uint32(_botAwaitState); - if (_ownerGuid && !HasBotCommandState(BOT_COMMAND_UNBIND) && (master->ToUnit() == me->ToUnit() || _ownerGuid != master->GetGUID().GetRawValue())) + report << "\nunit flags:"; + for (UnitFlags uf : EnumUtils::Iterate()) + if (me->HasUnitFlag(uf)) + report << "\n " << EnumUtils::ToString(uf).Title; + report << "\nunit states:"; + uint32 counter = 1; + for (uint32 st = UNIT_STATE_DIED; st <= UNIT_STATE_NO_ENVIRONMENT_UPD; st <<= 1u, ++counter) + if (me->HasUnitState(st)) + report << "\n UNIT_STATE_" << counter << " (" << st << ")"; + + report << "\nProblems:"; + + if (_ownerGuid) { - if (Player* real_owner = ObjectAccessor::FindPlayerByLowGUID(_ownerGuid)) + if (HasBotCommandState(BOT_COMMAND_UNBIND)) + { + report << "\n unbound, re-binding..."; + RemoveBotCommandState(BOT_COMMAND_UNBIND); + } + bool invalid_master = false; + if (master->GetGUID() == me->GetGUID()) + { + report << "\n master->GetGUID() == me->GetGUID()"; + invalid_master = true; + } + if (_ownerGuid != _botData->owner) { - report << "\n owner is in world by bot isn't owned by it"; - if (!SetBotOwner(real_owner)) - report << "\n (failed to set owner to '" << real_owner->GetName() << "'!)"; + report << "\n _ownerGuid != _botData->owner"; + invalid_master = true; } + if (master->GetGUID() == me->GetGUID()) + { + report << "\n _ownerGuid != master->GetGUID().GetRawValue()"; + invalid_master = true; + } + if (invalid_master) + { + if (Player* real_owner = ObjectAccessor::FindPlayerByLowGUID(_ownerGuid)) + { + report << "\n owner is in world by bot isn't owned by it"; + if (!SetBotOwner(real_owner)) + report << "\n (failed to set owner to '" << real_owner->GetName() << "'!)"; + } + else + { + ObjectGuid owner_guid = ObjectGuid::Create(_ownerGuid); + real_owner = ObjectAccessor::FindConnectedPlayer(owner_guid); + if (real_owner) + report << "\n owner is found (connected) but not in world!"; + else if (sCharacterCache->HasCharacterCacheEntry(owner_guid)) + report << "\n owner is found (logged out) but not in world!"; + else + report << "\n owner is not found!!!"; + } + } + } + if (!_atHome) + { + report << "\n _atHome == false"; + _atHome = true; + } + if (_evadeMode) + { + report << "\n _evadeMode == true"; + _evadeMode = false; } if ((me->HasUnitFlag(UNIT_FLAG_STUNNED) || me->HasUnitState(UNIT_STATE_STUNNED)) && !me->HasAuraType(SPELL_AURA_MOD_STUN)) diff --git a/src/server/game/AI/NpcBots/botcommands.cpp b/src/server/game/AI/NpcBots/botcommands.cpp index 99acc8d2fee1d0..6432bed0ac11a3 100644 --- a/src/server/game/AI/NpcBots/botcommands.cpp +++ b/src/server/game/AI/NpcBots/botcommands.cpp @@ -2691,9 +2691,9 @@ class script_bot_commands : public CommandScript Player* owner = !bot->IsFreeBot() ? bot->GetBotOwner() : nullptr; Player* tickler = handler->GetPlayer(); - if (tickler != owner && !tickler->IsGameMaster()) + if (!tickler->IsGameMaster()) { - handler->SendSysMessage("Must be in GM mode to fix other player's bot!"); + handler->SendSysMessage("Must be in GM mode to use this command!"); handler->SetSentErrorMessage(true); return false; }