From 287285c0a17c745afe5cb261a3a557d278c185c8 Mon Sep 17 00:00:00 2001 From: Rutherther Date: Fri, 30 Dec 2022 23:50:22 +0100 Subject: [PATCH] feat(pathfinding): create custom pathfinding --- .../Operations/WalkInRangeOperation.cs | 3 ++- .../Errors/PathNotFoundError.cs | 16 ++++++++++++++++ .../Pathfinder.cs | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 Extensions/NosSmooth.Extensions.Pathfinding/Errors/PathNotFoundError.cs diff --git a/Extensions/NosSmooth.Extensions.Combat/Operations/WalkInRangeOperation.cs b/Extensions/NosSmooth.Extensions.Combat/Operations/WalkInRangeOperation.cs index 16bd57d4016e5f82d04f0b7b813585c667a5efb5..6c1dd7425f15b7461d866917cea3b10bef1d5102 100644 --- a/Extensions/NosSmooth.Extensions.Combat/Operations/WalkInRangeOperation.cs +++ b/Extensions/NosSmooth.Extensions.Combat/Operations/WalkInRangeOperation.cs @@ -6,6 +6,7 @@ using NosSmooth.Extensions.Combat.Errors; using NosSmooth.Extensions.Pathfinding; +using NosSmooth.Extensions.Pathfinding.Errors; using NosSmooth.Game.Data.Entities; using NosSmooth.Game.Data.Info; using Remora.Results; @@ -96,7 +97,7 @@ public record WalkInRangeOperation return Result.FromSuccess(); } - if (!walkResult.IsSuccess && walkResult.Error is NotFoundError) + if (!walkResult.IsSuccess && walkResult.Error is PathNotFoundError) { if (distance - 1 > 0) { diff --git a/Extensions/NosSmooth.Extensions.Pathfinding/Errors/PathNotFoundError.cs b/Extensions/NosSmooth.Extensions.Pathfinding/Errors/PathNotFoundError.cs new file mode 100644 index 0000000000000000000000000000000000000000..57bc83fe43794c717d24c45ef75f314b8ae6326a --- /dev/null +++ b/Extensions/NosSmooth.Extensions.Pathfinding/Errors/PathNotFoundError.cs @@ -0,0 +1,16 @@ +// +// PathNotFoundError.cs +// +// Copyright (c) František Boháček. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using Remora.Results; + +namespace NosSmooth.Extensions.Pathfinding.Errors; + +/// +/// Could not find path to the given target. +/// +/// The target x coordinate. +/// The target y coordinate. +public record PathNotFoundError(short TargetX, short TargetY) : ResultError($"Path to {TargetX}, {TargetY} not found."); \ No newline at end of file diff --git a/Extensions/NosSmooth.Extensions.Pathfinding/Pathfinder.cs b/Extensions/NosSmooth.Extensions.Pathfinding/Pathfinder.cs index d5ee45d57f86372c7ff6c6b19e9bbd73f38460f7..74ed04ba28c68e600acbc08966d8f14adf2a5187 100644 --- a/Extensions/NosSmooth.Extensions.Pathfinding/Pathfinder.cs +++ b/Extensions/NosSmooth.Extensions.Pathfinding/Pathfinder.cs @@ -159,7 +159,7 @@ public class Pathfinder } } - return new NotFoundError("Could not find path to the given position."); + return new PathNotFoundError(targetX, targetY); } private Path ReconstructPath