fix(core): Converts healthbar packets (#367)
- [X] Converts healthbar packets
This commit is contained in:
parent
26243a72a7
commit
8f8b650ab5
22 changed files with 174 additions and 166 deletions
|
|
@ -133,6 +133,47 @@ namespace Server.Tests.Network
|
|||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("None")]
|
||||
[InlineData("Lesser")]
|
||||
[InlineData("Lethal")]
|
||||
public void TestHealthbarPoison(string pName)
|
||||
{
|
||||
var p = Poison.GetPoison(pName);
|
||||
var m = new Mobile(0x1);
|
||||
m.DefaultMobileInit();
|
||||
m.Poison = p;
|
||||
|
||||
var expected = new HealthbarPoison(m).Compile();
|
||||
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendMobileHealthbar(m, Healthbar.Poison);
|
||||
|
||||
var result = ns.SendPipe.Reader.TryRead();
|
||||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(false, false)]
|
||||
[InlineData(true, false)]
|
||||
[InlineData(false, true)]
|
||||
[InlineData(true, true)]
|
||||
public void TestYellowBar(bool isBlessed, bool isYellowHealth)
|
||||
{
|
||||
var m = new Mobile(0x1);
|
||||
m.DefaultMobileInit();
|
||||
m.Blessed = isBlessed;
|
||||
m.YellowHealthbar = isYellowHealth;
|
||||
|
||||
var expected = new HealthbarYellow(m).Compile();
|
||||
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendMobileHealthbar(m, Healthbar.Yellow);
|
||||
|
||||
var result = ns.SendPipe.Reader.TryRead();
|
||||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestMobileStatusCompact()
|
||||
{
|
||||
|
|
@ -279,51 +320,6 @@ namespace Server.Tests.Network
|
|||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Theory, InlineData("None"), InlineData("Lesser"), InlineData("Lethal")]
|
||||
public void TestHealthbarPoison(string pName)
|
||||
{
|
||||
var p = Poison.GetPoison(pName);
|
||||
var m = new Mobile(0x1);
|
||||
m.DefaultMobileInit();
|
||||
m.Poison = p;
|
||||
|
||||
var data = new HealthbarPoison(m).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[12];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x17); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)12); // Length
|
||||
expectedData.Write(ref pos, m.Serial);
|
||||
expectedData.Write(ref pos, 0x10001); // Show Bar?, Poison Bar
|
||||
expectedData.Write(ref pos, (byte)((p?.Level ?? -1) + 1));
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
Assert.Equal(p?.Level, m.Poison?.Level);
|
||||
}
|
||||
|
||||
[Theory, InlineData(false, false), InlineData(true, false), InlineData(false, true), InlineData(true, true)]
|
||||
public void TestYellowBar(bool isBlessed, bool isYellowHealth)
|
||||
{
|
||||
var m = new Mobile(0x1);
|
||||
m.DefaultMobileInit();
|
||||
m.Blessed = isBlessed;
|
||||
m.YellowHealthbar = isYellowHealth;
|
||||
|
||||
var data = new HealthbarYellow(m).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[12];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x17); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)12); // Length
|
||||
expectedData.Write(ref pos, m.Serial);
|
||||
expectedData.Write(ref pos, 0x10002); // Show Bar?, Yellow Bar
|
||||
expectedData.Write(ref pos, isBlessed || isYellowHealth);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestMobileUpdate()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -174,4 +174,50 @@ namespace Server.Tests.Network
|
|||
Stream.Write((byte)delay);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class HealthbarPoison : Packet
|
||||
{
|
||||
public HealthbarPoison(Mobile m) : base(0x17)
|
||||
{
|
||||
EnsureCapacity(12);
|
||||
|
||||
Stream.Write(m.Serial);
|
||||
Stream.Write((short)1); // Show Bar?
|
||||
|
||||
Stream.Write((short)1); // Poison Bar
|
||||
|
||||
var p = m.Poison;
|
||||
|
||||
if (p != null)
|
||||
{
|
||||
Stream.Write((byte)(p.Level + 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
Stream.Write((byte)0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class HealthbarYellow : Packet
|
||||
{
|
||||
public HealthbarYellow(Mobile m) : base(0x17)
|
||||
{
|
||||
EnsureCapacity(12);
|
||||
|
||||
Stream.Write(m.Serial);
|
||||
Stream.Write((short)1);
|
||||
|
||||
Stream.Write((short)2);
|
||||
|
||||
if (m.Blessed || m.YellowHealthbar)
|
||||
{
|
||||
Stream.Write((byte)1);
|
||||
}
|
||||
else
|
||||
{
|
||||
Stream.Write((byte)0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue