Converts Item & Entity Packets (#326)

- [X] Converts World Item packets
- [X] Converter Remove Entity packets
- [X] Updates `LOSBlocker` and `Blocker`
- [X] Fixes a few bugs
- [X] Converts container packets

Bumps release version
This commit is contained in:
Kamron Batman 2020-11-29 03:24:51 -08:00 committed by GitHub
parent c41906d3c7
commit 77f665502b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 1351 additions and 1606 deletions

View file

@ -379,6 +379,11 @@ namespace Server.Network
public void Send(ReadOnlySpan<byte> span)
{
if (span == null)
{
return;
}
var length = span.Length;
if (Connection == null || BlockAllPackets || length <= 0 || !GetSendBuffer(out var buffer))
{

View file

@ -1,472 +0,0 @@
/*************************************************************************
* ModernUO *
* Copyright 2019-2020 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: ItemPackets.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;
using System.IO;
using Server.Items;
namespace Server.Network
{
public sealed class WorldItem : Packet
{
public WorldItem(Item item) : base(0x1A)
{
EnsureCapacity(20);
// 14 base length
// +2 - Amount
// +2 - Hue
// +1 - Flags
var serial = item.Serial.Value;
var itemID = item.ItemID & 0x3FFF;
var amount = item.Amount;
var loc = item.Location;
var x = loc.m_X;
var y = loc.m_Y;
var hue = item.Hue;
var flags = item.GetPacketFlags();
var direction = (int)item.Direction;
if (amount != 0)
{
serial |= 0x80000000;
}
else
{
serial &= 0x7FFFFFFF;
}
Stream.Write(serial);
if (item is BaseMulti)
{
Stream.Write((short)(itemID | 0x4000));
}
else
{
Stream.Write((short)itemID);
}
if (amount != 0)
{
Stream.Write((short)amount);
}
x &= 0x7FFF;
if (direction != 0)
{
x |= 0x8000;
}
Stream.Write((short)x);
y &= 0x3FFF;
if (hue != 0)
{
y |= 0x8000;
}
if (flags != 0)
{
y |= 0x4000;
}
Stream.Write((short)y);
if (direction != 0)
{
Stream.Write((byte)direction);
}
Stream.Write((sbyte)loc.m_Z);
if (hue != 0)
{
Stream.Write((ushort)hue);
}
if (flags != 0)
{
Stream.Write((byte)flags);
}
}
}
public sealed class WorldItemSA : Packet
{
public WorldItemSA(Item item) : base(0xF3, 24)
{
Stream.Write((short)0x1);
var itemID = item.ItemID;
if (item is BaseMulti)
{
Stream.Write((byte)0x02);
Stream.Write(item.Serial);
itemID &= 0x3FFF;
Stream.Write((short)itemID);
Stream.Write((byte)0);
}
else
{
Stream.Write((byte)0x00);
Stream.Write(item.Serial);
itemID &= 0x7FFF;
Stream.Write((short)itemID);
Stream.Write((byte)0);
}
var amount = item.Amount;
Stream.Write((short)amount);
Stream.Write((short)amount);
var loc = item.Location;
Stream.Write((short)loc.m_X);
Stream.Write((short)loc.m_Y);
Stream.Write((sbyte)loc.m_Z);
Stream.Write((byte)item.Light);
Stream.Write((short)item.Hue);
Stream.Write((byte)item.GetPacketFlags());
}
}
public sealed class WorldItemHS : Packet
{
public WorldItemHS(Item item) : base(0xF3, 26)
{
Stream.Write((short)0x1);
var itemID = item.ItemID;
if (item is BaseMulti)
{
Stream.Write((byte)0x02);
Stream.Write(item.Serial);
itemID &= 0x3FFF;
Stream.Write((ushort)itemID);
Stream.Write((byte)0);
}
else
{
Stream.Write((byte)0x00);
Stream.Write(item.Serial);
itemID &= 0xFFFF;
Stream.Write((ushort)itemID);
Stream.Write((byte)0);
}
var amount = item.Amount;
Stream.Write((short)amount);
Stream.Write((short)amount);
var loc = item.Location;
Stream.Write((short)loc.m_X);
Stream.Write((short)loc.m_Y);
Stream.Write((sbyte)loc.m_Z);
Stream.Write((byte)item.Light);
Stream.Write((short)item.Hue);
Stream.Write((byte)item.GetPacketFlags());
Stream.Write((short)0x00); // ??
}
}
public sealed class DisplaySpellbook : Packet
{
public DisplaySpellbook(Serial book) : base(0x24, 7)
{
Stream.Write(book);
Stream.Write((short)-1);
}
}
public sealed class DisplaySpellbookHS : Packet
{
public DisplaySpellbookHS(Serial book) : base(0x24, 9)
{
Stream.Write(book);
Stream.Write((short)-1);
Stream.Write((short)0x7D);
}
}
public sealed class NewSpellbookContent : Packet
{
public NewSpellbookContent(Serial spellbook, int graphic, int offset, ulong content) : base(0xBF)
{
EnsureCapacity(23);
Stream.Write((short)0x1B);
Stream.Write((short)0x01);
Stream.Write(spellbook);
Stream.Write((short)graphic);
Stream.Write((short)offset);
for (var i = 0; i < 8; ++i)
{
Stream.Write((byte)(content >> (i * 8)));
}
}
}
public sealed class SpellbookContent : Packet
{
public SpellbookContent(Serial spellbook, int offset, ulong content) : base(0x3C)
{
EnsureCapacity(5 + 64 * 19);
var written = 0;
Stream.Write((ushort)0);
ulong mask = 1;
for (var i = 0; i < 64; ++i, mask <<= 1)
{
if ((content & mask) != 0)
{
Stream.Write(0x7FFFFFFF - i);
Stream.Write((ushort)0);
Stream.Write((byte)0);
Stream.Write((ushort)(i + offset));
Stream.Write((short)0);
Stream.Write((short)0);
Stream.Write(spellbook);
Stream.Write((short)0);
++written;
}
}
Stream.Seek(3, SeekOrigin.Begin);
Stream.Write((ushort)written);
}
}
public sealed class SpellbookContent6017 : Packet
{
public SpellbookContent6017(Serial spellbook, int offset, ulong content) : base(0x3C)
{
EnsureCapacity(5 + 64 * 20);
var written = 0;
Stream.Write((ushort)0);
ulong mask = 1;
for (var i = 0; i < 64; ++i, mask <<= 1)
{
if ((content & mask) != 0)
{
Stream.Write(0x7FFFFFFF - i);
Stream.Write((ushort)0);
Stream.Write((byte)0);
Stream.Write((ushort)(i + offset));
Stream.Write((short)0);
Stream.Write((short)0);
Stream.Write((byte)0); // Grid Location?
Stream.Write(spellbook);
Stream.Write((short)0);
++written;
}
}
Stream.Seek(3, SeekOrigin.Begin);
Stream.Write((ushort)written);
}
}
public sealed class ContainerDisplay : Packet
{
public ContainerDisplay(Serial cont, int gumpId) : base(0x24, 7)
{
Stream.Write(cont);
Stream.Write((short)gumpId);
}
}
public sealed class ContainerDisplayHS : Packet
{
public ContainerDisplayHS(Serial cont, int gumpId) : base(0x24, 9)
{
Stream.Write(cont);
Stream.Write((short)gumpId);
Stream.Write((short)0x7D);
}
}
public sealed class ContainerContentUpdate : Packet
{
public ContainerContentUpdate(Item item) : base(0x25, 20)
{
Serial parentSerial;
if (item.Parent is Item parentItem)
{
parentSerial = parentItem.Serial;
}
else
{
Console.WriteLine("Warning: ContainerContentUpdate on item with !(parent is Item)");
parentSerial = Serial.Zero;
}
Stream.Write(item.Serial);
Stream.Write((ushort)item.ItemID);
Stream.Write((byte)0); // signed, itemID offset
Stream.Write((ushort)Math.Min(item.Amount, ushort.MaxValue));
Stream.Write((short)item.X);
Stream.Write((short)item.Y);
Stream.Write(parentSerial);
Stream.Write((ushort)(item.QuestItem ? Item.QuestItemHue : item.Hue));
}
}
public sealed class ContainerContentUpdate6017 : Packet
{
public ContainerContentUpdate6017(Item item) : base(0x25, 21)
{
Serial parentSerial;
if (item.Parent is Item parentItem)
{
parentSerial = parentItem.Serial;
}
else
{
Console.WriteLine("Warning: ContainerContentUpdate on item with !(parent is Item)");
parentSerial = Serial.Zero;
}
Stream.Write(item.Serial);
Stream.Write((ushort)item.ItemID);
Stream.Write((byte)0); // signed, itemID offset
Stream.Write((ushort)Math.Min(item.Amount, ushort.MaxValue));
Stream.Write((short)item.X);
Stream.Write((short)item.Y);
Stream.Write((byte)0); // Grid Location?
Stream.Write(parentSerial);
Stream.Write((ushort)(item.QuestItem ? Item.QuestItemHue : item.Hue));
}
}
public sealed class ContainerContent : Packet
{
public ContainerContent(Mobile beholder, Item beheld) : base(0x3C)
{
var items = beheld.Items;
var count = items.Count;
EnsureCapacity(5 + count * 19);
var pos = Stream.Position;
var written = 0;
Stream.Write((ushort)0);
for (var i = 0; i < count; ++i)
{
var child = items[i];
if (!child.Deleted && beholder.CanSee(child))
{
var loc = child.Location;
Stream.Write(child.Serial);
Stream.Write((ushort)child.ItemID);
Stream.Write((byte)0); // signed, itemID offset
Stream.Write((ushort)Math.Min(child.Amount, ushort.MaxValue));
Stream.Write((short)loc.m_X);
Stream.Write((short)loc.m_Y);
Stream.Write(beheld.Serial);
Stream.Write((ushort)(child.QuestItem ? Item.QuestItemHue : child.Hue));
++written;
}
}
Stream.Seek(pos, SeekOrigin.Begin);
Stream.Write((ushort)written);
}
}
public sealed class ContainerContent6017 : Packet
{
public ContainerContent6017(Mobile beholder, Item beheld) : base(0x3C)
{
var items = beheld.Items;
var count = items.Count;
EnsureCapacity(5 + count * 20);
var pos = Stream.Position;
var written = 0;
Stream.Write((ushort)0);
for (var i = 0; i < count; ++i)
{
var child = items[i];
if (!child.Deleted && beholder.CanSee(child))
{
var loc = child.Location;
Stream.Write(child.Serial);
Stream.Write((ushort)child.ItemID);
Stream.Write((byte)0); // signed, itemID offset
Stream.Write((ushort)Math.Min(child.Amount, ushort.MaxValue));
Stream.Write((short)loc.m_X);
Stream.Write((short)loc.m_Y);
Stream.Write((byte)0); // Grid Location?
Stream.Write(beheld.Serial);
Stream.Write((ushort)(child.QuestItem ? Item.QuestItemHue : child.Hue));
++written;
}
}
Stream.Seek(pos, SeekOrigin.Begin);
Stream.Write((ushort)written);
}
}
}

View file

@ -0,0 +1,216 @@
/*************************************************************************
* ModernUO *
* Copyright 2019-2020 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: OutgoingContainerPackets.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;
using System.Buffers;
using System.IO;
namespace Server.Network
{
public static class OutgoingContainerPackets
{
public static void SendDisplaySpellbook(this NetState ns, Serial book) => ns.SendDisplayContainer(book, -1);
public static void SendSpellbookContent(this NetState ns, Serial book, int graphic, int offset, ulong content)
{
if (ns == null)
{
return;
}
if (ObjectPropertyList.Enabled && ns.NewSpellbook)
{
ns.SendNewSpellbookContent(book, graphic, offset, content);
}
else
{
ns.SendOldSpellbookContent(book, offset, content);
}
}
public static void SendNewSpellbookContent(this NetState ns, Serial book, int graphic, int offset, ulong content)
{
if (ns == null || !ns.GetSendBuffer(out var buffer))
{
return;
}
var writer = new CircularBufferWriter(buffer);
writer.Write((byte)0xBF); // Packet ID
writer.Write((ushort)23); // Length
writer.Write((short)0x1B); // Subpacket
writer.Write((short)0x01); // Command
writer.Write(book);
writer.Write((short)graphic);
writer.Write((short)offset);
for (var i = 0; i < 8; ++i)
{
writer.Write((byte)(content >> (i * 8)));
}
ns.Send(ref buffer, writer.Position);
}
public static void SendOldSpellbookContent(this NetState ns, Serial book, int offset, ulong content)
{
if (ns == null || !ns.GetSendBuffer(out var buffer))
{
return;
}
var writer = new CircularBufferWriter(buffer);
writer.Write((byte)0x3C); // Packet ID
writer.Seek(4, SeekOrigin.Current); // Length & written count
var written = 0;
ulong mask = 1;
for (var i = 0; i < 64; ++i, mask <<= 1)
{
if ((content & mask) != 0)
{
writer.Write(0x7FFFFFFF - i);
writer.Write((ushort)0); // child ItemID
writer.Write((byte)0); // ItemID offset
writer.Write((ushort)(i + offset)); // Amount
writer.Write(0); // X, Y
if (ns.ContainerGridLines)
{
writer.Write((byte)0); // Grid Location
}
writer.Write(book);
writer.Write((short)0); // Quest Hue
++written;
}
}
var length = writer.Position;
writer.Seek(1, SeekOrigin.Begin);
writer.Write((ushort)length);
writer.Write((ushort)written);
ns.Send(ref buffer, length);
}
public static void SendDisplayContainer(this NetState ns, Serial cont, int gumpId)
{
if (ns == null || !ns.GetSendBuffer(out var buffer))
{
return;
}
var writer = new CircularBufferWriter(buffer);
writer.Write((byte)0x24); // Packet ID
writer.Write(cont);
writer.Write((ushort)gumpId);
if (ns.HighSeas)
{
writer.Write((short)0x7D);
}
ns.Send(ref buffer, writer.Position);
}
public static void SendContainerContentUpdate(this NetState ns, Item item)
{
if (ns == null || !ns.GetSendBuffer(out var buffer))
{
return;
}
Serial parentSerial;
if (item.Parent is Item parentItem)
{
parentSerial = parentItem.Serial;
}
else
{
Console.WriteLine("Warning: ContainerContentUpdate on item with !(parent is Item)");
parentSerial = Serial.Zero;
}
var writer = new CircularBufferWriter(buffer);
writer.Write((byte)0x25); // Packet ID
writer.Write(item.Serial);
writer.Write((ushort)item.ItemID);
writer.Write((byte)0); // signed, itemID offset
writer.Write((ushort)Math.Min(item.Amount, ushort.MaxValue));
writer.Write((short)item.X);
writer.Write((short)item.Y);
if (ns.ContainerGridLines)
{
writer.Write((byte)0); // Grid Location?
}
writer.Write(parentSerial);
writer.Write((ushort)(item.QuestItem ? Item.QuestItemHue : item.Hue));
ns.Send(ref buffer, writer.Position);
}
public static void SendContainerContent(this NetState ns, Mobile beholder, Item beheld)
{
if (ns == null || !ns.GetSendBuffer(out var buffer))
{
return;
}
var items = beheld.Items;
var count = items.Count;
var writer = new CircularBufferWriter(buffer);
writer.Write((byte)0x3C); // Packet ID
writer.Seek(4, SeekOrigin.Current); // Length & writter count
var written = 0;
for (var i = 0; i < count; ++i)
{
var child = items[i];
if (!child.Deleted && beholder.CanSee(child))
{
var loc = child.Location;
writer.Write(child.Serial);
writer.Write((ushort)child.ItemID);
writer.Write((byte)0); // signed, itemID offset
writer.Write((ushort)Math.Min(child.Amount, ushort.MaxValue));
writer.Write((short)loc.X);
writer.Write((short)loc.Y);
if (ns.ContainerGridLines)
{
writer.Write((byte)0); // Grid Location?
}
writer.Write(beheld.Serial);
writer.Write((ushort)(child.QuestItem ? Item.QuestItemHue : child.Hue));
++written;
}
}
var length = writer.Position;
writer.Seek(1, SeekOrigin.Begin);
writer.Write((ushort)length);
writer.Write((ushort)written);
ns.Send(ref buffer, length);
}
}
}

View file

@ -0,0 +1,73 @@
/*************************************************************************
* ModernUO *
* Copyright 2019-2020 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: OutgoingEntityPackets.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;
using System.Buffers;
namespace Server.Network
{
public static class OutgoingEntityPackets
{
public const int OPLPacketLength = 9;
public const int RemoveEntityLength = 5;
public static void CreateOPLInfo(ref Span<byte> buffer, Item item) =>
CreateOPLInfo(ref buffer, item.Serial, item.PropertyList.Hash);
public static void CreateOPLInfo(ref Span<byte> buffer, Serial serial, int hash)
{
var writer = new SpanWriter(buffer);
writer.Write((byte)0xDC); // Packet ID
writer.Write(serial);
writer.Write(hash);
}
public static void SendOPLInfo(this NetState ns, IPropertyListObject obj) =>
ns.SendOPLInfo(obj.Serial, obj.PropertyList.Hash);
public static void SendOPLInfo(this NetState ns, Serial serial, int hash)
{
if (ns == null)
{
return;
}
Span<byte> buffer = stackalloc byte[OPLPacketLength];
CreateOPLInfo(ref buffer, serial, hash);
ns.Send(buffer);
}
public static void CreateRemoveEntity(ref Span<byte> buffer, Serial serial)
{
var writer = new SpanWriter(buffer);
writer.Write((byte)0x1D); // Packet ID
writer.Write(serial);
}
public static void SendRemoveEntity(this NetState ns, Serial serial)
{
if (ns == null)
{
return;
}
Span<byte> buffer = stackalloc byte[RemoveEntityLength];
CreateRemoveEntity(ref buffer, serial);
ns.Send(buffer);
}
}
}

View file

@ -0,0 +1,140 @@
/*************************************************************************
* ModernUO *
* Copyright 2019-2020 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: OutgoingItemPackets.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;
using System.Buffers;
using Server.Items;
namespace Server.Network
{
public static class OutgoingItemPackets
{
public const int MaxWorldItemPacketLength = 26;
public static int CreateWorldItem(ref Span<byte> buffer, Item item)
{
var itemID = item is BaseMulti ? item.ItemID | 0x4000 : item.ItemID & 0x3FFF;
var hasAmount = item.Amount != 0;
var amount = item.Amount;
var serial = hasAmount ? item.Serial | 0x80000000 : item.Serial & 0x7FFFFFFF;
var loc = item.Location;
var hue = item.Hue;
var flags = item.GetPacketFlags();
var direction = (int)item.Direction;
var hasDirection = direction != 0;
var hasHue = hue != 0;
var hasFlags = flags != 0;
var x = hasDirection ? loc.X | 0x8000 : loc.X & 0x7FFF;
var y = (loc.Y & 0x3FFF) | (hasHue ? 0x8000 : 0) | (hasFlags ? 0x4000 : 0);
var length = 14 + (hasAmount ? 2 : 0) +
(hasDirection ? 1 : 0) +
(hasHue ? 2 : 0) +
(hasFlags ? 1 : 0);
var writer = new SpanWriter(buffer);
writer.Write((byte)0x1A); // Packet ID
writer.Write((ushort)length);
writer.Write(serial);
writer.Write((ushort)itemID);
if (amount != 0)
{
writer.Write((ushort)amount);
}
writer.Write((ushort)x);
writer.Write((ushort)y);
if (direction != 0)
{
writer.Write((byte)direction);
}
writer.Write((sbyte)loc.Z);
if (hue != 0)
{
writer.Write((ushort)hue);
}
if (flags != 0)
{
writer.Write((byte)flags);
}
return writer.Position;
}
public static void SendWorldItem(this NetState ns, Item item)
{
if (ns == null)
{
return;
}
Span<byte> buffer = stackalloc byte[MaxWorldItemPacketLength];
var length = ns.StygianAbyss ?
CreateWorldItemNew(ref buffer, item, ns.HighSeas) :
CreateWorldItem(ref buffer, item);
ns.Send(buffer.Slice(0, length));
}
public static int CreateWorldItemNew(ref Span<byte> buffer, Item item, bool isHS)
{
var writer = new SpanWriter(buffer);
writer.Write((byte)0xF3); // Packet ID
writer.Write((short)0x1); // command
var itemID = item.ItemID;
if (item is BaseMulti)
{
writer.Write((byte)2);
writer.Write(item.Serial);
writer.Write((short)(itemID & 0x3FFF));
writer.Write((byte)0);
}
else
{
writer.Write((byte)0);
writer.Write(item.Serial);
writer.Write((short)(itemID & (isHS ? 0xFFFF : 0x7FFF)));
writer.Write((byte)0);
}
var amount = item.Amount;
writer.Write((short)amount); // Min
writer.Write((short)amount); // Max
var loc = item.Location;
writer.Write((short)loc.X);
writer.Write((short)loc.Y);
writer.Write((sbyte)loc.Z);
writer.Write((byte)item.Light);
writer.Write((short)item.Hue);
writer.Write((byte)item.GetPacketFlags());
if (isHS)
{
writer.Write((short)0);
}
return writer.Position;
}
}
}

View file

@ -1,138 +0,0 @@
/*************************************************************************
* ModernUO *
* Copyright 2019-2020 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: StaticPacketHandlers.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.Collections.Concurrent;
namespace Server.Network
{
public static class StaticPacketHandlers
{
private static readonly ConcurrentDictionary<IPropertyListObject, OPLInfo> OPLInfoPackets =
new();
private static readonly ConcurrentDictionary<IEntity, RemoveEntity> RemoveEntityPackets =
new();
private static readonly ConcurrentDictionary<Item, WorldItem> WorldItemPackets =
new();
private static readonly ConcurrentDictionary<Item, WorldItemSA> WorldItemSAPackets =
new();
private static readonly ConcurrentDictionary<Item, WorldItemHS> WorldItemHSPackets =
new();
public static OPLInfo GetOPLInfoPacket(IPropertyListObject obj)
{
return OPLInfoPackets.GetOrAdd(
obj,
value =>
{
var packet = new OPLInfo(value.PropertyList.Entity.Serial, value.PropertyList.Hash);
packet.SetStatic();
return packet;
}
);
}
public static OPLInfo FreeOPLInfoPacket(IPropertyListObject obj)
{
if (OPLInfoPackets.TryRemove(obj, out var p))
{
Packet.Release(p);
}
return p;
}
public static RemoveEntity GetRemoveEntityPacket(IEntity entity)
{
return RemoveEntityPackets.GetOrAdd(
entity,
value =>
{
var packet = new RemoveEntity(value.Serial);
packet.SetStatic();
return packet;
}
);
}
public static void FreeRemoveItemPacket(IEntity entity)
{
if (RemoveEntityPackets.TryRemove(entity, out var p))
{
Packet.Release(p);
}
}
public static WorldItem GetWorldItemPacket(Item item)
{
return WorldItemPackets.GetOrAdd(
item,
value =>
{
var packet = new WorldItem(value);
packet.SetStatic();
return packet;
}
);
}
public static WorldItemSA GetWorldItemSAPacket(Item item)
{
return WorldItemSAPackets.GetOrAdd(
item,
value =>
{
var packet = new WorldItemSA(value);
packet.SetStatic();
return packet;
}
);
}
public static WorldItemHS GetWorldItemHSPacket(Item item)
{
return WorldItemHSPackets.GetOrAdd(
item,
value =>
{
var packet = new WorldItemHS(value);
packet.SetStatic();
return packet;
}
);
}
public static void FreeWorldItemPackets(Item item)
{
if (WorldItemPackets.TryRemove(item, out var wi))
{
Packet.Release(wi);
}
if (WorldItemSAPackets.TryRemove(item, out var wisa))
{
Packet.Release(wisa);
}
if (WorldItemHSPackets.TryRemove(item, out var wihs))
{
Packet.Release(wihs);
}
}
}
}