mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-16 07:30:42 +01:00
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-implements8927a04253after2a84562dc8partially removed it. Fix #23724 (cherry picked from commit215a6cee24)
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user