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

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using Server.Mobiles;
using Server.Network;
@ -66,13 +67,19 @@ namespace Server.Commands
pm.VisibilityList.Clear();
pm.SendMessage("Your visibility list has been cleared.");
for (var i = 0; i < list.Count; ++i)
if (list.Count > 0)
{
var m = list[i];
Span<byte> removeEntity = stackalloc byte[OutgoingEntityPackets.RemoveEntityLength];
OutgoingEntityPackets.CreateRemoveEntity(ref removeEntity, pm.Serial);
if (!m.CanSee(pm) && Utility.InUpdateRange(m, pm))
for (var i = 0; i < list.Count; ++i)
{
m.Send(pm.RemovePacket);
var m = list[i];
if (!m.CanSee(pm) && Utility.InUpdateRange(m, pm))
{
m.NetState?.Send(removeEntity);
}
}
}
}
@ -113,19 +120,16 @@ namespace Server.Commands
{
ns.Send(MobileIncoming.Create(ns, targ, pm));
if (ObjectPropertyList.Enabled)
{
ns.Send(pm.OPLPacket);
pm.SendOPLPacketTo(ns);
foreach (var item in pm.Items)
{
ns.Send(item.OPLPacket);
}
foreach (var item in pm.Items)
{
item.SendOPLPacketTo(ns);
}
}
else
{
ns.Send(pm.RemovePacket);
ns.SendRemoveEntity(pm.Serial);
}
}
}

View file

@ -126,7 +126,7 @@ namespace Server.Engines.ConPVP
{
if (!mob.CanSee(view))
{
mob.Send(view.RemovePacket);
mob.NetState.SendRemoveEntity(view.Serial);
}
}

View file

@ -1,9 +1,13 @@
using System;
using System.Buffers.Binary;
using Server.Network;
namespace Server.Items
{
public class Blocker : Item
{
private const ushort GMItemId = 0x1183;
[Constructible]
public Blocker() : base(0x21A4) => Movable = false;
@ -13,16 +17,49 @@ namespace Server.Items
public override int LabelNumber => 503057; // Impassable!
protected override Packet GetWorldPacketFor(NetState state)
public override void SendWorldPacketTo(NetState ns, ReadOnlySpan<byte> world)
{
var mob = state.Mobile;
if (mob?.AccessLevel >= AccessLevel.GameMaster)
var mob = ns.Mobile;
if (AccessLevel.GameMaster >= mob?.AccessLevel)
{
return new GMItemPacket(this);
base.SendWorldPacketTo(ns, world);
return;
}
return base.GetWorldPacketFor(state);
SendGMItem(ns);
}
protected override void SendWorldPacketTo(NetState ns)
{
var mob = ns.Mobile;
if (AccessLevel.GameMaster >= mob?.AccessLevel)
{
base.SendWorldPacketTo(ns);
return;
}
SendGMItem(ns);
}
private void SendGMItem(NetState ns)
{
// GM Packet
Span<byte> buffer = stackalloc byte[OutgoingItemPackets.MaxWorldItemPacketLength];
int length;
if (ns.StygianAbyss)
{
length = OutgoingItemPackets.CreateWorldItemNew(ref buffer, this, ns.HighSeas);
BinaryPrimitives.WriteUInt16BigEndian(buffer.Slice(8, 2), GMItemId);
}
else
{
length = OutgoingItemPackets.CreateWorldItem(ref buffer, this);
BinaryPrimitives.WriteUInt16BigEndian(buffer.Slice(7, 2), GMItemId);
}
ns.Send(buffer.Slice(0, length));
}
public override void Serialize(IGenericWriter writer)
@ -38,85 +75,5 @@ namespace Server.Items
var version = reader.ReadInt();
}
public sealed class GMItemPacket : Packet
{
public GMItemPacket(Item item) : base(0x1A)
{
EnsureCapacity(20);
// 14 base length
// +2 - Amount
// +2 - Hue
// +1 - Flags
var serial = item.Serial.Value;
var itemID = 0x1183;
var amount = item.Amount;
var loc = item.Location;
var x = loc.X;
var y = loc.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);
Stream.Write((short)(itemID & 0x7FFF));
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.Z);
if (hue != 0)
{
Stream.Write((ushort)hue);
}
if (flags != 0)
{
Stream.Write((byte)flags);
}
}
}
}
}

View file

@ -167,14 +167,7 @@ namespace Server.Items
var state = from.NetState;
state.Send(new BBDisplayBoard(this));
if (state.ContainerGridLines)
{
state.Send(new ContainerContent6017(from, this));
}
else
{
state.Send(new ContainerContent(from, this));
}
state.SendContainerContent(from, this);
}
else
{

View file

@ -1,5 +1,7 @@
using System;
using System.Buffers;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using Server.ContextMenus;
using Server.Engines.PartySystem;
using Server.Engines.Quests.Doom;
@ -799,25 +801,39 @@ namespace Server.Items
return m_Devourer.Devour(this); // Devour the corpse if it hasn't
}
public override void SendInfoTo(NetState state, bool sendOplPacket)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void SendCorpseContent(NetState ns)
{
base.SendInfoTo(state, sendOplPacket);
if (!(((Body)Amount).IsHuman && ItemID == 0x2006))
if (ns.ContainerGridLines)
{
return;
}
if (state.ContainerGridLines)
{
state.Send(new CorpseContent6017(state.Mobile, this));
ns.Send(new CorpseContent6017(ns.Mobile, this));
}
else
{
state.Send(new CorpseContent(state.Mobile, this));
ns.Send(new CorpseContent(ns.Mobile, this));
}
state.Send(new CorpseEquip(state.Mobile, this));
ns.Send(new CorpseEquip(ns.Mobile, this));
}
public override void SendInfoTo(NetState ns, bool sendOplPacket)
{
base.SendInfoTo(ns, sendOplPacket);
if (((Body)Amount).IsHuman && ItemID == 0x2006)
{
SendCorpseContent(ns);
}
}
public override void SendInfoTo(NetState ns, ReadOnlySpan<byte> world, ReadOnlySpan<byte> opl = default)
{
base.SendInfoTo(ns, world, opl);
if (((Body)Amount).IsHuman && ItemID == 0x2006)
{
SendCorpseContent(ns);
}
}
public bool IsCriminalAction(Mobile from)

View file

@ -1,9 +1,13 @@
using System;
using System.Buffers.Binary;
using Server.Network;
namespace Server.Items
{
public class LOSBlocker : Item
{
private const ushort GMItemId = 0x36FF;
[Constructible]
public LOSBlocker() : base(0x21A2) => Movable = false;
@ -19,16 +23,49 @@ namespace Server.Items
TileData.ItemTable[0x21A2].Height = 20;
}
protected override Packet GetWorldPacketFor(NetState state)
public override void SendWorldPacketTo(NetState ns, ReadOnlySpan<byte> world)
{
var mob = state.Mobile;
if (mob?.AccessLevel >= AccessLevel.GameMaster)
var mob = ns.Mobile;
if (AccessLevel.GameMaster >= mob?.AccessLevel)
{
return new GMItemPacket(this);
base.SendWorldPacketTo(ns, world);
return;
}
return base.GetWorldPacketFor(state);
SendGMItem(ns);
}
protected override void SendWorldPacketTo(NetState ns)
{
var mob = ns.Mobile;
if (AccessLevel.GameMaster >= mob?.AccessLevel)
{
base.SendWorldPacketTo(ns);
return;
}
SendGMItem(ns);
}
private void SendGMItem(NetState ns)
{
// GM Packet
Span<byte> buffer = stackalloc byte[OutgoingItemPackets.MaxWorldItemPacketLength];
int length;
if (ns.StygianAbyss)
{
length = OutgoingItemPackets.CreateWorldItemNew(ref buffer, this, ns.HighSeas);
BinaryPrimitives.WriteUInt16BigEndian(buffer.Slice(8, 2), GMItemId);
}
else
{
length = OutgoingItemPackets.CreateWorldItem(ref buffer, this);
BinaryPrimitives.WriteUInt16BigEndian(buffer.Slice(7, 2), GMItemId);
}
ns.Send(buffer.Slice(0, length));
}
public override void Serialize(IGenericWriter writer)
@ -49,85 +86,5 @@ namespace Server.Items
ItemID = 0x21A2;
}
}
public sealed class GMItemPacket : Packet
{
public GMItemPacket(Item item) : base(0x1A)
{
EnsureCapacity(20);
// 14 base length
// +2 - Amount
// +2 - Hue
// +1 - Flags
var serial = item.Serial.Value;
var itemID = 0x36FF;
var amount = item.Amount;
var loc = item.Location;
var x = loc.X;
var y = loc.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);
Stream.Write((short)(itemID & 0x7FFF));
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.Z);
if (hue != 0)
{
Stream.Write((ushort)hue);
}
if (flags != 0)
{
Stream.Write((byte)flags);
}
}
}
}
}

View file

@ -669,7 +669,6 @@ namespace Server.Items
public void DisplayTo(Mobile to)
{
// The client must know about the spellbook or it will crash!
var ns = to.NetState;
if (ns == null)
@ -679,64 +678,19 @@ namespace Server.Items
if (Parent == null)
{
to.Send(WorldPacket);
SendWorldPacketTo(to.NetState);
}
else if (Parent is Item)
{
// What will happen if the client doesn't know about our parent?
if (ns.ContainerGridLines)
{
to.Send(new ContainerContentUpdate6017(this));
}
else
{
to.Send(new ContainerContentUpdate(this));
}
to.NetState.SendContainerContentUpdate(this);
}
else if (Parent is Mobile)
{
// What will happen if the client doesn't know about our parent?
to.NetState.SendEquipUpdate(this);
}
if (ns.HighSeas)
{
to.Send(new DisplaySpellbookHS(Serial));
}
else
{
to.Send(new DisplaySpellbook(Serial));
}
if (ObjectPropertyList.Enabled)
{
if (ns.NewSpellbook)
{
to.Send(new NewSpellbookContent(Serial, ItemID, BookOffset + 1, m_Content));
}
else
{
if (ns.ContainerGridLines)
{
to.Send(new SpellbookContent6017(Serial, BookOffset + 1, m_Content));
}
else
{
to.Send(new SpellbookContent(Serial, BookOffset + 1, m_Content));
}
}
}
else
{
if (ns.ContainerGridLines)
{
to.Send(new SpellbookContent6017(Serial, BookOffset + 1, m_Content));
}
else
{
to.Send(new SpellbookContent(Serial, BookOffset + 1, m_Content));
}
}
to.NetState.SendDisplaySpellbook(Serial);
to.NetState.SendSpellbookContent(Serial, ItemID, BookOffset + 1, m_Content);
}
public override void GetProperties(ObjectPropertyList list)

View file

@ -20,18 +20,13 @@ namespace Server.Misc
)
);
if (ObjectPropertyList.Enabled)
for (var i = 0; i < beheld.Items.Count; ++i)
{
var items = beheld.Items;
for (var i = 0; i < items.Count; ++i)
{
beholder.Send(items[i].OPLPacket);
}
// NOTE: OSI sends MobileUpdate when opening your own paperdoll.
// It has a very bad rubber-banding affect. What positive affects does it have?
beheld.Items[i].SendOPLPacketTo(beholder.NetState);
}
// NOTE: OSI sends MobileUpdate when opening your own paperdoll.
// It has a very bad rubber-banding affect. What positive affects does it have?
}
}
}

View file

@ -916,16 +916,13 @@ namespace Server.Mobiles
{
var mobiles = Map.GetMobilesInRange(location, 0);
var found = mobiles.Any(
m =>
m.Z >= location.Z && m.Z < location.Z + 16 && (!m.Hidden || m.AccessLevel == AccessLevel.Player)
);
mobiles.Free();
if (found)
foreach (Mobile m in mobiles)
{
return false;
if (m.Z >= location.Z && m.Z < location.Z + 16 && (!m.Hidden || m.AccessLevel == AccessLevel.Player))
{
mobiles.Free();
return false;
}
}
mobiles.Free();
@ -933,51 +930,51 @@ namespace Server.Mobiles
var bi = item.GetBounce();
if (bi != null)
if (bi == null)
{
var type = item.GetType();
return true;
}
if (type.IsDefined(typeof(FurnitureAttribute), true) ||
type.IsDefined(typeof(DynamicFlipingAttribute), true))
var type = item.GetType();
if (type.IsDefined(typeof(FurnitureAttribute), true) ||
type.IsDefined(typeof(DynamicFlipingAttribute), true))
{
var objs = type.GetCustomAttributes(typeof(FlippableAttribute), true);
if (objs.Length > 0)
{
var objs = type.GetCustomAttributes(typeof(FlippableAttribute), true);
if (objs.Length > 0)
if (objs[0] is FlippableAttribute fp)
{
if (objs[0] is FlippableAttribute fp)
var itemIDs = fp.ItemIDs;
var oldWorldLoc = bi.WorldLoc;
var newWorldLoc = location;
if (oldWorldLoc.X != newWorldLoc.X || oldWorldLoc.Y != newWorldLoc.Y)
{
var itemIDs = fp.ItemIDs;
var dir = GetDirection4(oldWorldLoc, newWorldLoc);
var oldWorldLoc = bi.WorldLoc;
var newWorldLoc = location;
if (oldWorldLoc.X != newWorldLoc.X || oldWorldLoc.Y != newWorldLoc.Y)
item.ItemID = itemIDs.Length switch
{
var dir = GetDirection4(oldWorldLoc, newWorldLoc);
if (itemIDs.Length == 2)
2 => dir switch
{
item.ItemID = dir switch
{
Direction.North => itemIDs[0],
Direction.South => itemIDs[0],
Direction.East => itemIDs[1],
Direction.West => itemIDs[1],
_ => item.ItemID
};
}
else if (itemIDs.Length == 4)
Direction.North => itemIDs[0],
Direction.South => itemIDs[0],
Direction.East => itemIDs[1],
Direction.West => itemIDs[1],
_ => item.ItemID
},
4 => dir switch
{
item.ItemID = dir switch
{
Direction.South => itemIDs[0],
Direction.East => itemIDs[1],
Direction.North => itemIDs[2],
Direction.West => itemIDs[3],
_ => item.ItemID
};
}
}
Direction.South => itemIDs[0],
Direction.East => itemIDs[1],
Direction.North => itemIDs[2],
Direction.West => itemIDs[3],
_ => item.ItemID
},
_ => item.ItemID
};
}
}
}

View file

@ -1005,7 +1005,7 @@ namespace Server.Mobiles
for (var i = 0; i < opls.Count; ++i)
{
from.Send(opls[i]);
from.NetState?.Send(opls[i].Buffer);
}
SayTo(from, 500186); // Greetings. Have a look around.

View file

@ -880,12 +880,20 @@ namespace Server.Multis
DesignState.SendDetailedInfoTo(ns);
}
public override void SendInfoTo(NetState state, bool sendOplPacket)
public override void SendInfoTo(NetState ns, bool sendOplPacket)
{
base.SendInfoTo(state, sendOplPacket);
base.SendInfoTo(ns, sendOplPacket);
var stateToSend = DesignContext.Find(state.Mobile)?.Foundation == this ? DesignState : CurrentState;
stateToSend.SendGeneralInfoTo(state);
var stateToSend = DesignContext.Find(ns.Mobile)?.Foundation == this ? DesignState : CurrentState;
stateToSend.SendGeneralInfoTo(ns);
}
public override void SendInfoTo(NetState ns, ReadOnlySpan<byte> world, ReadOnlySpan<byte> opl = default)
{
base.SendInfoTo(ns, world, opl);
var stateToSend = DesignContext.Find(ns.Mobile)?.Foundation == this ? DesignState : CurrentState;
stateToSend.SendGeneralInfoTo(ns);
}
public override void Serialize(IGenericWriter writer)
@ -2321,22 +2329,22 @@ namespace Server.Multis
{
var item = fixtures[i];
state.Send(item.RemovePacket);
state.SendRemoveEntity(item.Serial);
}
if (foundation.Signpost != null)
{
state.Send(foundation.Signpost.RemovePacket);
state.SendRemoveEntity(foundation.Signpost.Serial);
}
if (foundation.SignHanger != null)
{
state.Send(foundation.SignHanger.RemovePacket);
state.SendRemoveEntity(foundation.SignHanger.Serial);
}
if (foundation.Sign != null)
{
state.Send(foundation.Sign.RemovePacket);
state.SendRemoveEntity(foundation.Sign.Serial);
}
}