From 862376f5343f79ca08732559c2aa17f3c8dfec5c Mon Sep 17 00:00:00 2001 From: trickerer Date: Mon, 18 Nov 2024 09:22:38 +0700 Subject: [PATCH] NPCBot: Do not reset master on recall. Try to check bot ownership in `.npcbot fix` command (cherry picked from commit 40a60fbac6931be0e7e8881b855bcb329900c59f) --- src/server/game/AI/NpcBots/bot_ai.cpp | 12 +++++++++++- src/server/game/AI/NpcBots/botcommon.h | 3 ++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/server/game/AI/NpcBots/bot_ai.cpp b/src/server/game/AI/NpcBots/bot_ai.cpp index cb4e1f3754b1a2..67416fd8d46f86 100644 --- a/src/server/game/AI/NpcBots/bot_ai.cpp +++ b/src/server/game/AI/NpcBots/bot_ai.cpp @@ -593,7 +593,8 @@ void bot_ai::ResetBotAI(uint8 resetType) _botAwaitState = BOT_AWAIT_NONE; _reviveTimer = 0; - master = reinterpret_cast(me); + if (resetType & BOTAI_RESET_MASK_RESET_MASTER) + master = reinterpret_cast(me); if (resetType & BOTAI_RESET_MASK_ABANDON_MASTER) _ownerGuid = 0; if (resetType == BOTAI_RESET_INIT || resetType == BOTAI_RESET_LOGOUT) @@ -3480,6 +3481,15 @@ void bot_ai::ReceiveEmote(Player* player, uint32 emote) std::ostringstream report; report << "Problems:"; + if (_ownerGuid && !HasBotCommandState(BOT_COMMAND_UNBIND) && (master->ToUnit() == me->ToUnit() || _ownerGuid != master->GetGUID().GetRawValue())) + { + 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() << "'!)"; + } + } 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/botcommon.h b/src/server/game/AI/NpcBots/botcommon.h index cc8aef13757ced..4536321f9927c0 100644 --- a/src/server/game/AI/NpcBots/botcommon.h +++ b/src/server/game/AI/NpcBots/botcommon.h @@ -548,7 +548,8 @@ enum BotAIResetType BOTAI_RESET_LOGOUT = 0x08, BOTAI_RESET_FORCERECALL = 0x10, - BOTAI_RESET_MASK_ABANDON_MASTER = (BOTAI_RESET_INIT | BOTAI_RESET_DISMISS) + BOTAI_RESET_MASK_ABANDON_MASTER = (BOTAI_RESET_INIT | BOTAI_RESET_DISMISS), + BOTAI_RESET_MASK_RESET_MASTER = (BOTAI_RESET_INIT | BOTAI_RESET_DISMISS | BOTAI_RESET_UNBIND | BOTAI_RESET_LOGOUT) }; enum BotMovementType