L2Bot2.0/Client/Domain/AI/State/MoveToTargetState.cs
2024-08-18 17:32:29 +02:00

36 lines
1.1 KiB
C#

using Client.Domain.AI.Combat;
using Client.Domain.Entities;
using Client.Domain.Service;
using Client.Infrastructure.Service;
namespace Client.Domain.AI.State
{
public class MoveToTargetState : BaseState
{
public MoveToTargetState(AI ai) : base(ai)
{
}
protected override void DoExecute(WorldHandler worldHandler, Config config, AsyncPathMoverInterface asyncPathMover, Hero hero)
{
var target = hero.Target;
if (target == null)
{
target = hero;
}
var distance = hero.Transform.Position.HorizontalDistance(target.Transform.Position);
if (asyncPathMover.IsLocked)
{
return;
}
var hasLineOfSight = asyncPathMover.Pathfinder.HasLineOfSight(hero.Transform.Position, target.Transform.Position);
if (distance >= Helper.GetAttackDistanceByConfig(worldHandler, config, hero, target) || !hasLineOfSight)
{
asyncPathMover.MoveAsync(target.Transform.Position);
}
}
}
}