Revert "Updates Packets & Randomizer (#43)" (#61)

This reverts commit 179cb50557.
This commit is contained in:
Kamron Batman 2019-11-11 08:46:11 -08:00 • committed by GitHub
parent 179cb50557
commit c2ecc76457
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
588 changed files with 16260 additions and 10926 deletions

View file

@ -1,5 +1,6 @@
using System;
using System.Globalization;
using Server.Accounting;
using Server.Engines.Quests;
using Server.Engines.Quests.Haven;
using Server.Engines.Quests.Necro;

View file

@ -1,4 +1,3 @@
using Server.Buffers;
using Server.Network;
namespace Server.Items
@ -14,21 +13,14 @@ namespace Server.Items
public override int LabelNumber => 503057; // Impassable!
protected override void SendWorldPacketFor(NetState state)
protected override Packet GetWorldPacketFor(NetState state)
{
Mobile mob = state.Mobile;
if (mob?.AccessLevel >= AccessLevel.GameMaster)
{
if (state.HighSeas)
SendGMItemHS(state);
else if (state.StygianAbyss)
SendGMItemSA(state);
else
SendGMItem(state);
}
return new GMItemPacket(this);
base.SendWorldPacketFor(state);
return base.GetWorldPacketFor(state);
}
public override void Serialize(GenericWriter writer)
@ -45,138 +37,66 @@ namespace Server.Items
int version = reader.ReadInt();
}
private void SendGMItem(NetState ns)
public sealed class GMItemPacket : Packet
{
if (ns == null)
return;
public GMItemPacket(Item item) : base(0x1A)
{
EnsureCapacity(20);
SpanWriter w = new SpanWriter(stackalloc byte[20]);
w.Write((byte)0x1A); // Packet ID
w.Position += 2; // Dynamic Length
// 14 base length
// +2 - Amount
// +2 - Hue
// +1 - Flags
uint serial = Serial.Value;
int itemId = 0x1183;
int amount = Amount;
Point3D loc = Location;
int x = loc.X;
int y = loc.Y;
int hue = Hue;
int flags = GetPacketFlags();
int direction = (int)Direction;
uint serial = item.Serial.Value;
int itemID = 0x1183;
int amount = item.Amount;
Point3D loc = item.Location;
int x = loc.X;
int y = loc.Y;
int hue = item.Hue;
int flags = item.GetPacketFlags();
int direction = (int)item.Direction;
if (amount != 0)
serial |= 0x80000000;
else
serial &= 0x7FFFFFFF;
if (amount != 0)
serial |= 0x80000000;
else
serial &= 0x7FFFFFFF;
w.Write(serial);
m_Stream.Write(serial);
m_Stream.Write((short)(itemID & 0x7FFF));
w.Write((short)itemId);
if (amount != 0)
m_Stream.Write((short)amount);
if (amount != 0)
w.Write((short)amount);
x &= 0x7FFF;
x &= 0x7FFF;
if (direction != 0)
x |= 0x8000;
if (direction != 0) x |= 0x8000;
m_Stream.Write((short)x);
w.Write((short)x);
y &= 0x3FFF;
y &= 0x3FFF;
if (hue != 0)
y |= 0x8000;
if (hue != 0) y |= 0x8000;
if (flags != 0)
y |= 0x4000;
if (flags != 0) y |= 0x4000;
m_Stream.Write((short)y);
w.Write((short)y);
if (direction != 0)
m_Stream.Write((byte)direction);
if (direction != 0)
w.Write((byte)direction);
m_Stream.Write((sbyte)loc.Z);
w.Write((sbyte)loc.Z);
if (hue != 0)
m_Stream.Write((ushort)hue);
if (hue != 0)
w.Write((ushort)hue);
if (flags != 0)
w.Write((byte)flags);
w.Position = 1;
w.Write((ushort)w.WrittenCount);
ns.Send(w.Span);
}
public void SendGMItemSA(NetState ns)
{
if (ns == null)
return;
SpanWriter w = new SpanWriter(stackalloc byte[24]);
w.Write((byte)0xF3); // Packet ID
w.Write((short)0x01);
int itemId = 0x1183;
w.Position++; // w.Write((byte)0);
w.Write(Serial);
w.Write((short)itemId);
w.Write((byte)Direction);
short amount = (short)Amount;
w.Write(amount);
w.Write(amount);
Point3D loc = Location;
w.Write((short)(loc.X & 0x7FFF));
w.Write((short)(loc.Y & 0x3FFF));
w.Write((sbyte)loc.Z);
w.Write((byte)Light);
w.Write((short)Hue);
w.Write((byte)GetPacketFlags());
ns.Send(w.RawSpan);
}
public void SendGMItemHS(NetState ns)
{
if (ns == null)
return;
SpanWriter w = new SpanWriter(stackalloc byte[26]);
w.Write((byte)0xF3); // Packet ID
w.Write((short)0x01);
int itemId = 0x1183;
w.Position++; // w.Write((byte)0);
w.Write(Serial);
w.Write((short)itemId);
w.Write((byte)Direction);
short amount = (short)Amount;
w.Write(amount);
w.Write(amount);
Point3D loc = Location;
w.Write((short)(loc.X & 0x7FFF));
w.Write((short)(loc.Y & 0x3FFF));
w.Write((sbyte)loc.Z);
w.Write((byte)Light);
w.Write((short)Hue);
w.Write((byte)GetPacketFlags());
ns.Send(w.RawSpan);
if (flags != 0)
m_Stream.Write((byte)flags);
}
}
}
}

View file

@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using Server.Buffers;
using Server.Network;
using Server.Targeting;
@ -55,7 +54,7 @@ namespace Server.Items
}
[CommandProperty(AccessLevel.GameMaster)]
public string BoardName { get; set; }
public string BoardName{ get; set; }
public static bool CheckTime(DateTime time, TimeSpan range) => time + range < DateTime.UtcNow;
@ -67,10 +66,8 @@ namespace Server.Items
if (minutes != 0 && seconds != 0)
return $"{minutes} minute{(minutes == 1 ? "" : "s")} and {seconds} second{(seconds == 1 ? "" : "s")}";
if (minutes != 0)
return $"{minutes} minute{(minutes == 1 ? "" : "s")}";
return $"{seconds} second{(seconds == 1 ? "" : "s")}";
}
@ -149,8 +146,11 @@ namespace Server.Items
NetState state = from.NetState;
BBPackets.SendBBDisplayBoard(state, this);
Packets.SendContainerContent(state, from, this);
state.Send(new BBDisplayBoard(this));
if (state.ContainerGridLines)
state.Send(new ContainerContent6017(from, this));
else
state.Send(new ContainerContent(from, this));
}
else
{
@ -232,14 +232,18 @@ namespace Server.Items
public static void BBRequestContent(Mobile from, BaseBulletinBoard board, PacketReader pvSrc)
{
if (World.FindItem(pvSrc.ReadUInt32()) is BulletinMessage msg && msg.Parent == board)
BBPackets.SendBBMessageContent(from.NetState, board, msg);
if (!(World.FindItem(pvSrc.ReadUInt32()) is BulletinMessage msg) || msg.Parent != board)
return;
from.Send(new BBMessageContent(board, msg));
}
public static void BBRequestHeader(Mobile from, BaseBulletinBoard board, PacketReader pvSrc)
{
if (World.FindItem(pvSrc.ReadUInt32()) is BulletinMessage msg && msg.Parent == board)
BBPackets.SendBBMessageHeader(from.NetState, board, msg);
if (!(World.FindItem(pvSrc.ReadUInt32()) is BulletinMessage msg) || msg.Parent != board)
return;
from.Send(new BBMessageHeader(board, msg));
}
public static void BBPostMessage(Mobile from, BaseBulletinBoard board, PacketReader pvSrc)
@ -267,7 +271,7 @@ namespace Server.Items
return;
}
string subject = pvSrc.ReadStringSafe(pvSrc.ReadByte());
string subject = pvSrc.ReadUTF8StringSafe(pvSrc.ReadByte());
if (subject.Length == 0)
return;
@ -278,7 +282,7 @@ namespace Server.Items
return;
for (int i = 0; i < lines.Length; ++i)
lines[i] = pvSrc.ReadStringSafe(pvSrc.ReadByte());
lines[i] = pvSrc.ReadUTF8StringSafe(pvSrc.ReadByte());
board.PostMessage(from, thread, subject, lines);
}
@ -340,25 +344,25 @@ namespace Server.Items
{
}
public Mobile Poster { get; private set; }
public Mobile Poster{ get; private set; }
public BulletinMessage Thread { get; private set; }
public BulletinMessage Thread{ get; private set; }
public string Subject { get; private set; }
public string Subject{ get; private set; }
public DateTime Time { get; private set; }
public DateTime Time{ get; private set; }
public DateTime LastPostTime { get; set; }
public DateTime LastPostTime{ get; set; }
public string PostedName { get; private set; }
public string PostedName{ get; private set; }
public int PostedBody { get; private set; }
public int PostedBody{ get; private set; }
public int PostedHue { get; private set; }
public int PostedHue{ get; private set; }
public BulletinEquip[] PostedEquip { get; private set; }
public BulletinEquip[] PostedEquip{ get; private set; }
public string[] Lines { get; private set; }
public string[] Lines{ get; private set; }
public string GetTimeAsString() => Time.ToString("MMM dd, yyyy");
@ -448,64 +452,70 @@ namespace Server.Items
}
}
public static class BBPackets
public class BBDisplayBoard : Packet
{
public static void SendBBDisplayBoard(NetState ns, BaseBulletinBoard board)
public BBDisplayBoard(BaseBulletinBoard board) : base(0x71)
{
SpanWriter writer = new SpanWriter(stackalloc byte[38]);
writer.Write((byte)0x71); // Packet ID
writer.Write((ushort)38); // Dynamic Length
EnsureCapacity(38);
writer.Position++; // writer.Write((byte)0); // Command
writer.Write(board.Serial);
writer.WriteAsciiNull(board.BoardName ?? "", 29);
byte[] buffer = Utility.UTF8.GetBytes(board.BoardName ?? "");
ns.Send(writer.Span);
m_Stream.Write((byte)0x00); // PacketID
m_Stream.Write(board.Serial); // Bulletin board serial
// Bulletin board name
if (buffer.Length >= 29)
{
m_Stream.Write(buffer, 0, 29);
m_Stream.Write((byte)0);
}
else
{
m_Stream.Write(buffer, 0, buffer.Length);
m_Stream.Fill(30 - buffer.Length);
}
}
}
public class BBMessageHeader : Packet
{
public BBMessageHeader(BaseBulletinBoard board, BulletinMessage msg) : base(0x71)
{
string poster = SafeString(msg.PostedName);
string subject = SafeString(msg.Subject);
string time = SafeString(msg.GetTimeAsString());
EnsureCapacity(22 + poster.Length + subject.Length + time.Length);
m_Stream.Write((byte)0x01); // PacketID
m_Stream.Write(board.Serial); // Bulletin board serial
m_Stream.Write(msg.Serial); // Message serial
BulletinMessage thread = msg.Thread;
if (thread == null)
m_Stream.Write(0); // Thread serial--root
else
m_Stream.Write(thread.Serial); // Thread serial--parent
WriteString(poster);
WriteString(subject);
WriteString(time);
}
public static void SendBBMessageHeader(NetState ns, BaseBulletinBoard board, BulletinMessage msg)
public void WriteString(string v)
{
string poster = msg.PostedName ?? "";
string subject = msg.Subject ?? "";
string time = msg.GetTimeAsString() ?? "";
byte[] buffer = Utility.UTF8.GetBytes(v);
int len = buffer.Length + 1;
byte posterLength = Math.Min((byte)poster.Length, (byte)254);
byte subjectLength = Math.Min((byte)subject.Length, (byte)254);
byte timeLength = Math.Min((byte)time.Length, (byte)254);
if (len > 255)
len = 255;
int length = 22 + posterLength + subjectLength + timeLength;
SpanWriter writer = new SpanWriter(stackalloc byte[length]);
writer.Write((byte)0x71); // Packet ID
writer.Write((ushort)length); // Dynamic Length
writer.Write((byte)0x01); // Command
writer.Write(board.Serial); // Bulletin board serial
writer.Write(msg.Serial); // Message serial
writer.Write(msg.Thread?.Serial ?? 0);
writer.Write(posterLength);
writer.WriteAsciiNull(poster, posterLength + 1);
writer.Write(subjectLength);
writer.WriteAsciiNull(subject, subjectLength + 1);
writer.Write(timeLength);
writer.WriteAsciiNull(time, timeLength + 1);
ns.Send(writer.Span);
m_Stream.Write((byte)len);
m_Stream.Write(buffer, 0, len - 1);
m_Stream.Write((byte)0);
}
public static void SendBBMessageContent(NetState ns, BaseBulletinBoard board, BulletinMessage msg)
{
string poster = msg.PostedName ?? "";
string subject = msg.Subject ?? "";
string time = msg.GetTimeAsString() ?? "";
byte posterLength = Math.Min((byte)poster.Length, (byte)254);
byte subjectLength = Math.Min((byte)subject.Length, (byte)254);
byte timeLength = Math.Min((byte)time.Length, (byte)254);
int equipLength = Math.Min(msg.PostedEquip.Length, 255);
int msgLength = Math.Min(msg.Lines.Length, 255);
public string SafeString(string v) => v ?? string.Empty;
}
@ -519,43 +529,72 @@ namespace Server.Items
EnsureCapacity(22 + poster.Length + subject.Length + time.Length);
writer.Write((byte)0x02); // Command
writer.Write(board.Serial); // Bulletin board serial
writer.Write(msg.Serial); // Message serial
m_Stream.Write((byte)0x02); // PacketID
m_Stream.Write(board.Serial); // Bulletin board serial
m_Stream.Write(msg.Serial); // Message serial
writer.Write(posterLength);
writer.WriteAsciiNull(poster, posterLength + 1);
writer.Write(subjectLength);
writer.WriteAsciiNull(subject, subjectLength + 1);
writer.Write(timeLength);
writer.WriteAsciiNull(time, timeLength + 1);
WriteString(poster);
WriteString(subject);
WriteString(time);
writer.Write((short)msg.PostedBody);
writer.Write((short)msg.PostedHue);
m_Stream.Write((short)msg.PostedBody);
m_Stream.Write((short)msg.PostedHue);
writer.Write((byte)equipLength);
int len = msg.PostedEquip.Length;
for (int i = 0; i < equipLength; ++i)
if (len > 255)
len = 255;
m_Stream.Write((byte)len);
for (int i = 0; i < len; ++i)
{
BulletinEquip eq = msg.PostedEquip[i];
writer.Write((short)eq.itemID);
writer.Write((short)eq.hue);
m_Stream.Write((short)eq.itemID);
m_Stream.Write((short)eq.hue);
}
writer.Write((byte)msgLength);
len = msg.Lines.Length;
for (int i = 0; i < msgLength; ++i)
{
string line = msg.Lines[i];
byte len = Math.Min((byte)line.Length, (byte)254);
writer.WriteAsciiNull(line, len);
}
if (len > 255)
len = 255;
writer.Position = 1;
writer.Write((ushort)writer.WrittenCount);
m_Stream.Write((byte)len);
ns.Send(writer.Span);
for (int i = 0; i < len; ++i)
WriteString(msg.Lines[i], true);
}
public void WriteString(string v)
{
WriteString(v, false);
}
public void WriteString(string v, bool padding)
{
byte[] buffer = Utility.UTF8.GetBytes(v);
int tail = padding ? 2 : 1;
int len = buffer.Length + tail;
if (len > 255)
len = 255;
m_Stream.Write((byte)len);
m_Stream.Write(buffer, 0, len - tail);
if (padding)
m_Stream.Write((short)0); // padding compensates for a client bug
else
m_Stream.Write((byte)0);
}
public string SafeString(string v)
{
if (v == null)
return string.Empty;
return v;
}
}
}

View file

@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Server.Network;
using Server.Targeting;
@ -30,7 +29,14 @@ namespace Server.Items
public int Amount{ get; }
public static CrystalRechargeInfo Get(Type type) => Table.FirstOrDefault(info => info.Type == type);
public static CrystalRechargeInfo Get(Type type)
{
foreach (CrystalRechargeInfo info in Table)
if (info.Type == type)
return info;
return null;
}
}
public class BroadcastCrystal : Item

View file

@ -100,7 +100,7 @@ namespace Server.Items
public Corpse(Mobile owner, HairInfo hair, FacialHairInfo facialhair, List<Item> equipItems)
: base(0x2006)
{
// To suppress console warnings, stackable must be true
// To supress console warnings, stackable must be true
Stackable = true;
Amount = owner.Body; // protocol defines that for itemid 0x2006, amount=body
Stackable = false;
@ -193,7 +193,16 @@ namespace Server.Items
}
[CommandProperty(AccessLevel.GameMaster)]
public virtual bool InstancedCorpse => Core.SE && DateTime.UtcNow < TimeOfDeath + InstancedCorpseTime;
public virtual bool InstancedCorpse
{
get
{
if (!Core.SE)
return false;
return DateTime.UtcNow < TimeOfDeath + InstancedCorpseTime;
}
}
public override bool IsDecoContainer => false;
@ -293,7 +302,9 @@ namespace Server.Items
Mobile dead = Owner;
if (GetFlag(CorpseFlag.Carved) || dead == null)
{
from.SendLocalizedMessage(500485); // You see nothing useful to carve from the corpse.
}
else if (((Body)Amount).IsHuman && ItemID == 0x2006)
{
new Blood(0x122D).MoveToWorld(Location, Map);
@ -317,9 +328,13 @@ namespace Server.Items
from.CriminalAction(true);
}
else if (dead is BaseCreature creature)
{
creature.OnCarve(from, this, item);
}
else
{
from.SendLocalizedMessage(500485); // You see nothing useful to carve from the corpse.
}
}
public override bool IsChildVisibleTo(Mobile m, Item child) =>
@ -332,7 +347,8 @@ namespace Server.Items
if (Aggressors.Count == 0 || Items.Count == 0)
return;
m_InstancedItems ??= new Dictionary<Item, InstancedItemInfo>();
if (m_InstancedItems == null)
m_InstancedItems = new Dictionary<Item, InstancedItemInfo>();
List<Item> m_Stackables = new List<Item>();
List<Item> m_Unstackables = new List<Item>();
@ -385,7 +401,7 @@ namespace Server.Items
}
if (remainder == 0)
m_InstancedItems.Add(item, new InstancedItemInfo(item, attackers[^1]));
m_InstancedItems.Add(item, new InstancedItemInfo(item, attackers[attackers.Count - 1]));
else
m_Unstackables.Add(item);
}
@ -411,7 +427,9 @@ namespace Server.Items
if (InstancedCorpse)
{
m_InstancedItems ??= new Dictionary<Item, InstancedItemInfo>();
if (m_InstancedItems == null)
m_InstancedItems = new Dictionary<Item, InstancedItemInfo>();
m_InstancedItems.Add(carved, new InstancedItemInfo(carved, carver));
}
}
@ -446,6 +464,7 @@ namespace Server.Items
public override void OnAfterDelete()
{
m_DecayTimer?.Stop();
m_DecayTimer = null;
}
@ -524,23 +543,29 @@ namespace Server.Items
writer.WriteDeltaTime(TimeOfDeath);
if (m_RestoreTable == null)
writer.Write(0);
else
List<KeyValuePair<Item, Point3D>> list = m_RestoreTable == null
? null
: new List<KeyValuePair<Item, Point3D>>(m_RestoreTable);
int count = list?.Count ?? 0;
writer.Write(count);
for (int i = 0; i < count; ++i)
{
writer.Write(m_RestoreTable.Count);
KeyValuePair<Item, Point3D> kvp = list[i];
Item item = kvp.Key;
Point3D loc = kvp.Value;
foreach (var (item, loc) in m_RestoreTable)
writer.Write(item);
if (item.Location == loc)
{
writer.Write(item);
if (item.Location == loc)
writer.Write(false);
else
{
writer.Write(true);
writer.Write(loc);
}
writer.Write(false);
}
else
{
writer.Write(true);
writer.Write(loc);
}
}
@ -732,8 +757,12 @@ namespace Server.Items
if (!(((Body)Amount).IsHuman && ItemID == 0x2006))
return;
CorpsePackets.SendCorpseContent(state, state.Mobile, this);
CorpsePackets.SendCorpseEquip(state, state.Mobile, this);
if (state.ContainerGridLines)
state.Send(new CorpseContent6017(state.Mobile, this));
else
state.Send(new CorpseContent(state.Mobile, this));
state.Send(new CorpseEquip(state.Mobile, this));
}
public bool IsCriminalAction(Mobile from)
@ -807,7 +836,8 @@ namespace Server.Items
if (item == null)
return;
m_RestoreTable ??= new Dictionary<Item, Point3D>();
if (m_RestoreTable == null)
m_RestoreTable = new Dictionary<Item, Point3D>();
m_RestoreTable[item] = loc;
}
@ -1035,7 +1065,7 @@ namespace Server.Items
ObjectPropertyList opl = PropertyList;
if (opl.Header > 0)
Packets.SendMessageLocalized(from.NetState, Serial, ItemID, MessageType.Label, hue, 3, opl.Header, Name, opl.HeaderArgs);
from.Send(new MessageLocalized(Serial, ItemID, MessageType.Label, hue, 3, opl.Header, Name, opl.HeaderArgs));
}
public override void OnSingleClick(Mobile from)
@ -1045,12 +1075,14 @@ namespace Server.Items
if (ItemID == 0x2006) // Corpse form
{
if (m_CorpseName != null)
Packets.SendAsciiMessage(from.NetState, Serial, ItemID, MessageType.Label, hue, 3, "", m_CorpseName);
from.Send(new AsciiMessage(Serial, ItemID, MessageType.Label, hue, 3, "", m_CorpseName));
else
Packets.SendMessageLocalized(from.NetState, Serial, ItemID, MessageType.Label, hue, 3, 1046414, "", Name);
from.Send(new MessageLocalized(Serial, ItemID, MessageType.Label, hue, 3, 1046414, "", Name));
}
else // Bone form
Packets.SendMessageLocalized(from.NetState, Serial, ItemID, MessageType.Label, hue, 3, 1046414, "", Name);
{
from.Send(new MessageLocalized(Serial, ItemID, MessageType.Label, hue, 3, 1046414, "", Name));
}
}
private class InstancedItemInfo

View file

@ -1,29 +1,24 @@
using System.Collections.Generic;
using Server.Buffers;
using System.IO;
using Server.Items;
namespace Server.Network
{
public static class CorpsePackets
public sealed class CorpseEquip : Packet
{
public static void SendCorpseEquip(NetState ns, Mobile beholder, Corpse beheld)
public CorpseEquip(Mobile beholder, Corpse beheld) : base(0x89)
{
if (ns == null)
return;
List<Item> list = beheld.EquipItems;
int length = 8 + list.Count * 5;
if (beheld.Hair?.ItemID > 0)
length += 5;
if (beheld.FacialHair?.ItemID > 0)
length += 5;
int count = list.Count;
if (beheld.Hair != null && beheld.Hair.ItemID > 0)
count++;
if (beheld.FacialHair != null && beheld.FacialHair.ItemID > 0)
count++;
SpanWriter writer = new SpanWriter(stackalloc byte[length]);
writer.Write((byte)0x89); // Packet ID
writer.Write((ushort)length); // Dynamic Length
EnsureCapacity(8 + count * 5);
writer.Write(beheld.Serial);
m_Stream.Write(beheld.Serial);
for (int i = 0; i < list.Count; ++i)
{
@ -31,180 +26,173 @@ namespace Server.Network
if (!item.Deleted && beholder.CanSee(item) && item.Parent == beheld)
{
writer.Write((byte)(item.Layer + 1));
writer.Write(item.Serial);
m_Stream.Write((byte)(item.Layer + 1));
m_Stream.Write(item.Serial);
}
}
if (beheld.Hair?.ItemID > 0)
if (beheld.Hair != null && beheld.Hair.ItemID > 0)
{
writer.Write((byte)(Layer.Hair + 1));
writer.Write(HairInfo.FakeSerial(beheld.Owner.Serial) - 2);
m_Stream.Write((byte)(Layer.Hair + 1));
m_Stream.Write(HairInfo.FakeSerial(beheld.Owner) - 2);
}
if (beheld.FacialHair?.ItemID > 0)
if (beheld.FacialHair != null && beheld.FacialHair.ItemID > 0)
{
writer.Write((byte)(Layer.FacialHair + 1));
writer.Write(FacialHairInfo.FakeSerial(beheld.Owner.Serial) - 2);
m_Stream.Write((byte)(Layer.FacialHair + 1));
m_Stream.Write(FacialHairInfo.FakeSerial(beheld.Owner) - 2);
}
writer.Position++; // writer.Write((byte)Layer.Invalid);
ns.Send(writer.Span);
}
public static void SendCorpseContent(NetState ns, Mobile beholder, Corpse corpse)
{
if (ns == null)
return;
if (ns.ContainerGridLines)
SendCorpseContentNew(ns, beholder, corpse);
else
SendCorpseContentOld(ns, beholder, corpse);
}
public static void SendCorpseContentOld(NetState ns, Mobile beholder, Corpse corpse)
{
if (ns == null)
return;
List<Item> items = corpse.EquipItems;
int length = 5 + items.Count * 19;
if (corpse.Hair?.ItemID > 0)
length += 19;
if (corpse.FacialHair?.ItemID > 0)
length += 19;
SpanWriter writer = new SpanWriter(stackalloc byte[length]);
writer.Write((byte)0x3C); // Packet ID
writer.Write((ushort)length); // Dynamic Length
writer.Position += 2;
ushort written = 0;
for (int i = 0; i < items.Count; ++i)
{
Item child = items[i];
if (!child.Deleted && child.Parent == corpse && beholder.CanSee(child))
{
writer.Write(child.Serial);
writer.Write((ushort)child.ItemID);
writer.Position++; // signed, itemID offset
writer.Write((ushort)child.Amount);
writer.Write((short)child.X);
writer.Write((short)child.Y);
writer.Write(corpse.Serial);
writer.Write((ushort)child.Hue);
++written;
}
}
if (corpse.Hair?.ItemID > 0)
{
writer.Write(HairInfo.FakeSerial(corpse.Owner.Serial) - 2);
writer.Write((ushort)corpse.Hair.ItemID);
writer.Position++; // signed, itemID offset
writer.Write((ushort)1);
writer.Position += 4;
writer.Write(corpse.Serial);
writer.Write((ushort)corpse.Hair.Hue);
++written;
}
if (corpse.FacialHair?.ItemID > 0)
{
writer.Write(FacialHairInfo.FakeSerial(corpse.Owner.Serial) - 2);
writer.Write((ushort)corpse.FacialHair.ItemID);
writer.Position++; // signed, itemID offset
writer.Write((ushort)1);
writer.Position += 4;
writer.Write(corpse.Serial);
writer.Write((ushort)corpse.FacialHair.Hue);
++written;
}
writer.Position = 3;
writer.Write(written);
ns.Send(writer.Span);
}
public static void SendCorpseContentNew(NetState ns, Mobile beholder, Corpse corpse)
{
if (ns == null)
return;
List<Item> items = corpse.EquipItems;
int length = 5 + items.Count * 20;
if (corpse.Hair?.ItemID > 0)
length += 20;
if (corpse.FacialHair?.ItemID > 0)
length += 20;
SpanWriter writer = new SpanWriter(stackalloc byte[length]);
writer.Write((byte)0x3C); // Packet ID
writer.Write((ushort)length); // Dynamic Length
writer.Position += 2;
ushort written = 0;
for (int i = 0; i < items.Count; ++i)
{
Item child = items[i];
if (!child.Deleted && child.Parent == corpse && beholder.CanSee(child))
{
writer.Write(child.Serial);
writer.Write((ushort)child.ItemID);
writer.Position++; // signed, itemID offset
writer.Write((ushort)child.Amount);
writer.Write((short)child.X);
writer.Write((short)child.Y);
writer.Position++; // grid location
writer.Write(corpse.Serial);
writer.Write((ushort)child.Hue);
++written;
}
}
if (corpse.Hair?.ItemID > 0)
{
writer.Write(HairInfo.FakeSerial(corpse.Owner.Serial) - 2);
writer.Write((ushort)corpse.Hair.ItemID);
writer.Position++; // signed, itemID offset
writer.Write((ushort)1);
writer.Position += 5;
writer.Write(corpse.Serial);
writer.Write((ushort)corpse.Hair.Hue);
++written;
}
if (corpse.FacialHair?.ItemID > 0)
{
writer.Write(FacialHairInfo.FakeSerial(corpse.Owner.Serial) - 2);
writer.Write((ushort)corpse.FacialHair.ItemID);
writer.Position++; // signed, itemID offset
writer.Write((ushort)1);
writer.Position += 5;
writer.Write(corpse.Serial);
writer.Write((ushort)corpse.FacialHair.Hue);
++written;
}
writer.Position = 3;
writer.Write(written);
ns.Send(writer.Span);
m_Stream.Write((byte)Layer.Invalid);
}
}
}
public sealed class CorpseContent : Packet
{
public CorpseContent(Mobile beholder, Corpse beheld)
: base(0x3C)
{
List<Item> items = beheld.EquipItems;
int count = items.Count;
if (beheld.Hair != null && beheld.Hair.ItemID > 0)
count++;
if (beheld.FacialHair != null && beheld.FacialHair.ItemID > 0)
count++;
EnsureCapacity(5 + count * 19);
long pos = m_Stream.Position;
int written = 0;
m_Stream.Write((ushort)0);
for (int i = 0; i < items.Count; ++i)
{
Item child = items[i];
if (!child.Deleted && child.Parent == beheld && beholder.CanSee(child))
{
m_Stream.Write(child.Serial);
m_Stream.Write((ushort)child.ItemID);
m_Stream.Write((byte)0); // signed, itemID offset
m_Stream.Write((ushort)child.Amount);
m_Stream.Write((short)child.X);
m_Stream.Write((short)child.Y);
m_Stream.Write(beheld.Serial);
m_Stream.Write((ushort)child.Hue);
++written;
}
}
if (beheld.Hair != null && beheld.Hair.ItemID > 0)
{
m_Stream.Write(HairInfo.FakeSerial(beheld.Owner) - 2);
m_Stream.Write((ushort)beheld.Hair.ItemID);
m_Stream.Write((byte)0); // signed, itemID offset
m_Stream.Write((ushort)1);
m_Stream.Write((short)0);
m_Stream.Write((short)0);
m_Stream.Write(beheld.Serial);
m_Stream.Write((ushort)beheld.Hair.Hue);
++written;
}
if (beheld.FacialHair != null && beheld.FacialHair.ItemID > 0)
{
m_Stream.Write(FacialHairInfo.FakeSerial(beheld.Owner) - 2);
m_Stream.Write((ushort)beheld.FacialHair.ItemID);
m_Stream.Write((byte)0); // signed, itemID offset
m_Stream.Write((ushort)1);
m_Stream.Write((short)0);
m_Stream.Write((short)0);
m_Stream.Write(beheld.Serial);
m_Stream.Write((ushort)beheld.FacialHair.Hue);
++written;
}
m_Stream.Seek(pos, SeekOrigin.Begin);
m_Stream.Write((ushort)written);
}
}
public sealed class CorpseContent6017 : Packet
{
public CorpseContent6017(Mobile beholder, Corpse beheld)
: base(0x3C)
{
List<Item> items = beheld.EquipItems;
int count = items.Count;
if (beheld.Hair != null && beheld.Hair.ItemID > 0)
count++;
if (beheld.FacialHair != null && beheld.FacialHair.ItemID > 0)
count++;
EnsureCapacity(5 + count * 20);
long pos = m_Stream.Position;
int written = 0;
m_Stream.Write((ushort)0);
for (int i = 0; i < items.Count; ++i)
{
Item child = items[i];
if (!child.Deleted && child.Parent == beheld && beholder.CanSee(child))
{
m_Stream.Write(child.Serial);
m_Stream.Write((ushort)child.ItemID);
m_Stream.Write((byte)0); // signed, itemID offset
m_Stream.Write((ushort)child.Amount);
m_Stream.Write((short)child.X);
m_Stream.Write((short)child.Y);
m_Stream.Write((byte)0); // Grid Location?
m_Stream.Write(beheld.Serial);
m_Stream.Write((ushort)child.Hue);
++written;
}
}
if (beheld.Hair != null && beheld.Hair.ItemID > 0)
{
m_Stream.Write(HairInfo.FakeSerial(beheld.Owner) - 2);
m_Stream.Write((ushort)beheld.Hair.ItemID);
m_Stream.Write((byte)0); // signed, itemID offset
m_Stream.Write((ushort)1);
m_Stream.Write((short)0);
m_Stream.Write((short)0);
m_Stream.Write((byte)0); // Grid Location?
m_Stream.Write(beheld.Serial);
m_Stream.Write((ushort)beheld.Hair.Hue);
++written;
}
if (beheld.FacialHair != null && beheld.FacialHair.ItemID > 0)
{
m_Stream.Write(FacialHairInfo.FakeSerial(beheld.Owner) - 2);
m_Stream.Write((ushort)beheld.FacialHair.ItemID);
m_Stream.Write((byte)0); // signed, itemID offset
m_Stream.Write((ushort)1);
m_Stream.Write((short)0);
m_Stream.Write((short)0);
m_Stream.Write((byte)0); // Grid Location?
m_Stream.Write(beheld.Serial);
m_Stream.Write((ushort)beheld.FacialHair.Hue);
++written;
}
m_Stream.Seek(pos, SeekOrigin.Begin);
m_Stream.Write((ushort)written);
}
}
}

View file

@ -304,7 +304,7 @@ namespace Server.Items
{
case ECEffectType.Lightning:
{
Effects.SendBoltEffect(from, false);
Effects.SendBoltEffect(from, false, EffectHue);
break;
}
case ECEffectType.Location:
@ -334,4 +334,4 @@ namespace Server.Items
}
}
}
}
}

View file

@ -83,4 +83,4 @@ namespace Server.Items
}
}
}
}
}

View file

@ -66,7 +66,8 @@ namespace Server.Items
from.SendLocalizedMessage(1060581); // You've already lit it! Better throw it now!
}
m_Users ??= new List<Mobile>();
if (m_Users == null)
m_Users = new List<Mobile>();
if (!m_Users.Contains(from))
m_Users.Add(from);

View file

@ -1,4 +1,5 @@
using System;
using Server.Accounting;
namespace Server.Items
{

View file

@ -182,7 +182,8 @@ namespace Server.Items
if (addon != null)
{
isDecorableComponent |= count == 1 && Core.SE;
if (count == 1 && Core.SE)
isDecorableComponent = true;
if (m_Decorator.Command == DecorateCommand.Turn)
{
@ -190,7 +191,8 @@ namespace Server.Items
(FlippableAddonAttribute[])addon.GetType()
.GetCustomAttributes(typeof(FlippableAddonAttribute), false);
isDecorableComponent = attributes.Length > 0;
if (attributes.Length > 0)
isDecorableComponent = true;
}
}

View file

@ -1,4 +1,5 @@
using Server.Network;
using Server.Prompts;
using Server.Targeting;
namespace Server.Items
@ -203,9 +204,14 @@ namespace Server.Items
{
base.GetProperties(list);
string desc = m_KeyVal == 0 ? "(blank)" : m_Description?.Trim() ?? "";
string desc;
if (desc != "")
if (m_KeyVal == 0)
desc = "(blank)";
else if ((desc = m_Description) == null || (desc = desc.Trim()).Length <= 0)
desc = null;
if (desc != null)
list.Add(desc);
}
@ -213,10 +219,15 @@ namespace Server.Items
{
base.OnSingleClick(from);
string desc = m_KeyVal == 0 ? "(blank)" : m_Description?.Trim() ?? "";
string desc;
if (m_KeyVal == 0)
desc = "(blank)";
else if ((desc = m_Description) == null || (desc = desc.Trim()).Length <= 0)
desc = "";
if (desc.Length > 0)
Packets.SendUnicodeMessage(from.NetState, Serial, ItemID, MessageType.Regular, 0x3B2, 3, "ENU", "", desc);
from.Send(new UnicodeMessage(Serial, ItemID, MessageType.Regular, 0x3B2, 3, "ENU", "", desc));
}
public bool UseOn(Mobile from, ILockable o)

View file

@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using Server.Targeting;
namespace Server.Items
@ -110,7 +109,14 @@ namespace Server.Items
UpdateItemID();
}
public bool ContainsKey(uint keyValue) => Keys.Any(key => key.KeyValue == keyValue);
public bool ContainsKey(uint keyValue)
{
foreach (Key key in Keys)
if (key.KeyValue == keyValue)
return true;
return false;
}
private void UpdateItemID()
{
@ -163,7 +169,9 @@ namespace Server.Items
}
else if (targeted is ILockable o)
{
if (m_KeyRing.Keys.Any(key => key.UseOn(from, o))) return;
foreach (Key key in m_KeyRing.Keys)
if (key.UseOn(from, o))
return;
from.SendLocalizedMessage(1008140); // You do not have a key for that.
}
@ -174,4 +182,4 @@ namespace Server.Items
}
}
}
}
}

View file

@ -1,4 +1,3 @@
using Server.Buffers;
using Server.Network;
namespace Server.Items
@ -20,21 +19,13 @@ namespace Server.Items
TileData.ItemTable[0x21A2].Height = 20;
}
protected override void SendWorldPacketFor(NetState state)
protected override Packet GetWorldPacketFor(NetState state)
{
Mobile mob = state.Mobile;
if (mob?.AccessLevel >= AccessLevel.GameMaster)
{
if (state.HighSeas)
SendGMItemHS(state);
else if (state.StygianAbyss)
SendGMItemSA(state);
else
SendGMItem(state);
}
if (mob?.AccessLevel >= AccessLevel.GameMaster) return new GMItemPacket(this);
base.SendWorldPacketFor(state);
return base.GetWorldPacketFor(state);
}
public override void Serialize(GenericWriter writer)
@ -54,138 +45,66 @@ namespace Server.Items
ItemID = 0x21A2;
}
private void SendGMItem(NetState ns)
public sealed class GMItemPacket : Packet
{
if (ns == null)
return;
public GMItemPacket(Item item) : base(0x1A)
{
EnsureCapacity(20);
SpanWriter w = new SpanWriter(stackalloc byte[20]);
w.Write((byte)0x1A); // Packet ID
w.Position += 2; // Dynamic Length
// 14 base length
// +2 - Amount
// +2 - Hue
// +1 - Flags
uint serial = Serial.Value;
int itemId = 0x36FF;
int amount = Amount;
Point3D loc = Location;
int x = loc.X;
int y = loc.Y;
int hue = Hue;
int flags = GetPacketFlags();
int direction = (int)Direction;
uint serial = item.Serial.Value;
int itemID = 0x36FF;
int amount = item.Amount;
Point3D loc = item.Location;
int x = loc.X;
int y = loc.Y;
int hue = item.Hue;
int flags = item.GetPacketFlags();
int direction = (int)item.Direction;
if (amount != 0)
serial |= 0x80000000;
else
serial &= 0x7FFFFFFF;
if (amount != 0)
serial |= 0x80000000;
else
serial &= 0x7FFFFFFF;
w.Write(serial);
m_Stream.Write(serial);
m_Stream.Write((short)(itemID & 0x7FFF));
w.Write((short)itemId);
if (amount != 0)
m_Stream.Write((short)amount);
if (amount != 0)
w.Write((short)amount);
x &= 0x7FFF;
x &= 0x7FFF;
if (direction != 0)
x |= 0x8000;
if (direction != 0) x |= 0x8000;
m_Stream.Write((short)x);
w.Write((short)x);
y &= 0x3FFF;
y &= 0x3FFF;
if (hue != 0)
y |= 0x8000;
if (hue != 0) y |= 0x8000;
if (flags != 0)
y |= 0x4000;
if (flags != 0) y |= 0x4000;
m_Stream.Write((short)y);
w.Write((short)y);
if (direction != 0)
m_Stream.Write((byte)direction);
if (direction != 0)
w.Write((byte)direction);
m_Stream.Write((sbyte)loc.Z);
w.Write((sbyte)loc.Z);
if (hue != 0)
m_Stream.Write((ushort)hue);
if (hue != 0)
w.Write((ushort)hue);
if (flags != 0)
w.Write((byte)flags);
w.Position = 1;
w.Write((ushort)w.WrittenCount);
ns.Send(w.Span);
}
public void SendGMItemSA(NetState ns)
{
if (ns == null)
return;
SpanWriter w = new SpanWriter(stackalloc byte[24]);
w.Write((byte)0xF3); // Packet ID
w.Write((short)0x01);
int itemId = 0x36FF;
w.Position++; // w.Write((byte)0);
w.Write(Serial);
w.Write((short)itemId);
w.Write((byte)Direction);
short amount = (short)Amount;
w.Write(amount);
w.Write(amount);
Point3D loc = Location;
w.Write((short)(loc.X & 0x7FFF));
w.Write((short)(loc.Y & 0x3FFF));
w.Write((sbyte)loc.Z);
w.Write((byte)Light);
w.Write((short)Hue);
w.Write((byte)GetPacketFlags());
ns.Send(w.RawSpan);
}
public void SendGMItemHS(NetState ns)
{
if (ns == null)
return;
SpanWriter w = new SpanWriter(stackalloc byte[26]);
w.Write((byte)0xF3); // Packet ID
w.Write((short)0x01);
int itemId = 0x36FF;
w.Position++; // w.Write((byte)0);
w.Write(Serial);
w.Write((short)itemId);
w.Write((byte)Direction);
short amount = (short)Amount;
w.Write(amount);
w.Write(amount);
Point3D loc = Location;
w.Write((short)(loc.X & 0x7FFF));
w.Write((short)(loc.Y & 0x3FFF));
w.Write((sbyte)loc.Z);
w.Write((byte)Light);
w.Write((short)Hue);
w.Write((byte)GetPacketFlags());
ns.Send(w.RawSpan);
if (flags != 0)
m_Stream.Write((byte)flags);
}
}
}
}

View file

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using Server.Gumps;
using Server.Multis;
using Server.Prompts;
using Server.Mobiles;
using Server.Network;
using Server.ContextMenus;

View file

@ -31,7 +31,11 @@ namespace Server.Items
private void AddGeneratorComponent(int itemID, int x, int y, int z)
{
AddComponent(new AddonComponent(itemID){ Name = "a power generator", Hue = 0x451 }, x, y, z);
AddonComponent component = new AddonComponent(itemID);
component.Name = "a power generator";
component.Hue = 0x451;
AddComponent(component, x, y, z);
}
public override void Serialize(GenericWriter writer)
@ -144,7 +148,9 @@ namespace Server.Items
visited[current.X, current.Y] = true;
}
else
{
current = stack[--stackSize - 1];
}
}
Path = new Node[stackSize];
@ -191,8 +197,9 @@ namespace Server.Items
public void DoDamage(Mobile to)
{
Packets.SendMessageLocalized(to.NetState, Serial, ItemID, MessageType.Regular, 0x3B2, 3, 1152372); // The Nexus shoots an arc of energy at you!
to.BoltEffect();
to.Send(new UnicodeMessage(Serial, ItemID, MessageType.Regular, 0x3B2, 3, "", "",
"The generator shoots an arc of electricity at you!"));
to.BoltEffect(0);
to.LocalOverheadMessage(MessageType.Regular, 0xC9, true, "* Your body convulses from electric shock *");
to.NonlocalOverheadMessage(MessageType.Regular, 0xC9, true, $"* {to.Name} spasms from electric shock *");
@ -351,7 +358,7 @@ namespace Server.Items
hues[n.X, n.Y] = NodeHue.Blue;
}
Node lastNode = path[^1];
Node lastNode = path[path.Length - 1];
hues[lastNode.X, lastNode.Y] = NodeHue.Red;
for (int i = 0; i < sideLength; i++)

View file

@ -119,7 +119,11 @@ namespace Server.Items
private static void DeleteAll()
{
List<Item> list = World.Items.Values.OfType<PublicMoongate>().Cast<Item>().ToList();
List<Item> list = new List<Item>();
foreach (Item item in World.Items.Values)
if (item is PublicMoongate)
list.Add(item);
foreach (Item item in list)
item.Delete();
@ -345,7 +349,7 @@ namespace Server.Items
}
}
public override void OnResponse(NetState sender, RelayInfo info)
public override void OnResponse(NetState state, RelayInfo info)
{
if (info.ButtonID == 0) // Cancel
return;

View file

@ -157,7 +157,10 @@ namespace Server.Items
{
base.GetProperties(list);
list.Add(m_Active ? 1060742 : 1060743);
if (m_Active)
list.Add(1060742); // active
else
list.Add(1060743); // inactive
if (m_MapDest != null)
list.Add(1060658, "Map\t{0}", m_MapDest);
@ -231,12 +234,12 @@ namespace Server.Items
bool sendEffect = !m.Hidden || m.AccessLevel == AccessLevel.Player;
if (m_SourceEffect && sendEffect)
Effects.SendLocationEffect(m.Location, m.Map, 0x3728, 10);
Effects.SendLocationEffect(m.Location, m.Map, 0x3728, 10, 10);
m.MoveToWorld(p, map);
if (m_DestEffect && sendEffect)
Effects.SendLocationEffect(m.Location, m.Map, 0x3728, 10);
Effects.SendLocationEffect(m.Location, m.Map, 0x3728, 10, 10);
if (m_SoundID > 0 && sendEffect)
Effects.PlaySound(m.Location, m.Map, m_SoundID);
@ -392,10 +395,11 @@ namespace Server.Items
if (m.BeginAction(this))
{
if (m_MessageString != null)
Packets.SendUnicodeMessage(m.NetState, Serial, ItemID, MessageType.Regular, 0x3B2, 3, "ENU", "",
m_MessageString);
m.Send(new UnicodeMessage(Serial, ItemID, MessageType.Regular, 0x3B2, 3, "ENU", null,
m_MessageString));
else if (m_MessageNumber != 0)
Packets.SendMessageLocalized(m.NetState, Serial, ItemID, MessageType.Regular, 0x3B2, 3, m_MessageNumber);
m.Send(new MessageLocalized(Serial, ItemID, MessageType.Regular, 0x3B2, 3, m_MessageNumber, null,
""));
Timer.DelayCall(TimeSpan.FromSeconds(5.0), () => m.EndAction(this));
}
@ -521,7 +525,12 @@ namespace Server.Items
if (!m.InRange(GetWorldLocation(), m_Range))
return;
bool isMatch = m_Keyword >= 0 && e.HasKeyword(m_Keyword) || m_Substring != null && e.Speech.ToLower().IndexOf(m_Substring.ToLower()) >= 0;
bool isMatch = false;
if (m_Keyword >= 0 && e.HasKeyword(m_Keyword))
isMatch = true;
else if (m_Substring != null && e.Speech.ToLower().IndexOf(m_Substring.ToLower()) >= 0)
isMatch = true;
if (!isMatch || !CanTeleport(m))
return;
@ -811,10 +820,10 @@ namespace Server.Items
writer.Write(TimeoutDelay);
writer.Write(m_Teleporting.Count);
foreach (var (key, value) in m_Teleporting)
foreach (KeyValuePair<Mobile, Timer> kvp in m_Teleporting)
{
writer.Write(key);
writer.Write(value.Next);
writer.Write(kvp.Key);
writer.Write(kvp.Value.Next);
}
}
@ -1054,7 +1063,9 @@ namespace Server.Items
case Layer.Backpack:
case Layer.Mount:
case Layer.Bank:
{
continue; // ignore
}
default:
{
m.SendMessage("You must remove all of your equipment before proceeding.");

View file

@ -112,7 +112,7 @@ namespace Server.Items
if (items.Count > 0)
{
PublicOverheadMessage(MessageType.Regular, 0x3B2, message);
PublicOverheadMessage(MessageType.Regular, 0x3B2, message, "");
for (int i = items.Count - 1; i >= 0; --i)
{

View file

@ -26,7 +26,7 @@ namespace Server.Items
public void Carve(Mobile from, Item item)
{
Effects.PlaySound(GetWorldLocation(), Map, 0x48F);
Effects.SendLocationEffect(GetWorldLocation(), Map, 0x3728, 10);
Effects.SendLocationEffect(GetWorldLocation(), Map, 0x3728, 10, 10, 0, 0);
if (0.3 > Utility.RandomDouble())
{