fix(core): Converts corpse packets (#400)
- [X] Converts corpse packets - [X] Some cleanup
This commit is contained in:
parent
764d303543
commit
f52e63f320
9 changed files with 210 additions and 245 deletions
|
|
@ -800,28 +800,14 @@ namespace Server.Items
|
|||
return m_Devourer.Devour(this); // Devour the corpse if it hasn't
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private void SendCorpseContent(NetState ns)
|
||||
{
|
||||
if (ns.ContainerGridLines)
|
||||
{
|
||||
ns.Send(new CorpseContent6017(ns.Mobile, this));
|
||||
}
|
||||
else
|
||||
{
|
||||
ns.Send(new CorpseContent(ns.Mobile, this));
|
||||
}
|
||||
|
||||
ns.Send(new CorpseEquip(ns.Mobile, this));
|
||||
}
|
||||
|
||||
public override void SendInfoTo(NetState ns, ReadOnlySpan<byte> world, Span<byte> opl)
|
||||
public override void SendInfoTo(NetState ns, ReadOnlySpan<byte> world = default, Span<byte> opl = default)
|
||||
{
|
||||
base.SendInfoTo(ns, world, opl);
|
||||
|
||||
if (((Body)Amount).IsHuman && ItemID == 0x2006)
|
||||
{
|
||||
SendCorpseContent(ns);
|
||||
ns.SendCorpseContent(ns.Mobile, this);
|
||||
ns.SendCorpseEquip(ns.Mobile, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
147
Projects/UOContent/Items/Misc/Corpses/CorpsePackets.cs
Normal file
147
Projects/UOContent/Items/Misc/Corpses/CorpsePackets.cs
Normal file
|
|
@ -0,0 +1,147 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright (C) 2019-2021 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: CorpsePackets.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/>. *
|
||||
*************************************************************************/
|
||||
|
||||
using System.Buffers;
|
||||
using System.IO;
|
||||
using Server.Items;
|
||||
|
||||
namespace Server.Network
|
||||
{
|
||||
public static class CorpsePackets
|
||||
{
|
||||
public static void SendCorpseEquip(this NetState ns, Mobile beholder, Corpse beheld)
|
||||
{
|
||||
if (ns == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var list = beheld.EquipItems;
|
||||
|
||||
var maxLength = 8 + (list.Count + 2) * 5;
|
||||
var writer = new SpanWriter(stackalloc byte[maxLength]);
|
||||
writer.Write((byte)0x89);
|
||||
writer.Seek(2, SeekOrigin.Current);
|
||||
writer.Write(beheld.Serial);
|
||||
|
||||
for (var i = 0; i < list.Count; ++i)
|
||||
{
|
||||
var item = list[i];
|
||||
|
||||
if (!item.Deleted && beholder.CanSee(item) && item.Parent == beheld)
|
||||
{
|
||||
writer.Write((byte)(item.Layer + 1));
|
||||
writer.Write(item.Serial);
|
||||
}
|
||||
}
|
||||
|
||||
if (beheld.Hair?.ItemID > 0)
|
||||
{
|
||||
writer.Write((byte)(Layer.Hair + 1));
|
||||
writer.Write(HairInfo.FakeSerial(beheld.Owner.Serial) - 2);
|
||||
}
|
||||
|
||||
if (beheld.FacialHair?.ItemID > 0)
|
||||
{
|
||||
writer.Write((byte)(Layer.FacialHair + 1));
|
||||
writer.Write(FacialHairInfo.FakeSerial(beheld.Owner.Serial) - 2);
|
||||
}
|
||||
|
||||
writer.Write((byte)Layer.Invalid);
|
||||
|
||||
writer.WritePacketLength();
|
||||
ns.Send(writer.Span);
|
||||
}
|
||||
|
||||
public static void SendCorpseContent(this NetState ns, Mobile beholder, Corpse beheld)
|
||||
{
|
||||
if (ns == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var list = beheld.EquipItems;
|
||||
|
||||
var maxLength = 5 + (list.Count + 2) * (ns.ContainerGridLines ? 19 : 20);
|
||||
var writer = new SpanWriter(stackalloc byte[maxLength]);
|
||||
writer.Write((byte)0x3C);
|
||||
writer.Seek(4, SeekOrigin.Current); // Length and Count
|
||||
|
||||
var written = 0;
|
||||
for (var i = 0; i < list.Count; ++i)
|
||||
{
|
||||
var child = list[i];
|
||||
|
||||
if (!child.Deleted && child.Parent == beheld && beholder.CanSee(child))
|
||||
{
|
||||
writer.Write(child.Serial);
|
||||
writer.Write((ushort)child.ItemID);
|
||||
writer.Write((byte)0); // signed, itemID offset
|
||||
writer.Write((ushort)child.Amount);
|
||||
writer.Write((short)child.X);
|
||||
writer.Write((short)child.Y);
|
||||
if (ns.ContainerGridLines)
|
||||
{
|
||||
writer.Write((byte)0); // Grid Location?
|
||||
}
|
||||
writer.Write(beheld.Serial);
|
||||
writer.Write((ushort)child.Hue);
|
||||
|
||||
++written;
|
||||
}
|
||||
}
|
||||
|
||||
if (beheld.Hair?.ItemID > 0)
|
||||
{
|
||||
writer.Write(HairInfo.FakeSerial(beheld.Owner.Serial) - 2);
|
||||
writer.Write((ushort)beheld.Hair.ItemID);
|
||||
writer.Write((byte)0); // signed, itemID offset
|
||||
writer.Write((ushort)1);
|
||||
writer.Write(0); // X/Y
|
||||
if (ns.ContainerGridLines)
|
||||
{
|
||||
writer.Write((byte)0); // Grid Location?
|
||||
}
|
||||
writer.Write(beheld.Serial);
|
||||
writer.Write((ushort)beheld.Hair.Hue);
|
||||
|
||||
++written;
|
||||
}
|
||||
|
||||
if (beheld.FacialHair?.ItemID > 0)
|
||||
{
|
||||
writer.Write(FacialHairInfo.FakeSerial(beheld.Owner.Serial) - 2);
|
||||
writer.Write((ushort)beheld.FacialHair.ItemID);
|
||||
writer.Write((byte)0); // signed, itemID offset
|
||||
writer.Write((ushort)1);
|
||||
writer.Write(0); // X/Y
|
||||
if (ns.ContainerGridLines)
|
||||
{
|
||||
writer.Write((byte)0); // Grid Location?
|
||||
}
|
||||
writer.Write(beheld.Serial);
|
||||
writer.Write((ushort)beheld.FacialHair.Hue);
|
||||
|
||||
++written;
|
||||
}
|
||||
|
||||
writer.Seek(1, SeekOrigin.Begin);
|
||||
writer.Write((ushort)writer.BytesWritten);
|
||||
writer.Write((ushort)written);
|
||||
writer.Seek(0, SeekOrigin.End);
|
||||
ns.Send(writer.Span);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,212 +0,0 @@
|
|||
using System.IO;
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue