diff --git a/Projects/Server.Tests/Network/Packets/Old/Outgoing/TargetPacketsTests.cs b/Projects/Server.Tests/Network/Packets/Old/Outgoing/TargetPacketsTests.cs new file mode 100644 index 000000000..6bb26c7bf --- /dev/null +++ b/Projects/Server.Tests/Network/Packets/Old/Outgoing/TargetPacketsTests.cs @@ -0,0 +1,161 @@ +using System; +using System.Buffers; +using Server.Network; +using Server.Targeting; +using Xunit; + +namespace Server.Tests.Network.Packets +{ + public class TestMultiTarget : MultiTarget + { + public TestMultiTarget( + int multiID, + Point3D offset, + int range = 10, + bool allowGround = true, + TargetFlags flags = TargetFlags.None + ) : base(multiID, offset, range, allowGround, flags) + { + } + } + + public class TestTarget : Target + { + public TestTarget( + int range, + bool allowGround, + TargetFlags flags + ) : base(range, allowGround, flags) + { + } + } + + public class TargetPacketsTests + { + [Fact] + public void TestMultiTargetReqHS() + { + int multiID = 0x1024; + Point3D p = new Point3D(1000, 100, 10); + MultiTarget t = new TestMultiTarget(multiID, p); + + Span data = new MultiTargetReqHS(t).Compile(); + + Span expectedData = stackalloc byte[30]; + int pos = 0; + + expectedData.Write(ref pos, (byte)0x99); // Packet ID + expectedData.Write(ref pos, t.AllowGround); + expectedData.Write(ref pos, t.TargetID); + +#if NO_LOCAL_INIT + expectedData.Write(ref pos, 0); + expectedData.Write(ref pos, (ushort)0); + expectedData.Write(ref pos, (ushort)0); + expectedData.Write(ref pos, (byte)0); + expectedData.Write(ref pos, (byte)0); + expectedData.Write(ref pos, (ushort)0); +#else + pos += 12; +#endif + + expectedData.Write(ref pos, (short)t.MultiID); + expectedData.Write(ref pos, (ushort)t.Offset.X); + expectedData.Write(ref pos, (ushort)t.Offset.Y); + expectedData.Write(ref pos, (short)t.Offset.Z); + +#if NO_LOCAL_INIT + // Hue (4 bytes) + expectedData.Write(ref pos, 0); +#endif + + AssertThat.Equal(data, expectedData); + } + + [Fact] + public void TestMultiTargetReq() + { + int multiID = 0x1024; + Point3D p = new Point3D(1000, 100, 10); + MultiTarget t = new TestMultiTarget(multiID, p); + + Span data = new MultiTargetReq(t).Compile(); + + Span expectedData = stackalloc byte[26]; + int pos = 0; + + expectedData.Write(ref pos, (byte)0x99); // Packet ID + expectedData.Write(ref pos, t.AllowGround); + expectedData.Write(ref pos, t.TargetID); + +#if NO_LOCAL_INIT + expectedData.Write(ref pos, 0); + expectedData.Write(ref pos, (ushort)0); + expectedData.Write(ref pos, (ushort)0); + expectedData.Write(ref pos, (byte)0); + expectedData.Write(ref pos, (byte)0); + expectedData.Write(ref pos, (ushort)0); +#else + pos += 12; +#endif + + expectedData.Write(ref pos, (short)t.MultiID); + expectedData.Write(ref pos, (ushort)t.Offset.X); + expectedData.Write(ref pos, (ushort)t.Offset.Y); + expectedData.Write(ref pos, (short)t.Offset.Z); + + AssertThat.Equal(data, expectedData); + } + + [Fact] + public void TestCancelTarget() + { + Span data = new CancelTarget().Compile(); + + Span expectedData = stackalloc byte[19]; + int pos = 0; + + expectedData.Write(ref pos, (byte)0x6C); // Packet ID + expectedData.Write(ref pos, (byte)0); + expectedData.Write(ref pos, 0); + expectedData.Write(ref pos, (byte)3); // Beneficial / Harmful + +#if NO_LOCAL_INIT + expectedData.Write(ref pos, 0); + expectedData.Write(ref pos, (ushort)0); + expectedData.Write(ref pos, (ushort)0); + expectedData.Write(ref pos, (byte)0); + expectedData.Write(ref pos, (byte)0); + expectedData.Write(ref pos, (ushort)0); +#endif + + AssertThat.Equal(data, expectedData); + } + + [Fact] + public void TestTargetReq() + { + var t = new TestTarget(10, true, TargetFlags.Beneficial); + Span data = new TargetReq(t).Compile(); + + Span expectedData = stackalloc byte[19]; + int pos = 0; + + expectedData.Write(ref pos, (byte)0x6C); // Packet ID + expectedData.Write(ref pos, t.AllowGround); + expectedData.Write(ref pos, t.TargetID); + expectedData.Write(ref pos, (byte)t.Flags); + +#if NO_LOCAL_INIT + expectedData.Write(ref pos, 0); + expectedData.Write(ref pos, (ushort)0); + expectedData.Write(ref pos, (ushort)0); + expectedData.Write(ref pos, (byte)0); + expectedData.Write(ref pos, (byte)0); + expectedData.Write(ref pos, (ushort)0); +#endif + + AssertThat.Equal(data, expectedData); + } + } +}