Core/Movement: Add more LOS checks

Port From (https://github.com/TrinityCore/TrinityCore/commit/1635a342284145cb4572840f2f3fdc29e4498bc3)
This commit is contained in:
hondacrx
2022-01-05 23:19:46 -05:00
parent 5e0fd36ada
commit c32ccf7e4e
3 changed files with 21 additions and 5 deletions
@@ -21,9 +21,9 @@ using System;
namespace Game.Movement
{
public class ConfusedGenerator<T> : MovementGeneratorMedium<T> where T : Unit
public class ConfusedMovementGenerator<T> : MovementGeneratorMedium<T> where T : Unit
{
public ConfusedGenerator()
public ConfusedMovementGenerator()
{
_timer = new TimeTracker();
_reference = new();
@@ -83,6 +83,14 @@ namespace Game.Movement
float angle = RandomHelper.FRand(0.0f, 1.0f) * MathF.PI * 2.0f;
owner.MovePositionToFirstCollision(destination, distance, angle);
// Check if the destination is in LOS
if (!owner.IsWithinLOS(destination.GetPositionX(), destination.GetPositionY(), destination.GetPositionZ()))
{
// Retry later on
_timer.Reset(200);
return true;
}
if (_path == null)
{
_path = new PathGenerator(owner);
@@ -21,12 +21,12 @@ using System;
namespace Game.Movement
{
public class FleeingGenerator<T> : MovementGeneratorMedium<T> where T : Unit
public class FleeingMovementGenerator<T> : MovementGeneratorMedium<T> where T : Unit
{
public const float MIN_QUIET_DISTANCE = 28.0f;
public const float MAX_QUIET_DISTANCE = 43.0f;
public FleeingGenerator(ObjectGuid fright)
public FleeingMovementGenerator(ObjectGuid fright)
{
_fleeTargetGUID = fright;
_timer = new TimeTracker();
@@ -208,7 +208,7 @@ namespace Game.Movement
TimeTracker _timer;
}
public class TimedFleeingGenerator : FleeingGenerator<Creature>
public class TimedFleeingGenerator : FleeingMovementGenerator<Creature>
{
public TimedFleeingGenerator(ObjectGuid fright, uint time) : base(fright)
{
@@ -144,6 +144,14 @@ namespace Game.Movement
float angle = RandomHelper.FRand(0.0f, 1.0f) * MathF.PI * 2.0f;
owner.MovePositionToFirstCollision(position, distance, angle);
// Check if the destination is in LOS
if (!owner.IsWithinLOS(position.GetPositionX(), position.GetPositionY(), position.GetPositionZ()))
{
// Retry later on
_timer.Reset(200);
return;
}
uint resetTimer = RandomHelper.randChance(50) ? RandomHelper.URand(5000, 10000) : RandomHelper.URand(1000, 2000);
if (_path == null)