feat: add pathfinding
This commit is contained in:
15
Client/Domain/DTO/PathSegment.cs
Normal file
15
Client/Domain/DTO/PathSegment.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using Client.Domain.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Client.Domain.DTO
|
||||
{
|
||||
public class PathSegment
|
||||
{
|
||||
public Vector3 From = new Vector3(0, 0, 0);
|
||||
public Vector3 To = new Vector3(0, 0, 0);
|
||||
}
|
||||
}
|
18
Client/Domain/Service/AsyncPathMoverInterface.cs
Normal file
18
Client/Domain/Service/AsyncPathMoverInterface.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using Client.Domain.DTO;
|
||||
using Client.Domain.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Client.Domain.Service
|
||||
{
|
||||
public interface AsyncPathMoverInterface
|
||||
{
|
||||
public ObservableCollection<PathSegment> Path { get; }
|
||||
public Task<bool> MoveAsync(Vector3 location);
|
||||
public Task MoveUntilReachedAsync(Vector3 location);
|
||||
}
|
||||
}
|
15
Client/Domain/Service/PathfinderInterface.cs
Normal file
15
Client/Domain/Service/PathfinderInterface.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using Client.Domain.DTO;
|
||||
using Client.Domain.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Client.Domain.Service
|
||||
{
|
||||
public interface PathfinderInterface
|
||||
{
|
||||
public List<PathSegment> FindPath(Vector3 start, Vector3 end);
|
||||
}
|
||||
}
|
@@ -27,6 +27,8 @@ namespace Client.Domain.Service
|
||||
EventHandlerInterface<ItemCreatedEvent>,
|
||||
EventHandlerInterface<ItemDeletedEvent>
|
||||
{
|
||||
public Hero? Hero => hero;
|
||||
|
||||
public void RequestMoveToLocation(Vector3 location)
|
||||
{
|
||||
if (hero == null)
|
||||
@@ -37,24 +39,6 @@ namespace Client.Domain.Service
|
||||
SendMessage(OutgoingMessageTypeEnum.Move, location);
|
||||
}
|
||||
|
||||
public void RequestMoveToEntity(uint id)
|
||||
{
|
||||
if (hero == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!creatures.ContainsKey(id) && !drops.ContainsKey(id))
|
||||
{
|
||||
Debug.WriteLine("RequestMoveToEntity: entity " + id + " not found");
|
||||
return;
|
||||
}
|
||||
|
||||
var position = creatures.ContainsKey(id) ? creatures[id].Transform.Position : drops[id].Transform.Position;
|
||||
|
||||
RequestMoveToLocation(position);
|
||||
}
|
||||
|
||||
public void RequestAcquireTarget(uint id)
|
||||
{
|
||||
if (hero == null)
|
||||
|
18
Client/Domain/ValueObjects/PathNode.cs
Normal file
18
Client/Domain/ValueObjects/PathNode.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Client.Domain.ValueObjects
|
||||
{
|
||||
public struct PathNode
|
||||
{
|
||||
public readonly uint minX;
|
||||
public readonly uint minY;
|
||||
public readonly uint maxX;
|
||||
public readonly uint maxY;
|
||||
public readonly short height;
|
||||
}
|
||||
}
|
@@ -11,7 +11,7 @@ namespace Client.Domain.ValueObjects
|
||||
|
||||
public float X { get => x; set { if (value != x) { x = value; OnPropertyChanged("X"); } } }
|
||||
public float Y { get => y; set { if (value != y) { y = value; OnPropertyChanged("Y"); } } }
|
||||
public float Z { get => z; set { if (value != z) { z = value; OnPropertyChanged("X"); } } }
|
||||
public float Z { get => z; set { if (value != z) { z = value; OnPropertyChanged("Z"); } } }
|
||||
|
||||
public Vector3(float x, float y, float z)
|
||||
{
|
||||
@@ -29,5 +29,34 @@ namespace Client.Domain.ValueObjects
|
||||
{
|
||||
return MathF.Sqrt(HorizontalSqrDistance(other));
|
||||
}
|
||||
|
||||
public override bool Equals(object? other)
|
||||
{
|
||||
if (!(other is Vector3))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var obj = (Vector3)other;
|
||||
return MathF.Abs(x - obj.x) < float.Epsilon && MathF.Abs(y - obj.y) < float.Epsilon && MathF.Abs(z - obj.z) < float.Epsilon;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
|
||||
public bool ApproximatelyEquals(Vector3 other, float epsilon, bool withZ = false)
|
||||
{
|
||||
var equals = MathF.Abs(x - other.x) < epsilon && MathF.Abs(y - other.y) < epsilon;
|
||||
if (withZ)
|
||||
{
|
||||
equals = equals && MathF.Abs(z - other.z) < epsilon;
|
||||
}
|
||||
|
||||
return equals;
|
||||
}
|
||||
|
||||
public static readonly Vector3 Zero = new Vector3(0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user