fix(core): Converts mobile stats packets (#360)

- [X] Converts mobile stats packets
- [X] Removes human racial from non-players
This commit is contained in:
Kamron Batman 2020-12-27 14:44:03 -08:00 • committed by GitHub
parent d73afdba8e
commit 5b69f1d389
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 413 additions and 423 deletions

View file

@ -1,93 +0,0 @@
using System;
using System.Buffers;
using Server.Network;
using Xunit;
namespace Server.Tests.Network
{
[Collection("Sequential Tests")]
public class AttributeNormalizerTests
{
[Fact]
public void TestAttributeNormalizerEnabled()
{
AttributeNormalizer.Enabled = true;
AttributeNormalizer.Maximum = 25;
var stream = new PacketWriter(4);
const ushort cur = 50;
const ushort max = 100;
AttributeNormalizer.Write(stream, cur, max);
Span<byte> expectedData = stackalloc byte[4];
var pos = 0;
expectedData.Write(ref pos, (ushort)AttributeNormalizer.Maximum);
expectedData.Write(ref pos, (ushort)(cur * 25 / max));
AssertThat.Equal(stream.ToArray(), expectedData);
}
[Fact]
public void TestAttributeNormalizerReversedEnabled()
{
AttributeNormalizer.Enabled = true;
AttributeNormalizer.Maximum = 25;
var stream = new PacketWriter(4);
const ushort cur = 50;
const ushort max = 100;
AttributeNormalizer.WriteReverse(stream, cur, max);
Span<byte> expectedData = stackalloc byte[4];
var pos = 0;
expectedData.Write(ref pos, (ushort)(cur * 25 / max));
expectedData.Write(ref pos, (ushort)AttributeNormalizer.Maximum);
AssertThat.Equal(stream.ToArray(), expectedData);
}
[Fact]
public void TestAttributeNormalizerDisabled()
{
AttributeNormalizer.Enabled = false;
var stream = new PacketWriter(4);
const ushort cur = 50;
const ushort max = 100;
AttributeNormalizer.Write(stream, cur, max);
Span<byte> expectedData = stackalloc byte[4];
var pos = 0;
expectedData.Write(ref pos, max);
expectedData.Write(ref pos, cur);
AssertThat.Equal(stream.ToArray(), expectedData);
}
[Fact]
public void TestAttributeNormalizerReversedDisabled()
{
AttributeNormalizer.Enabled = false;
var stream = new PacketWriter(4);
const ushort cur = 50;
const ushort max = 100;
AttributeNormalizer.WriteReverse(stream, cur, max);
Span<byte> expectedData = stackalloc byte[4];
var pos = 0;
expectedData.Write(ref pos, cur);
expectedData.Write(ref pos, max);
AssertThat.Equal(stream.ToArray(), expectedData);
}
}
}

View file

@ -625,17 +625,16 @@ namespace Server.Tests.Network
{
var m = new Mobile(0x1);
m.DefaultMobileInit();
m.Str = 100;
m.Hits = 100;
var data = new MobileHits(m).Compile();
var expected = new MobileHits(m).Compile();
Span<byte> expectedData = stackalloc byte[9];
var pos = 0;
using var ns = PacketTestUtilities.CreateTestNetState();
ns.SendMobileHits(m);
expectedData.Write(ref pos, (byte)0xA1); // Packet ID
expectedData.Write(ref pos, m.Serial);
expectedData.WriteAttribute(ref pos, m.Hits, m.HitsMax, false);
AssertThat.Equal(data, expectedData);
var result = ns.SendPipe.Reader.TryRead();
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
}
[Fact]
@ -643,17 +642,16 @@ namespace Server.Tests.Network
{
var m = new Mobile(0x1);
m.DefaultMobileInit();
m.Str = 100;
m.Hits = 100;
var data = new MobileHitsN(m).Compile();
var expected = new MobileHitsN(m).Compile();
Span<byte> expectedData = stackalloc byte[9];
var pos = 0;
using var ns = PacketTestUtilities.CreateTestNetState();
ns.SendMobileHits(m, true);
expectedData.Write(ref pos, (byte)0xA1); // Packet ID
expectedData.Write(ref pos, m.Serial);
expectedData.WriteAttribute(ref pos, m.Hits, m.HitsMax, true);
AssertThat.Equal(data, expectedData);
var result = ns.SendPipe.Reader.TryRead();
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
}
[Fact]
@ -661,17 +659,16 @@ namespace Server.Tests.Network
{
var m = new Mobile(0x1);
m.DefaultMobileInit();
m.Int = 75;
m.Mana = 100;
var data = new MobileMana(m).Compile();
var expected = new MobileMana(m).Compile();
Span<byte> expectedData = stackalloc byte[9];
var pos = 0;
using var ns = PacketTestUtilities.CreateTestNetState();
ns.SendMobileMana(m);
expectedData.Write(ref pos, (byte)0xA2); // Packet ID
expectedData.Write(ref pos, m.Serial);
expectedData.WriteAttribute(ref pos, m.Mana, m.ManaMax, false);
AssertThat.Equal(data, expectedData);
var result = ns.SendPipe.Reader.TryRead();
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
}
[Fact]
@ -679,17 +676,16 @@ namespace Server.Tests.Network
{
var m = new Mobile(0x1);
m.DefaultMobileInit();
m.Int = 75;
m.Mana = 100;
var data = new MobileManaN(m).Compile();
var expected = new MobileManaN(m).Compile();
Span<byte> expectedData = stackalloc byte[9];
var pos = 0;
using var ns = PacketTestUtilities.CreateTestNetState();
ns.SendMobileMana(m, true);
expectedData.Write(ref pos, (byte)0xA2); // Packet ID
expectedData.Write(ref pos, m.Serial);
expectedData.WriteAttribute(ref pos, m.Mana, m.ManaMax, true);
AssertThat.Equal(data, expectedData);
var result = ns.SendPipe.Reader.TryRead();
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
}
[Fact]
@ -697,17 +693,16 @@ namespace Server.Tests.Network
{
var m = new Mobile(0x1);
m.DefaultMobileInit();
m.Dex = 75;
m.Stam = 100;
var data = new MobileStam(m).Compile();
var expected = new MobileStam(m).Compile();
Span<byte> expectedData = stackalloc byte[9];
var pos = 0;
using var ns = PacketTestUtilities.CreateTestNetState();
ns.SendMobileStam(m);
expectedData.Write(ref pos, (byte)0xA3); // Packet ID
expectedData.Write(ref pos, m.Serial);
expectedData.WriteAttribute(ref pos, m.Stam, m.StamMax, false);
AssertThat.Equal(data, expectedData);
var result = ns.SendPipe.Reader.TryRead();
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
}
[Fact]
@ -715,17 +710,16 @@ namespace Server.Tests.Network
{
var m = new Mobile(0x1);
m.DefaultMobileInit();
m.Dex = 75;
m.Stam = 100;
var data = new MobileStamN(m).Compile();
var expected = new MobileStamN(m).Compile();
Span<byte> expectedData = stackalloc byte[9];
var pos = 0;
using var ns = PacketTestUtilities.CreateTestNetState();
ns.SendMobileStam(m, true);
expectedData.Write(ref pos, (byte)0xA3); // Packet ID
expectedData.Write(ref pos, m.Serial);
expectedData.WriteAttribute(ref pos, m.Stam, m.StamMax, true);
AssertThat.Equal(data, expectedData);
var result = ns.SendPipe.Reader.TryRead();
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
}
[Fact]
@ -733,19 +727,20 @@ namespace Server.Tests.Network
{
var m = new Mobile(0x1);
m.DefaultMobileInit();
m.Str = 50;
m.Hits = 100;
m.Int = 75;
m.Mana = 100;
m.Dex = 25;
m.Stam = 100;
var data = new MobileAttributes(m).Compile();
var expected = new MobileAttributes(m).Compile();
Span<byte> expectedData = stackalloc byte[17];
var pos = 0;
using var ns = PacketTestUtilities.CreateTestNetState();
ns.SendMobileAttributes(m);
expectedData.Write(ref pos, (byte)0x2D); // Packet ID
expectedData.Write(ref pos, m.Serial);
expectedData.WriteAttribute(ref pos, m.Hits, m.HitsMax, false);
expectedData.WriteAttribute(ref pos, m.Mana, m.ManaMax, false);
expectedData.WriteAttribute(ref pos, m.Stam, m.StamMax, false);
AssertThat.Equal(data, expectedData);
var result = ns.SendPipe.Reader.TryRead();
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
}
[Fact]
@ -753,19 +748,20 @@ namespace Server.Tests.Network
{
var m = new Mobile(0x1);
m.DefaultMobileInit();
m.Str = 50;
m.Hits = 100;
m.Int = 75;
m.Mana = 100;
m.Dex = 25;
m.Stam = 100;
var data = new MobileAttributesN(m).Compile();
var expected = new MobileAttributesN(m).Compile();
Span<byte> expectedData = stackalloc byte[17];
var pos = 0;
using var ns = PacketTestUtilities.CreateTestNetState();
ns.SendMobileAttributes(m, true);
expectedData.Write(ref pos, (byte)0x2D); // Packet ID
expectedData.Write(ref pos, m.Serial);
expectedData.WriteAttribute(ref pos, m.Hits, m.HitsMax, true);
expectedData.WriteAttribute(ref pos, m.Mana, m.ManaMax, true);
expectedData.WriteAttribute(ref pos, m.Stam, m.StamMax, true);
AssertThat.Equal(data, expectedData);
var result = ns.SendPipe.Reader.TryRead();
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
}
}
}

View file

@ -49,4 +49,90 @@ namespace Server.Tests.Network
Stream.Write((byte)noto);
}
}
public sealed class MobileHits : Packet
{
public MobileHits(Mobile m) : base(0xA1, 9)
{
Stream.Write(m.Serial);
Stream.Write((short)m.HitsMax);
Stream.Write((short)m.Hits);
}
}
public sealed class MobileHitsN : Packet
{
public MobileHitsN(Mobile m) : base(0xA1, 9)
{
Stream.Write(m.Serial);
AttributeNormalizer.Write(Stream, m.Hits, m.HitsMax);
}
}
public sealed class MobileMana : Packet
{
public MobileMana(Mobile m) : base(0xA2, 9)
{
Stream.Write(m.Serial);
Stream.Write((short)m.ManaMax);
Stream.Write((short)m.Mana);
}
}
public sealed class MobileManaN : Packet
{
public MobileManaN(Mobile m) : base(0xA2, 9)
{
Stream.Write(m.Serial);
AttributeNormalizer.Write(Stream, m.Mana, m.ManaMax);
}
}
public sealed class MobileStam : Packet
{
public MobileStam(Mobile m) : base(0xA3, 9)
{
Stream.Write(m.Serial);
Stream.Write((short)m.StamMax);
Stream.Write((short)m.Stam);
}
}
public sealed class MobileStamN : Packet
{
public MobileStamN(Mobile m) : base(0xA3, 9)
{
Stream.Write(m.Serial);
AttributeNormalizer.Write(Stream, m.Stam, m.StamMax);
}
}
public sealed class MobileAttributes : Packet
{
public MobileAttributes(Mobile m) : base(0x2D, 17)
{
Stream.Write(m.Serial);
Stream.Write((short)m.HitsMax);
Stream.Write((short)m.Hits);
Stream.Write((short)m.ManaMax);
Stream.Write((short)m.Mana);
Stream.Write((short)m.StamMax);
Stream.Write((short)m.Stam);
}
}
public sealed class MobileAttributesN : Packet
{
public MobileAttributesN(Mobile m) : base(0x2D, 17)
{
Stream.Write(m.Serial);
AttributeNormalizer.Write(Stream, m.Hits, m.HitsMax);
AttributeNormalizer.Write(Stream, m.Mana, m.ManaMax);
AttributeNormalizer.Write(Stream, m.Stam, m.StamMax);
}
}
}