feat: adjust route to target

This commit is contained in:
Иванов Иван 2024-08-21 22:40:23 +02:00
parent 914f6ba20f
commit d0baa5c21a
3 changed files with 28 additions and 11 deletions

View File

@ -99,11 +99,6 @@ namespace Client.Domain.AI.Combat
return false;
}
if (!pathMover.Pathfinder.HasLineOfSight(worldHandler.Hero.Transform.Position, worldHandler.Hero.Target.Transform.Position))
{
return false;
}
if (config.Combat.SpoilIsPriority) {
var spoil = worldHandler.GetSkillById(config.Combat.SpoilSkillId);
if (spoil != null && !spoil.IsReadyToUse) {
@ -112,7 +107,8 @@ namespace Client.Domain.AI.Combat
}
var distance = worldHandler.Hero.Transform.Position.HorizontalDistance(worldHandler.Hero.Target.Transform.Position);
return distance < Helper.GetAttackDistanceByConfig(worldHandler, config, worldHandler.Hero, worldHandler.Hero.Target);
return distance < Helper.GetAttackDistanceByConfig(worldHandler, config, worldHandler.Hero, worldHandler.Hero.Target)
&& pathMover.Pathfinder.HasLineOfSight(worldHandler.Hero.Transform.Position, worldHandler.Hero.Target.Transform.Position);
}),
new(new List<BaseState.Type>{BaseState.Type.Attack}, BaseState.Type.Pickup, (state) => {
if (worldHandler.Hero == null) {

View File

@ -1,7 +1,8 @@
using Client.Domain.AI.Combat;
using Client.Domain.Entities;
using Client.Domain.Service;
using Client.Infrastructure.Service;
using Client.Domain.ValueObjects;
using System;
namespace Client.Domain.AI.State
{
@ -19,17 +20,32 @@ namespace Client.Domain.AI.State
target = hero;
}
var distance = hero.Transform.Position.HorizontalDistance(target.Transform.Position);
var distanceToPrevPosition = targetPosition != null ? targetPosition.HorizontalDistance(target.Transform.Position) : 0;
var routeNeedsToBeAdjusted = MathF.Abs(distanceToPrevPosition) > config.Combat.AttackDistanceMili;
if (routeNeedsToBeAdjusted)
{
asyncPathMover.Unlock();
}
if (asyncPathMover.IsLocked)
{
return;
}
var hasLineOfSight = asyncPathMover.Pathfinder.HasLineOfSight(hero.Transform.Position, target.Transform.Position);
if (distance >= Helper.GetAttackDistanceByConfig(worldHandler, config, hero, target) || !hasLineOfSight)
var distance = hero.Transform.Position.HorizontalDistance(target.Transform.Position);
if (routeNeedsToBeAdjusted || distance >= Helper.GetAttackDistanceByConfig(worldHandler, config, hero, target) || !asyncPathMover.Pathfinder.HasLineOfSight(hero.Transform.Position, target.Transform.Position))
{
targetPosition = target.Transform.Position.Clone() as Vector3;
asyncPathMover.MoveAsync(target.Transform.Position);
}
}
protected override void DoOnLeave(WorldHandler worldHandler, Config config, Hero hero)
{
targetPosition = null;
}
private Vector3? targetPosition = null;
}
}

View File

@ -3,7 +3,7 @@ using System;
namespace Client.Domain.ValueObjects
{
public class Vector3 : ObservableObject
public class Vector3 : ObservableObject, ICloneable
{
private float x;
private float y;
@ -77,6 +77,11 @@ namespace Client.Domain.ValueObjects
return MathF.Sqrt(MathF.Pow(x - other.x, 2) + MathF.Pow(y - other.y, 2) + MathF.Pow(z - other.z, 2));
}
public object Clone()
{
return MemberwiseClone();
}
public static Vector3 operator -(Vector3 left, Vector3 right)
{
return new Vector3(left.x - right.x, left.y - right.y, left.z - right.z);