From 55eecba11b7206b87ad2835ba212b83c4e1a70f9 Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Tue, 4 Jun 2024 09:47:40 +0800 Subject: [PATCH] [Crash fix] Target IsInWorld check --- src/PlayerbotAI.cpp | 4 ++++ src/RandomPlayerbotMgr.cpp | 4 ++-- src/strategy/actions/AttackAction.cpp | 4 ++++ src/strategy/values/AoeHealValues.cpp | 5 ++++- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/PlayerbotAI.cpp b/src/PlayerbotAI.cpp index 5038832e..e7d9552b 100644 --- a/src/PlayerbotAI.cpp +++ b/src/PlayerbotAI.cpp @@ -3090,6 +3090,10 @@ bool PlayerbotAI::IsInterruptableSpellCasting(Unit* target, std::string const sp bool PlayerbotAI::HasAuraToDispel(Unit* target, uint32 dispelType) { + if (!target->IsInWorld()) + { + return false; + } bool isFriend = bot->IsFriendlyTo(target); for (uint32 type = SPELL_AURA_NONE; type < TOTAL_AURAS; ++type) { diff --git a/src/RandomPlayerbotMgr.cpp b/src/RandomPlayerbotMgr.cpp index a1b10558..80c4a1bc 100644 --- a/src/RandomPlayerbotMgr.cpp +++ b/src/RandomPlayerbotMgr.cpp @@ -1196,8 +1196,8 @@ void RandomPlayerbotMgr::RandomTeleport(Player* bot, std::vector& z = 0.05f + ground; - LOG_INFO("playerbots", "Random teleporting bot (level {}) {} to {} {},{},{} ({}/{} locations)", - bot->GetLevel(), bot->GetName().c_str(), zone->area_name[0], x, y, z, attemtps, tlocs.size()); + LOG_INFO("playerbots", "Random teleporting bot {} (level {}) to {} {},{},{} ({}/{} locations)", + bot->GetName().c_str(), bot->GetLevel(), zone->area_name[0], x, y, z, attemtps, tlocs.size()); if (hearth) { diff --git a/src/strategy/actions/AttackAction.cpp b/src/strategy/actions/AttackAction.cpp index 58ebd02f..978eb1d9 100644 --- a/src/strategy/actions/AttackAction.cpp +++ b/src/strategy/actions/AttackAction.cpp @@ -63,6 +63,10 @@ bool AttackAction::Attack(Unit* target, bool with_pet /*true*/) return false; } + if (!target->IsInWorld()) + { + return false; + } std::ostringstream msg; msg << target->GetName(); diff --git a/src/strategy/values/AoeHealValues.cpp b/src/strategy/values/AoeHealValues.cpp index 9fc1d242..20a388a1 100644 --- a/src/strategy/values/AoeHealValues.cpp +++ b/src/strategy/values/AoeHealValues.cpp @@ -29,7 +29,10 @@ uint8 AoeHealValue::Calculate() Player* player = ObjectAccessor::FindPlayer(itr->guid); if (!player || !player->IsAlive()) continue; - + + if (player->GetDistance(bot) >= sPlayerbotAIConfig->sightDistance) + continue; + float percent = (static_cast (player->GetHealth()) / player->GetMaxHealth()) * 100; if (percent <= range) ++count;