fix(core): Converts death animation (#356)

- [X] Converts death animation
- [X] Fixes tests for movement packets
This commit is contained in:
Kamron Batman 2020-12-21 23:43:45 -08:00 • committed by GitHub
parent 77ce2e1980
commit 90393fea2a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 65 additions and 89 deletions

View file

@ -13,19 +13,13 @@ namespace Server.Tests.Network
Serial killed = 0x1;
Serial corpse = 0x1000;
var data = new DeathAnimation(killed, corpse).Compile();
var expected = new DeathAnimation(killed, corpse).Compile();
Span<byte> expectedData = stackalloc byte[13];
var pos = 0;
using var ns = PacketTestUtilities.CreateTestNetState();
ns.SendDeathAnimation(killed, corpse);
expectedData.Write(ref pos, (byte)0xAF); // Packet ID
expectedData.Write(ref pos, killed);
expectedData.Write(ref pos, corpse);
#if NO_LOCAL_INIT
expectedData.Write(ref pos, 0);
#endif
AssertThat.Equal(data, expectedData);
var result = ns.SendPipe.Reader.TryRead();
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
}
[Fact]

View file

@ -1,5 +1,4 @@
using System;
using System.Buffers;
using Server.Network;
using Xunit;
@ -7,35 +6,32 @@ namespace Server.Tests.Network
{
public class MovementPacketTests : IClassFixture<ServerFixture>
{
[Theory, InlineData(0), InlineData(1), InlineData(2)]
[Theory]
[InlineData(0)]
[InlineData(1)]
[InlineData(2)]
public void TestSpeedControl(byte speedControl)
{
var data = new SpeedControl(speedControl).Compile();
var expected = new SpeedControl(speedControl).Compile();
Span<byte> expectedData = stackalloc byte[6];
var pos = 0;
using var ns = PacketTestUtilities.CreateTestNetState();
ns.SendSpeedControl((SpeedControlSetting)speedControl);
expectedData.Write(ref pos, (byte)0xBF); // Packet ID
expectedData.Write(ref pos, (ushort)6); // Length
expectedData.Write(ref pos, (ushort)0x26); // Command
expectedData.Write(ref pos, speedControl);
AssertThat.Equal(data, expectedData);
var result = ns.SendPipe.Reader.TryRead();
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
}
[Fact]
public void TestMovePlayer()
{
const Direction d = Direction.Left;
var data = new MovePlayer(d).Compile();
var expected = new MovePlayer(d).Compile();
Span<byte> expectedData = stackalloc byte[2];
var pos = 0;
using var ns = PacketTestUtilities.CreateTestNetState();
ns.SendMovePlayer(d);
expectedData.Write(ref pos, (byte)0x97); // Packet ID
expectedData.Write(ref pos, (byte)d);
AssertThat.Equal(data, expectedData);
var result = ns.SendPipe.Reader.TryRead();
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
}
[Fact]
@ -46,19 +42,13 @@ namespace Server.Tests.Network
const byte seq = 100;
var data = new MovementRej(seq, m).Compile();
var expected = new MovementRej(seq, m).Compile();
Span<byte> expectedData = stackalloc byte[8];
var pos = 0;
using var ns = PacketTestUtilities.CreateTestNetState();
ns.SendMovementRej(seq, m);
expectedData.Write(ref pos, (byte)0x21); // Packet ID
expectedData.Write(ref pos, seq);
expectedData.Write(ref pos, (short)m.X);
expectedData.Write(ref pos, (short)m.Y);
expectedData.Write(ref pos, (byte)m.Direction);
expectedData.Write(ref pos, (byte)m.Z);
AssertThat.Equal(data, expectedData);
var result = ns.SendPipe.Reader.TryRead();
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
}
[Fact]
@ -68,42 +58,26 @@ namespace Server.Tests.Network
m.DefaultMobileInit();
const byte seq = 100;
var noto = Notoriety.Compute(m, m);
var data = MovementAck.Instantiate(seq, m).Compile();
var expected = MovementAck.Instantiate(seq, m).Compile();
Span<byte> expectedData = stackalloc byte[3];
var pos = 0;
using var ns = PacketTestUtilities.CreateTestNetState();
ns.SendMovementAck(seq, m);
expectedData.Write(ref pos, (byte)0x22); // Packet ID
expectedData.Write(ref pos, seq);
expectedData.Write(ref pos, (byte)noto);
AssertThat.Equal(data, expectedData);
var result = ns.SendPipe.Reader.TryRead();
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
}
[Fact]
public void TestNullFastwalkStack()
{
var data = new NullFastwalkStack().Compile();
var expected = new NullFastwalkStack().Compile();
Span<byte> expectedData = stackalloc byte[29];
var pos = 0;
using var ns = PacketTestUtilities.CreateTestNetState();
ns.SendInitialFastwalkStack(new uint[]{ 0, 0, 0, 0, 0, 0 });
expectedData.Write(ref pos, (byte)0xBF); // Packet ID
expectedData.Write(ref pos, (ushort)29); // Length
expectedData.Write(ref pos, (short)0x1); // Sub-packet
#if NO_LOCAL_INIT
expectedData.Write(ref pos, 0); // Key 1
expectedData.Write(ref pos, 0); // Key 2
expectedData.Write(ref pos, 0); // Key 3
expectedData.Write(ref pos, 0); // Key 4
expectedData.Write(ref pos, 0); // Key 5
expectedData.Write(ref pos, 0); // Key 6
#endif
AssertThat.Equal(data, expectedData);
var result = ns.SendPipe.Reader.TryRead();
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
}
}
}

View file

@ -1,5 +1,4 @@
using System;
using System.Buffers;
using Server.Network;
using Server.Targeting;
using Xunit;

View file

@ -1,8 +1,5 @@
using System;
using System.Buffers;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using Server.Items;
using Server.Network;
using Xunit;