From 0d4562a31eb75ad8cd5a0c53a0f401016bf140d4 Mon Sep 17 00:00:00 2001 From: trickerer Date: Mon, 2 Dec 2024 07:52:11 +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 --- 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 73a475b935ab9..dab4b8ce5effe 100644 --- a/src/server/game/AI/NpcBots/bot_druid_ai.cpp +++ b/src/server/game/AI/NpcBots/bot_druid_ai.cpp @@ -361,7 +361,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 216f32984e89d..f76526fe0aab0 100644 --- a/src/server/game/AI/NpcBots/botcommands.cpp +++ b/src/server/game/AI/NpcBots/botcommands.cpp @@ -2583,8 +2583,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; } @@ -2612,8 +2615,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 62ab4ff9b1ce6..728d360567516 100644 --- a/src/server/game/AI/NpcBots/botmgr.cpp +++ b/src/server/game/AI/NpcBots/botmgr.cpp @@ -1607,10 +1607,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(); @@ -1831,6 +1827,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(); @@ -2779,6 +2778,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 e3ffc6b961aa9..43ce19abad8ad 100644 --- a/src/server/game/AI/NpcBots/botmgr.h +++ b/src/server/game/AI/NpcBots/botmgr.h @@ -310,6 +310,7 @@ class TC_GAME_API BotMgr bool GetBotAllowCombatPositioning() const; void SetBotAllowCombatPositioning(bool allow); + bool GetBotsHidden() const; void SetBotsHidden(bool hidden); uint32 GetEngageDelayDPS() const;