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:
parent
c41906d3c7
commit
77f665502b
26 changed files with 1351 additions and 1606 deletions
|
|
@ -695,24 +695,15 @@ namespace Server.Items
|
|||
|
||||
if (ns != null)
|
||||
{
|
||||
if (ns.HighSeas)
|
||||
{
|
||||
to.Send(new ContainerDisplayHS(Serial, GumpID));
|
||||
}
|
||||
else
|
||||
{
|
||||
to.Send(new ContainerDisplay(Serial, GumpID));
|
||||
}
|
||||
ns.SendDisplayContainer(Serial, GumpID);
|
||||
|
||||
SendContentTo(ns);
|
||||
|
||||
if (ObjectPropertyList.Enabled)
|
||||
{
|
||||
var items = Items;
|
||||
|
||||
for (var i = 0; i < items.Count; ++i)
|
||||
for (var i = 0; i < Items.Count; ++i)
|
||||
{
|
||||
to.Send(items[i].OPLPacket);
|
||||
Items[i].SendOPLPacketTo(to.NetState, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -764,22 +755,7 @@ namespace Server.Items
|
|||
}
|
||||
}
|
||||
|
||||
public virtual void SendContentTo(NetState state)
|
||||
{
|
||||
if (state == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (state.ContainerGridLines)
|
||||
{
|
||||
state.Send(new ContainerContent6017(state.Mobile, this));
|
||||
}
|
||||
else
|
||||
{
|
||||
state.Send(new ContainerContent(state.Mobile, this));
|
||||
}
|
||||
}
|
||||
public virtual void SendContentTo(NetState state) => state.SendContainerContent(state.Mobile, this);
|
||||
|
||||
public override void GetProperties(ObjectPropertyList list)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ namespace Server.Items
|
|||
|
||||
if (SendDeleteOnClose)
|
||||
{
|
||||
Owner?.Send(RemovePacket);
|
||||
Owner?.NetState.SendRemoveEntity(Serial);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -353,19 +353,6 @@ namespace Server
|
|||
set => SetFlag(ImplFlag.Stackable, value);
|
||||
}
|
||||
|
||||
public Packet RemovePacket => StaticPacketHandlers.GetRemoveEntityPacket(this);
|
||||
|
||||
// World packets need to be invalidated when any of the following changes:
|
||||
// - ItemID
|
||||
// - Amount
|
||||
// - Location
|
||||
// - Hue
|
||||
// - Packet Flags
|
||||
// - Direction
|
||||
public Packet WorldPacket => StaticPacketHandlers.GetWorldItemPacket(this);
|
||||
public Packet WorldPacketSA => StaticPacketHandlers.GetWorldItemSAPacket(this);
|
||||
public Packet WorldPacketHS => StaticPacketHandlers.GetWorldItemHSPacket(this);
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public bool Visible
|
||||
{
|
||||
|
|
@ -375,7 +362,6 @@ namespace Server
|
|||
if (GetFlag(ImplFlag.Visible) != value)
|
||||
{
|
||||
SetFlag(ImplFlag.Visible, value);
|
||||
ReleaseWorldPackets();
|
||||
|
||||
if (m_Map != null)
|
||||
{
|
||||
|
|
@ -383,13 +369,16 @@ namespace Server
|
|||
|
||||
var eable = m_Map.GetClientsInRange(worldLoc, GetMaxUpdateRange());
|
||||
|
||||
Span<byte> removeEntity = stackalloc byte[OutgoingEntityPackets.RemoveEntityLength];
|
||||
OutgoingEntityPackets.CreateRemoveEntity(ref removeEntity, Serial);
|
||||
|
||||
foreach (var state in eable)
|
||||
{
|
||||
var m = state.Mobile;
|
||||
|
||||
if (!m.CanSee(this) && m.InRange(worldLoc, GetUpdateRange(m)))
|
||||
{
|
||||
state.Send(RemovePacket);
|
||||
state.Send(removeEntity);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -410,7 +399,7 @@ namespace Server
|
|||
if (GetFlag(ImplFlag.Movable) != value)
|
||||
{
|
||||
SetFlag(ImplFlag.Movable, value);
|
||||
ReleaseWorldPackets();
|
||||
|
||||
Delta(ItemDelta.Update);
|
||||
}
|
||||
}
|
||||
|
|
@ -533,7 +522,6 @@ namespace Server
|
|||
if (m_Hue != value)
|
||||
{
|
||||
m_Hue = value;
|
||||
ReleaseWorldPackets();
|
||||
|
||||
Delta(ItemDelta.Update);
|
||||
}
|
||||
|
|
@ -599,7 +587,6 @@ namespace Server
|
|||
var oldPileWeight = PileWeight;
|
||||
|
||||
m_ItemID = value;
|
||||
ReleaseWorldPackets();
|
||||
|
||||
var newPileWeight = PileWeight;
|
||||
|
||||
|
|
@ -673,8 +660,6 @@ namespace Server
|
|||
if ((LightType)m_Direction != value)
|
||||
{
|
||||
m_Direction = (Direction)value;
|
||||
ReleaseWorldPackets();
|
||||
|
||||
Delta(ItemDelta.Update);
|
||||
}
|
||||
}
|
||||
|
|
@ -689,8 +674,6 @@ namespace Server
|
|||
if (m_Direction != value)
|
||||
{
|
||||
m_Direction = value;
|
||||
ReleaseWorldPackets();
|
||||
|
||||
Delta(ItemDelta.Update);
|
||||
}
|
||||
}
|
||||
|
|
@ -709,7 +692,6 @@ namespace Server
|
|||
var oldPileWeight = PileWeight;
|
||||
|
||||
m_Amount = value;
|
||||
ReleaseWorldPackets();
|
||||
|
||||
var newPileWeight = PileWeight;
|
||||
|
||||
|
|
@ -757,11 +739,7 @@ namespace Server
|
|||
set
|
||||
{
|
||||
SetFlag(ImplFlag.QuestItem, value);
|
||||
|
||||
InvalidateProperties();
|
||||
|
||||
ReleaseWorldPackets();
|
||||
|
||||
Delta(ItemDelta.Update);
|
||||
}
|
||||
}
|
||||
|
|
@ -803,8 +781,7 @@ namespace Server
|
|||
public int CompareTo(Item other) => other == null ? -1 : Serial.CompareTo(other.Serial);
|
||||
|
||||
public virtual int HuedItemID => m_ItemID;
|
||||
public OPLInfo OPLPacket => StaticPacketHandlers.GetOPLInfoPacket(this);
|
||||
public ObjectPropertyList PropertyList => m_PropertyList ??= NewObjectPropertyList();
|
||||
public ObjectPropertyList PropertyList => m_PropertyList ??= InitializePropertyList(new ObjectPropertyList(this));
|
||||
|
||||
/// <summary>
|
||||
/// Overridable. Fills an <see cref="ObjectPropertyList" /> with everything applicable. By default, this invokes
|
||||
|
|
@ -923,7 +900,7 @@ namespace Server
|
|||
flags |= SaveFlag.Parent;
|
||||
}
|
||||
|
||||
if (items?.Count > 0)
|
||||
if (items.Count > 0)
|
||||
{
|
||||
flags |= SaveFlag.Items;
|
||||
}
|
||||
|
|
@ -1151,35 +1128,18 @@ namespace Server
|
|||
|
||||
if (oldLocation.m_X != 0)
|
||||
{
|
||||
var eable = m_Map.GetClientsInRange(oldLocation, GetMaxUpdateRange());
|
||||
|
||||
foreach (var state in eable)
|
||||
{
|
||||
var m = state.Mobile;
|
||||
|
||||
if (m.InRange(oldLocation, GetUpdateRange(m)))
|
||||
{
|
||||
state.Send(RemovePacket);
|
||||
}
|
||||
}
|
||||
|
||||
eable.Free();
|
||||
SendRemovePacket(oldLocation);
|
||||
}
|
||||
}
|
||||
|
||||
m_Location = location;
|
||||
OnLocationChange(oldRealLocation);
|
||||
|
||||
ReleaseWorldPackets();
|
||||
|
||||
var items = LookupItems();
|
||||
|
||||
if (items != null)
|
||||
for (var i = 0; i < items.Count; ++i)
|
||||
{
|
||||
for (var i = 0; i < items.Count; ++i)
|
||||
{
|
||||
items[i].Map = map;
|
||||
}
|
||||
items[i].Map = map;
|
||||
}
|
||||
|
||||
m_Map = map;
|
||||
|
|
@ -1189,6 +1149,24 @@ namespace Server
|
|||
|
||||
if (m_Map != null)
|
||||
{
|
||||
Span<byte> oldWorldItem = stackalloc byte[OutgoingItemPackets.MaxWorldItemPacketLength];
|
||||
var length = OutgoingItemPackets.CreateWorldItem(ref oldWorldItem, this);
|
||||
oldWorldItem = oldWorldItem.Slice(0, length);
|
||||
|
||||
Span<byte> saWorldItem = stackalloc byte[OutgoingItemPackets.MaxWorldItemPacketLength];
|
||||
length = OutgoingItemPackets.CreateWorldItemNew(ref saWorldItem, this, false);
|
||||
saWorldItem = saWorldItem.Slice(0, length);
|
||||
|
||||
Span<byte> hsWorldItem = stackalloc byte[OutgoingItemPackets.MaxWorldItemPacketLength];
|
||||
length = OutgoingItemPackets.CreateWorldItemNew(ref hsWorldItem, this, true);
|
||||
hsWorldItem = hsWorldItem.Slice(0, length);
|
||||
|
||||
Span<byte> opl = ObjectPropertyList.Enabled ? stackalloc byte[OutgoingEntityPackets.OPLPacketLength] : null;
|
||||
if (opl != null)
|
||||
{
|
||||
OutgoingEntityPackets.CreateOPLInfo(ref opl, this);
|
||||
}
|
||||
|
||||
var eable = m_Map.GetClientsInRange(m_Location, GetMaxUpdateRange());
|
||||
|
||||
foreach (var state in eable)
|
||||
|
|
@ -1197,7 +1175,18 @@ namespace Server
|
|||
|
||||
if (m.CanSee(this) && m.InRange(m_Location, GetUpdateRange(m)))
|
||||
{
|
||||
SendInfoTo(state);
|
||||
if (state.HighSeas)
|
||||
{
|
||||
SendInfoTo(state, hsWorldItem, opl);
|
||||
}
|
||||
else if (state.StygianAbyss)
|
||||
{
|
||||
SendInfoTo(state, saWorldItem, opl);
|
||||
}
|
||||
else
|
||||
{
|
||||
SendInfoTo(state, oldWorldItem, opl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1219,13 +1208,16 @@ namespace Server
|
|||
{
|
||||
eable = m_Map.GetClientsInRange(oldLocation, GetMaxUpdateRange());
|
||||
|
||||
Span<byte> removeEntity = stackalloc byte[OutgoingEntityPackets.RemoveEntityLength];
|
||||
OutgoingEntityPackets.CreateRemoveEntity(ref removeEntity, Serial);
|
||||
|
||||
foreach (var state in eable)
|
||||
{
|
||||
var m = state.Mobile;
|
||||
|
||||
if (!m.InRange(location, GetUpdateRange(m)))
|
||||
{
|
||||
state.Send(RemovePacket);
|
||||
state.Send(removeEntity);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1237,8 +1229,6 @@ namespace Server
|
|||
m_Location = location;
|
||||
OnLocationChange(oldRealLocation);
|
||||
|
||||
ReleaseWorldPackets();
|
||||
|
||||
eable = m_Map.GetClientsInRange(m_Location, GetMaxUpdateRange());
|
||||
|
||||
foreach (var state in eable)
|
||||
|
|
@ -1287,12 +1277,9 @@ namespace Server
|
|||
|
||||
var items = LookupItems();
|
||||
|
||||
if (items != null)
|
||||
for (var i = 0; i < items.Count; ++i)
|
||||
{
|
||||
for (var i = 0; i < items.Count; ++i)
|
||||
{
|
||||
items[i].Map = value;
|
||||
}
|
||||
items[i].Map = value;
|
||||
}
|
||||
|
||||
m_Map = value;
|
||||
|
|
@ -1342,19 +1329,8 @@ namespace Server
|
|||
|
||||
if (ns != null && rootParent.CanSee(this) && rootParent.InRange(worldLoc, GetUpdateRange(rootParent)))
|
||||
{
|
||||
if (ns.ContainerGridLines)
|
||||
{
|
||||
ns.Send(new ContainerContentUpdate6017(this));
|
||||
}
|
||||
else
|
||||
{
|
||||
ns.Send(new ContainerContentUpdate(this));
|
||||
}
|
||||
|
||||
if (ObjectPropertyList.Enabled)
|
||||
{
|
||||
ns.Send(OPLPacket);
|
||||
}
|
||||
ns.SendContainerContentUpdate(this);
|
||||
SendOPLPacketTo(ns);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1380,19 +1356,8 @@ namespace Server
|
|||
|
||||
if (ns != null && tradeRecip.CanSee(this) && tradeRecip.InRange(worldLoc, GetUpdateRange(tradeRecip)))
|
||||
{
|
||||
if (ns.ContainerGridLines)
|
||||
{
|
||||
ns.Send(new ContainerContentUpdate6017(this));
|
||||
}
|
||||
else
|
||||
{
|
||||
ns.Send(new ContainerContentUpdate(this));
|
||||
}
|
||||
|
||||
if (ObjectPropertyList.Enabled)
|
||||
{
|
||||
ns.Send(OPLPacket);
|
||||
}
|
||||
ns.SendContainerContentUpdate(this);
|
||||
SendOPLPacketTo(ns);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1423,19 +1388,8 @@ namespace Server
|
|||
|
||||
if (ns != null && mob.CanSee(this))
|
||||
{
|
||||
if (ns.ContainerGridLines)
|
||||
{
|
||||
ns.Send(new ContainerContentUpdate6017(this));
|
||||
}
|
||||
else
|
||||
{
|
||||
ns.Send(new ContainerContentUpdate(this));
|
||||
}
|
||||
|
||||
if (ObjectPropertyList.Enabled)
|
||||
{
|
||||
ns.Send(OPLPacket);
|
||||
}
|
||||
ns.SendContainerContentUpdate(this);
|
||||
SendOPLPacketTo(ns);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1465,20 +1419,14 @@ namespace Server
|
|||
{
|
||||
if (m_Parent == null)
|
||||
{
|
||||
SendInfoTo(state, ObjectPropertyList.Enabled);
|
||||
SendInfoTo(state);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_Parent is Item)
|
||||
{
|
||||
if (state.ContainerGridLines)
|
||||
{
|
||||
state.Send(new ContainerContentUpdate6017(this));
|
||||
}
|
||||
else
|
||||
{
|
||||
state.Send(new ContainerContentUpdate(this));
|
||||
}
|
||||
// TODO: Optimize by writing once?
|
||||
state.SendContainerContentUpdate(this);
|
||||
}
|
||||
else if (m_Parent is Mobile)
|
||||
{
|
||||
|
|
@ -1486,24 +1434,17 @@ namespace Server
|
|||
state.SendEquipUpdate(this);
|
||||
}
|
||||
|
||||
if (ObjectPropertyList.Enabled)
|
||||
{
|
||||
state.Send(OPLPacket);
|
||||
}
|
||||
SendOPLPacketTo(state);
|
||||
}
|
||||
}
|
||||
else if ((flags & ItemDelta.EquipOnly) != 0 && m_Parent is Mobile)
|
||||
{
|
||||
state.SendEquipUpdate(this);
|
||||
|
||||
if (ObjectPropertyList.Enabled)
|
||||
{
|
||||
state.Send(OPLPacket);
|
||||
}
|
||||
SendOPLPacketTo(state);
|
||||
}
|
||||
else if (ObjectPropertyList.Enabled && (flags & ItemDelta.Properties) != 0)
|
||||
{
|
||||
state.Send(OPLPacket);
|
||||
SendOPLPacketTo(state);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1521,14 +1462,11 @@ namespace Server
|
|||
|
||||
var items = LookupItems();
|
||||
|
||||
if (items != null)
|
||||
for (var i = items.Count - 1; i >= 0; --i)
|
||||
{
|
||||
for (var i = items.Count - 1; i >= 0; --i)
|
||||
if (i < items.Count)
|
||||
{
|
||||
if (i < items.Count)
|
||||
{
|
||||
items[i].OnParentDeleted(this);
|
||||
}
|
||||
items[i].OnParentDeleted(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1561,7 +1499,7 @@ namespace Server
|
|||
|
||||
OnAfterDelete();
|
||||
|
||||
FreeCache();
|
||||
m_PropertyList = null;
|
||||
}
|
||||
|
||||
public ISpawner Spawner
|
||||
|
|
@ -1611,13 +1549,16 @@ namespace Server
|
|||
{
|
||||
eable = m_Map.GetClientsInRange(oldLocation, GetMaxUpdateRange());
|
||||
|
||||
Span<byte> removeEntity = stackalloc byte[OutgoingEntityPackets.RemoveEntityLength];
|
||||
OutgoingEntityPackets.CreateRemoveEntity(ref removeEntity, Serial);
|
||||
|
||||
foreach (var state in eable)
|
||||
{
|
||||
var m = state.Mobile;
|
||||
|
||||
if (!m.InRange(value, GetUpdateRange(m)))
|
||||
{
|
||||
state.Send(RemovePacket);
|
||||
state.Send(removeEntity);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1626,7 +1567,6 @@ namespace Server
|
|||
|
||||
var oldLoc = m_Location;
|
||||
m_Location = value;
|
||||
ReleaseWorldPackets();
|
||||
|
||||
SetLastMoved();
|
||||
|
||||
|
|
@ -1648,17 +1588,13 @@ namespace Server
|
|||
|
||||
RemDelta(ItemDelta.Update);
|
||||
}
|
||||
else if (m_Parent is Item)
|
||||
{
|
||||
m_Location = value;
|
||||
ReleaseWorldPackets();
|
||||
|
||||
Delta(ItemDelta.Update);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Location = value;
|
||||
ReleaseWorldPackets();
|
||||
if (m_Parent is Item)
|
||||
{
|
||||
Delta(ItemDelta.Update);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_Parent == null)
|
||||
|
|
@ -1669,7 +1605,6 @@ namespace Server
|
|||
else
|
||||
{
|
||||
m_Location = value;
|
||||
ReleaseWorldPackets();
|
||||
}
|
||||
|
||||
OnLocationChange(oldLocation);
|
||||
|
|
@ -1715,17 +1650,6 @@ namespace Server
|
|||
&& p.Y >= Location.m_Y - range
|
||||
&& p.Y <= Location.m_Y + range;
|
||||
|
||||
public void ReleaseOPLPacket()
|
||||
{
|
||||
if (m_PropertyList == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Packet.Release(m_PropertyList);
|
||||
m_PropertyList = null;
|
||||
}
|
||||
|
||||
public ExpandFlag GetExpandFlags()
|
||||
{
|
||||
var info = LookupCompactInfo();
|
||||
|
|
@ -1817,15 +1741,7 @@ namespace Server
|
|||
}
|
||||
}
|
||||
|
||||
public List<Item> LookupItems()
|
||||
{
|
||||
if (this is Container container)
|
||||
{
|
||||
return container.m_Items;
|
||||
}
|
||||
|
||||
return LookupCompactInfo()?.m_Items;
|
||||
}
|
||||
public List<Item> LookupItems() => (this is Container container ? container.m_Items : LookupCompactInfo()?.m_Items) ?? EmptyItems;
|
||||
|
||||
public List<Item> AcquireItems()
|
||||
{
|
||||
|
|
@ -1937,7 +1853,7 @@ namespace Server
|
|||
/// </summary>
|
||||
public virtual void SendPropertiesTo(Mobile from)
|
||||
{
|
||||
from.Send(PropertyList);
|
||||
from.NetState?.Send(PropertyList.Buffer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -2164,8 +2080,7 @@ namespace Server
|
|||
|
||||
public void Bounce(Mobile from)
|
||||
{
|
||||
m_Parent.RemoveItem(this);
|
||||
|
||||
m_Parent?.RemoveItem(this);
|
||||
m_Parent = null;
|
||||
|
||||
var bounce = GetBounce();
|
||||
|
|
@ -2491,22 +2406,17 @@ namespace Server
|
|||
}
|
||||
}
|
||||
|
||||
public ObjectPropertyList NewObjectPropertyList()
|
||||
private ObjectPropertyList InitializePropertyList(ObjectPropertyList list)
|
||||
{
|
||||
var list = new ObjectPropertyList(this);
|
||||
|
||||
GetProperties(list);
|
||||
AppendChildProperties(list);
|
||||
|
||||
list.Terminate();
|
||||
list.SetStatic();
|
||||
return list;
|
||||
}
|
||||
|
||||
public void ClearProperties()
|
||||
{
|
||||
ReleaseOPLPacket();
|
||||
StaticPacketHandlers.FreeOPLInfoPacket(this);
|
||||
m_PropertyList = null;
|
||||
}
|
||||
|
||||
public void InvalidateProperties()
|
||||
|
|
@ -2518,12 +2428,23 @@ namespace Server
|
|||
|
||||
if (m_Map != null && m_Map != Map.Internal && !World.Loading)
|
||||
{
|
||||
var oldList = m_PropertyList;
|
||||
m_PropertyList = null;
|
||||
|
||||
if (oldList != null && oldList.Hash != PropertyList.Hash)
|
||||
int? oldHash;
|
||||
int newHash;
|
||||
if (m_PropertyList != null)
|
||||
{
|
||||
oldHash = m_PropertyList.Hash;
|
||||
m_PropertyList.Reset();
|
||||
InitializePropertyList(m_PropertyList);
|
||||
newHash = m_PropertyList.Hash;
|
||||
}
|
||||
else
|
||||
{
|
||||
oldHash = null;
|
||||
newHash = PropertyList.Hash;
|
||||
}
|
||||
|
||||
if (oldHash != newHash)
|
||||
{
|
||||
StaticPacketHandlers.FreeOPLInfoPacket(this);
|
||||
Delta(ItemDelta.Properties);
|
||||
}
|
||||
}
|
||||
|
|
@ -2533,11 +2454,6 @@ namespace Server
|
|||
}
|
||||
}
|
||||
|
||||
public void ReleaseWorldPackets()
|
||||
{
|
||||
StaticPacketHandlers.FreeWorldItemPackets(this);
|
||||
}
|
||||
|
||||
public virtual int GetPacketFlags()
|
||||
{
|
||||
var flags = 0;
|
||||
|
|
@ -3163,36 +3079,39 @@ namespace Server
|
|||
|
||||
public virtual int GetUpdateRange(Mobile m) => 18;
|
||||
|
||||
public void SendInfoTo(NetState state)
|
||||
public virtual void SendInfoTo(NetState ns, ReadOnlySpan<byte> world, ReadOnlySpan<byte> opl = default)
|
||||
{
|
||||
SendInfoTo(state, ObjectPropertyList.Enabled);
|
||||
SendWorldPacketTo(ns, world);
|
||||
SendOPLPacketTo(ns, opl);
|
||||
}
|
||||
|
||||
public virtual void SendInfoTo(NetState state, bool sendOplPacket)
|
||||
{
|
||||
state.Send(GetWorldPacketFor(state));
|
||||
public void SendInfoTo(NetState ns) => SendInfoTo(ns, ObjectPropertyList.Enabled);
|
||||
|
||||
public virtual void SendInfoTo(NetState ns, bool sendOplPacket)
|
||||
{
|
||||
SendWorldPacketTo(ns);
|
||||
SendOPLPacketTo(ns, sendOplPacket);
|
||||
}
|
||||
|
||||
public void SendOPLPacketTo(NetState ns) => SendOPLPacketTo(ns, ObjectPropertyList.Enabled);
|
||||
|
||||
public virtual void SendOPLPacketTo(NetState ns, bool sendOplPacket)
|
||||
{
|
||||
if (sendOplPacket)
|
||||
{
|
||||
state.Send(OPLPacket);
|
||||
ns.SendOPLInfo(this);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual Packet GetWorldPacketFor(NetState state)
|
||||
public virtual void SendOPLPacketTo(NetState ns, ReadOnlySpan<byte> opl)
|
||||
{
|
||||
if (state.HighSeas)
|
||||
{
|
||||
return WorldPacketHS;
|
||||
}
|
||||
|
||||
if (state.StygianAbyss)
|
||||
{
|
||||
return WorldPacketSA;
|
||||
}
|
||||
|
||||
return WorldPacket;
|
||||
ns?.Send(opl);
|
||||
}
|
||||
|
||||
protected virtual void SendWorldPacketTo(NetState ns) => ns.SendWorldItem(this);
|
||||
|
||||
public virtual void SendWorldPacketTo(NetState ns, ReadOnlySpan<byte> world) => ns?.Send(world);
|
||||
|
||||
public virtual int GetTotal(TotalType type) => 0;
|
||||
|
||||
public virtual void UpdateTotal(Item sender, TotalType type, int delta)
|
||||
|
|
@ -3408,14 +3327,6 @@ namespace Server
|
|||
Delete();
|
||||
}
|
||||
|
||||
public virtual void FreeCache()
|
||||
{
|
||||
ReleaseWorldPackets();
|
||||
StaticPacketHandlers.FreeRemoveItemPacket(this);
|
||||
StaticPacketHandlers.FreeOPLInfoPacket(this);
|
||||
ReleaseOPLPacket();
|
||||
}
|
||||
|
||||
public void PublicOverheadMessage(MessageType type, int hue, bool ascii, string text)
|
||||
{
|
||||
if (m_Map == null)
|
||||
|
|
@ -3489,12 +3400,10 @@ namespace Server
|
|||
{
|
||||
var items = LookupItems();
|
||||
|
||||
if (items?.Contains(item) == true)
|
||||
if (items.Remove(item))
|
||||
{
|
||||
item.SendRemovePacket();
|
||||
|
||||
items.Remove(item);
|
||||
|
||||
if (!item.IsVirtualItem)
|
||||
{
|
||||
UpdateTotal(item, TotalType.Gold, -item.TotalGold);
|
||||
|
|
@ -3712,28 +3621,27 @@ namespace Server
|
|||
var eable = map.GetItemsInRange(p, 0);
|
||||
|
||||
var items = eable.Where(
|
||||
item =>
|
||||
item =>
|
||||
{
|
||||
if (item is BaseMulti || item.ItemID > TileData.MaxItemValue)
|
||||
{
|
||||
if (item is BaseMulti || item.ItemID > TileData.MaxItemValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var id = item.ItemData;
|
||||
|
||||
if (id.Surface)
|
||||
{
|
||||
var top = item.Z + id.CalcHeight;
|
||||
if (top <= maxZ && top >= z)
|
||||
{
|
||||
z = top;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
)
|
||||
.ToList();
|
||||
|
||||
var id = item.ItemData;
|
||||
|
||||
if (id.Surface)
|
||||
{
|
||||
var top = item.Z + id.CalcHeight;
|
||||
if (top <= maxZ && top >= z)
|
||||
{
|
||||
z = top;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
).ToList();
|
||||
|
||||
eable.Free();
|
||||
|
||||
|
|
@ -3915,24 +3823,27 @@ namespace Server
|
|||
return true;
|
||||
}
|
||||
|
||||
public void SendRemovePacket()
|
||||
public void SendRemovePacket() => SendRemovePacket(GetWorldLocation());
|
||||
|
||||
public void SendRemovePacket(Point3D worldLoc)
|
||||
{
|
||||
if (Deleted || m_Map == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var worldLoc = GetWorldLocation();
|
||||
|
||||
var eable = m_Map.GetClientsInRange(worldLoc, GetMaxUpdateRange());
|
||||
|
||||
Span<byte> removeEntity = stackalloc byte[OutgoingEntityPackets.RemoveEntityLength];
|
||||
OutgoingEntityPackets.CreateRemoveEntity(ref removeEntity, Serial);
|
||||
|
||||
foreach (var state in eable)
|
||||
{
|
||||
var m = state.Mobile;
|
||||
|
||||
if (m.InRange(worldLoc, GetUpdateRange(m)))
|
||||
{
|
||||
state.Send(RemovePacket);
|
||||
state.Send(removeEntity);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1787,8 +1787,6 @@ namespace Server
|
|||
|
||||
public Region Region => m_Region ?? (Map == null ? Map.Internal.DefaultRegion : Map.DefaultRegion);
|
||||
|
||||
public Packet RemovePacket => StaticPacketHandlers.GetRemoveEntityPacket(this);
|
||||
|
||||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public int SolidHueOverride
|
||||
{
|
||||
|
|
@ -2566,8 +2564,7 @@ namespace Server
|
|||
public int CompareTo(Mobile other) => other == null ? -1 : Serial.CompareTo(other.Serial);
|
||||
|
||||
public virtual int HuedItemID => m_Female ? 0x2107 : 0x2106;
|
||||
public OPLInfo OPLPacket => StaticPacketHandlers.GetOPLInfoPacket(this);
|
||||
public ObjectPropertyList PropertyList => m_PropertyList ??= NewObjectPropertyList();
|
||||
public ObjectPropertyList PropertyList => m_PropertyList ??= InitializePropertyList(new ObjectPropertyList(this));
|
||||
|
||||
public virtual void GetProperties(ObjectPropertyList list)
|
||||
{
|
||||
|
|
@ -2783,7 +2780,7 @@ namespace Server
|
|||
|
||||
OnAfterDelete();
|
||||
|
||||
FreeCache();
|
||||
m_PropertyList = null;
|
||||
}
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)]
|
||||
|
|
@ -3305,7 +3302,7 @@ namespace Server
|
|||
|
||||
if (sendOPLUpdate)
|
||||
{
|
||||
ourState.Send(OPLPacket);
|
||||
SendOPLPacketTo(ourState);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -3332,6 +3329,9 @@ namespace Server
|
|||
|
||||
var eable = m.Map.GetClientsInRange(m.m_Location);
|
||||
|
||||
Span<byte> removeEntity = stackalloc byte[OutgoingEntityPackets.RemoveEntityLength];
|
||||
OutgoingEntityPackets.CreateRemoveEntity(ref removeEntity, Serial);
|
||||
|
||||
foreach (var state in eable)
|
||||
{
|
||||
beholder = state.Mobile;
|
||||
|
|
@ -3340,7 +3340,7 @@ namespace Server
|
|||
{
|
||||
if (sendRemove)
|
||||
{
|
||||
state.Send(RemovePacket);
|
||||
state.Send(removeEntity);
|
||||
}
|
||||
|
||||
if (sendIncoming)
|
||||
|
|
@ -3440,10 +3440,7 @@ namespace Server
|
|||
state.Send(facialhairPacket);
|
||||
}
|
||||
|
||||
if (sendOPLUpdate)
|
||||
{
|
||||
state.Send(OPLPacket);
|
||||
}
|
||||
SendOPLPacketTo(state);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -3498,17 +3495,6 @@ namespace Server
|
|||
&& p.Y >= Location.m_Y - range
|
||||
&& p.Y <= Location.m_Y + range;
|
||||
|
||||
public void ReleaseOPLPacket()
|
||||
{
|
||||
if (m_PropertyList == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Packet.Release(m_PropertyList);
|
||||
m_PropertyList = null;
|
||||
}
|
||||
|
||||
protected virtual void OnRaceChange(Race oldRace)
|
||||
{
|
||||
}
|
||||
|
|
@ -3667,7 +3653,7 @@ namespace Server
|
|||
|
||||
public virtual void SendPropertiesTo(Mobile from)
|
||||
{
|
||||
from.Send(PropertyList);
|
||||
from.NetState?.Send(PropertyList.Buffer);
|
||||
}
|
||||
|
||||
public virtual void OnAosSingleClick(Mobile from)
|
||||
|
|
@ -5230,6 +5216,9 @@ namespace Server
|
|||
var eable = m_Map.GetClientsInRange(m_Location);
|
||||
var corpseSerial = c?.Serial ?? Serial.Zero;
|
||||
|
||||
Span<byte> removeEntity = stackalloc byte[OutgoingEntityPackets.RemoveEntityLength];
|
||||
OutgoingEntityPackets.CreateRemoveEntity(ref removeEntity, Serial);
|
||||
|
||||
foreach (var state in eable)
|
||||
{
|
||||
if (state != m_NetState)
|
||||
|
|
@ -5240,7 +5229,7 @@ namespace Server
|
|||
|
||||
if (!state.Mobile.CanSee(this))
|
||||
{
|
||||
state.Send(RemovePacket);
|
||||
state.Send(removeEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -5587,14 +5576,7 @@ namespace Server
|
|||
|
||||
if (item.Parent is Item)
|
||||
{
|
||||
if (state.ContainerGridLines)
|
||||
{
|
||||
state.Send(new ContainerContentUpdate6017(item));
|
||||
}
|
||||
else
|
||||
{
|
||||
state.Send(new ContainerContentUpdate(item));
|
||||
}
|
||||
state.SendContainerContentUpdate(item);
|
||||
}
|
||||
else if (item.Parent is Mobile)
|
||||
{
|
||||
|
|
@ -5605,9 +5587,9 @@ namespace Server
|
|||
item.SendInfoTo(state);
|
||||
}
|
||||
|
||||
if (ObjectPropertyList.Enabled && item.Parent != null)
|
||||
if (item.Parent != null)
|
||||
{
|
||||
state.Send(item.OPLPacket);
|
||||
item.SendOPLPacketTo(state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -7062,14 +7044,10 @@ namespace Server
|
|||
return;
|
||||
}
|
||||
|
||||
if (Items.Contains(item))
|
||||
if (Items.Remove(item))
|
||||
{
|
||||
item.SendRemovePacket();
|
||||
|
||||
// int oldCount = m_Items.Count;
|
||||
|
||||
Items.Remove(item);
|
||||
|
||||
if (!item.IsVirtualItem)
|
||||
{
|
||||
UpdateTotal(item, TotalType.Gold, -item.TotalGold);
|
||||
|
|
@ -7230,6 +7208,21 @@ namespace Server
|
|||
eable.Free();
|
||||
}
|
||||
|
||||
public void SendOPLPacketTo(NetState state) => SendOPLPacketTo(state, ObjectPropertyList.Enabled);
|
||||
|
||||
protected virtual void SendOPLPacketTo(NetState ns, bool sendOplPacket)
|
||||
{
|
||||
if (sendOplPacket)
|
||||
{
|
||||
ns.SendOPLInfo(this);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void SendOPLPacketTo(NetState ns, ReadOnlySpan<byte> opl)
|
||||
{
|
||||
ns?.Send(opl);
|
||||
}
|
||||
|
||||
public virtual void OnAccessLevelChanged(AccessLevel oldLevel)
|
||||
{
|
||||
}
|
||||
|
|
@ -7262,11 +7255,14 @@ namespace Server
|
|||
|
||||
var eable = m_Map.GetClientsInRange(m_Location);
|
||||
|
||||
Span<byte> removeEntity = stackalloc byte[OutgoingEntityPackets.RemoveEntityLength];
|
||||
OutgoingEntityPackets.CreateRemoveEntity(ref removeEntity, Serial);
|
||||
|
||||
foreach (var state in eable)
|
||||
{
|
||||
if (state != m_NetState && (everyone || !state.Mobile.CanSee(this)))
|
||||
{
|
||||
state.Send(RemovePacket);
|
||||
state.Send(removeEntity);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -7288,14 +7284,14 @@ namespace Server
|
|||
{
|
||||
if (m != this && Utility.InUpdateRange(m_Location, m.m_Location))
|
||||
{
|
||||
m_NetState.Send(m.RemovePacket);
|
||||
m_NetState.SendRemoveEntity(m.Serial);
|
||||
}
|
||||
}
|
||||
else if (o is Item item)
|
||||
{
|
||||
if (InRange(item.Location, item.GetUpdateRange(this)))
|
||||
{
|
||||
m_NetState.Send(item.RemovePacket);
|
||||
m_NetState.SendRemoveEntity(item.Serial);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -7399,10 +7395,7 @@ namespace Server
|
|||
ns.SendBondedStatus(m.Serial, true);
|
||||
}
|
||||
|
||||
if (ObjectPropertyList.Enabled)
|
||||
{
|
||||
ns.Send(m.OPLPacket);
|
||||
}
|
||||
m.SendOPLPacketTo(ns);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -7544,11 +7537,14 @@ namespace Server
|
|||
|
||||
var eable = m_Map.GetClientsInRange(m_Location);
|
||||
|
||||
Span<byte> removeEntity = stackalloc byte[OutgoingEntityPackets.RemoveEntityLength];
|
||||
OutgoingEntityPackets.CreateRemoveEntity(ref removeEntity, Serial);
|
||||
|
||||
foreach (var state in eable)
|
||||
{
|
||||
if (!state.Mobile.CanSee(this))
|
||||
{
|
||||
state.Send(RemovePacket);
|
||||
state.Send(removeEntity);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -7559,10 +7555,7 @@ namespace Server
|
|||
state.SendBondedStatus(Serial, true);
|
||||
}
|
||||
|
||||
if (ObjectPropertyList.Enabled)
|
||||
{
|
||||
state.Send(OPLPacket);
|
||||
}
|
||||
SendOPLPacketTo(state);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -7685,28 +7678,16 @@ namespace Server
|
|||
return delta != 0 ? body : 0;
|
||||
}
|
||||
|
||||
public virtual void FreeCache()
|
||||
private ObjectPropertyList InitializePropertyList(ObjectPropertyList list)
|
||||
{
|
||||
StaticPacketHandlers.FreeRemoveItemPacket(this);
|
||||
StaticPacketHandlers.FreeOPLInfoPacket(this);
|
||||
ReleaseOPLPacket();
|
||||
}
|
||||
|
||||
public ObjectPropertyList NewObjectPropertyList()
|
||||
{
|
||||
var list = new ObjectPropertyList(this);
|
||||
|
||||
GetProperties(list);
|
||||
|
||||
list.Terminate();
|
||||
list.SetStatic();
|
||||
return list;
|
||||
}
|
||||
|
||||
public void ClearProperties()
|
||||
{
|
||||
ReleaseOPLPacket();
|
||||
StaticPacketHandlers.FreeOPLInfoPacket(this);
|
||||
m_PropertyList = null;
|
||||
}
|
||||
|
||||
public void InvalidateProperties()
|
||||
|
|
@ -7718,12 +7699,23 @@ namespace Server
|
|||
|
||||
if (m_Map != null && m_Map != Map.Internal && !World.Loading)
|
||||
{
|
||||
var oldList = m_PropertyList;
|
||||
m_PropertyList = null;
|
||||
|
||||
if (oldList != null && oldList.Hash != PropertyList.Hash)
|
||||
int? oldHash;
|
||||
int newHash;
|
||||
if (m_PropertyList != null)
|
||||
{
|
||||
oldHash = m_PropertyList.Hash;
|
||||
m_PropertyList.Reset();
|
||||
InitializePropertyList(m_PropertyList);
|
||||
newHash = m_PropertyList.Hash;
|
||||
}
|
||||
else
|
||||
{
|
||||
oldHash = null;
|
||||
newHash = PropertyList.Hash;
|
||||
}
|
||||
|
||||
if (oldHash != newHash)
|
||||
{
|
||||
StaticPacketHandlers.FreeOPLInfoPacket(this);
|
||||
Delta(MobileDelta.Properties);
|
||||
}
|
||||
}
|
||||
|
|
@ -7783,11 +7775,14 @@ namespace Server
|
|||
|
||||
var eable = map.GetClientsInRange(oldLocation);
|
||||
|
||||
Span<byte> removeEntity = stackalloc byte[OutgoingEntityPackets.RemoveEntityLength];
|
||||
OutgoingEntityPackets.CreateRemoveEntity(ref removeEntity, Serial);
|
||||
|
||||
foreach (var ns in eable)
|
||||
{
|
||||
if (ns != m_NetState && !Utility.InUpdateRange(newLocation, ns.Mobile.Location))
|
||||
{
|
||||
ns.Send(RemovePacket);
|
||||
ns.Send(removeEntity);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -7843,10 +7838,7 @@ namespace Server
|
|||
m.m_NetState.SendBondedStatus(Serial, true);
|
||||
}
|
||||
|
||||
if (ObjectPropertyList.Enabled)
|
||||
{
|
||||
m.m_NetState.Send(OPLPacket);
|
||||
}
|
||||
SendOPLPacketTo(m.m_NetState);
|
||||
}
|
||||
|
||||
if (inOldRange || !CanSee(m))
|
||||
|
|
@ -7870,10 +7862,7 @@ namespace Server
|
|||
ourState.SendBondedStatus(m.Serial, true);
|
||||
}
|
||||
|
||||
if (ObjectPropertyList.Enabled)
|
||||
{
|
||||
ourState.Send(m.OPLPacket);
|
||||
}
|
||||
m.SendOPLPacketTo(ourState);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -7905,10 +7894,7 @@ namespace Server
|
|||
ns.SendBondedStatus(Serial, true);
|
||||
}
|
||||
|
||||
if (ObjectPropertyList.Enabled)
|
||||
{
|
||||
ns.Send(OPLPacket);
|
||||
}
|
||||
SendOPLPacketTo(ns);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -7993,10 +7979,7 @@ namespace Server
|
|||
state.SendBondedStatus(Serial, true);
|
||||
}
|
||||
|
||||
if (ObjectPropertyList.Enabled)
|
||||
{
|
||||
state.Send(OPLPacket);
|
||||
}
|
||||
SendOPLPacketTo(state);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
216
Projects/Server/Network/Packets/OutgoingContainerPackets.cs
Normal file
216
Projects/Server/Network/Packets/OutgoingContainerPackets.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
73
Projects/Server/Network/Packets/OutgoingEntityPackets.cs
Normal file
73
Projects/Server/Network/Packets/OutgoingEntityPackets.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
140
Projects/Server/Network/Packets/OutgoingItemPackets.cs
Normal file
140
Projects/Server/Network/Packets/OutgoingItemPackets.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,21 +1,18 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Buffers;
|
||||
using System.Text;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
public interface IPropertyListObject : IEntity
|
||||
{
|
||||
ObjectPropertyList PropertyList { get; }
|
||||
OPLInfo OPLPacket { get; }
|
||||
|
||||
void GetProperties(ObjectPropertyList list);
|
||||
}
|
||||
|
||||
public sealed class ObjectPropertyList : Packet
|
||||
public sealed class ObjectPropertyList
|
||||
{
|
||||
private static byte[] m_Buffer = new byte[1024];
|
||||
private static readonly Encoding m_Encoding = Encoding.Unicode;
|
||||
|
||||
// Each of these are localized to "~1_NOTHING~" which allows the string argument to be used
|
||||
|
|
@ -25,25 +22,26 @@ namespace Server
|
|||
1070722
|
||||
};
|
||||
|
||||
private int m_Hash;
|
||||
private int m_Strings;
|
||||
private int _hash;
|
||||
private int _strings;
|
||||
private byte[] _buffer = new byte[64];
|
||||
private int _position;
|
||||
|
||||
public ObjectPropertyList(IEntity e) : base(0xD6)
|
||||
public ObjectPropertyList(IEntity e)
|
||||
{
|
||||
EnsureCapacity(128);
|
||||
|
||||
Entity = e;
|
||||
|
||||
Stream.Write((short)1);
|
||||
Stream.Write(e.Serial);
|
||||
Stream.Write((byte)0);
|
||||
Stream.Write((byte)0);
|
||||
Stream.Write(e.Serial);
|
||||
Span<byte> buffer = _buffer;
|
||||
buffer.Write(ref _position, (byte)0xD6); // Packet ID
|
||||
_position += 2; // Length
|
||||
buffer.Write(ref _position, (ushort)1);
|
||||
buffer.Write(ref _position, e.Serial);
|
||||
buffer.Write(ref _position, (ushort)0);
|
||||
_position += 4; // Hash
|
||||
}
|
||||
|
||||
public IEntity Entity { get; }
|
||||
|
||||
public int Hash => 0x40000000 + m_Hash;
|
||||
public int Hash => 0x40000000 + _hash;
|
||||
|
||||
public int Header { get; set; }
|
||||
|
||||
|
|
@ -51,40 +49,46 @@ namespace Server
|
|||
|
||||
public static bool Enabled { get; set; }
|
||||
|
||||
public void Add(int number)
|
||||
public byte[] Buffer => _buffer;
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
if (number == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_position = 15;
|
||||
_hash = 0;
|
||||
_strings = 0;
|
||||
}
|
||||
|
||||
AddHash(number);
|
||||
public void Flush()
|
||||
{
|
||||
Resize(_buffer.Length * 2);
|
||||
}
|
||||
|
||||
if (Header == 0)
|
||||
{
|
||||
Header = number;
|
||||
HeaderArgs = "";
|
||||
}
|
||||
|
||||
Stream.Write(number);
|
||||
Stream.Write((short)0);
|
||||
private void Resize(int amount)
|
||||
{
|
||||
Array.Resize(ref _buffer, amount);
|
||||
}
|
||||
|
||||
public void Terminate()
|
||||
{
|
||||
Stream.Write(0);
|
||||
int length = _position + 4;
|
||||
if (length != _buffer.Length)
|
||||
{
|
||||
Resize(length);
|
||||
}
|
||||
|
||||
Stream.Seek(11, SeekOrigin.Begin);
|
||||
Stream.Write(m_Hash);
|
||||
Span<byte> buffer = _buffer;
|
||||
buffer.Write(ref _position, 0);
|
||||
buffer.Slice(11, 4).Write(_hash);
|
||||
buffer.Slice(1, 2).Write((ushort)_position);
|
||||
}
|
||||
|
||||
public void AddHash(int val)
|
||||
{
|
||||
m_Hash ^= val & 0x3FFFFFF;
|
||||
m_Hash ^= (val >> 26) & 0x3F;
|
||||
_hash ^= val & 0x3FFFFFF;
|
||||
_hash ^= (val >> 26) & 0x3F;
|
||||
}
|
||||
|
||||
public void Add(int number, string arguments)
|
||||
public void Add(int number, string arguments = null)
|
||||
{
|
||||
if (number == 0)
|
||||
{
|
||||
|
|
@ -100,21 +104,27 @@ namespace Server
|
|||
}
|
||||
|
||||
AddHash(number);
|
||||
AddHash(arguments.GetHashCode(StringComparison.Ordinal));
|
||||
|
||||
Stream.Write(number);
|
||||
|
||||
var byteCount = m_Encoding.GetByteCount(arguments);
|
||||
|
||||
if (byteCount > m_Buffer.Length)
|
||||
if (arguments.Length > 0)
|
||||
{
|
||||
m_Buffer = new byte[byteCount];
|
||||
AddHash(arguments.GetHashCode(StringComparison.Ordinal));
|
||||
}
|
||||
|
||||
byteCount = m_Encoding.GetBytes(arguments, 0, arguments.Length, m_Buffer, 0);
|
||||
int strLength = m_Encoding.GetByteCount(arguments);
|
||||
|
||||
Stream.Write((short)byteCount);
|
||||
Stream.Write(m_Buffer, 0, byteCount);
|
||||
int length = _position + 6 + strLength;
|
||||
if (length > _buffer.Length)
|
||||
{
|
||||
Flush();
|
||||
}
|
||||
|
||||
Span<byte> buffer = _buffer;
|
||||
buffer.Write(ref _position, number);
|
||||
buffer.Write(ref _position, (ushort)strLength);
|
||||
if (strLength > 0)
|
||||
{
|
||||
m_Encoding.GetBytes(arguments, buffer.Slice(_position));
|
||||
_position += strLength;
|
||||
}
|
||||
}
|
||||
|
||||
public void Add(int number, string format, object arg0)
|
||||
|
|
@ -137,7 +147,7 @@ namespace Server
|
|||
Add(number, string.Format(format, args));
|
||||
}
|
||||
|
||||
private int GetStringNumber() => m_StringNumbers[m_Strings++ % m_StringNumbers.Length];
|
||||
private int GetStringNumber() => m_StringNumbers[_strings++ % m_StringNumbers.Length];
|
||||
|
||||
public void Add(string text)
|
||||
{
|
||||
|
|
@ -164,22 +174,4 @@ namespace Server
|
|||
Add(GetStringNumber(), string.Format(format, args));
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class OPLInfo : Packet
|
||||
{
|
||||
/*public OPLInfo( ObjectPropertyList list ) : base( 0xBF )
|
||||
{
|
||||
EnsureCapacity( 13 );
|
||||
|
||||
m_Stream.Write( (short) 0x10 );
|
||||
m_Stream.Write( (int) list.Entity.Serial );
|
||||
m_Stream.Write( (int) list.Hash );
|
||||
}*/
|
||||
|
||||
public OPLInfo(Serial serial, int hash) : base(0xDC, 9)
|
||||
{
|
||||
Stream.Write(serial);
|
||||
Stream.Write(hash);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue