//
// PtctlResponder.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 System.Security;
using NosSmooth.Core.Packets;
using NosSmooth.Packets.Client.Mates;
using Remora.Results;
namespace NosSmooth.Extensions.Pathfinding.Responders;
///
public class PtctlResponder : IPacketResponder
{
private readonly PathfinderState _state;
///
/// Initializes a new instance of the class.
///
/// The state.
public PtctlResponder(PathfinderState state)
{
_state = state;
}
///
public Task Respond(PacketEventArgs packetArgs, CancellationToken ct = default)
{
var packet = packetArgs.Packet;
foreach (var walkControl in packet.Controls)
{
if (!_state.Entities.TryGetValue(walkControl.MateTransportId, out var entityState))
{
_state.AddEntity(walkControl.MateTransportId, walkControl.PositionX, walkControl.PositionY);
continue;
}
entityState.X = walkControl.PositionX;
entityState.Y = walkControl.PositionY;
}
return Task.FromResult(Result.FromSuccess());
}
}