From 51a0d643b6c7004086055dc199a05b2f0301f4bb Mon Sep 17 00:00:00 2001 From: kadeshar Date: Sat, 11 Apr 2026 00:17:13 +0200 Subject: [PATCH] Crashfix for wait for attack (#2303) ## Pull Request Description Fixed crash related with setting height for new best safe spot. ## How to Test the Changes 1. Create raid group 2. Go to Molten Core 3. Add wait for attack strategy to bot and set time 4. Attack mob 5. If bot/bots will wait set time and server dont crash then is ok ## Impact Assessment - Does this change increase per-bot/per-tick processing or risk scaling poorly with thousands of bots? - - [x] No, not at all - - [ ] Minimal impact (**explain below**) - - [ ] Moderate impact (**explain below**) - Does this change modify default bot behavior? - - [x] No - - [ ] Yes (**explain why**) - Does this change add new decision branches or increase maintenance complexity? - - [x] No - - [ ] Yes (**explain below**) ## AI Assistance Was AI assistance used while working on this change? - - [ ] No - - [x] Yes (**explain below**) To find existing method which safetly get height for specific point. ## Final Checklist - - [x] Stability is not compromised. - - [x] Performance impact is understood, tested, and acceptable. - - [x] Added logic complexity is justified and explained. - - [x] Any new bot dialogue lines are translated. - - [x] Documentation updated if needed (Conf comments, WiKi commands). ## Notes for Reviewers --- src/Ai/Base/Actions/WaitForAttackAction.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Ai/Base/Actions/WaitForAttackAction.cpp b/src/Ai/Base/Actions/WaitForAttackAction.cpp index 4fb8918c6..737e891da 100644 --- a/src/Ai/Base/Actions/WaitForAttackAction.cpp +++ b/src/Ai/Base/Actions/WaitForAttackAction.cpp @@ -44,7 +44,12 @@ WorldPosition GetBestPoint(AiObjectContext* context, Player* bot, Unit* target, float z = targetPosition.GetPositionZ() + 1.0f; WorldPosition point(targetPosition.GetMapId(), x, y, z); - point.setZ(point.getHeight()); + + float groundZ = bot->GetMapHeight(x, y, z); + if (groundZ == INVALID_HEIGHT || groundZ == VMAP_INVALID_HEIGHT_VALUE) + continue; + + point.setZ(groundZ); // Check line of sight to target if (!target->IsWithinLOS(point.GetPositionX(), point.GetPositionY(), @@ -88,8 +93,11 @@ bool WaitForAttackKeepSafeDistanceAction::Execute(Event /*event*/) { Unit* target = AI_VALUE(Unit*, "current target"); + if (!target) + return false; + // If our target is moving towards a stationary unit, use that unit as anchor - if (target && !target->IsStopped()) + if (!target->IsStopped()) { ObjectGuid targetGuid = target->GetTarget(); if (targetGuid) @@ -100,7 +108,7 @@ bool WaitForAttackKeepSafeDistanceAction::Execute(Event /*event*/) } } - if (target && target->IsAlive()) + if (target->IsAlive()) { float safeDistance = std::max( target->GetCombatReach() + ATTACK_DISTANCE,