From 95574fd3b93fcf508043ff5104efeedcbd8d0fba Mon Sep 17 00:00:00 2001 From: NotKappa Date: Sun, 12 Feb 2023 21:14:55 +0300 Subject: [PATCH] Add PtctlResponder --- .../Extensions/ServiceCollectionExtensions.cs | 1 + .../PacketHandlers/Entities/PtctlResponder.cs | 59 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 Core/NosSmooth.Game/PacketHandlers/Entities/PtctlResponder.cs diff --git a/Core/NosSmooth.Game/Extensions/ServiceCollectionExtensions.cs b/Core/NosSmooth.Game/Extensions/ServiceCollectionExtensions.cs index e4c6ec2..27922f2 100644 --- a/Core/NosSmooth.Game/Extensions/ServiceCollectionExtensions.cs +++ b/Core/NosSmooth.Game/Extensions/ServiceCollectionExtensions.cs @@ -72,6 +72,7 @@ public static class ServiceCollectionExtensions // mates .AddPacketResponder() + .AddPacketResponder() // map .AddPacketResponder() diff --git a/Core/NosSmooth.Game/PacketHandlers/Entities/PtctlResponder.cs b/Core/NosSmooth.Game/PacketHandlers/Entities/PtctlResponder.cs new file mode 100644 index 0000000..14df91f --- /dev/null +++ b/Core/NosSmooth.Game/PacketHandlers/Entities/PtctlResponder.cs @@ -0,0 +1,59 @@ +// +// 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 NosSmooth.Core.Packets; +using NosSmooth.Game.Data.Entities; +using NosSmooth.Game.Data.Info; +using NosSmooth.Packets.Client.Mates; +using Remora.Results; + +namespace NosSmooth.Game.PacketHandlers.Entities; + +/// +/// Responds to Ptctl packet. +/// +public class PtctlResponder : IPacketResponder +{ + private readonly Game _game; + + /// + /// Initializes a new instance of the class. + /// + /// The nostale game. + public PtctlResponder(Game game) + { + _game = game; + } + + /// + public Task Respond(PacketEventArgs packetArgs, CancellationToken ct = default) + { + var map = _game.CurrentMap; + + if (map is null) + { + return Task.FromResult(Result.FromSuccess()); + } + + var packet = packetArgs.Packet; + + foreach (var control in packet.Controls) + { + var entity = map.Entities.GetEntity(control.MateTransportId); + if (entity is not null) + { + entity.Position = new Position(control.PositionX, control.PositionY); + + if (packet.EntityId == control.MateTransportId) + { + entity.Speed = packet.Speed; + } + } + } + + return Task.FromResult(Result.FromSuccess()); + } +} \ No newline at end of file -- 2.48.1