diff options
author | jackpoz <giacomopoz@gmail.com> | 2019-09-13 21:06:28 +0200 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2021-12-18 22:19:03 +0100 |
commit | f012d4b7fcf0376de75f09c2b59509247fd133cb (patch) | |
tree | 90d3e084814f5844ee13ccd142c7cf55ba876905 /src | |
parent | 1e77bfe3ca45fe0626c217cb67e8ae6c1e1ffc40 (diff) |
Core/Movement: Fix LoS issue of NPCs chasing targets
Add Line of Sight checks to ChaseMovementGenerator::Update(), fixing to ChaseMovementGenerator not reaching a point with valid LoS to the target.
Fix re-implements 8927a042536d4671e94ad901e9209efcf78ffa2c after 2a84562dc85516f432bb1e5de9add23c28b26ce4 partially removed it.
Fix #23724
(cherry picked from commit 215a6cee24896f2def2a5af390c089ac1d947e65)
Diffstat (limited to 'src')
-rw-r--r-- | src/server/game/Movement/MovementGenerators/ChaseMovementGenerator.cpp | 6 | ||||
-rw-r--r-- | src/server/game/Movement/PathGenerator.cpp | 10 |
2 files changed, 15 insertions, 1 deletions
diff --git a/src/server/game/Movement/MovementGenerators/ChaseMovementGenerator.cpp b/src/server/game/Movement/MovementGenerators/ChaseMovementGenerator.cpp index 0e22919e155..9cd58ee0f82 100644 --- a/src/server/game/Movement/MovementGenerators/ChaseMovementGenerator.cpp +++ b/src/server/game/Movement/MovementGenerators/ChaseMovementGenerator.cpp @@ -44,7 +44,11 @@ static bool PositionOkay(Unit* owner, Unit* target, Optional<float> minDistance, return false; if (maxDistance && distSq > square(*maxDistance)) return false; - return !angle || angle->IsAngleOkay(target->GetRelativeAngle(owner)); + if (angle && !angle->IsAngleOkay(target->GetRelativeAngle(owner))) + return false; + if (!owner->IsWithinLOSInMap(target)) + return false; + return true; } static void DoMovementInform(Unit* owner, Unit* target) diff --git a/src/server/game/Movement/PathGenerator.cpp b/src/server/game/Movement/PathGenerator.cpp index 33e6f786c75..f179579b5e3 100644 --- a/src/server/game/Movement/PathGenerator.cpp +++ b/src/server/game/Movement/PathGenerator.cpp @@ -927,6 +927,7 @@ void PathGenerator::ShortenPathUntilDist(G3D::Vector3 const& target, float dist) return; size_t i = _pathPoints.size()-1; + float x, y, z, collisionHeight = _sourceUnit->GetCollisionHeight(); // find the first i s.t.: // - _pathPoints[i] is still too close // - _pathPoints[i-1] is too far away @@ -937,6 +938,15 @@ void PathGenerator::ShortenPathUntilDist(G3D::Vector3 const& target, float dist) if ((_pathPoints[i-1] - target).squaredLength() >= distSq) break; // bingo! + // check if the shortened path is still in LoS with the target + _sourceUnit->GetHitSpherePointFor({ _pathPoints[i - 1].x, _pathPoints[i - 1].y, _pathPoints[i - 1].z + collisionHeight }, x, y, z); + if (!_sourceUnit->GetMap()->isInLineOfSight(_sourceUnit->GetPhaseShift(), x, y, z, _pathPoints[i - 1].x, _pathPoints[i - 1].y, _pathPoints[i - 1].z + collisionHeight, LINEOFSIGHT_ALL_CHECKS, VMAP::ModelIgnoreFlags::Nothing)) + { + // whenver we find a point that is not in LoS anymore, simply use last valid path + _pathPoints.resize(i + 1); + return; + } + if (!--i) { // no point found that fulfills the condition |