feat: adjust route to target
This commit is contained in:
parent
914f6ba20f
commit
d0baa5c21a
@ -99,11 +99,6 @@ namespace Client.Domain.AI.Combat
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pathMover.Pathfinder.HasLineOfSight(worldHandler.Hero.Transform.Position, worldHandler.Hero.Target.Transform.Position))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config.Combat.SpoilIsPriority) {
|
if (config.Combat.SpoilIsPriority) {
|
||||||
var spoil = worldHandler.GetSkillById(config.Combat.SpoilSkillId);
|
var spoil = worldHandler.GetSkillById(config.Combat.SpoilSkillId);
|
||||||
if (spoil != null && !spoil.IsReadyToUse) {
|
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);
|
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) => {
|
new(new List<BaseState.Type>{BaseState.Type.Attack}, BaseState.Type.Pickup, (state) => {
|
||||||
if (worldHandler.Hero == null) {
|
if (worldHandler.Hero == null) {
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
using Client.Domain.AI.Combat;
|
using Client.Domain.AI.Combat;
|
||||||
using Client.Domain.Entities;
|
using Client.Domain.Entities;
|
||||||
using Client.Domain.Service;
|
using Client.Domain.Service;
|
||||||
using Client.Infrastructure.Service;
|
using Client.Domain.ValueObjects;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace Client.Domain.AI.State
|
namespace Client.Domain.AI.State
|
||||||
{
|
{
|
||||||
@ -19,17 +20,32 @@ namespace Client.Domain.AI.State
|
|||||||
target = hero;
|
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)
|
if (asyncPathMover.IsLocked)
|
||||||
{
|
{
|
||||||
return;
|
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);
|
asyncPathMover.MoveAsync(target.Transform.Position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void DoOnLeave(WorldHandler worldHandler, Config config, Hero hero)
|
||||||
|
{
|
||||||
|
targetPosition = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Vector3? targetPosition = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ using System;
|
|||||||
|
|
||||||
namespace Client.Domain.ValueObjects
|
namespace Client.Domain.ValueObjects
|
||||||
{
|
{
|
||||||
public class Vector3 : ObservableObject
|
public class Vector3 : ObservableObject, ICloneable
|
||||||
{
|
{
|
||||||
private float x;
|
private float x;
|
||||||
private float y;
|
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));
|
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)
|
public static Vector3 operator -(Vector3 left, Vector3 right)
|
||||||
{
|
{
|
||||||
return new Vector3(left.x - right.x, left.y - right.y, left.z - right.z);
|
return new Vector3(left.x - right.x, left.y - right.y, left.z - right.z);
|
||||||
|
Loading…
Reference in New Issue
Block a user