~ruther/NosSmooth

ref: 213fe53ae3a31d69b20543002b447347cf7893c0 NosSmooth/Extensions/NosSmooth.Extensions.Pathfinding/Responders/TpPacketResponder.cs -rw-r--r-- 1.1 KiB
213fe53a — Rutherther Merge pull request #81 from Rutherther/feat/pathfinding-mates 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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 (_state.Entities.TryGetValue(packet.EntityId, out var entityState))
        {
            entityState.X = packet.PositionX;
            entityState.Y = packet.PositionY;
        }

        return Task.FromResult(Result.FromSuccess());
    }
}
Do not follow this link