fix(content): Converts buff icon packets (#389)

- [X] Converts buff icon packets, and avoids string formatting.
This commit is contained in:
Kamron Batman 2021-01-06 01:01:21 -08:00 • committed by GitHub
parent 0912876f7c
commit 03bdff2293
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 243 additions and 96 deletions

View file

@ -18,7 +18,10 @@ namespace Server.Tests.Network
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
}
[Theory, InlineData(0, 0), InlineData(100, 10), InlineData(100000, 100000)]
[Theory]
[InlineData(0, 0)]
[InlineData(100, 10)]
[InlineData(100000, 100000)]
public void TestSetArrow(int x, int y)
{
var expected = new SetArrow(x, y).Compile();
@ -30,7 +33,10 @@ namespace Server.Tests.Network
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
}
[Theory, InlineData(0, 0), InlineData(100, 10), InlineData(100000, 100000)]
[Theory]
[InlineData(0, 0)]
[InlineData(100, 10)]
[InlineData(100000, 100000)]
public void TestCancelArrowHS(int x, int y)
{
Serial serial = 0x1024;
@ -45,7 +51,10 @@ namespace Server.Tests.Network
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
}
[Theory, InlineData(0, 0), InlineData(100, 10), InlineData(100000, 100000)]
[Theory]
[InlineData(0, 0)]
[InlineData(100, 10)]
[InlineData(100000, 100000)]
public void TestSetArrowHS(int x, int y)
{
Serial serial = 0x1024;

View file

@ -0,0 +1,42 @@
using System;
using Server;
using Server.Tests;
using Server.Tests.Network;
using Xunit;
namespace UOContent.Tests
{
public class BuffIconPacketTests
{
[Theory]
[InlineData(0x1024u, BuffIcon.Clumsy, 500100, 300200, "123456", 8000)]
[InlineData(0x2048u, BuffIcon.Disguised, 500102, 300203, null, 9000)]
public void TestAddBuffIcon(uint mob, BuffIcon iconID, int titleCliloc, int secondaryCliloc, string args, int ts)
{
var timeSpan = new TimeSpan(ts);
var expected = new AddBuffPacket(
mob, iconID, titleCliloc, secondaryCliloc, args, timeSpan
).Compile();
using var ns = PacketTestUtilities.CreateTestNetState();
BuffInfo.SendAddBuffPacket(ns, mob, iconID, titleCliloc, secondaryCliloc, args, timeSpan);
var result = ns.SendPipe.Reader.TryRead();
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
}
[Fact]
public void TestRemoveBuffIcon()
{
Serial m = 0x1024;
var buffIcon = BuffIcon.Disguised;
var expected = new RemoveBuffPacket(m, buffIcon).Compile();
using var ns = PacketTestUtilities.CreateTestNetState();
BuffInfo.SendRemoveBuffPacket(ns, m, buffIcon);
var result = ns.SendPipe.Reader.TryRead();
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
}
}
}

View file

@ -0,0 +1,89 @@
using System;
using Server.Network;
namespace Server
{
public sealed class AddBuffPacket : Packet
{
public AddBuffPacket(Serial m, BuffInfo info)
: this(
m,
info.ID,
info.TitleCliloc,
info.SecondaryCliloc,
info.Args,
info.TimeStart != DateTime.MinValue ? info.TimeStart + info.TimeLength - DateTime.UtcNow : TimeSpan.Zero
)
{
}
public AddBuffPacket(
Serial mob, BuffIcon iconID, int titleCliloc, int secondaryCliloc, TextDefinition args,
TimeSpan length
)
: base(0xDF)
{
var hasArgs = args != null;
EnsureCapacity(hasArgs ? 48 + args.ToString().Length * 2 : 44);
Stream.Write(mob);
Stream.Write((short)iconID); // ID
Stream.Write((short)0x1); // Type 0 for removal. 1 for add 2 for Data
Stream.Fill(4);
Stream.Write((short)iconID); // ID
Stream.Write((short)0x01); // Type 0 for removal. 1 for add 2 for Data
Stream.Fill(4);
if (length < TimeSpan.Zero)
{
length = TimeSpan.Zero;
}
Stream.Write((short)length.TotalSeconds); // Time in seconds
Stream.Fill(3);
Stream.Write(titleCliloc);
Stream.Write(secondaryCliloc);
if (!hasArgs)
{
// m_Stream.Fill( 2 );
Stream.Fill(10);
}
else
{
Stream.Fill(4);
Stream.Write((short)0x1); // Unknown -> Possibly something saying 'hey, I have more data!'?
Stream.Fill(2);
// m_Stream.WriteLittleUniNull( "\t#1018280" );
Stream.WriteLittleUniNull($"\t{args}");
Stream.Write((short)0x1); // Even more Unknown -> Possibly something saying 'hey, I have more data!'?
Stream.Fill(2);
}
}
}
public sealed class RemoveBuffPacket : Packet
{
public RemoveBuffPacket(Serial mob, BuffInfo info) : this(mob, info.ID)
{
}
public RemoveBuffPacket(Serial mob, BuffIcon iconID) : base(0xDF)
{
EnsureCapacity(13);
Stream.Write(mob);
Stream.Write((short)iconID); // ID
Stream.Write((short)0x0); // Type 0 for removal. 1 for add 2 for Data
Stream.Fill(4);
}
}
}