From b54039fcfc7c9184908f5601ac07361be94e234a Mon Sep 17 00:00:00 2001 From: Rutherther Date: Fri, 6 Jan 2023 23:34:53 +0100 Subject: [PATCH] feat(game): add revive handling --- .../PacketHandlers/Map/ReviveResponder.cs | 53 +++++++++++++++++++ .../Server/Entities/RevivePacket.cs | 22 ++++++++ 2 files changed, 75 insertions(+) create mode 100644 Core/NosSmooth.Game/PacketHandlers/Map/ReviveResponder.cs create mode 100644 Packets/NosSmooth.Packets/Server/Entities/RevivePacket.cs diff --git a/Core/NosSmooth.Game/PacketHandlers/Map/ReviveResponder.cs b/Core/NosSmooth.Game/PacketHandlers/Map/ReviveResponder.cs new file mode 100644 index 0000000..29b56ca --- /dev/null +++ b/Core/NosSmooth.Game/PacketHandlers/Map/ReviveResponder.cs @@ -0,0 +1,53 @@ +// +// ReviveResponder.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.Packets.Server.Entities; +using Remora.Results; + +namespace NosSmooth.Game.PacketHandlers.Map; + +/// +/// A handler of . +/// +public class ReviveResponder : IPacketResponder +{ + private readonly Game _game; + + /// + /// Initializes a new instance of the class. + /// + /// The game. + public ReviveResponder(Game game) + { + _game = game; + } + + /// + public Task Respond(PacketEventArgs packetArgs, CancellationToken ct = default) + { + var packet = packetArgs.Packet; + var entity = _game.CurrentMap?.Entities.GetEntity(packet.EntityId); + + if (entity is not null) + { + var hp = entity.Hp; + var mp = entity.Mp; + if (hp is not null) + { + hp.Percentage = 100; + } + + if (mp is not null) + { + mp.Percentage = 100; + } + } + + return Task.FromResult(Result.FromSuccess()); + } +} \ No newline at end of file diff --git a/Packets/NosSmooth.Packets/Server/Entities/RevivePacket.cs b/Packets/NosSmooth.Packets/Server/Entities/RevivePacket.cs new file mode 100644 index 0000000..66c3cbe --- /dev/null +++ b/Packets/NosSmooth.Packets/Server/Entities/RevivePacket.cs @@ -0,0 +1,22 @@ +// +// RevivePacket.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.Packets.Enums.Entities; +using NosSmooth.PacketSerializer.Abstractions.Attributes; + +namespace NosSmooth.Packets.Server.Entities; + +[PacketHeader("revive", PacketSource.Server)] +[GenerateSerializer(true)] +public record RevivePacket +( + [PacketIndex(0)] + EntityType EntityType, + [PacketIndex(1)] + long EntityId, + [PacketIndex(2)] + short TimeSpaceLives +) : IPacket; \ No newline at end of file -- 2.49.0