M Extensions/NosSmooth.Extensions.Pathfinding/Extensions/ServiceCollectionExtensions.cs => Extensions/NosSmooth.Extensions.Pathfinding/Extensions/ServiceCollectionExtensions.cs +4 -0
@@ 7,6 7,7 @@
using Microsoft.Extensions.DependencyInjection;
using NosSmooth.Core.Extensions;
using NosSmooth.Extensions.Pathfinding.Responders;
+using NosSmooth.Packets.Server.Character;
using NosSmooth.Packets.Server.Maps;
namespace NosSmooth.Extensions.Pathfinding.Extensions;
@@ 30,6 31,9 @@ public static class ServiceCollectionExtensions
.AddPacketResponder<AtResponder>()
.AddPacketResponder<CMapResponder>()
.AddPacketResponder<WalkResponder>()
+ .AddPacketResponder<SuPacketResponder>()
+ .AddPacketResponder<TpPacketResponder>()
+ .AddPacketResponder<CInfoPacketResponder>()
.AddSingleton<WalkManager>()
.AddSingleton<Pathfinder>()
.AddSingleton<PathfinderState>();
M Extensions/NosSmooth.Extensions.Pathfinding/NosSmooth.Extensions.Pathfinding.csproj => Extensions/NosSmooth.Extensions.Pathfinding/NosSmooth.Extensions.Pathfinding.csproj +2 -2
@@ 8,8 8,8 @@
<RepositoryUrl>https://github.com/Rutherther/NosSmooth/</RepositoryUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Description>NosSmooth extension allowing for finding paths on maps.</Description>
- <VersionPrefix>1.1.3</VersionPrefix>
- <PackageReleaseNotes>Update dependencies</PackageReleaseNotes>
+ <VersionPrefix>1.2.0</VersionPrefix>
+ <PackageReleaseNotes>React to su and tp packet by changing character position.</PackageReleaseNotes>
</PropertyGroup>
<ItemGroup>
M Extensions/NosSmooth.Extensions.Pathfinding/PathfinderState.cs => Extensions/NosSmooth.Extensions.Pathfinding/PathfinderState.cs +5 -0
@@ 34,4 34,9 @@ public class PathfinderState : IStatefulEntity
/// Gets or sets the current y.
/// </summary>
internal short Y { get; set; }
+
+ /// <summary>
+ /// Gets or sets the id of the charcter.
+ /// </summary>
+ internal long CharacterId { get; set; }
}=
\ No newline at end of file
A Extensions/NosSmooth.Extensions.Pathfinding/Responders/CInfoPacketResponder.cs => Extensions/NosSmooth.Extensions.Pathfinding/Responders/CInfoPacketResponder.cs +34 -0
@@ 0,0 1,34 @@
+//
+// CInfoPacketResponder.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 NosSmooth.Core.Packets;
+using NosSmooth.Packets.Server.Character;
+using Remora.Results;
+
+namespace NosSmooth.Extensions.Pathfinding.Responders;
+
+/// <inheritdoc />
+public class CInfoPacketResponder : IPacketResponder<CInfoPacket>
+{
+ private readonly PathfinderState _state;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="CInfoPacketResponder"/> class.
+ /// </summary>
+ /// <param name="state">The state.</param>
+ public CInfoPacketResponder(PathfinderState state)
+ {
+ _state = state;
+
+ }
+
+ /// <inheritdoc />
+ public Task<Result> Respond(PacketEventArgs<CInfoPacket> packetArgs, CancellationToken ct = default)
+ {
+ _state.CharacterId = packetArgs.Packet.CharacterId;
+ return Task.FromResult(Result.FromSuccess());
+ }
+}<
\ No newline at end of file
A Extensions/NosSmooth.Extensions.Pathfinding/Responders/SuPacketResponder.cs => Extensions/NosSmooth.Extensions.Pathfinding/Responders/SuPacketResponder.cs +50 -0
@@ 0,0 1,50 @@
+//
+// SuPacketResponder.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 NosSmooth.Core.Packets;
+using NosSmooth.Packets.Server.Battle;
+using Remora.Results;
+
+namespace NosSmooth.Extensions.Pathfinding.Responders;
+
+/// <inheritdoc />
+public class SuPacketResponder : IPacketResponder<SuPacket>
+{
+ private readonly PathfinderState _state;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="SuPacketResponder"/> class.
+ /// </summary>
+ /// <param name="state">The state.</param>
+ public SuPacketResponder(PathfinderState state)
+ {
+ _state = state;
+
+ }
+
+ /// <inheritdoc />
+ public Task<Result> Respond(PacketEventArgs<SuPacket> packetArgs, CancellationToken ct = default)
+ {
+ var packet = packetArgs.Packet;
+ if (packet.CasterEntityId == _state.CharacterId)
+ {
+ if (packet.PositionX is null || packet.PositionY is null)
+ {
+ return Task.FromResult(Result.FromSuccess());
+ }
+
+ if (packet.PositionX == 0 || packet.PositionY == 0)
+ {
+ return Task.FromResult(Result.FromSuccess());
+ }
+
+ _state.X = packet.PositionX.Value;
+ _state.Y = packet.PositionY.Value;
+ }
+
+ return Task.FromResult(Result.FromSuccess());
+ }
+}<
\ No newline at end of file
A Extensions/NosSmooth.Extensions.Pathfinding/Responders/TpPacketResponder.cs => Extensions/NosSmooth.Extensions.Pathfinding/Responders/TpPacketResponder.cs +39 -0
@@ 0,0 1,39 @@
+//
+// TpPacketResponder.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 NosSmooth.Core.Packets;
+using NosSmooth.Packets.Server.Maps;
+using Remora.Results;
+
+namespace NosSmooth.Extensions.Pathfinding.Responders;
+
+/// <inheritdoc />
+public class TpPacketResponder : IPacketResponder<TpPacket>
+{
+ private readonly PathfinderState _state;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="TpPacketResponder"/> class.
+ /// </summary>
+ /// <param name="state">The state.</param>
+ public TpPacketResponder(PathfinderState state)
+ {
+ _state = state;
+ }
+
+ /// <inheritdoc />
+ public Task<Result> Respond(PacketEventArgs<TpPacket> packetArgs, CancellationToken ct = default)
+ {
+ var packet = packetArgs.Packet;
+ if (packet.EntityId == _state.CharacterId)
+ {
+ _state.X = packet.PositionX;
+ _state.Y = packet.PositionY;
+ }
+
+ return Task.FromResult(Result.FromSuccess());
+ }
+}<
\ No newline at end of file