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
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue