From 092afaf47312b7a5ac76919c9ce4825c420c00a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Boh=C3=A1=C4=8Dek?= Date: Thu, 30 Dec 2021 00:29:57 +0100 Subject: [PATCH] feat: add fc packet --- Core/NosSmooth.Packets/Enums/Act4Mode.cs | 33 +++++++++ Core/NosSmooth.Packets/Enums/FactionType.cs | 28 ++++++++ .../Packets/Server/Act4/FcPacket.cs | 37 ++++++++++ .../Packets/Server/Act4/FcSubPacket.cs | 47 ++++++++++++ .../Packets/FcPacketConverterTests.cs | 72 +++++++++++++++++++ 5 files changed, 217 insertions(+) create mode 100644 Core/NosSmooth.Packets/Enums/Act4Mode.cs create mode 100644 Core/NosSmooth.Packets/Enums/FactionType.cs create mode 100644 Core/NosSmooth.Packets/Packets/Server/Act4/FcPacket.cs create mode 100644 Core/NosSmooth.Packets/Packets/Server/Act4/FcSubPacket.cs create mode 100644 Tests/NosSmooth.Packets.Tests/Converters/Packets/FcPacketConverterTests.cs diff --git a/Core/NosSmooth.Packets/Enums/Act4Mode.cs b/Core/NosSmooth.Packets/Enums/Act4Mode.cs new file mode 100644 index 0000000..7a3bca8 --- /dev/null +++ b/Core/NosSmooth.Packets/Enums/Act4Mode.cs @@ -0,0 +1,33 @@ +// +// Act4Mode.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. + +namespace NosSmooth.Packets.Enums; + +/// +/// The act4 mode. +/// +public enum Act4Mode +{ + /// + /// There is nothing currently running, percentage has to reach 100 % for Mukraju to spawn. + /// + None = 0, + + /// + /// Mukraju has been spawned and has to be killed in order to start raid. + /// + Mukraju = 1, + + /// + /// Unknown mode. + /// + Unknown = 2, + + /// + /// Raid is in progress. + /// + Raid = 3, +} \ No newline at end of file diff --git a/Core/NosSmooth.Packets/Enums/FactionType.cs b/Core/NosSmooth.Packets/Enums/FactionType.cs new file mode 100644 index 0000000..cae8ee0 --- /dev/null +++ b/Core/NosSmooth.Packets/Enums/FactionType.cs @@ -0,0 +1,28 @@ +// +// FactionType.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. + +namespace NosSmooth.Packets.Enums; + +/// +/// Faction of an entity. +/// +public enum FactionType +{ + /// + /// No faction. + /// + Neutral = 0, + + /// + /// Angel faction. + /// + Angel = 1, + + /// + /// Demon faction. + /// + Demon = 2 +} \ No newline at end of file diff --git a/Core/NosSmooth.Packets/Packets/Server/Act4/FcPacket.cs b/Core/NosSmooth.Packets/Packets/Server/Act4/FcPacket.cs new file mode 100644 index 0000000..148fbad --- /dev/null +++ b/Core/NosSmooth.Packets/Packets/Server/Act4/FcPacket.cs @@ -0,0 +1,37 @@ +// +// FcPacket.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.Attributes; +using NosSmooth.Packets.Enums; + +namespace NosSmooth.Packets.Packets.Server.Act4; + +/// +/// Contains the state of the act4. +/// +/// +/// Sent only in act4. Receiving the packet +/// will make status bar appear in the game. +/// The packet contains all information about +/// the current status such as percentage till Mukraju, +/// type of raid etc. +/// +/// The faction of the player playing. +/// The minutes it will take to reset. +/// The status of angel faction, see . +/// The status of demon faction, see . +[PacketHeader("fc", PacketSource.Server)] +[GenerateSerializer] +public record FcPacket( + [PacketIndex(0)] + FactionType Faction, + [PacketIndex(1)] + long MinutesUntilReset, + [PacketIndex(2, InnerSeparator = ' ')] + FcSubPacket AngelState, + [PacketIndex(3, InnerSeparator = ' ')] + FcSubPacket DemonState +) : IPacket; \ No newline at end of file diff --git a/Core/NosSmooth.Packets/Packets/Server/Act4/FcSubPacket.cs b/Core/NosSmooth.Packets/Packets/Server/Act4/FcSubPacket.cs new file mode 100644 index 0000000..4e30522 --- /dev/null +++ b/Core/NosSmooth.Packets/Packets/Server/Act4/FcSubPacket.cs @@ -0,0 +1,47 @@ +// +// FcSubPacket.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.Attributes; +using NosSmooth.Packets.Enums; + +namespace NosSmooth.Packets.Packets.Server.Act4; + +/// +/// Sub packet of , containing +/// either the state of angels or demons +/// +/// The percentage of the faction. +/// The mode +/// The time the raid has been open for so far. +/// The total time the raid will be open for. +/// Whether the current raid is Marcos. +/// Whether the current raid is Hatus. +/// Whether the current raid is Calvina. +/// Whether the current raid is Berios. +/// Unknown value, seems to be always 0. +[GenerateSerializer] +[PacketHeader(null, PacketSource.Server)] +public record FcSubPacket +( + [PacketIndex(0)] + short Percentage, + [PacketIndex(1)] + Act4Mode Mode, + [PacketIndex(2)] + long CurrentTime, + [PacketIndex(3)] + long TotalTime, + [PacketIndex(4)] + bool IsMorcos, + [PacketIndex(5)] + bool IsHatus, + [PacketIndex(6)] + bool IsCalvina, + [PacketIndex(7)] + bool IsBerios, + [PacketIndex(8)] + byte Unknown +) : IPacket; \ No newline at end of file diff --git a/Tests/NosSmooth.Packets.Tests/Converters/Packets/FcPacketConverterTests.cs b/Tests/NosSmooth.Packets.Tests/Converters/Packets/FcPacketConverterTests.cs new file mode 100644 index 0000000..5ea36b7 --- /dev/null +++ b/Tests/NosSmooth.Packets.Tests/Converters/Packets/FcPacketConverterTests.cs @@ -0,0 +1,72 @@ +// +// FcPacketConverterTests.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 Microsoft.Extensions.DependencyInjection; +using NosSmooth.Packets.Attributes; +using NosSmooth.Packets.Converters; +using NosSmooth.Packets.Enums; +using NosSmooth.Packets.Extensions; +using NosSmooth.Packets.Packets.Server.Act4; +using Xunit; + +namespace NosSmooth.Packets.Tests.Converters.Packets; + +/// +/// Tests . +/// +public class FcPacketConverterTests +{ + private readonly IPacketSerializer _packetSerializer; + + /// + /// Initializes a new instance of the class. + /// + public FcPacketConverterTests() + { + var provider = new ServiceCollection() + .AddSingleton() + .AddPacketSerialization() + .BuildServiceProvider(); + + _packetSerializer = provider.GetRequiredService(); + } + + /// + /// Tests that the serialization runs correctly. + /// + [Fact] + public void Converter_Serialization_SerializesCorrectly() + { + var packet = new FcPacket( + FactionType.Angel, + 15122, + new FcSubPacket(76, Act4Mode.None, 0, 0, false, false, false, false, 0), + new FcSubPacket(100, Act4Mode.Raid, 10, 1000, true, false, false, false, 0) + ); + var packetResult = _packetSerializer.Serialize(packet); + Assert.True(packetResult.IsSuccess); + + Assert.Equal("fc 1 15122 76 0 0 0 0 0 0 0 0 100 3 10 1000 1 0 0 0 0", packetResult.Entity); + } + + /// + /// Tests that the deserialization runs correctly. + /// + [Fact] + public void Converter_Deserialization_DeserializesCorrectly() + { + var packetResult = _packetSerializer.Deserialize("fc 1 15122 76 0 0 0 0 0 0 0 0 100 3 10 1000 1 0 0 0 0", PacketSource.Server); + Assert.True(packetResult.IsSuccess); + + var expectedPacket = new FcPacket( + FactionType.Angel, + 15122, + new FcSubPacket(76, Act4Mode.None, 0, 0, false, false, false, false, 0), + new FcSubPacket(100, Act4Mode.Raid, 10, 1000, true, false, false, false, 0) + ); + Assert.Equal(expectedPacket, packetResult.Entity); + } +} \ No newline at end of file -- 2.49.0