fix: Fixes flaky tests, formatting, and sequential testing. (#2168)
This commit is contained in:
parent
415c7a6bfd
commit
7dbfc9d161
60 changed files with 1304 additions and 1289 deletions
|
|
@ -15,78 +15,79 @@ public class TestBook : BaseBook
|
|||
|
||||
public TestBook(int itemID, string title, string author, int pageCount, bool writable) : base(itemID, title, author, pageCount, writable)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public TestBook(int itemID, bool writable) : base(itemID, writable)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public TestBook(Serial serial) : base(serial)
|
||||
{
|
||||
Pages = new BookPageInfo[20];
|
||||
Pages = new BookPageInfo[20];
|
||||
|
||||
for (var i = 0; i < Pages.Length; ++i)
|
||||
{
|
||||
Pages[i] = new BookPageInfo();
|
||||
}
|
||||
for (var i = 0; i < Pages.Length; ++i)
|
||||
{
|
||||
Pages[i] = new BookPageInfo();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class BookPacketTests : IClassFixture<ServerFixture>
|
||||
[Collection("Sequential UOContent Tests")]
|
||||
public class BookPacketTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("🅵🅰🅽🅲🆈 🆃🅴🆇🆃 Author", "🅵🅰🅽🅲🆈 🆃🅴🆇🆃 Title")]
|
||||
public void TestBookCover(string author, string title)
|
||||
{
|
||||
var m = new Mobile((Serial)0x1);
|
||||
m.DefaultMobileInit();
|
||||
var m = new Mobile((Serial)0x1);
|
||||
m.DefaultMobileInit();
|
||||
|
||||
Serial serial = (Serial)0x1001;
|
||||
var book = new TestBook(serial) { Author = author, Title = title };
|
||||
Serial serial = (Serial)0x1001;
|
||||
var book = new TestBook(serial) { Author = author, Title = title };
|
||||
|
||||
var expected = new BookHeader(m, book).Compile();
|
||||
var expected = new BookHeader(m, book).Compile();
|
||||
|
||||
var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendBookCover(m, book);
|
||||
var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendBookCover(m, book);
|
||||
|
||||
var result = ns.SendPipe.Reader.AvailableToRead();
|
||||
AssertThat.Equal(result, expected);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestBookContent()
|
||||
{
|
||||
var m = new Mobile((Serial)0x1);
|
||||
m.DefaultMobileInit();
|
||||
var m = new Mobile((Serial)0x1);
|
||||
m.DefaultMobileInit();
|
||||
|
||||
Serial serial = (Serial)0x1001;
|
||||
var book = new TestBook(serial) { Author = "Some Author", Title = "Some Title" };
|
||||
book.Pages[0].Lines = new[]
|
||||
{
|
||||
"Some books start with actual content",
|
||||
"This book does not have any actual content",
|
||||
"Instead it has several pages of useless text"
|
||||
};
|
||||
Serial serial = (Serial)0x1001;
|
||||
var book = new TestBook(serial) { Author = "Some Author", Title = "Some Title" };
|
||||
book.Pages[0].Lines = new[]
|
||||
{
|
||||
"Some books start with actual content",
|
||||
"This book does not have any actual content",
|
||||
"Instead it has several pages of useless text"
|
||||
};
|
||||
|
||||
book.Pages[1].Lines = new[]
|
||||
{
|
||||
"Another page exists but this page:",
|
||||
"Has lots of: 🅵🅰🅽🅲🆈 🆃🅴🆇🆃",
|
||||
"And just more: 🅵🅰🅽🅲🆈 🆃🅴🆇🆃",
|
||||
"So everyone can read: 🅵🅰🅽🅲🆈 🆃🅴🆇🆃"
|
||||
};
|
||||
book.Pages[1].Lines = new[]
|
||||
{
|
||||
"Another page exists but this page:",
|
||||
"Has lots of: 🅵🅰🅽🅲🆈 🆃🅴🆇🆃",
|
||||
"And just more: 🅵🅰🅽🅲🆈 🆃🅴🆇🆃",
|
||||
"So everyone can read: 🅵🅰🅽🅲🆈 🆃🅴🆇🆃"
|
||||
};
|
||||
|
||||
book.Pages[2].Lines = new[]
|
||||
{
|
||||
"The end"
|
||||
};
|
||||
book.Pages[2].Lines = new[]
|
||||
{
|
||||
"The end"
|
||||
};
|
||||
|
||||
var expected = new BookPageDetails(book).Compile();
|
||||
var expected = new BookPageDetails(book).Compile();
|
||||
|
||||
var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendBookContent(book);
|
||||
var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendBookContent(book);
|
||||
|
||||
var result = ns.SendPipe.Reader.AvailableToRead();
|
||||
AssertThat.Equal(result, expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,52 +7,52 @@ public sealed class BookPageDetails : Packet
|
|||
{
|
||||
public BookPageDetails(BaseBook book) : base(0x66)
|
||||
{
|
||||
EnsureCapacity(256);
|
||||
EnsureCapacity(256);
|
||||
|
||||
Stream.Write(book.Serial);
|
||||
Stream.Write((ushort)book.PagesCount);
|
||||
Stream.Write(book.Serial);
|
||||
Stream.Write((ushort)book.PagesCount);
|
||||
|
||||
for (var i = 0; i < book.PagesCount; ++i)
|
||||
for (var i = 0; i < book.PagesCount; ++i)
|
||||
{
|
||||
var page = book.Pages[i];
|
||||
|
||||
Stream.Write((ushort)(i + 1));
|
||||
Stream.Write((ushort)page.Lines.Length);
|
||||
|
||||
for (var j = 0; j < page.Lines.Length; ++j)
|
||||
{
|
||||
var page = book.Pages[i];
|
||||
var buffer = page.Lines[j].GetBytesUtf8();
|
||||
|
||||
Stream.Write((ushort)(i + 1));
|
||||
Stream.Write((ushort)page.Lines.Length);
|
||||
|
||||
for (var j = 0; j < page.Lines.Length; ++j)
|
||||
{
|
||||
var buffer = page.Lines[j].GetBytesUtf8();
|
||||
|
||||
Stream.Write(buffer, 0, buffer.Length);
|
||||
Stream.Write((byte)0);
|
||||
}
|
||||
Stream.Write(buffer, 0, buffer.Length);
|
||||
Stream.Write((byte)0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class BookHeader : Packet
|
||||
{
|
||||
public BookHeader(Mobile from, BaseBook book) : base(0xD4)
|
||||
{
|
||||
var title = book.Title ?? "";
|
||||
var author = book.Author ?? "";
|
||||
var title = book.Title ?? "";
|
||||
var author = book.Author ?? "";
|
||||
|
||||
var titleBuffer = title.GetBytesUtf8();
|
||||
var authorBuffer = author.GetBytesUtf8();
|
||||
var titleBuffer = title.GetBytesUtf8();
|
||||
var authorBuffer = author.GetBytesUtf8();
|
||||
|
||||
EnsureCapacity(15 + titleBuffer.Length + authorBuffer.Length);
|
||||
EnsureCapacity(15 + titleBuffer.Length + authorBuffer.Length);
|
||||
|
||||
Stream.Write(book.Serial);
|
||||
Stream.Write(true);
|
||||
Stream.Write(book.Writable && from.InRange(book.GetWorldLocation(), 1));
|
||||
Stream.Write((ushort)book.PagesCount);
|
||||
Stream.Write(book.Serial);
|
||||
Stream.Write(true);
|
||||
Stream.Write(book.Writable && from.InRange(book.GetWorldLocation(), 1));
|
||||
Stream.Write((ushort)book.PagesCount);
|
||||
|
||||
Stream.Write((ushort)(titleBuffer.Length + 1));
|
||||
Stream.Write(titleBuffer, 0, titleBuffer.Length);
|
||||
Stream.Write((byte)0); // terminate
|
||||
Stream.Write((ushort)(titleBuffer.Length + 1));
|
||||
Stream.Write(titleBuffer, 0, titleBuffer.Length);
|
||||
Stream.Write((byte)0); // terminate
|
||||
|
||||
Stream.Write((ushort)(authorBuffer.Length + 1));
|
||||
Stream.Write(authorBuffer, 0, authorBuffer.Length);
|
||||
Stream.Write((byte)0); // terminate
|
||||
}
|
||||
}
|
||||
Stream.Write((ushort)(authorBuffer.Length + 1));
|
||||
Stream.Write(authorBuffer, 0, authorBuffer.Length);
|
||||
Stream.Write((byte)0); // terminate
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ using Xunit;
|
|||
|
||||
namespace UOContent.Tests;
|
||||
|
||||
[Collection("Sequential Tests")]
|
||||
public class BulletinBoardPacketTests : IClassFixture<ServerFixture>
|
||||
[Collection("Sequential UOContent Tests")]
|
||||
public class BulletinBoardPacketTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("Test Name")]
|
||||
|
|
@ -16,16 +16,16 @@ public class BulletinBoardPacketTests : IClassFixture<ServerFixture>
|
|||
[InlineData("🅵🅰🅽🅲🆈 🆃🅴🆇🆃")]
|
||||
public void TestSendBBDisplayBoard(string boardName)
|
||||
{
|
||||
var bb = new TestBulletinBoard(0x234) { BoardName = boardName };
|
||||
var bb = new TestBulletinBoard(0x234) { BoardName = boardName };
|
||||
|
||||
var expected = new BBDisplayBoard(bb).Compile();
|
||||
var expected = new BBDisplayBoard(bb).Compile();
|
||||
|
||||
var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendBBDisplayBoard(bb);
|
||||
var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendBBDisplayBoard(bb);
|
||||
|
||||
var result = ns.SendPipe.Reader.AvailableToRead();
|
||||
AssertThat.Equal(result, expected);
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("The Subject", false, "First Line", "Second Line", "Third Line")]
|
||||
|
|
@ -36,32 +36,32 @@ public class BulletinBoardPacketTests : IClassFixture<ServerFixture>
|
|||
[InlineData("🅵🅰🅽🅲🆈 🆃🅴🆇🆃", true, "First Line", "Second Line")]
|
||||
public void TestSendBBHeaderMessage(string subject, bool content, params string[] lines)
|
||||
{
|
||||
var poster = new Mobile((Serial)0x1024u) { Name = "Kamron" };
|
||||
poster.DefaultMobileInit();
|
||||
var poster = new Mobile((Serial)0x1024u) { Name = "Kamron" };
|
||||
poster.DefaultMobileInit();
|
||||
|
||||
var bb = new TestBulletinBoard(0x234);
|
||||
bb.PostMessage(poster, null, subject, lines);
|
||||
var bb = new TestBulletinBoard(0x234);
|
||||
bb.PostMessage(poster, null, subject, lines);
|
||||
|
||||
var msg = bb.Items[0] as BulletinMessage;
|
||||
var msg = bb.Items[0] as BulletinMessage;
|
||||
|
||||
var expected = (content ?
|
||||
(Packet)new BBMessageContent(bb, msg) : new BBMessageHeader(bb, msg)).Compile();
|
||||
var expected = (content ?
|
||||
(Packet)new BBMessageContent(bb, msg) : new BBMessageHeader(bb, msg)).Compile();
|
||||
|
||||
var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendBBMessage(bb, msg, content);
|
||||
var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendBBMessage(bb, msg, content);
|
||||
|
||||
var result = ns.SendPipe.Reader.AvailableToRead();
|
||||
AssertThat.Equal(result, expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class TestBulletinBoard : BaseBulletinBoard
|
||||
{
|
||||
public TestBulletinBoard(int itemID) : base(itemID)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public TestBulletinBoard(Serial serial) : base(serial)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,149 +1,148 @@
|
|||
using Server.Items;
|
||||
using Server.Text;
|
||||
|
||||
namespace Server.Network
|
||||
namespace Server.Network;
|
||||
|
||||
public class BBDisplayBoard : Packet
|
||||
{
|
||||
public class BBDisplayBoard : Packet
|
||||
public BBDisplayBoard(BaseBulletinBoard board) : base(0x71)
|
||||
{
|
||||
public BBDisplayBoard(BaseBulletinBoard board) : base(0x71)
|
||||
EnsureCapacity(38);
|
||||
|
||||
var buffer = (board.BoardName ?? "").GetBytesUtf8();
|
||||
|
||||
Stream.Write((byte)0x00); // Packet ID
|
||||
Stream.Write(board.Serial); // Bulletin board serial
|
||||
|
||||
// Bulletin board name
|
||||
if (buffer.Length >= 29)
|
||||
{
|
||||
EnsureCapacity(38);
|
||||
|
||||
var buffer = (board.BoardName ?? "").GetBytesUtf8();
|
||||
|
||||
Stream.Write((byte)0x00); // Packet ID
|
||||
Stream.Write(board.Serial); // Bulletin board serial
|
||||
|
||||
// Bulletin board name
|
||||
if (buffer.Length >= 29)
|
||||
{
|
||||
Stream.Write(buffer, 0, 29);
|
||||
Stream.Write((byte)0);
|
||||
}
|
||||
else
|
||||
{
|
||||
Stream.Write(buffer, 0, buffer.Length);
|
||||
Stream.Fill(30 - buffer.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class BBMessageHeader : Packet
|
||||
{
|
||||
public BBMessageHeader(BaseBulletinBoard board, BulletinMessage msg) : base(0x71)
|
||||
{
|
||||
var poster = SafeString(msg.PostedName);
|
||||
var subject = SafeString(msg.Subject);
|
||||
var time = SafeString(msg.GetTimeAsString());
|
||||
|
||||
EnsureCapacity(22 + poster.Length + subject.Length + time.Length);
|
||||
|
||||
Stream.Write((byte)0x01); // Packet ID
|
||||
Stream.Write(board.Serial); // Bulletin board serial
|
||||
Stream.Write(msg.Serial); // Message serial
|
||||
|
||||
Stream.Write(msg.Thread?.Serial ?? Serial.Zero); // Thread serial--parent
|
||||
|
||||
WriteString(poster);
|
||||
WriteString(subject);
|
||||
WriteString(time);
|
||||
}
|
||||
|
||||
public void WriteString(string v)
|
||||
{
|
||||
var buffer = v.GetBytesUtf8();
|
||||
var len = buffer.Length + 1;
|
||||
|
||||
if (len > 255)
|
||||
{
|
||||
len = 255;
|
||||
}
|
||||
|
||||
Stream.Write((byte)len);
|
||||
Stream.Write(buffer, 0, len - 1);
|
||||
Stream.Write(buffer, 0, 29);
|
||||
Stream.Write((byte)0);
|
||||
}
|
||||
|
||||
public string SafeString(string v) => v ?? string.Empty;
|
||||
}
|
||||
|
||||
public class BBMessageContent : Packet
|
||||
{
|
||||
public BBMessageContent(BaseBulletinBoard board, BulletinMessage msg) : base(0x71)
|
||||
else
|
||||
{
|
||||
var poster = SafeString(msg.PostedName);
|
||||
var subject = SafeString(msg.Subject);
|
||||
var time = SafeString(msg.GetTimeAsString());
|
||||
|
||||
EnsureCapacity(22 + poster.Length + subject.Length + time.Length);
|
||||
|
||||
Stream.Write((byte)0x02); // Packet ID
|
||||
Stream.Write(board.Serial); // Bulletin board serial
|
||||
Stream.Write(msg.Serial); // Message serial
|
||||
|
||||
WriteString(poster);
|
||||
WriteString(subject);
|
||||
WriteString(time);
|
||||
|
||||
Stream.Write((short)msg.PostedBody);
|
||||
Stream.Write((short)msg.PostedHue);
|
||||
|
||||
var len = msg.PostedEquip.Length;
|
||||
|
||||
if (len > 255)
|
||||
{
|
||||
len = 255;
|
||||
}
|
||||
|
||||
Stream.Write((byte)len);
|
||||
|
||||
for (var i = 0; i < len; ++i)
|
||||
{
|
||||
var eq = msg.PostedEquip[i];
|
||||
|
||||
Stream.Write((short)eq._itemID);
|
||||
Stream.Write((short)eq._hue);
|
||||
}
|
||||
|
||||
len = msg.Lines.Length;
|
||||
|
||||
if (len > 255)
|
||||
{
|
||||
len = 255;
|
||||
}
|
||||
|
||||
Stream.Write((byte)len);
|
||||
|
||||
for (var i = 0; i < len; ++i)
|
||||
{
|
||||
WriteString(msg.Lines[i], true);
|
||||
}
|
||||
Stream.Write(buffer, 0, buffer.Length);
|
||||
Stream.Fill(30 - buffer.Length);
|
||||
}
|
||||
|
||||
public void WriteString(string v, bool padding = false)
|
||||
{
|
||||
var buffer = v.GetBytesUtf8();
|
||||
var tail = padding ? 2 : 1;
|
||||
var len = buffer.Length + tail;
|
||||
|
||||
if (len > 255)
|
||||
{
|
||||
len = 255;
|
||||
}
|
||||
|
||||
Stream.Write((byte)len);
|
||||
Stream.Write(buffer, 0, len - tail);
|
||||
|
||||
if (padding)
|
||||
{
|
||||
Stream.Write((short)0); // padding compensates for a client bug
|
||||
}
|
||||
else
|
||||
{
|
||||
Stream.Write((byte)0);
|
||||
}
|
||||
}
|
||||
|
||||
public string SafeString(string v) => v ?? string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public class BBMessageHeader : Packet
|
||||
{
|
||||
public BBMessageHeader(BaseBulletinBoard board, BulletinMessage msg) : base(0x71)
|
||||
{
|
||||
var poster = SafeString(msg.PostedName);
|
||||
var subject = SafeString(msg.Subject);
|
||||
var time = SafeString(msg.GetTimeAsString());
|
||||
|
||||
EnsureCapacity(22 + poster.Length + subject.Length + time.Length);
|
||||
|
||||
Stream.Write((byte)0x01); // Packet ID
|
||||
Stream.Write(board.Serial); // Bulletin board serial
|
||||
Stream.Write(msg.Serial); // Message serial
|
||||
|
||||
Stream.Write(msg.Thread?.Serial ?? Serial.Zero); // Thread serial--parent
|
||||
|
||||
WriteString(poster);
|
||||
WriteString(subject);
|
||||
WriteString(time);
|
||||
}
|
||||
|
||||
public void WriteString(string v)
|
||||
{
|
||||
var buffer = v.GetBytesUtf8();
|
||||
var len = buffer.Length + 1;
|
||||
|
||||
if (len > 255)
|
||||
{
|
||||
len = 255;
|
||||
}
|
||||
|
||||
Stream.Write((byte)len);
|
||||
Stream.Write(buffer, 0, len - 1);
|
||||
Stream.Write((byte)0);
|
||||
}
|
||||
|
||||
public string SafeString(string v) => v ?? string.Empty;
|
||||
}
|
||||
|
||||
public class BBMessageContent : Packet
|
||||
{
|
||||
public BBMessageContent(BaseBulletinBoard board, BulletinMessage msg) : base(0x71)
|
||||
{
|
||||
var poster = SafeString(msg.PostedName);
|
||||
var subject = SafeString(msg.Subject);
|
||||
var time = SafeString(msg.GetTimeAsString());
|
||||
|
||||
EnsureCapacity(22 + poster.Length + subject.Length + time.Length);
|
||||
|
||||
Stream.Write((byte)0x02); // Packet ID
|
||||
Stream.Write(board.Serial); // Bulletin board serial
|
||||
Stream.Write(msg.Serial); // Message serial
|
||||
|
||||
WriteString(poster);
|
||||
WriteString(subject);
|
||||
WriteString(time);
|
||||
|
||||
Stream.Write((short)msg.PostedBody);
|
||||
Stream.Write((short)msg.PostedHue);
|
||||
|
||||
var len = msg.PostedEquip.Length;
|
||||
|
||||
if (len > 255)
|
||||
{
|
||||
len = 255;
|
||||
}
|
||||
|
||||
Stream.Write((byte)len);
|
||||
|
||||
for (var i = 0; i < len; ++i)
|
||||
{
|
||||
var eq = msg.PostedEquip[i];
|
||||
|
||||
Stream.Write((short)eq._itemID);
|
||||
Stream.Write((short)eq._hue);
|
||||
}
|
||||
|
||||
len = msg.Lines.Length;
|
||||
|
||||
if (len > 255)
|
||||
{
|
||||
len = 255;
|
||||
}
|
||||
|
||||
Stream.Write((byte)len);
|
||||
|
||||
for (var i = 0; i < len; ++i)
|
||||
{
|
||||
WriteString(msg.Lines[i], true);
|
||||
}
|
||||
}
|
||||
|
||||
public void WriteString(string v, bool padding = false)
|
||||
{
|
||||
var buffer = v.GetBytesUtf8();
|
||||
var tail = padding ? 2 : 1;
|
||||
var len = buffer.Length + tail;
|
||||
|
||||
if (len > 255)
|
||||
{
|
||||
len = 255;
|
||||
}
|
||||
|
||||
Stream.Write((byte)len);
|
||||
Stream.Write(buffer, 0, len - tail);
|
||||
|
||||
if (padding)
|
||||
{
|
||||
Stream.Write((short)0); // padding compensates for a client bug
|
||||
}
|
||||
else
|
||||
{
|
||||
Stream.Write((byte)0);
|
||||
}
|
||||
}
|
||||
|
||||
public string SafeString(string v) => v ?? string.Empty;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,42 +6,42 @@ using Xunit;
|
|||
|
||||
namespace UOContent.Tests;
|
||||
|
||||
[Collection("Sequential Tests")]
|
||||
public class MahjongPacketTests : IClassFixture<ServerFixture>
|
||||
[Collection("Sequential UOContent Tests")]
|
||||
public class MahjongPacketTests
|
||||
{
|
||||
[Fact]
|
||||
public void TestMahjongJoinGame()
|
||||
{
|
||||
Serial game = (Serial)0x1024u;
|
||||
Serial game = (Serial)0x1024u;
|
||||
|
||||
var expected = new MahjongJoinGame(game).Compile();
|
||||
var expected = new MahjongJoinGame(game).Compile();
|
||||
|
||||
var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendMahjongJoinGame(game);
|
||||
var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendMahjongJoinGame(game);
|
||||
|
||||
var result = ns.SendPipe.Reader.AvailableToRead();
|
||||
AssertThat.Equal(result, expected);
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(true)]
|
||||
[InlineData(false)]
|
||||
public void TestMahjongPlayersInfo(bool showScores)
|
||||
{
|
||||
var m = new Mobile((Serial)0x1);
|
||||
m.DefaultMobileInit();
|
||||
var m = new Mobile((Serial)0x1);
|
||||
m.DefaultMobileInit();
|
||||
|
||||
var game = new MahjongGame { ShowScores = showScores };
|
||||
game.Players.Join(m);
|
||||
var game = new MahjongGame { ShowScores = showScores };
|
||||
game.Players.Join(m);
|
||||
|
||||
var expected = new MahjongPlayersInfo(game, m).Compile();
|
||||
var expected = new MahjongPlayersInfo(game, m).Compile();
|
||||
|
||||
var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendMahjongPlayersInfo(game, m);
|
||||
var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendMahjongPlayersInfo(game, m);
|
||||
|
||||
var result = ns.SendPipe.Reader.AvailableToRead();
|
||||
AssertThat.Equal(result, expected);
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(true, true)]
|
||||
|
|
@ -50,68 +50,68 @@ public class MahjongPacketTests : IClassFixture<ServerFixture>
|
|||
[InlineData(false, false)]
|
||||
public void TestMahjongGeneralInfo(bool showScores, bool spectatorVision)
|
||||
{
|
||||
var game = new MahjongGame { ShowScores = showScores, SpectatorVision = spectatorVision};
|
||||
var game = new MahjongGame { ShowScores = showScores, SpectatorVision = spectatorVision};
|
||||
|
||||
var expected = new MahjongGeneralInfo(game).Compile();
|
||||
var expected = new MahjongGeneralInfo(game).Compile();
|
||||
|
||||
var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendMahjongGeneralInfo(game);
|
||||
var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendMahjongGeneralInfo(game);
|
||||
|
||||
var result = ns.SendPipe.Reader.AvailableToRead();
|
||||
AssertThat.Equal(result, expected);
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(true)]
|
||||
[InlineData(false)]
|
||||
public void TestMahjongTilesInfo(bool spectatorVision)
|
||||
{
|
||||
var m = new Mobile((Serial)0x1);
|
||||
m.DefaultMobileInit();
|
||||
var m = new Mobile((Serial)0x1);
|
||||
m.DefaultMobileInit();
|
||||
|
||||
var game = new MahjongGame { SpectatorVision = spectatorVision };
|
||||
game.Players.Join(m);
|
||||
var game = new MahjongGame { SpectatorVision = spectatorVision };
|
||||
game.Players.Join(m);
|
||||
|
||||
var expected = new MahjongTilesInfo(game, m).Compile();
|
||||
var expected = new MahjongTilesInfo(game, m).Compile();
|
||||
|
||||
var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendMahjongTilesInfo(game, m);
|
||||
var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendMahjongTilesInfo(game, m);
|
||||
|
||||
var result = ns.SendPipe.Reader.AvailableToRead();
|
||||
AssertThat.Equal(result, expected);
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(true)]
|
||||
[InlineData(false)]
|
||||
public void TestMahjongTileInfo(bool spectatorVision)
|
||||
{
|
||||
var m = new Mobile((Serial)0x1);
|
||||
m.DefaultMobileInit();
|
||||
var m = new Mobile((Serial)0x1);
|
||||
m.DefaultMobileInit();
|
||||
|
||||
var game = new MahjongGame { SpectatorVision = spectatorVision };
|
||||
game.Players.Join(m);
|
||||
var game = new MahjongGame { SpectatorVision = spectatorVision };
|
||||
game.Players.Join(m);
|
||||
|
||||
var expected = new MahjongTileInfo(game.Tiles[0], m).Compile();
|
||||
var expected = new MahjongTileInfo(game.Tiles[0], m).Compile();
|
||||
|
||||
var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendMahjongTileInfo(game.Tiles[0], m);
|
||||
var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendMahjongTileInfo(game.Tiles[0], m);
|
||||
|
||||
var result = ns.SendPipe.Reader.AvailableToRead();
|
||||
AssertThat.Equal(result, expected);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestMahjongRelieve()
|
||||
{
|
||||
Serial game = (Serial)0x1024u;
|
||||
Serial game = (Serial)0x1024u;
|
||||
|
||||
var expected = new MahjongRelieve(game).Compile();
|
||||
var expected = new MahjongRelieve(game).Compile();
|
||||
|
||||
var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendMahjongRelieve(game);
|
||||
var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendMahjongRelieve(game);
|
||||
|
||||
var result = ns.SendPipe.Reader.AvailableToRead();
|
||||
AssertThat.Equal(result, expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,176 +7,132 @@ public sealed class MahjongJoinGame : Packet
|
|||
{
|
||||
public MahjongJoinGame(Serial game) : base(0xDA)
|
||||
{
|
||||
EnsureCapacity(9);
|
||||
EnsureCapacity(9);
|
||||
|
||||
Stream.Write(game);
|
||||
Stream.Write((byte)0);
|
||||
Stream.Write((byte)0x19);
|
||||
}
|
||||
Stream.Write(game);
|
||||
Stream.Write((byte)0);
|
||||
Stream.Write((byte)0x19);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class MahjongPlayersInfo : Packet
|
||||
{
|
||||
public MahjongPlayersInfo(MahjongGame game, Mobile to) : base(0xDA)
|
||||
{
|
||||
var players = game.Players;
|
||||
var players = game.Players;
|
||||
|
||||
EnsureCapacity(11 + 45 * players.Seats);
|
||||
EnsureCapacity(11 + 45 * players.Seats);
|
||||
|
||||
Stream.Write(game.Serial);
|
||||
Stream.Write((byte)0);
|
||||
Stream.Write((byte)0x2);
|
||||
Stream.Write(game.Serial);
|
||||
Stream.Write((byte)0);
|
||||
Stream.Write((byte)0x2);
|
||||
|
||||
Stream.Write((byte)0);
|
||||
Stream.Write((byte)players.Seats);
|
||||
Stream.Write((byte)0);
|
||||
Stream.Write((byte)players.Seats);
|
||||
|
||||
var n = 0;
|
||||
for (var i = 0; i < players.Seats; i++)
|
||||
var n = 0;
|
||||
for (var i = 0; i < players.Seats; i++)
|
||||
{
|
||||
var mobile = players.GetPlayer(i);
|
||||
|
||||
if (mobile != null)
|
||||
{
|
||||
var mobile = players.GetPlayer(i);
|
||||
Stream.Write(mobile.Serial);
|
||||
Stream.Write(players.DealerPosition == i ? (byte)0x1 : (byte)0x2);
|
||||
Stream.Write((byte)i);
|
||||
|
||||
if (mobile != null)
|
||||
if (game.ShowScores || mobile == to)
|
||||
{
|
||||
Stream.Write(mobile.Serial);
|
||||
Stream.Write(players.DealerPosition == i ? (byte)0x1 : (byte)0x2);
|
||||
Stream.Write((byte)i);
|
||||
|
||||
if (game.ShowScores || mobile == to)
|
||||
{
|
||||
Stream.Write(players.GetScore(i));
|
||||
}
|
||||
else
|
||||
{
|
||||
Stream.Write(0);
|
||||
}
|
||||
|
||||
Stream.Write((short)0);
|
||||
Stream.Write((byte)0);
|
||||
|
||||
Stream.Write(players.IsPublic(i));
|
||||
|
||||
Stream.WriteAsciiFixed(mobile.Name, 30);
|
||||
Stream.Write(!players.IsInGamePlayer(i));
|
||||
|
||||
n++;
|
||||
Stream.Write(players.GetScore(i));
|
||||
}
|
||||
else if (game.ShowScores)
|
||||
else
|
||||
{
|
||||
Stream.Write(0);
|
||||
Stream.Write((byte)0x2);
|
||||
Stream.Write((byte)i);
|
||||
|
||||
Stream.Write(players.GetScore(i));
|
||||
|
||||
Stream.Write((short)0);
|
||||
Stream.Write((byte)0);
|
||||
|
||||
Stream.Write(players.IsPublic(i));
|
||||
|
||||
Stream.WriteAsciiFixed("", 30);
|
||||
Stream.Write(true);
|
||||
|
||||
n++;
|
||||
}
|
||||
}
|
||||
|
||||
if (n != players.Seats)
|
||||
Stream.Write((short)0);
|
||||
Stream.Write((byte)0);
|
||||
|
||||
Stream.Write(players.IsPublic(i));
|
||||
|
||||
Stream.WriteAsciiFixed(mobile.Name, 30);
|
||||
Stream.Write(!players.IsInGamePlayer(i));
|
||||
|
||||
n++;
|
||||
}
|
||||
else if (game.ShowScores)
|
||||
{
|
||||
Stream.Seek(10, SeekOrigin.Begin);
|
||||
Stream.Write((byte)n);
|
||||
Stream.Write(0);
|
||||
Stream.Write((byte)0x2);
|
||||
Stream.Write((byte)i);
|
||||
|
||||
Stream.Write(players.GetScore(i));
|
||||
|
||||
Stream.Write((short)0);
|
||||
Stream.Write((byte)0);
|
||||
|
||||
Stream.Write(players.IsPublic(i));
|
||||
|
||||
Stream.WriteAsciiFixed("", 30);
|
||||
Stream.Write(true);
|
||||
|
||||
n++;
|
||||
}
|
||||
}
|
||||
|
||||
if (n != players.Seats)
|
||||
{
|
||||
Stream.Seek(10, SeekOrigin.Begin);
|
||||
Stream.Write((byte)n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class MahjongGeneralInfo : Packet
|
||||
{
|
||||
public MahjongGeneralInfo(MahjongGame game) : base(0xDA)
|
||||
{
|
||||
EnsureCapacity(13);
|
||||
EnsureCapacity(13);
|
||||
|
||||
Stream.Write(game.Serial);
|
||||
Stream.Write((byte)0);
|
||||
Stream.Write((byte)0x5);
|
||||
Stream.Write(game.Serial);
|
||||
Stream.Write((byte)0);
|
||||
Stream.Write((byte)0x5);
|
||||
|
||||
Stream.Write((short)0);
|
||||
Stream.Write((byte)0);
|
||||
Stream.Write((short)0);
|
||||
Stream.Write((byte)0);
|
||||
|
||||
Stream.Write((byte)((game.ShowScores ? 0x1 : 0x0) | (game.SpectatorVision ? 0x2 : 0x0)));
|
||||
Stream.Write((byte)((game.ShowScores ? 0x1 : 0x0) | (game.SpectatorVision ? 0x2 : 0x0)));
|
||||
|
||||
Stream.Write((byte)game.Dices.First);
|
||||
Stream.Write((byte)game.Dices.Second);
|
||||
Stream.Write((byte)game.Dices.First);
|
||||
Stream.Write((byte)game.Dices.Second);
|
||||
|
||||
Stream.Write((byte)game.DealerIndicator.Wind);
|
||||
Stream.Write((short)game.DealerIndicator.Position.Y);
|
||||
Stream.Write((short)game.DealerIndicator.Position.X);
|
||||
Stream.Write((byte)game.DealerIndicator.Direction);
|
||||
Stream.Write((byte)game.DealerIndicator.Wind);
|
||||
Stream.Write((short)game.DealerIndicator.Position.Y);
|
||||
Stream.Write((short)game.DealerIndicator.Position.X);
|
||||
Stream.Write((byte)game.DealerIndicator.Direction);
|
||||
|
||||
Stream.Write((short)game.WallBreakIndicator.Position.Y);
|
||||
Stream.Write((short)game.WallBreakIndicator.Position.X);
|
||||
}
|
||||
Stream.Write((short)game.WallBreakIndicator.Position.Y);
|
||||
Stream.Write((short)game.WallBreakIndicator.Position.X);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class MahjongTilesInfo : Packet
|
||||
{
|
||||
public MahjongTilesInfo(MahjongGame game, Mobile to) : base(0xDA)
|
||||
{
|
||||
var tiles = game.Tiles;
|
||||
var players = game.Players;
|
||||
var tiles = game.Tiles;
|
||||
var players = game.Players;
|
||||
|
||||
EnsureCapacity(11 + 9 * tiles.Length);
|
||||
EnsureCapacity(11 + 9 * tiles.Length);
|
||||
|
||||
Stream.Write(game.Serial);
|
||||
Stream.Write((byte)0);
|
||||
Stream.Write((byte)0x4);
|
||||
Stream.Write(game.Serial);
|
||||
Stream.Write((byte)0);
|
||||
Stream.Write((byte)0x4);
|
||||
|
||||
Stream.Write((short)tiles.Length);
|
||||
|
||||
foreach (var tile in tiles)
|
||||
{
|
||||
Stream.Write((byte)tile.Number);
|
||||
|
||||
if (tile.Flipped)
|
||||
{
|
||||
var hand = tile.Dimensions.GetHandArea();
|
||||
|
||||
if (hand < 0 || players.IsPublic(hand) || players.GetPlayer(hand) == to ||
|
||||
game.SpectatorVision && players.IsSpectator(to))
|
||||
{
|
||||
Stream.Write((byte)tile.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
Stream.Write((byte)0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Stream.Write((byte)0);
|
||||
}
|
||||
|
||||
Stream.Write((short)tile.Position.Y);
|
||||
Stream.Write((short)tile.Position.X);
|
||||
Stream.Write((byte)tile.StackLevel);
|
||||
Stream.Write((byte)tile.Direction);
|
||||
|
||||
Stream.Write(tile.Flipped ? (byte)0x10 : (byte)0x0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class MahjongTileInfo : Packet
|
||||
{
|
||||
public MahjongTileInfo(MahjongTile tile, Mobile to) : base(0xDA)
|
||||
{
|
||||
var game = tile.Game;
|
||||
var players = game.Players;
|
||||
|
||||
EnsureCapacity(18);
|
||||
|
||||
Stream.Write(tile.Game.Serial);
|
||||
Stream.Write((byte)0);
|
||||
Stream.Write((byte)0x3);
|
||||
Stream.Write((short)tiles.Length);
|
||||
|
||||
foreach (var tile in tiles)
|
||||
{
|
||||
Stream.Write((byte)tile.Number);
|
||||
|
||||
if (tile.Flipped)
|
||||
|
|
@ -205,16 +161,60 @@ public sealed class MahjongTileInfo : Packet
|
|||
|
||||
Stream.Write(tile.Flipped ? (byte)0x10 : (byte)0x0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class MahjongTileInfo : Packet
|
||||
{
|
||||
public MahjongTileInfo(MahjongTile tile, Mobile to) : base(0xDA)
|
||||
{
|
||||
var game = tile.Game;
|
||||
var players = game.Players;
|
||||
|
||||
EnsureCapacity(18);
|
||||
|
||||
Stream.Write(tile.Game.Serial);
|
||||
Stream.Write((byte)0);
|
||||
Stream.Write((byte)0x3);
|
||||
|
||||
Stream.Write((byte)tile.Number);
|
||||
|
||||
if (tile.Flipped)
|
||||
{
|
||||
var hand = tile.Dimensions.GetHandArea();
|
||||
|
||||
if (hand < 0 || players.IsPublic(hand) || players.GetPlayer(hand) == to ||
|
||||
game.SpectatorVision && players.IsSpectator(to))
|
||||
{
|
||||
Stream.Write((byte)tile.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
Stream.Write((byte)0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Stream.Write((byte)0);
|
||||
}
|
||||
|
||||
Stream.Write((short)tile.Position.Y);
|
||||
Stream.Write((short)tile.Position.X);
|
||||
Stream.Write((byte)tile.StackLevel);
|
||||
Stream.Write((byte)tile.Direction);
|
||||
|
||||
Stream.Write(tile.Flipped ? (byte)0x10 : (byte)0x0);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class MahjongRelieve : Packet
|
||||
{
|
||||
public MahjongRelieve(Serial game) : base(0xDA)
|
||||
{
|
||||
EnsureCapacity(9);
|
||||
EnsureCapacity(9);
|
||||
|
||||
Stream.Write(game);
|
||||
Stream.Write((byte)0);
|
||||
Stream.Write((byte)0x1A);
|
||||
}
|
||||
}
|
||||
Stream.Write(game);
|
||||
Stream.Write((byte)0);
|
||||
Stream.Write((byte)0x1A);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,62 +6,62 @@ public sealed class MapDetails : Packet
|
|||
{
|
||||
public MapDetails(MapItem map) : base(0x90, 19)
|
||||
{
|
||||
Stream.Write(map.Serial);
|
||||
Stream.Write((short)0x139D);
|
||||
Stream.Write((short)map.Bounds.Start.X);
|
||||
Stream.Write((short)map.Bounds.Start.Y);
|
||||
Stream.Write((short)map.Bounds.End.X);
|
||||
Stream.Write((short)map.Bounds.End.Y);
|
||||
Stream.Write((short)map.Width);
|
||||
Stream.Write((short)map.Height);
|
||||
}
|
||||
Stream.Write(map.Serial);
|
||||
Stream.Write((short)0x139D);
|
||||
Stream.Write((short)map.Bounds.Start.X);
|
||||
Stream.Write((short)map.Bounds.Start.Y);
|
||||
Stream.Write((short)map.Bounds.End.X);
|
||||
Stream.Write((short)map.Bounds.End.Y);
|
||||
Stream.Write((short)map.Width);
|
||||
Stream.Write((short)map.Height);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class MapDetailsNew : Packet
|
||||
{
|
||||
public MapDetailsNew(MapItem map) : base(0xF5, 21)
|
||||
{
|
||||
Stream.Write(map.Serial);
|
||||
Stream.Write((short)0x139D);
|
||||
Stream.Write((short)map.Bounds.Start.X);
|
||||
Stream.Write((short)map.Bounds.Start.Y);
|
||||
Stream.Write((short)map.Bounds.End.X);
|
||||
Stream.Write((short)map.Bounds.End.Y);
|
||||
Stream.Write((short)map.Width);
|
||||
Stream.Write((short)map.Height);
|
||||
Stream.Write((short)(map.Facet?.MapID ?? 0));
|
||||
}
|
||||
Stream.Write(map.Serial);
|
||||
Stream.Write((short)0x139D);
|
||||
Stream.Write((short)map.Bounds.Start.X);
|
||||
Stream.Write((short)map.Bounds.Start.Y);
|
||||
Stream.Write((short)map.Bounds.End.X);
|
||||
Stream.Write((short)map.Bounds.End.Y);
|
||||
Stream.Write((short)map.Width);
|
||||
Stream.Write((short)map.Height);
|
||||
Stream.Write((short)(map.Facet?.MapID ?? 0));
|
||||
}
|
||||
}
|
||||
|
||||
public class MapCommand : Packet
|
||||
{
|
||||
public MapCommand(MapItem map, int command, int number, int x, int y) : base(0x56, 11)
|
||||
{
|
||||
Stream.Write(map.Serial);
|
||||
Stream.Write((byte)command);
|
||||
Stream.Write((byte)number);
|
||||
Stream.Write((short)x);
|
||||
Stream.Write((short)y);
|
||||
}
|
||||
Stream.Write(map.Serial);
|
||||
Stream.Write((byte)command);
|
||||
Stream.Write((byte)number);
|
||||
Stream.Write((short)x);
|
||||
Stream.Write((short)y);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class MapDisplay : MapCommand
|
||||
{
|
||||
public MapDisplay(MapItem map) : base(map, 5, 0, 0, 0)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class MapAddPin : MapCommand
|
||||
{
|
||||
public MapAddPin(MapItem map, Point2D point) : base(map, 1, 0, point.X, point.Y)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class MapSetEditable : MapCommand
|
||||
{
|
||||
public MapSetEditable(MapItem map, bool editable) : base(map, 7, editable ? 1 : 0, 0, 0)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,26 +7,26 @@ using Xunit;
|
|||
|
||||
namespace UOContent.Tests;
|
||||
|
||||
[Collection("Sequential Tests")]
|
||||
public class TestMapItemPackets : IClassFixture<ServerFixture>
|
||||
[Collection("Sequential UOContent Tests")]
|
||||
public class TestMapItemPackets
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(ProtocolChanges.NewCharacterList)]
|
||||
[InlineData(ProtocolChanges.None)]
|
||||
public void TestSendMapDetails(ProtocolChanges changes)
|
||||
{
|
||||
var mapItem = new MapItem(Map.Trammel);
|
||||
var mapItem = new MapItem(Map.Trammel);
|
||||
|
||||
var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.ProtocolChanges = changes;
|
||||
var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.ProtocolChanges = changes;
|
||||
|
||||
var expected = (ns.NewCharacterList ?
|
||||
(Packet)new MapDetailsNew(mapItem) : new MapDetails(mapItem)).Compile();
|
||||
ns.SendMapDetails(mapItem);
|
||||
var expected = (ns.NewCharacterList ?
|
||||
(Packet)new MapDetailsNew(mapItem) : new MapDetails(mapItem)).Compile();
|
||||
ns.SendMapDetails(mapItem);
|
||||
|
||||
var result = ns.SendPipe.Reader.AvailableToRead();
|
||||
AssertThat.Equal(result, expected);
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(5, 0, 0, 0)]
|
||||
|
|
@ -35,14 +35,14 @@ public class TestMapItemPackets : IClassFixture<ServerFixture>
|
|||
[InlineData(7, 0, 0, 0)]
|
||||
public void TestSendMapCommand(int command, int number, int x, int y)
|
||||
{
|
||||
var mapItem = new MapItem(Map.Trammel);
|
||||
var mapItem = new MapItem(Map.Trammel);
|
||||
|
||||
var expected = new MapCommand(mapItem, command, number, x, y).Compile();
|
||||
var expected = new MapCommand(mapItem, command, number, x, y).Compile();
|
||||
|
||||
var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendMapCommand(mapItem, command, x, y, number > 0);
|
||||
var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendMapCommand(mapItem, command, x, y, number > 0);
|
||||
|
||||
var result = ns.SendPipe.Reader.AvailableToRead();
|
||||
AssertThat.Equal(result, expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,50 +7,50 @@ using Xunit;
|
|||
|
||||
namespace UOContent.Tests;
|
||||
|
||||
[Collection("Sequential Tests")]
|
||||
public class CorpsePacketTests : IClassFixture<ServerFixture>
|
||||
[Collection("Sequential UOContent Tests")]
|
||||
public class CorpsePacketTests
|
||||
{
|
||||
[Fact]
|
||||
public void TestCorpseEquipPacket()
|
||||
{
|
||||
var m = new Mobile((Serial)0x1);
|
||||
m.DefaultMobileInit();
|
||||
var m = new Mobile((Serial)0x1);
|
||||
m.DefaultMobileInit();
|
||||
|
||||
var weapon = new VikingSword();
|
||||
m.EquipItem(weapon);
|
||||
var weapon = new VikingSword();
|
||||
m.EquipItem(weapon);
|
||||
|
||||
var c = new Corpse(m, m.Items);
|
||||
var c = new Corpse(m, m.Items);
|
||||
|
||||
var expected = new CorpseEquip(m, c).Compile();
|
||||
var expected = new CorpseEquip(m, c).Compile();
|
||||
|
||||
var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendCorpseEquip(m, c);
|
||||
var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendCorpseEquip(m, c);
|
||||
|
||||
var result = ns.SendPipe.Reader.AvailableToRead();
|
||||
AssertThat.Equal(result, expected);
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(ProtocolChanges.None)]
|
||||
[InlineData(ProtocolChanges.ContainerGridLines)]
|
||||
public void TestCorpseContainerPacket(ProtocolChanges changes)
|
||||
{
|
||||
var m = new Mobile((Serial)0x1);
|
||||
m.DefaultMobileInit();
|
||||
var m = new Mobile((Serial)0x1);
|
||||
m.DefaultMobileInit();
|
||||
|
||||
var weapon = new VikingSword();
|
||||
m.EquipItem(weapon);
|
||||
var weapon = new VikingSword();
|
||||
m.EquipItem(weapon);
|
||||
|
||||
var c = new Corpse(m, m.Items);
|
||||
var c = new Corpse(m, m.Items);
|
||||
|
||||
var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.ProtocolChanges = changes;
|
||||
var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.ProtocolChanges = changes;
|
||||
|
||||
var expected = (ns.ContainerGridLines ? (Packet)new CorpseContent6017(m, c) : new CorpseContent(m, c)).Compile();
|
||||
var expected = (ns.ContainerGridLines ? (Packet)new CorpseContent6017(m, c) : new CorpseContent(m, c)).Compile();
|
||||
|
||||
ns.SendCorpseContent(m, c);
|
||||
ns.SendCorpseContent(m, c);
|
||||
|
||||
var result = ns.SendPipe.Reader.AvailableToRead();
|
||||
AssertThat.Equal(result, expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,24 +14,24 @@ public class WeaponAbilityPacketTests
|
|||
[InlineData(1000, false)]
|
||||
public void TestSpecialAbility(int abilityId, bool active)
|
||||
{
|
||||
var expected = new ToggleSpecialAbility(abilityId, active).Compile();
|
||||
var expected = new ToggleSpecialAbility(abilityId, active).Compile();
|
||||
|
||||
var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendToggleSpecialAbility(abilityId, active);
|
||||
var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendToggleSpecialAbility(abilityId, active);
|
||||
|
||||
var result = ns.SendPipe.Reader.AvailableToRead();
|
||||
AssertThat.Equal(result, expected);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestClearAbility()
|
||||
{
|
||||
var expected = new ClearWeaponAbility().Compile();
|
||||
var expected = new ClearWeaponAbility().Compile();
|
||||
|
||||
var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendClearWeaponAbility();
|
||||
var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendClearWeaponAbility();
|
||||
|
||||
var result = ns.SendPipe.Reader.AvailableToRead();
|
||||
AssertThat.Equal(result, expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@ public sealed class ToggleSpecialAbility : Packet
|
|||
{
|
||||
public ToggleSpecialAbility(int abilityID, bool active) : base(0xBF)
|
||||
{
|
||||
EnsureCapacity(7);
|
||||
EnsureCapacity(7);
|
||||
|
||||
Stream.Write((short)0x25);
|
||||
Stream.Write((short)0x25);
|
||||
|
||||
Stream.Write((short)abilityID);
|
||||
Stream.Write(active);
|
||||
}
|
||||
Stream.Write((short)abilityID);
|
||||
Stream.Write(active);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ClearWeaponAbility : Packet
|
||||
|
|
@ -21,8 +21,8 @@ public sealed class ClearWeaponAbility : Packet
|
|||
|
||||
public ClearWeaponAbility() : base(0xBF)
|
||||
{
|
||||
EnsureCapacity(5);
|
||||
EnsureCapacity(5);
|
||||
|
||||
Stream.Write((short)0x21);
|
||||
}
|
||||
}
|
||||
Stream.Write((short)0x21);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue