fix(core): Converts mobile moving packet (#357)

- [X] Converts mobile moving packet
This commit is contained in:
Kamron Batman 2020-12-24 17:13:55 -08:00 • committed by GitHub
parent c2143584bc
commit 10a6e17640
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 147 additions and 170 deletions

View file

@ -26,52 +26,35 @@ namespace Server.Tests.Network
public void TestBondStatus()
{
Serial petSerial = 0x1;
var bonded = true;
const bool bonded = true;
var data = new BondedStatus(petSerial, bonded).Compile();
var expected = new BondedStatus(petSerial, bonded).Compile();
Span<byte> expectedData = stackalloc byte[11];
var pos = 0;
using var ns = PacketTestUtilities.CreateTestNetState();
ns.SendBondedStatus(petSerial, bonded);
expectedData.Write(ref pos, (byte)0xBF); // Packet ID
expectedData.Write(ref pos, (ushort)0x0B); // Length
expectedData.Write(ref pos, (ushort)0x19); // Sub-packet
#if NO_LOCAL_INIT
expectedData.Write(ref pos, (byte)0); // Command
#else
pos++;
#endif
expectedData.Write(ref pos, petSerial);
expectedData.Write(ref pos, bonded);
AssertThat.Equal(data, expectedData);
var result = ns.SendPipe.Reader.TryRead();
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
}
[Fact]
public void TestMobileMoving()
[Theory]
[InlineData(ProtocolChanges.StygianAbyss)]
[InlineData(ProtocolChanges.None)]
public void TestMobileMoving(ProtocolChanges protocolChanges)
{
var m = new Mobile(0x1);
m.DefaultMobileInit();
var noto = 10;
var data = new MobileMoving(m, noto, true).Compile();
using var ns = PacketTestUtilities.CreateTestNetState();
ns.ProtocolChanges = protocolChanges;
var expected = new MobileMoving(m, noto, ns.StygianAbyss).Compile();
Span<byte> expectedData = stackalloc byte[17];
var pos = 0;
ns.SendMobileMoving(m, noto);
expectedData.Write(ref pos, (byte)0x77); // Packet ID
expectedData.Write(ref pos, m.Serial);
expectedData.Write(ref pos, (ushort)m.Body);
expectedData.Write(ref pos, m.Location);
expectedData.Write(ref pos, (byte)m.Direction);
expectedData.Write(ref pos, (ushort)m.Hue);
expectedData.Write(ref pos, (byte)m.GetPacketFlags(true));
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]

View file

@ -14,4 +14,39 @@ namespace Server.Tests.Network
Stream.Write((byte)(bonded ? 1 : 0));
}
}
public sealed class DeathAnimation : Packet
{
public DeathAnimation(Serial killed, Serial corpse) : base(0xAF, 13)
{
Stream.Write(killed);
Stream.Write(corpse);
Stream.Write(0);
}
}
public sealed class MobileMoving : Packet
{
public MobileMoving(Mobile m, int noto, bool stygianAbyss) : base(0x77, 17)
{
var loc = m.Location;
var hue = m.Hue;
if (m.SolidHueOverride >= 0)
{
hue = m.SolidHueOverride;
}
Stream.Write(m.Serial);
Stream.Write((short)m.Body);
Stream.Write((short)loc.X);
Stream.Write((short)loc.Y);
Stream.Write((sbyte)loc.Z);
Stream.Write((byte)m.Direction);
Stream.Write((short)hue);
Stream.Write((byte)m.GetPacketFlags(stygianAbyss));
Stream.Write((byte)noto);
}
}
}