From cde40813c0fae7ce8541a8a680db1959cce75ab6 Mon Sep 17 00:00:00 2001 From: trickerer Date: Mon, 2 Dec 2024 08:45:37 +0700 Subject: [PATCH] NPCBots: Fix bots teleportation to invalid coords on leaving a dungeon. Do not display hide/unhide messages if bots are already hidden/unhidden. Druid: Do not use Tranquility out of combat (cherry picked from commit 0d4562a31eb75ad8cd5a0c53a0f401016bf140d4) --- src/server/game/AI/NpcBots/bot_druid_ai.cpp | 2 +- src/server/game/AI/NpcBots/botcommands.cpp | 14 ++++++++++---- src/server/game/AI/NpcBots/botmgr.cpp | 11 +++++++---- src/server/game/AI/NpcBots/botmgr.h | 1 + 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/server/game/AI/NpcBots/bot_druid_ai.cpp b/src/server/game/AI/NpcBots/bot_druid_ai.cpp index 7ba7cc4695bd58..e0ea6768f84a87 100644 --- a/src/server/game/AI/NpcBots/bot_druid_ai.cpp +++ b/src/server/game/AI/NpcBots/bot_druid_ai.cpp @@ -360,7 +360,7 @@ class druid_bot : public CreatureScript if (Rand() > 30 + 50 * (me->GetMap()->IsRaid())) return false; if (!gPlayer->GetGroup()) return false; - bool tranq = IsSpellReady(TRANQUILITY_1, diff, false); + bool tranq = IsSpellReady(TRANQUILITY_1, diff, false) && master->GetBotMgr()->IsPartyInCombat(false); bool growt = IsSpellReady(WILD_GROWTH_1, diff, false) && !HasRole(BOT_ROLE_DPS); if (!tranq && !growt) return false; diff --git a/src/server/game/AI/NpcBots/botcommands.cpp b/src/server/game/AI/NpcBots/botcommands.cpp index 6432bed0ac11a3..079f42d9383c6f 100644 --- a/src/server/game/AI/NpcBots/botcommands.cpp +++ b/src/server/game/AI/NpcBots/botcommands.cpp @@ -2609,8 +2609,11 @@ class script_bot_commands : public CommandScript return false; } - owner->GetBotMgr()->SetBotsHidden(true); - handler->SendSysMessage("Bots hidden"); + if (!owner->GetBotMgr()->GetBotsHidden()) + { + owner->GetBotMgr()->SetBotsHidden(true); + handler->SendSysMessage("Bots hidden"); + } return true; } @@ -2638,8 +2641,11 @@ class script_bot_commands : public CommandScript return false; } - owner->GetBotMgr()->SetBotsHidden(false); - handler->SendSysMessage("Bots unhidden"); + if (owner->GetBotMgr()->GetBotsHidden()) + { + owner->GetBotMgr()->SetBotsHidden(false); + handler->SendSysMessage("Bots unhidden"); + } return true; } diff --git a/src/server/game/AI/NpcBots/botmgr.cpp b/src/server/game/AI/NpcBots/botmgr.cpp index 97961b20ebf695..69a462ef542b10 100644 --- a/src/server/game/AI/NpcBots/botmgr.cpp +++ b/src/server/game/AI/NpcBots/botmgr.cpp @@ -1608,10 +1608,6 @@ void BotMgr::_teleportBot(Creature* bot, Map* newMap, float x, float y, float z, BotLogger::Log(NPCBOT_LOG_TELEPORT_START, bot, bot->IsInGrid(), bot->IsWandererBot(), botai->CanAppearInWorld(), newMap->GetId(), bool(reset)); - if (Map* bmap = bot->FindMap()) - if (bmap->GetEntry()->Instanceable() && bot->IsInGrid()) - bmap->RemoveFromMap(bot, false); - BotMgr::AddDelayedTeleportCallback([bot, botai, newMap, x, y, z, ori, quick, reset]() { if (bot->GetVehicle()) bot->ExitVehicle(); @@ -1832,6 +1828,9 @@ void BotMgr::RemoveBot(ObjectGuid guid, uint8 removetype) Creature* bot = itr->second; CleanupsBeforeBotDelete(guid, removetype); + if (_owner->GetSession()->PlayerLogout() && bot->IsInGrid() && bot->FindMap() && bot->FindMap()->GetEntry()->Instanceable()) + bot->FindMap()->RemoveFromMap(bot, false); + ////remove control bar //if (GetNpcBotsCount() <= 1 && !_owner->GetPetGUID() && _owner->m_Controlled.empty()) // _owner->SendRemoveControlBar(); @@ -2780,6 +2779,10 @@ void BotMgr::SetBotAllowCombatPositioning(bool allow) allow ? _data->RemoveFlag(NPCBOT_MGR_FLAG_DISABLE_COMBAT_POSITIONING) : _data->SetFlag(NPCBOT_MGR_FLAG_DISABLE_COMBAT_POSITIONING); } +bool BotMgr::GetBotsHidden() const +{ + return _data->HasFlag(NPCBOT_MGR_FLAG_HIDE_BOTS); +} void BotMgr::SetBotsHidden(bool hidden) { hidden ? _data->SetFlag(NPCBOT_MGR_FLAG_HIDE_BOTS) : _data->RemoveFlag(NPCBOT_MGR_FLAG_HIDE_BOTS); diff --git a/src/server/game/AI/NpcBots/botmgr.h b/src/server/game/AI/NpcBots/botmgr.h index 496f5cb449a20b..d2f8e4c70bf21a 100644 --- a/src/server/game/AI/NpcBots/botmgr.h +++ b/src/server/game/AI/NpcBots/botmgr.h @@ -311,6 +311,7 @@ class AC_GAME_API BotMgr bool GetBotAllowCombatPositioning() const; void SetBotAllowCombatPositioning(bool allow); + bool GetBotsHidden() const; void SetBotsHidden(bool hidden); uint32 GetEngageDelayDPS() const;