ModernUO/Projects/UOContent/Items/Misc/Blocker.cs
Kamron Batman 03d0a4664e
fix(core): Adds SkipLocalsInitAttribute support, optimizes broadcasted packets (#363)
- [X] Adds support for `SkipLocalsInitAttribute`. SkipLocalsInitAttribute skips initializing stack variables including `stackalloc`. I don't think it is wired/working yet but should be implemented soon.
- [X] Optimizes broadcasted packets by checking if the first byte (packet ID) is non-zero. If it is already set, it reuses the buffer.
- [X] Removes unnecessary refs to Spans. I don't think the Span struct itself is mutable, so a ref is not helpful.
2020-12-26 12:46:06 -08:00

79 lines
2 KiB
C#

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;
public Blocker(Serial serial) : base(serial)
{
}
public override int LabelNumber => 503057; // Impassable!
public override void SendWorldPacketTo(NetState ns, ReadOnlySpan<byte> world)
{
var mob = ns.Mobile;
if (AccessLevel.GameMaster >= mob?.AccessLevel)
{
base.SendWorldPacketTo(ns, world);
return;
}
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(buffer, this, ns.HighSeas);
BinaryPrimitives.WriteUInt16BigEndian(buffer.Slice(8, 2), GMItemId);
}
else
{
length = OutgoingItemPackets.CreateWorldItem(buffer, this);
BinaryPrimitives.WriteUInt16BigEndian(buffer.Slice(7, 2), GMItemId);
}
ns.Send(buffer.Slice(0, length));
}
public override void Serialize(IGenericWriter writer)
{
base.Serialize(writer);
writer.Write(0);
}
public override void Deserialize(IGenericReader reader)
{
base.Deserialize(reader);
var version = reader.ReadInt();
}
}
}