fix(core): Converts corpse packets (#400)

- [X] Converts corpse packets
- [X] Some cleanup
This commit is contained in:
Kamron Batman 2021-01-10 09:53:05 -08:00 • committed by GitHub
parent 764d303543
commit f52e63f320
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 210 additions and 245 deletions

View file

@ -0,0 +1,57 @@
using System;
using Server;
using Server.Items;
using Server.Network;
using Server.Tests;
using Server.Tests.Network;
using Xunit;
namespace UOContent.Tests
{
public class PacketTests : IClassFixture<ServerFixture>
{
[Fact]
public void TestCorpseEquipPacket()
{
var m = new Mobile(0x1);
m.DefaultMobileInit();
var weapon = new VikingSword();
m.EquipItem(weapon);
var c = new Corpse(m, m.Items);
var expected = new CorpseEquip(m, c).Compile();
using var ns = PacketTestUtilities.CreateTestNetState();
ns.SendCorpseEquip(m, c);
var result = ns.SendPipe.Reader.TryRead();
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
}
[Theory]
[InlineData(ProtocolChanges.None)]
[InlineData(ProtocolChanges.ContainerGridLines)]
public void TestCorpseContainerPacket(ProtocolChanges changes)
{
var m = new Mobile(0x1);
m.DefaultMobileInit();
var weapon = new VikingSword();
m.EquipItem(weapon);
var c = new Corpse(m, m.Items);
using var ns = PacketTestUtilities.CreateTestNetState();
ns.ProtocolChanges = changes;
var expected = (ns.ContainerGridLines ? (Packet)new CorpseContent6017(m, c) : new CorpseContent(m, c)).Compile();
ns.SendCorpseContent(m, c);
var result = ns.SendPipe.Reader.TryRead();
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
}
}
}

View file

@ -0,0 +1,213 @@
using System.IO;
using Server;
using Server.Items;
namespace Server.Network
{
public sealed class CorpseEquip : Packet
{
public CorpseEquip(Mobile beholder, Corpse beheld) : base(0x89)
{
var list = beheld.EquipItems;
var count = list.Count;
if (beheld.Hair?.ItemID > 0)
{
count++;
}
if (beheld.FacialHair?.ItemID > 0)
{
count++;
}
EnsureCapacity(8 + count * 5);
Stream.Write(beheld.Serial);
for (var i = 0; i < list.Count; ++i)
{
var item = list[i];
if (!item.Deleted && beholder.CanSee(item) && item.Parent == beheld)
{
Stream.Write((byte)(item.Layer + 1));
Stream.Write(item.Serial);
}
}
if (beheld.Hair?.ItemID > 0)
{
Stream.Write((byte)(Layer.Hair + 1));
Stream.Write(HairInfo.FakeSerial(beheld.Owner.Serial) - 2);
}
if (beheld.FacialHair?.ItemID > 0)
{
Stream.Write((byte)(Layer.FacialHair + 1));
Stream.Write(FacialHairInfo.FakeSerial(beheld.Owner.Serial) - 2);
}
Stream.Write((byte)Layer.Invalid);
}
}
public sealed class CorpseContent : Packet
{
public CorpseContent(Mobile beholder, Corpse beheld)
: base(0x3C)
{
var items = beheld.EquipItems;
var count = items.Count;
if (beheld.Hair?.ItemID > 0)
{
count++;
}
if (beheld.FacialHair?.ItemID > 0)
{
count++;
}
EnsureCapacity(5 + count * 19);
var pos = Stream.Position;
var written = 0;
Stream.Write((ushort)0);
for (var i = 0; i < items.Count; ++i)
{
var child = items[i];
if (!child.Deleted && child.Parent == beheld && beholder.CanSee(child))
{
Stream.Write(child.Serial);
Stream.Write((ushort)child.ItemID);
Stream.Write((byte)0); // signed, itemID offset
Stream.Write((ushort)child.Amount);
Stream.Write((short)child.X);
Stream.Write((short)child.Y);
Stream.Write(beheld.Serial);
Stream.Write((ushort)child.Hue);
++written;
}
}
if (beheld.Hair?.ItemID > 0)
{
Stream.Write(HairInfo.FakeSerial(beheld.Owner.Serial) - 2);
Stream.Write((ushort)beheld.Hair.ItemID);
Stream.Write((byte)0); // signed, itemID offset
Stream.Write((ushort)1);
Stream.Write((short)0);
Stream.Write((short)0);
Stream.Write(beheld.Serial);
Stream.Write((ushort)beheld.Hair.Hue);
++written;
}
if (beheld.FacialHair?.ItemID > 0)
{
Stream.Write(FacialHairInfo.FakeSerial(beheld.Owner.Serial) - 2);
Stream.Write((ushort)beheld.FacialHair.ItemID);
Stream.Write((byte)0); // signed, itemID offset
Stream.Write((ushort)1);
Stream.Write((short)0);
Stream.Write((short)0);
Stream.Write(beheld.Serial);
Stream.Write((ushort)beheld.FacialHair.Hue);
++written;
}
Stream.Seek(pos, SeekOrigin.Begin);
Stream.Write((ushort)written);
}
}
public sealed class CorpseContent6017 : Packet
{
public CorpseContent6017(Mobile beholder, Corpse beheld)
: base(0x3C)
{
var items = beheld.EquipItems;
var count = items.Count;
if (beheld.Hair?.ItemID > 0)
{
count++;
}
if (beheld.FacialHair?.ItemID > 0)
{
count++;
}
EnsureCapacity(5 + count * 20);
var pos = Stream.Position;
var written = 0;
Stream.Write((ushort)0);
for (var i = 0; i < items.Count; ++i)
{
var child = items[i];
if (!child.Deleted && child.Parent == beheld && beholder.CanSee(child))
{
Stream.Write(child.Serial);
Stream.Write((ushort)child.ItemID);
Stream.Write((byte)0); // signed, itemID offset
Stream.Write((ushort)child.Amount);
Stream.Write((short)child.X);
Stream.Write((short)child.Y);
Stream.Write((byte)0); // Grid Location?
Stream.Write(beheld.Serial);
Stream.Write((ushort)child.Hue);
++written;
}
}
if (beheld.Hair?.ItemID > 0)
{
Stream.Write(HairInfo.FakeSerial(beheld.Owner.Serial) - 2);
Stream.Write((ushort)beheld.Hair.ItemID);
Stream.Write((byte)0); // signed, itemID offset
Stream.Write((ushort)1);
Stream.Write((short)0);
Stream.Write((short)0);
Stream.Write((byte)0); // Grid Location?
Stream.Write(beheld.Serial);
Stream.Write((ushort)beheld.Hair.Hue);
++written;
}
if (beheld.FacialHair?.ItemID > 0)
{
Stream.Write(FacialHairInfo.FakeSerial(beheld.Owner.Serial) - 2);
Stream.Write((ushort)beheld.FacialHair.ItemID);
Stream.Write((byte)0); // signed, itemID offset
Stream.Write((ushort)1);
Stream.Write((short)0);
Stream.Write((short)0);
Stream.Write((byte)0); // Grid Location?
Stream.Write(beheld.Serial);
Stream.Write((ushort)beheld.FacialHair.Hue);
++written;
}
Stream.Seek(pos, SeekOrigin.Begin);
Stream.Write((ushort)written);
}
}
}

View file

@ -1,18 +1,3 @@
/*************************************************************************
* ModernUO *
* Copyright 2019-2020 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: ArrowPackets.cs *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*************************************************************************/
namespace Server.Network
{
public sealed class CancelArrow : Packet

View file

@ -1,5 +1,6 @@
using System;
using Server;
using Server.Network;
using Server.Tests;
using Server.Tests.Network;
using Xunit;

View file

@ -1,7 +1,6 @@
using System;
using Server.Network;
namespace Server
namespace Server.Network
{
public sealed class AddBuffPacket : Packet
{