diff --git a/Projects/Server.Tests/Tests/Network/Packets/Outgoing/MenuPacketTests.cs b/Projects/Server.Tests/Tests/Network/Packets/Outgoing/MenuPacketTests.cs index 6eeaa0359..243bff188 100644 --- a/Projects/Server.Tests/Tests/Network/Packets/Outgoing/MenuPacketTests.cs +++ b/Projects/Server.Tests/Tests/Network/Packets/Outgoing/MenuPacketTests.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using Server.Collections; using Server.ContextMenus; using Server.Menus.ItemLists; using Server.Menus.Questions; @@ -9,13 +9,13 @@ namespace Server.Tests.Network { internal class ContextMenuItem : Item { - private bool _requiresNewPacket; + private readonly bool _requiresNewPacket; public ContextMenuItem(Serial serial, bool requiresNewPacket) : base(serial) => _requiresNewPacket = requiresNewPacket; - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); list.Add(new ContextMenuEntry(3000001)); list.Add(new ContextMenuEntry(3000002)); @@ -35,12 +35,11 @@ namespace Server.Tests.Network { var menu = new ItemListMenu( "Which item would you choose?", - new[] - { + [ new ItemListEntry("Item 1", 0x01), new ItemListEntry("Item 2", 0x100), new ItemListEntry("Item 3", 0x1000, 250) - } + ] ); var expected = new DisplayItemListMenu(menu).Compile(); @@ -57,12 +56,11 @@ namespace Server.Tests.Network { var menu = new QuestionMenu( "Which option would you choose?", - new[] - { + [ "Option 1", "Option 2", "Option 3" - } + ] ); var expected = new DisplayQuestionMenu(menu).Compile(); @@ -84,7 +82,7 @@ namespace Server.Tests.Network m.DefaultMobileInit(); var item = new ContextMenuItem(World.NewItem, newPacket); - var menu = new ContextMenu(m, item); + var menu = ContextMenuSystem.CreateContextMenu(m, item); var packet = newHaven && newPacket ? (Packet)new DisplayContextMenu(menu) : new DisplayContextMenuOld(menu); var expected = packet.Compile(); diff --git a/Projects/Server/ContextMenus/ContextMenu.cs b/Projects/Server/ContextMenus/ContextMenu.cs index 27260b769..ea5b4f620 100644 --- a/Projects/Server/ContextMenus/ContextMenu.cs +++ b/Projects/Server/ContextMenus/ContextMenu.cs @@ -1,4 +1,17 @@ -using System.Collections.Generic; +/************************************************************************* + * ModernUO * + * Copyright 2019-2024 - ModernUO Development Team * + * Email: hi@modernuo.com * + * File: ContextMenu.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 . * + *************************************************************************/ namespace Server.ContextMenus; @@ -18,30 +31,28 @@ public class ContextMenu /// /// /// - /// The or for which this ContextMenu is on. + /// The or to execute the ContextMenu on. /// /// - public ContextMenu(Mobile from, IEntity target) + /// + /// An array of entries contained in this ContextMenu. + /// + /// + public ContextMenu(Mobile from, IEntity target, ContextMenuEntry[] entries) { From = from; Target = target; + Entries = entries; - var list = new List(); - - if (target is Mobile mobile) + for (var i = 0; i < Entries.Length; i++) { - mobile.GetContextMenuEntries(from, list); - } - else if (target is Item item) - { - item.GetContextMenuEntries(from, list); - } + var entry = Entries[i]; - Entries = list.ToArray(); - - for (var i = 0; i < Entries.Length; ++i) - { - Entries[i].Owner = this; + if (entry.Number is < 3000000 or > 3032767) + { + RequiresNewPacket = true; + break; + } } } @@ -63,20 +74,5 @@ public class ContextMenu /// /// Returns true if this ContextMenu requires packet version 2. /// - public bool RequiresNewPacket - { - get - { - for (var i = 0; i < Entries.Length; ++i) - { - var number = Entries[i].Number; - if (number is < 3000000 or > 3032767) - { - return true; - } - } - - return false; - } - } + public bool RequiresNewPacket { get; } } diff --git a/Projects/Server/ContextMenus/ContextMenuEntry.cs b/Projects/Server/ContextMenus/ContextMenuEntry.cs index 35155056b..96088b6d7 100644 --- a/Projects/Server/ContextMenus/ContextMenuEntry.cs +++ b/Projects/Server/ContextMenus/ContextMenuEntry.cs @@ -1,3 +1,18 @@ +/************************************************************************* + * ModernUO * + * Copyright 2019-2024 - ModernUO Development Team * + * Email: hi@modernuo.com * + * File: ContextMenuEntry.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 . * + *************************************************************************/ + using Server.Network; namespace Server.ContextMenus; @@ -42,11 +57,6 @@ public class ContextMenuEntry /// public CMEFlags Flags { get; set; } - /// - /// Gets or sets the that owns this entry. - /// - public ContextMenu Owner { get; set; } - /// /// Gets or sets the localization number containing the name of this entry. /// @@ -76,7 +86,7 @@ public class ContextMenuEntry /// /// Overridable. Virtual event invoked when the entry is clicked. /// - public virtual void OnClick() + public virtual void OnClick(Mobile from, IEntity target) { } } diff --git a/Projects/Server/ContextMenus/OpenBackpackEntry.cs b/Projects/Server/ContextMenus/OpenBackpackEntry.cs deleted file mode 100644 index 8928191f1..000000000 --- a/Projects/Server/ContextMenus/OpenBackpackEntry.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace Server.ContextMenus; - -public class OpenBackpackEntry : ContextMenuEntry -{ - private readonly Mobile m_Mobile; - - public OpenBackpackEntry(Mobile m) : base(6145) => m_Mobile = m; - - public override void OnClick() - { - m_Mobile.Use(m_Mobile.Backpack); - } -} diff --git a/Projects/Server/ContextMenus/PaperdollEntry.cs b/Projects/Server/ContextMenus/PaperdollEntry.cs deleted file mode 100644 index 1660d58e4..000000000 --- a/Projects/Server/ContextMenus/PaperdollEntry.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace Server.ContextMenus; - -public class PaperdollEntry : ContextMenuEntry -{ - private readonly Mobile m_Mobile; - - public PaperdollEntry(Mobile m) : base(6123, 18) => m_Mobile = m; - - public override void OnClick() - { - if (m_Mobile.CanPaperdollBeOpenedBy(Owner.From)) - { - m_Mobile.DisplayPaperdollTo(Owner.From); - } - } -} diff --git a/Projects/Server/Items/Item.cs b/Projects/Server/Items/Item.cs index 228e5b6eb..368991f2a 100644 --- a/Projects/Server/Items/Item.cs +++ b/Projects/Server/Items/Item.cs @@ -2131,27 +2131,27 @@ public class Item : IHued, IComparable, ISpawnable, IObjectPropertyListEnt public virtual bool CanEquip(Mobile m) => m_Layer != Layer.Invalid && m.FindItemOnLayer(m_Layer) == null; - public virtual void GetChildContextMenuEntries(Mobile from, List list, Item item) + public virtual void GetChildContextMenuEntries(Mobile from, ref PooledRefList list, Item item) { if (m_Parent is Item parentItem) { - parentItem.GetChildContextMenuEntries(from, list, item); + parentItem.GetChildContextMenuEntries(from, ref list, item); } else if (m_Parent is Mobile parentMobile) { - parentMobile.GetChildContextMenuEntries(from, list, item); + parentMobile.GetChildContextMenuEntries(from, ref list, item); } } - public virtual void GetContextMenuEntries(Mobile from, List list) + public virtual void GetContextMenuEntries(Mobile from, ref PooledRefList list) { if (m_Parent is Item item) { - item.GetChildContextMenuEntries(from, list, this); + item.GetChildContextMenuEntries(from, ref list, this); } else if (m_Parent is Mobile mobile) { - mobile.GetChildContextMenuEntries(from, list, this); + mobile.GetChildContextMenuEntries(from, ref list, this); } } diff --git a/Projects/Server/Mobiles/Mobile.cs b/Projects/Server/Mobiles/Mobile.cs index 3349817f5..0a98f00b4 100644 --- a/Projects/Server/Mobiles/Mobile.cs +++ b/Projects/Server/Mobiles/Mobile.cs @@ -264,7 +264,6 @@ public partial class Mobile : IHued, IComparable, ISpawnable, IObjectPro private int m_ChangingCombatant; private Mobile m_Combatant; private TimerExecutionToken _combatTimerToken; - private ContextMenu m_ContextMenu; private bool m_Criminal; private MobileDelta m_DeltaFlags; @@ -870,16 +869,6 @@ public partial class Mobile : IHued, IComparable, ISpawnable, IObjectPro } } - public ContextMenu ContextMenu - { - get => m_ContextMenu; - set - { - m_ContextMenu = value; - m_NetState.SendDisplayContextMenu(m_ContextMenu); - } - } - [IgnoreDupe] public bool Pushing { get; set; } @@ -6521,26 +6510,12 @@ public partial class Mobile : IHued, IComparable, ISpawnable, IObjectPro public virtual bool CanPaperdollBeOpenedBy(Mobile from) => Body.IsHuman || Body.IsGhost || IsBodyMod; - public virtual void GetChildContextMenuEntries(Mobile from, List list, Item item) + public virtual void GetChildContextMenuEntries(Mobile from, ref PooledRefList list, Item item) { } - public virtual void GetContextMenuEntries(Mobile from, List list) + public virtual void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - if (Deleted) - { - return; - } - - if (CanPaperdollBeOpenedBy(from)) - { - list.Add(new PaperdollEntry(this)); - } - - if (from == this && Backpack != null && CanSee(Backpack) && CheckAlive(false)) - { - list.Add(new OpenBackpackEntry(this)); - } } public void Internalize() diff --git a/Projects/Server/Network/Packets/OutgoingMenuPackets.cs b/Projects/Server/Network/Packets/OutgoingMenuPackets.cs index 71db481cc..96787c9f0 100644 --- a/Projects/Server/Network/Packets/OutgoingMenuPackets.cs +++ b/Projects/Server/Network/Packets/OutgoingMenuPackets.cs @@ -1,7 +1,21 @@ +/************************************************************************* + * ModernUO * + * Copyright 2019-2024 - ModernUO Development Team * + * Email: hi@modernuo.com * + * File: OutgoingMenuPackets.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 . * + *************************************************************************/ + using System; using System.Buffers; using System.IO; -using Server.ContextMenus; using Server.Menus.ItemLists; using Server.Menus.Questions; @@ -132,82 +146,4 @@ public static class OutgoingMenuPackets writer.WritePacketLength(); ns.Send(writer.Span); } - - public static void SendDisplayContextMenu(this NetState ns, ContextMenu menu) - { - if (ns == null || menu == null) - { - return; - } - - var newCommand = ns.NewHaven && menu.RequiresNewPacket; - - var entries = menu.Entries; - var entriesLength = (byte)entries.Length; - var maxLength = 12 + entriesLength * 8; - - var writer = new SpanWriter(stackalloc byte[maxLength]); - writer.Write((byte)0xBF); // Packet ID - writer.Seek(2, SeekOrigin.Current); // Length - writer.Write((short)0x14); // Subpacket - writer.Write((short)(newCommand ? 0x02 : 0x01)); // Command - - var target = menu.Target; - writer.Write(target.Serial); - writer.Write(entriesLength); - - var p = target switch - { - Mobile _ => target.Location, - Item item => item.GetWorldLocation(), - _ => Point3D.Zero - }; - - for (var i = 0; i < entriesLength; ++i) - { - var e = entries[i]; - - var range = e.Range; - - if (range == -1) - { - range = Core.GlobalUpdateRange; - } - - var flags = e.Flags; - if (!(e.Enabled && menu.From.InRange(p, range))) - { - flags |= CMEFlags.Disabled; - } - - if (newCommand) - { - writer.Write(e.Number); - writer.Write((short)i); - writer.Write((short)flags); - } - else - { - writer.Write((short)i); - writer.Write((ushort)(e.Number - 3000000)); - - var color = e.Color & 0xFFFF; - - if (color != 0xFFFF) - { - flags |= CMEFlags.Colored; - } - - writer.Write((short)flags); - - if ((flags & CMEFlags.Colored) != 0) - { - writer.Write((short)color); - } - } - } - - writer.WritePacketLength(); - ns.Send(writer.Span); - } } diff --git a/Projects/UOContent/Context Menus/AddToParty.cs b/Projects/UOContent/Context Menus/AddToParty.cs index a88cdc57f..979d5ab9d 100644 --- a/Projects/UOContent/Context Menus/AddToParty.cs +++ b/Projects/UOContent/Context Menus/AddToParty.cs @@ -4,47 +4,47 @@ namespace Server.ContextMenus { public class AddToPartyEntry : ContextMenuEntry { - private readonly Mobile m_From; - private readonly Mobile m_Target; - - public AddToPartyEntry(Mobile from, Mobile target) : base(0197, 12) + public AddToPartyEntry() : base(0197, 12) { - m_From = from; - m_Target = target; } - public override void OnClick() + public override void OnClick(Mobile from, IEntity target) { - var p = Party.Get(m_From); - var mp = Party.Get(m_Target); - - if (m_From == m_Target) + if (target is not Mobile targetMobile) { - m_From.SendLocalizedMessage(1005439); // You cannot add yourself to a party. + return; } - else if (p != null && p.Leader != m_From) + + var p = Party.Get(from); + var mp = Party.Get(targetMobile); + + if (from == targetMobile) { - m_From.SendLocalizedMessage(1005453); // You may only add members to the party if you are the leader. + from.SendLocalizedMessage(1005439); // You cannot add yourself to a party. + } + else if (p != null && p.Leader != from) + { + from.SendLocalizedMessage(1005453); // You may only add members to the party if you are the leader. } else if (p != null && p.Members.Count + p.Candidates.Count >= Party.Capacity) { - m_From.SendLocalizedMessage(1008095); // You may only have 10 in your party (this includes candidates). + from.SendLocalizedMessage(1008095); // You may only have 10 in your party (this includes candidates). } - else if (!m_Target.Player) + else if (!targetMobile.Player) { - m_From.SendLocalizedMessage(1005444); // The creature ignores your offer. + from.SendLocalizedMessage(1005444); // The creature ignores your offer. } else if (mp != null && mp == p) { - m_From.SendLocalizedMessage(1005440); // This person is already in your party! + from.SendLocalizedMessage(1005440); // This person is already in your party! } else if (mp != null) { - m_From.SendLocalizedMessage(1005441); // This person is already in a party! + from.SendLocalizedMessage(1005441); // This person is already in a party! } else { - Party.Invite(m_From, m_Target); + Party.Invite(from, targetMobile); } } } diff --git a/Projects/UOContent/Context Menus/AddToSpellbookEntry.cs b/Projects/UOContent/Context Menus/AddToSpellbookEntry.cs index 3f16c9503..27014de2c 100644 --- a/Projects/UOContent/Context Menus/AddToSpellbookEntry.cs +++ b/Projects/UOContent/Context Menus/AddToSpellbookEntry.cs @@ -9,11 +9,11 @@ namespace Server.ContextMenus { } - public override void OnClick() + public override void OnClick(Mobile from, IEntity target) { - if (Owner.From.CheckAlive() && Owner.Target is SpellScroll scroll) + if (from.CheckAlive() && target is SpellScroll scroll) { - Owner.From.Target = new InternalTarget(scroll); + from.Target = new InternalTarget(scroll); } } diff --git a/Projects/UOContent/Context Menus/ContextMenuSystem.cs b/Projects/UOContent/Context Menus/ContextMenuSystem.cs new file mode 100644 index 000000000..b20bb0d40 --- /dev/null +++ b/Projects/UOContent/Context Menus/ContextMenuSystem.cs @@ -0,0 +1,220 @@ +using System.Buffers; +using System.Collections.Generic; +using System.IO; +using Server.Collections; +using Server.Network; + +namespace Server.ContextMenus; + +public static class ContextMenuSystem +{ + private static readonly Dictionary _menus = []; + + public static unsafe void Configure() + { + IncomingExtendedCommandPackets.RegisterExtended(0x13, true, &ContextMenuRequest); + IncomingExtendedCommandPackets.RegisterExtended(0x15, true, &ContextMenuResponse); + } + + public static ContextMenu CreateContextMenu(Mobile from, IEntity target) + { + if (target?.Deleted != false) + { + return new ContextMenu(from, target, []); + } + + var list = PooledRefList.Create(); + + if (target is Mobile mobile) + { + if (mobile.CanPaperdollBeOpenedBy(from)) + { + list.Add(new PaperdollEntry()); + } + + mobile.GetContextMenuEntries(from, ref list); + } + else if (target is Item item) + { + item.GetContextMenuEntries(from, ref list); + } + + var entries = list.ToArray(); + list.Dispose(); + + return new ContextMenu(from, target, entries); + } + + public static void ContextMenuResponse(NetState state, SpanReader reader) + { + var from = state.Mobile; + + if (from == null || !_menus.Remove(from, out var menu) || from != menu.From) + { + return; + } + + var entity = World.FindEntity((Serial)reader.ReadUInt32()); + + if (entity == null || entity != menu.Target || !from.CanSee(entity)) + { + return; + } + + Point3D p; + + if (entity is Mobile) + { + p = entity.Location; + } + else if (entity is Item item) + { + p = item.GetWorldLocation(); + } + else + { + return; + } + + int index = reader.ReadUInt16(); + + if (index >= menu.Entries.Length) + { + return; + } + + var e = menu.Entries[index]; + + var range = e.Range; + + if (range == -1) + { + range = 18; + } + + if (e.Enabled && from.InRange(p, range)) + { + e.OnClick(from, entity); + } + } + + public static void ContextMenuRequest(NetState state, SpanReader reader) + { + var from = state.Mobile; + var target = World.FindEntity((Serial)reader.ReadUInt32()); + + if (from == null || target == null || from.Map != target.Map || !from.CanSee(target)) + { + return; + } + + var item = target as Item; + + var checkLocation = item?.GetWorldLocation() ?? target.Location; + if (!(Utility.InUpdateRange(from.Location, checkLocation) && from.CheckContextMenuDisplay(target))) + { + return; + } + + var c = CreateContextMenu(from, target); + + if (c.Entries.Length <= 0) + { + return; + } + + if (item?.RootParent is Mobile mobile && mobile != from && mobile.AccessLevel >= from.AccessLevel) + { + for (var i = 0; i < c.Entries.Length; ++i) + { + var entry = c.Entries[i]; + if (!entry.NonLocalUse) + { + entry.Enabled = false; + } + } + } + + _menus[from] = c; + state.SendDisplayContextMenu(c); + } + + public static void SendDisplayContextMenu(this NetState ns, ContextMenu menu) + { + if (ns == null || menu == null) + { + return; + } + + var newCommand = ns.NewHaven && menu.RequiresNewPacket; + + var entries = menu.Entries; + var entriesLength = (byte)entries.Length; + var maxLength = 12 + entriesLength * 8; + + var writer = new SpanWriter(stackalloc byte[maxLength]); + writer.Write((byte)0xBF); // Packet ID + writer.Seek(2, SeekOrigin.Current); // Length + writer.Write((short)0x14); // Subpacket + writer.Write((short)(newCommand ? 0x02 : 0x01)); // Command + + var target = menu.Target; + writer.Write(target.Serial); + writer.Write(entriesLength); + + var p = target switch + { + Mobile _ => target.Location, + Item item => item.GetWorldLocation(), + _ => Point3D.Zero + }; + + for (var i = 0; i < entriesLength; ++i) + { + var e = entries[i]; + + var range = e.Range; + + if (range == -1) + { + range = Core.GlobalUpdateRange; + } + + var flags = e.Flags; + if (!(e.Enabled && menu.From.InRange(p, range))) + { + flags |= CMEFlags.Disabled; + } + + if (newCommand) + { + writer.Write(e.Number); + writer.Write((short)i); + writer.Write((short)flags); + } + else + { + + writer.Write((short)i); + writer.Write((ushort)(e.Number - 3000000)); + + var color = e.Color & 0xFFFF; + + if (color != 0xFFFF) + { + flags |= CMEFlags.Colored; + } + + writer.Write((short)flags); + + if ((flags & CMEFlags.Colored) != 0) + { + writer.Write((short)color); + } + } + } + + writer.WritePacketLength(); + ns.Send(writer.Span); + } +} diff --git a/Projects/UOContent/Context Menus/EatEntry.cs b/Projects/UOContent/Context Menus/EatEntry.cs index d78ffc9cf..3bd16b2db 100644 --- a/Projects/UOContent/Context Menus/EatEntry.cs +++ b/Projects/UOContent/Context Menus/EatEntry.cs @@ -4,23 +4,16 @@ namespace Server.ContextMenus { public class EatEntry : ContextMenuEntry { - private readonly Food m_Food; - private readonly Mobile m_From; - - public EatEntry(Mobile from, Food food) : base(6135, 1) + public EatEntry() : base(6135, 1) { - m_From = from; - m_Food = food; } - public override void OnClick() + public override void OnClick(Mobile from, IEntity target) { - if (m_Food?.Deleted != false || !m_Food.Movable || !m_From.CheckAlive() || !m_Food.CheckItemUse(m_From)) + if (from.CheckAlive() && target is Food { Deleted: false, Movable: true } food && food.CheckItemUse(from)) { - return; + food.Eat(from); } - - m_Food.Eat(m_From); } } } diff --git a/Projects/UOContent/Context Menus/EjectPlayer.cs b/Projects/UOContent/Context Menus/EjectPlayer.cs index e00a87802..87a986d9b 100644 --- a/Projects/UOContent/Context Menus/EjectPlayer.cs +++ b/Projects/UOContent/Context Menus/EjectPlayer.cs @@ -4,25 +4,25 @@ namespace Server.ContextMenus { public class EjectPlayerEntry : ContextMenuEntry { - private readonly Mobile m_From; - private readonly Mobile m_Target; - private readonly BaseHouse m_TargetHouse; - - public EjectPlayerEntry(Mobile from, Mobile target) : base(6206, 12) + public EjectPlayerEntry() : base(6206, 12) { - m_From = from; - m_Target = target; - m_TargetHouse = BaseHouse.FindHouseAt(m_Target); } - public override void OnClick() + public override void OnClick(Mobile from, IEntity target) { - if (!m_From.Alive || m_TargetHouse.Deleted || !m_TargetHouse.IsFriend(m_From)) + if (target is not Mobile targetMobile) { return; } - m_TargetHouse.Kick(m_From, m_Target); + var house = BaseHouse.FindHouseAt(targetMobile); + + if (!from.Alive || house.Deleted || !house.IsFriend(from)) + { + return; + } + + house.Kick(from, targetMobile); } } } diff --git a/Projects/UOContent/Context Menus/OpenBackpackEntry.cs b/Projects/UOContent/Context Menus/OpenBackpackEntry.cs new file mode 100644 index 000000000..0751d5ae2 --- /dev/null +++ b/Projects/UOContent/Context Menus/OpenBackpackEntry.cs @@ -0,0 +1,13 @@ +namespace Server.ContextMenus; + +public class OpenBackpackEntry : ContextMenuEntry +{ + public OpenBackpackEntry() : base(6145) + { + } + + public override void OnClick(Mobile from, IEntity target) + { + from.Use(from.Backpack); + } +} diff --git a/Projects/UOContent/Context Menus/OpenBankEntry.cs b/Projects/UOContent/Context Menus/OpenBankEntry.cs index faf3468f5..47ad75f02 100644 --- a/Projects/UOContent/Context Menus/OpenBankEntry.cs +++ b/Projects/UOContent/Context Menus/OpenBankEntry.cs @@ -2,24 +2,24 @@ namespace Server.ContextMenus { public class OpenBankEntry : ContextMenuEntry { - private readonly Mobile m_Banker; - - public OpenBankEntry(Mobile banker) : base(6105, 12) => m_Banker = banker; - - public override void OnClick() + public OpenBankEntry() : base(6105, 12) { - if (!Owner.From.CheckAlive()) + } + + public override void OnClick(Mobile from, IEntity target) + { + if (!from.CheckAlive() || target is not Mobile banker) { return; } - if (Owner.From.Criminal) + if (from.Criminal) { - m_Banker.Say(500378); // Thou art a criminal and cannot access thy bank box. + banker.Say(500378); // Thou art a criminal and cannot access thy bank box. } else { - Owner.From.BankBox.Open(); + from.BankBox.Open(); } } } diff --git a/Projects/UOContent/Context Menus/PaperdollEntry.cs b/Projects/UOContent/Context Menus/PaperdollEntry.cs new file mode 100644 index 000000000..095451e5a --- /dev/null +++ b/Projects/UOContent/Context Menus/PaperdollEntry.cs @@ -0,0 +1,16 @@ +namespace Server.ContextMenus; + +public class PaperdollEntry : ContextMenuEntry +{ + public PaperdollEntry() : base(6123, 18) + { + } + + public override void OnClick(Mobile from, IEntity target) + { + if (target is Mobile mobile && mobile.CanPaperdollBeOpenedBy(from)) + { + mobile.DisplayPaperdollTo(from); + } + } +} diff --git a/Projects/UOContent/Context Menus/TeachEntry.cs b/Projects/UOContent/Context Menus/TeachEntry.cs index e609041ff..066fdea86 100644 --- a/Projects/UOContent/Context Menus/TeachEntry.cs +++ b/Projects/UOContent/Context Menus/TeachEntry.cs @@ -1,34 +1,25 @@ using Server.Mobiles; -using Server.Network; namespace Server.ContextMenus { public class TeachEntry : ContextMenuEntry { - private readonly Mobile m_From; - private readonly BaseCreature m_Mobile; - private readonly SkillName m_Skill; + private readonly SkillName _skill; - public TeachEntry(SkillName skill, BaseCreature m, Mobile from, bool enabled) : base(6000 + (int)skill) + public TeachEntry(SkillName skill, bool enabled) : base(6000 + (int)skill) { - m_Skill = skill; - m_Mobile = m; - m_From = from; - - if (!enabled) - { - Flags |= CMEFlags.Disabled; - } + _skill = skill; + Enabled = enabled; } - public override void OnClick() + public override void OnClick(Mobile from, IEntity target) { - if (!m_From.CheckAlive()) + if (!from.CheckAlive() || target is not BaseCreature bc) { return; } - m_Mobile.Teach(m_Skill, m_From, 0, false); + bc.Teach(_skill, from, 0, false); } } } diff --git a/Projects/UOContent/Engines/Bulk Orders/Books/BulkOrderBook.cs b/Projects/UOContent/Engines/Bulk Orders/Books/BulkOrderBook.cs index 04ead61d2..4e67ca620 100644 --- a/Projects/UOContent/Engines/Bulk Orders/Books/BulkOrderBook.cs +++ b/Projects/UOContent/Engines/Bulk Orders/Books/BulkOrderBook.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using ModernUO.Serialization; +using Server.Collections; using Server.ContextMenus; using Server.Gumps; using Server.Mobiles; @@ -277,36 +278,33 @@ public partial class BulkOrderBook : Item, ISecurable } } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); if (from.CheckAlive() && IsChildOf(from.Backpack)) { - list.Add(new NameBookEntry(from, this)); + list.Add(new NameBookEntry()); } - SetSecureLevelEntry.AddTo(from, this, list); + SetSecureLevelEntry.AddTo(from, this, ref list); } private class NameBookEntry : ContextMenuEntry { - private readonly BulkOrderBook m_Book; - private readonly Mobile m_From; - - public NameBookEntry(Mobile from, BulkOrderBook book) : base(6216) + public NameBookEntry() : base(6216) { - m_From = from; - m_Book = book; } - public override void OnClick() + public override void OnClick(Mobile from, IEntity target) { - if (m_From.CheckAlive() && m_Book.IsChildOf(m_From.Backpack)) + if (!from.CheckAlive() || target is not BulkOrderBook book || !book.IsChildOf(from.Backpack)) { - m_From.Prompt = new NameBookPrompt(m_Book); - m_From.SendLocalizedMessage(1062479); // Type in the new name of the book: + return; } + + from.Prompt = new NameBookPrompt(book); + from.SendLocalizedMessage(1062479); // Type in the new name of the book: } } diff --git a/Projects/UOContent/Engines/ConPVP/TournamentController.cs b/Projects/UOContent/Engines/ConPVP/TournamentController.cs index 91a1a0544..88a352320 100644 --- a/Projects/UOContent/Engines/ConPVP/TournamentController.cs +++ b/Projects/UOContent/Engines/ConPVP/TournamentController.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using Server.Collections; using Server.ContextMenus; using Server.Gumps; @@ -46,17 +47,17 @@ namespace Server.Engines.ConPVP public override string DefaultName => "tournament controller"; - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); if (from.AccessLevel >= AccessLevel.GameMaster && Tournament != null) { - list.Add(new EditEntry(Tournament)); + list.Add(new EditEntry()); if (Tournament.CurrentStage == TournamentStage.Inactive) { - list.Add(new StartEntry(Tournament)); + list.Add(new StartEntry()); } } } @@ -107,35 +108,42 @@ namespace Server.Engines.ConPVP private class EditEntry : ContextMenuEntry { - private readonly Tournament m_Tournament; - - public EditEntry(Tournament tourney) : base(5101) => m_Tournament = tourney; - - public override void OnClick() + public EditEntry() : base(5101) { - Owner.From.SendGump(new PropertiesGump(Owner.From, m_Tournament)); + } + + public override void OnClick(Mobile from, IEntity target) + { + if (target is not TournamentController controller) + { + return; + } + + from.SendGump(new PropertiesGump(from, controller.Tournament)); } } private class StartEntry : ContextMenuEntry { - private readonly Tournament m_Tournament; - - public StartEntry(Tournament tourney) : base(5113) => m_Tournament = tourney; - - public override void OnClick() + public StartEntry() : base(5113) { - if (m_Tournament.Stage == TournamentStage.Inactive) + } + + public override void OnClick(Mobile from, IEntity target) + { + if (target is not TournamentController controller || controller.Tournament.Stage != TournamentStage.Inactive) { - m_Tournament.SignupStart = Core.Now; - m_Tournament.Stage = TournamentStage.Signup; - m_Tournament.Participants.Clear(); - m_Tournament.Pyramid.Levels.Clear(); - m_Tournament.Alert( - "Hear ye! Hear ye!", - "Tournament signup has opened. You can enter by signing up with the registrar." - ); + return; } + + controller.Tournament.SignupStart = Core.Now; + controller.Tournament.Stage = TournamentStage.Signup; + controller.Tournament.Participants.Clear(); + controller.Tournament.Pyramid.Levels.Clear(); + controller.Tournament.Alert( + "Hear ye! Hear ye!", + "Tournament signup has opened. You can enter by signing up with the registrar." + ); } } } diff --git a/Projects/UOContent/Engines/Party/RemoveFromParty.cs b/Projects/UOContent/Engines/Party/RemoveFromParty.cs index 0d8d2978d..c096579b9 100644 --- a/Projects/UOContent/Engines/Party/RemoveFromParty.cs +++ b/Projects/UOContent/Engines/Party/RemoveFromParty.cs @@ -4,31 +4,26 @@ namespace Server.ContextMenus { public class RemoveFromPartyEntry : ContextMenuEntry { - private readonly Mobile m_From; - private readonly Mobile m_Target; - - public RemoveFromPartyEntry(Mobile from, Mobile target) : base(0198, 12) + public RemoveFromPartyEntry() : base(0198, 12) { - m_From = from; - m_Target = target; } - public override void OnClick() + public override void OnClick(Mobile from, IEntity target) { - var p = Party.Get(m_From); + var p = Party.Get(from); - if (p == null || p.Leader != m_From || !p.Contains(m_Target)) + if (target is not Mobile mobile || p == null || p.Leader != from || !p.Contains(mobile)) { return; } - if (m_From == m_Target) + if (from == mobile) { - m_From.SendLocalizedMessage(1005446); // You may only remove yourself from a party if you are not the leader. + from.SendLocalizedMessage(1005446); // You may only remove yourself from a party if you are not the leader. } else { - p.Remove(m_Target); + p.Remove(mobile); } } } diff --git a/Projects/UOContent/Engines/Plants/PlantItem.cs b/Projects/UOContent/Engines/Plants/PlantItem.cs index 8a8183a66..3bc098ffe 100644 --- a/Projects/UOContent/Engines/Plants/PlantItem.cs +++ b/Projects/UOContent/Engines/Plants/PlantItem.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using ModernUO.Serialization; +using Server.Collections; using Server.ContextMenus; using Server.Gumps; using Server.Items; @@ -221,10 +222,10 @@ public partial class PlantItem : Item, ISecurable } } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); - SetSecureLevelEntry.AddTo(from, this, list); + base.GetContextMenuEntries(from, ref list); + SetSecureLevelEntry.AddTo(from, this, ref list); } public int GetLocalizedPlantStatus() diff --git a/Projects/UOContent/Engines/Quests/Collector/Items/Obsidian.cs b/Projects/UOContent/Engines/Quests/Collector/Items/Obsidian.cs index 476789861..0ffd19bbf 100644 --- a/Projects/UOContent/Engines/Quests/Collector/Items/Obsidian.cs +++ b/Projects/UOContent/Engines/Quests/Collector/Items/Obsidian.cs @@ -1,5 +1,5 @@ -using System.Collections.Generic; using ModernUO.Serialization; +using Server.Collections; using Server.ContextMenus; using Server.Network; using Server.Targeting; @@ -153,13 +153,13 @@ public partial class Obsidian : Item } } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); if (from.Alive && _quantity is >= Partial and < Completed && IsChildOf(from.Backpack)) { - list.Add(new DisassembleEntry(this)); + list.Add(new DisassembleEntry()); } } @@ -187,23 +187,24 @@ public partial class Obsidian : Item private class DisassembleEntry : ContextMenuEntry { - private readonly Obsidian _obsidian; - - public DisassembleEntry(Obsidian obsidian) : base(6142) => _obsidian = obsidian; - - public override void OnClick() + public DisassembleEntry() : base(6142) { - var from = Owner.From; - if (!_obsidian.Deleted && _obsidian.Quantity >= Partial && _obsidian.Quantity < Completed && - _obsidian.IsChildOf(from.Backpack) && from.CheckAlive()) - { - for (var i = 0; i < _obsidian.Quantity - 1; i++) - { - from.AddToBackpack(new Obsidian()); - } + } - _obsidian.Quantity = 1; + public override void OnClick(Mobile from, IEntity target) + { + if (!from.CheckAlive() || target is not Obsidian obsidian || obsidian.Deleted || obsidian.Quantity < Partial || + obsidian.Quantity >= Completed || !obsidian.IsChildOf(from.Backpack)) + { + return; } + + for (var i = 0; i < obsidian.Quantity - 1; i++) + { + from.AddToBackpack(new Obsidian()); + } + + obsidian.Quantity = 1; } } diff --git a/Projects/UOContent/Engines/Quests/Core/BaseQuester.cs b/Projects/UOContent/Engines/Quests/Core/BaseQuester.cs index 003acf1af..fd9573fe2 100644 --- a/Projects/UOContent/Engines/Quests/Core/BaseQuester.cs +++ b/Projects/UOContent/Engines/Quests/Core/BaseQuester.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using ModernUO.Serialization; +using Server.Collections; using Server.ContextMenus; using Server.Items; using Server.Mobiles; @@ -8,17 +9,15 @@ namespace Server.Engines.Quests; public class TalkEntry : ContextMenuEntry { - private readonly BaseQuester _quester; - - public TalkEntry(BaseQuester quester) : base(quester.TalkNumber) => _quester = quester; - - public override void OnClick() + public TalkEntry(int talkNumber) : base(talkNumber) { - var from = Owner.From; + } - if (from.CheckAlive() && from is PlayerMobile mobile && _quester.CanTalkTo(mobile)) + public override void OnClick(Mobile from, IEntity target) + { + if (from.CheckAlive() && from is PlayerMobile mobile && target is BaseQuester quester && quester.CanTalkTo(mobile)) { - _quester.OnTalk(mobile, true); + quester.OnTalk(mobile, true); } } } @@ -60,13 +59,13 @@ public abstract partial class BaseQuester : BaseVendor return item; } - public override void AddCustomContextEntries(Mobile from, List list) + public override void AddCustomContextEntries(Mobile from, ref PooledRefList list) { - base.AddCustomContextEntries(from, list); + base.AddCustomContextEntries(from, ref list); if (from.Alive && from is PlayerMobile mobile && TalkNumber > 0 && CanTalkTo(mobile)) { - list.Add(new TalkEntry(this)); + list.Add(new TalkEntry(TalkNumber)); } } diff --git a/Projects/UOContent/Engines/Quests/Core/QuestCallbackEntry.cs b/Projects/UOContent/Engines/Quests/Core/QuestCallbackEntry.cs index 98706f103..9c4bf60ea 100644 --- a/Projects/UOContent/Engines/Quests/Core/QuestCallbackEntry.cs +++ b/Projects/UOContent/Engines/Quests/Core/QuestCallbackEntry.cs @@ -13,7 +13,7 @@ namespace Server.Engines.Quests public QuestCallbackEntry(int number, int range, QuestCallback callback) : base(number, range) => m_Callback = callback; - public override void OnClick() + public override void OnClick(Mobile from, IEntity target) { m_Callback?.Invoke(); } diff --git a/Projects/UOContent/Engines/Quests/Core/QuestSystem.cs b/Projects/UOContent/Engines/Quests/Core/QuestSystem.cs index 7d0be4bbf..11a3de25e 100644 --- a/Projects/UOContent/Engines/Quests/Core/QuestSystem.cs +++ b/Projects/UOContent/Engines/Quests/Core/QuestSystem.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using Server.Collections; using Server.ContextMenus; using Server.Engines.Quests.Ambitious; using Server.Engines.Quests.Collector; @@ -246,7 +247,7 @@ namespace Server.Engines.Quests From.SendGump(new QuestOfferGump(this)); } - public virtual void GetContextMenuEntries(List list) + public virtual void GetContextMenuEntries(ref PooledRefList list) { if (Objectives.Count > 0) { diff --git a/Projects/UOContent/Engines/Quests/Dark Tides/Mobiles/Horus.cs b/Projects/UOContent/Engines/Quests/Dark Tides/Mobiles/Horus.cs index fb74f2afd..b55b93026 100644 --- a/Projects/UOContent/Engines/Quests/Dark Tides/Mobiles/Horus.cs +++ b/Projects/UOContent/Engines/Quests/Dark Tides/Mobiles/Horus.cs @@ -1,9 +1,8 @@ -using System.Collections.Generic; using ModernUO.Serialization; +using Server.Collections; using Server.ContextMenus; using Server.Items; using Server.Mobiles; -using Server.Network; namespace Server.Engines.Quests.Necro; @@ -115,9 +114,9 @@ public partial class Horus : BaseQuester } } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); if (!from.Alive || from is not PlayerMobile pm) { @@ -131,7 +130,7 @@ public partial class Horus : BaseQuester var obj = qs.FindObjective(); var enabled = obj?.Completed == false; - list.Add(new SpeakPasswordEntry(this, pm, enabled)); + list.Add(new SpeakPasswordEntry(enabled)); } } @@ -150,25 +149,13 @@ public partial class Horus : BaseQuester private class SpeakPasswordEntry : ContextMenuEntry { - private readonly PlayerMobile _from; - private readonly Horus _horus; + public SpeakPasswordEntry(bool enabled) : base(6193, 3) => Enabled = enabled; - public SpeakPasswordEntry(Horus horus, PlayerMobile from, bool enabled) : base(6193, 3) + public override void OnClick(Mobile from, IEntity target) { - _horus = horus; - _from = from; - - if (!enabled) + if (from.Alive && from is PlayerMobile pm && target is Horus horus) { - Flags |= CMEFlags.Disabled; - } - } - - public override void OnClick() - { - if (_from.Alive) - { - _horus.OnPasswordSpoken(_from); + horus.OnPasswordSpoken(pm); } } } diff --git a/Projects/UOContent/Engines/Quests/Solen Matriarch/Mobiles/SolenMatriarch.cs b/Projects/UOContent/Engines/Quests/Solen Matriarch/Mobiles/SolenMatriarch.cs index 270b970f5..d08d535d9 100644 --- a/Projects/UOContent/Engines/Quests/Solen Matriarch/Mobiles/SolenMatriarch.cs +++ b/Projects/UOContent/Engines/Quests/Solen Matriarch/Mobiles/SolenMatriarch.cs @@ -1,5 +1,5 @@ -using System.Collections.Generic; using ModernUO.Serialization; +using Server.Collections; using Server.ContextMenus; using Server.Engines.Plants; using Server.Items; @@ -141,14 +141,14 @@ public abstract partial class BaseSolenMatriarch : BaseQuester return true; } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); if (from.Alive && from is PlayerMobile pm && pm.Quest is SolenMatriarchQuest qs && qs.RedSolen == RedSolen && qs.IsObjectiveInProgress(typeof(ProcessFungiObjective))) { - list.Add(new ProcessZoogiFungusEntry(this, pm)); + list.Add(new ProcessZoogiFungusEntry()); } } @@ -197,20 +197,15 @@ public abstract partial class BaseSolenMatriarch : BaseQuester private class ProcessZoogiFungusEntry : ContextMenuEntry { - private readonly PlayerMobile _from; - private readonly BaseSolenMatriarch _matriarch; - - public ProcessZoogiFungusEntry(BaseSolenMatriarch matriarch, PlayerMobile from) : base(6184) + public ProcessZoogiFungusEntry() : base(6184) { - _matriarch = matriarch; - _from = from; } - public override void OnClick() + public override void OnClick(Mobile from, IEntity target) { - if (_from.Alive) + if (from.Alive && from is PlayerMobile pm && target is BaseSolenMatriarch matriarch) { - _from.Target = new ProcessFungiTarget(_matriarch, _from); + from.Target = new ProcessFungiTarget(matriarch, pm); } } } diff --git a/Projects/UOContent/Engines/Veteran Rewards/Character Statue Maker/CharacterStatue.cs b/Projects/UOContent/Engines/Veteran Rewards/Character Statue Maker/CharacterStatue.cs index 0d116dd2a..b60da0188 100644 --- a/Projects/UOContent/Engines/Veteran Rewards/Character Statue Maker/CharacterStatue.cs +++ b/Projects/UOContent/Engines/Veteran Rewards/Character Statue Maker/CharacterStatue.cs @@ -1,8 +1,8 @@ using System; -using System.Collections.Generic; using System.Runtime.CompilerServices; using ModernUO.Serialization; using Server.Accounting; +using Server.Collections; using Server.ContextMenus; using Server.Engines.VeteranRewards; using Server.Gumps; @@ -135,9 +135,9 @@ public partial class CharacterStatue : Mobile, IRewardItem } } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); if (from.Alive && _sculptedBy != null) { @@ -145,7 +145,7 @@ public partial class CharacterStatue : Mobile, IRewardItem if (house?.IsCoOwner(from) == true || from.AccessLevel > AccessLevel.Counselor) { - list.Add(new DemolishEntry(this)); + list.Add(new DemolishEntry()); } } } @@ -382,15 +382,15 @@ public partial class CharacterStatue : Mobile, IRewardItem private class DemolishEntry : ContextMenuEntry { - private readonly CharacterStatue m_Statue; - - public DemolishEntry(CharacterStatue statue) : base(6275, 2) => m_Statue = statue; - - public override void OnClick() + public DemolishEntry() : base(6275, 2) { - if (!m_Statue.Deleted) + } + + public override void OnClick(Mobile from, IEntity target) + { + if (from.Alive && target is CharacterStatue { Deleted: false } statue) { - m_Statue.Demolish(Owner.From); + statue.Demolish(from); } } } diff --git a/Projects/UOContent/Items/Addons/AddonComponent.cs b/Projects/UOContent/Items/Addons/AddonComponent.cs index 3cc8d0706..ce155cec9 100644 --- a/Projects/UOContent/Items/Addons/AddonComponent.cs +++ b/Projects/UOContent/Items/Addons/AddonComponent.cs @@ -162,7 +162,7 @@ namespace Server.Items /* public override void GetProperties(IPropertyList list) => _addon?.GetProperties(list); - public override void GetContextMenuEntries(Mobile from, List list) => + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) => _addon?.GetContextMenuEntries(from, list); */ public override void OnAfterDelete() diff --git a/Projects/UOContent/Items/Addons/AddonContainerComponent.cs b/Projects/UOContent/Items/Addons/AddonContainerComponent.cs index 81b1813ef..19ac684a0 100644 --- a/Projects/UOContent/Items/Addons/AddonContainerComponent.cs +++ b/Projects/UOContent/Items/Addons/AddonContainerComponent.cs @@ -1,7 +1,7 @@ using System; using System.Buffers.Binary; -using System.Collections.Generic; using ModernUO.Serialization; +using Server.Collections; using Server.ContextMenus; using Server.Network; @@ -79,8 +79,8 @@ namespace Server.Items public override void GetProperties(IPropertyList list) => _addon?.GetProperties(list); - public override void GetContextMenuEntries(Mobile from, List list) => - _addon?.GetContextMenuEntries(from, list); + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) => + _addon?.GetContextMenuEntries(from, ref list); public override void OnAfterDelete() { diff --git a/Projects/UOContent/Items/Aquarium/Aquarium.cs b/Projects/UOContent/Items/Aquarium/Aquarium.cs index 8ffeb3fe7..f124a354e 100644 --- a/Projects/UOContent/Items/Aquarium/Aquarium.cs +++ b/Projects/UOContent/Items/Aquarium/Aquarium.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Runtime.CompilerServices; using ModernUO.Serialization; +using Server.Collections; using Server.ContextMenus; using Server.Multis; using Server.Network; @@ -438,40 +439,40 @@ namespace Server.Items } } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); if (from.Alive) { - list.Add(new ExamineEntry(this)); + list.Add(new ExamineEntry()); if (HasAccess(from)) { if (_rewardAvailable) { - list.Add(new CollectRewardEntry(this)); + list.Add(new CollectRewardEntry()); } if (_events.Count > 0) { - list.Add(new ViewEventEntry(this)); + list.Add(new ViewEventEntry()); } if (_vacationLeft > 0) { - list.Add(new CancelVacationMode(this)); + list.Add(new CancelVacationMode()); } } } if (from.AccessLevel >= AccessLevel.GameMaster) { - list.Add(new GMAddFood(this)); - list.Add(new GMAddWater(this)); - list.Add(new GMForceEvaluate(this)); - list.Add(new GMOpen(this)); - list.Add(new GMFill(this)); + list.Add(new GMAddFood()); + list.Add(new GMAddWater()); + list.Add(new GMForceEvaluate()); + list.Add(new GMOpen()); + list.Add(new GMFill()); } } @@ -982,177 +983,171 @@ namespace Server.Items private class ExamineEntry : ContextMenuEntry { - private readonly Aquarium m_Aquarium; - - public ExamineEntry(Aquarium aquarium) : base(6235, 2) // Examine Aquarium - => - m_Aquarium = aquarium; - - public override void OnClick() + public ExamineEntry() : base(6235, 2) { - if (m_Aquarium.Deleted) + } + + public override void OnClick(Mobile from, IEntity target) + { + if (!from.Alive || target is not Aquarium aquarium || aquarium.Deleted) { return; } - m_Aquarium.ExamineAquarium(Owner.From); + aquarium.ExamineAquarium(from); } } private class CollectRewardEntry : ContextMenuEntry { - private readonly Aquarium m_Aquarium; - - public CollectRewardEntry(Aquarium aquarium) : base(6237, 2) // Collect Reward - => - m_Aquarium = aquarium; - - public override void OnClick() + public CollectRewardEntry() : base(6237, 2) { - if (m_Aquarium.Deleted || !m_Aquarium.HasAccess(Owner.From)) + } + + public override void OnClick(Mobile from, IEntity target) + { + if (!from.Alive || target is not Aquarium aquarium || aquarium.Deleted) { return; } - m_Aquarium.GiveReward(Owner.From); + aquarium.GiveReward(from); } } private class ViewEventEntry : ContextMenuEntry { - private readonly Aquarium m_Aquarium; - - public ViewEventEntry(Aquarium aquarium) : base(6239, 2) // View events - => - m_Aquarium = aquarium; - - public override void OnClick() + public ViewEventEntry() : base(6239, 2) { - if (m_Aquarium.Deleted || !m_Aquarium.HasAccess(Owner.From) || m_Aquarium._events.Count == 0) + } + + public override void OnClick(Mobile from, IEntity target) + { + if (!from.Alive || target is not Aquarium aquarium || aquarium.Deleted || aquarium.HasAccess(from) || + aquarium._events.Count == 0) { return; } - Owner.From.SendLocalizedMessage(m_Aquarium.Events[0]); + var firstEvent = aquarium.Events[0]; + from.SendLocalizedMessage(firstEvent); - if (m_Aquarium.Events[0] == 1074366) + if (firstEvent == 1074366) { - Owner.From.PlaySound(0x5A2); + from.PlaySound(0x5A2); } - m_Aquarium.RemoveFromEventsAt(0); - m_Aquarium.InvalidateProperties(); + aquarium.RemoveFromEventsAt(0); + aquarium.InvalidateProperties(); } } private class CancelVacationMode : ContextMenuEntry { - private readonly Aquarium m_Aquarium; - - public CancelVacationMode(Aquarium aquarium) : base(6240, 2) // Cancel vacation mode - => - m_Aquarium = aquarium; - - public override void OnClick() + public CancelVacationMode() : base(6240, 2) { - if (m_Aquarium.Deleted || !m_Aquarium.HasAccess(Owner.From)) + } + + public override void OnClick(Mobile from, IEntity target) + { + if (!from.Alive || target is not Aquarium aquarium || aquarium.Deleted || aquarium.HasAccess(from)) { return; } - Owner.From.SendLocalizedMessage(1074429); // Vacation mode has been cancelled. - m_Aquarium.VacationLeft = 0; - m_Aquarium.InvalidateProperties(); + from.SendLocalizedMessage(1074429); // Vacation mode has been cancelled. + aquarium.VacationLeft = 0; + aquarium.InvalidateProperties(); } } // GM context entries private class GMAddFood : ContextMenuEntry { - private readonly Aquarium m_Aquarium; - - public GMAddFood(Aquarium aquarium) : base(6231) => m_Aquarium = aquarium; - - public override void OnClick() + public GMAddFood() : base(6231) { - if (m_Aquarium.Deleted) + } + + public override void OnClick(Mobile from, IEntity target) + { + if (from.AccessLevel < AccessLevel.GameMaster || target is not Aquarium aquarium || aquarium.Deleted) { return; } - m_Aquarium.Food.Added += 1; - m_Aquarium.InvalidateProperties(); + aquarium.Food.Added += 1; + aquarium.InvalidateProperties(); } } private class GMAddWater : ContextMenuEntry { - private readonly Aquarium m_Aquarium; - - public GMAddWater(Aquarium aquarium) : base(6232) => m_Aquarium = aquarium; - - public override void OnClick() + public GMAddWater() : base(6232) { - if (m_Aquarium.Deleted) + } + + public override void OnClick(Mobile from, IEntity target) + { + if (from.AccessLevel < AccessLevel.GameMaster || target is not Aquarium aquarium || aquarium.Deleted) { return; } - m_Aquarium.Water.Added += 1; - m_Aquarium.InvalidateProperties(); + aquarium.Water.Added += 1; + aquarium.InvalidateProperties(); } } private class GMForceEvaluate : ContextMenuEntry { - private readonly Aquarium m_Aquarium; - - public GMForceEvaluate(Aquarium aquarium) : base(6233) => m_Aquarium = aquarium; - - public override void OnClick() + public GMForceEvaluate() : base(6233) { - if (m_Aquarium.Deleted) + } + + public override void OnClick(Mobile from, IEntity target) + { + if (from.AccessLevel < AccessLevel.GameMaster || target is not Aquarium aquarium || aquarium.Deleted) { return; } - m_Aquarium.Evaluate(); + aquarium.Evaluate(); } } private class GMOpen : ContextMenuEntry { - private readonly Aquarium m_Aquarium; - - public GMOpen(Aquarium aquarium) : base(6234) => m_Aquarium = aquarium; - - public override void OnClick() + public GMOpen() : base(6234) { - if (m_Aquarium.Deleted) + } + + public override void OnClick(Mobile from, IEntity target) + { + if (from.AccessLevel < AccessLevel.GameMaster || target is not Aquarium aquarium || aquarium.Deleted) { return; } - Owner.From.SendGump(new AquariumGump(m_Aquarium, true)); + from.SendGump(new AquariumGump(aquarium, true)); } } private class GMFill : ContextMenuEntry { - private readonly Aquarium m_Aquarium; - - public GMFill(Aquarium aquarium) : base(6236) => m_Aquarium = aquarium; - - public override void OnClick() + public GMFill() : base(6236) { - if (m_Aquarium.Deleted) + } + + public override void OnClick(Mobile from, IEntity target) + { + if (from.AccessLevel < AccessLevel.GameMaster || target is not Aquarium aquarium || aquarium.Deleted) { return; } - m_Aquarium.Food.Added = m_Aquarium.Food.Maintain; - m_Aquarium.Water.Added = m_Aquarium.Water.Maintain; - m_Aquarium.InvalidateProperties(); + aquarium.Food.Added = aquarium.Food.Maintain; + aquarium.Water.Added = aquarium.Water.Maintain; + aquarium.InvalidateProperties(); } } } diff --git a/Projects/UOContent/Items/Aquarium/FishBowl.cs b/Projects/UOContent/Items/Aquarium/FishBowl.cs index 52f73788f..9d8375551 100644 --- a/Projects/UOContent/Items/Aquarium/FishBowl.cs +++ b/Projects/UOContent/Items/Aquarium/FishBowl.cs @@ -1,5 +1,5 @@ -using System.Collections.Generic; using ModernUO.Serialization; +using Server.Collections; using Server.ContextMenus; using Server.Network; @@ -93,30 +93,30 @@ namespace Server.Items } } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); if (!Empty && IsAccessibleTo(from)) { - list.Add(new RemoveCreature(this)); + list.Add(new RemoveCreature()); } } private class RemoveCreature : ContextMenuEntry { - private readonly FishBowl m_Bowl; - - public RemoveCreature(FishBowl bowl) : base(6242, 3) => m_Bowl = bowl; - - public override void OnClick() + public RemoveCreature() : base(6242, 3) { - if (m_Bowl?.Deleted != false || !m_Bowl.IsAccessibleTo(Owner.From)) + } + + public override void OnClick(Mobile from, IEntity target) + { + if (target is not FishBowl { Deleted: false } bowl || !bowl.IsAccessibleTo(from)) { return; } - var fish = m_Bowl.Fish; + var fish = bowl.Fish; if (fish == null) { @@ -125,17 +125,17 @@ namespace Server.Items if (fish.IsLockedDown) // for legacy fish bowls { - Owner.From.SendLocalizedMessage(1010449); // You may not use this object while it is locked down. + from.SendLocalizedMessage(1010449); // You may not use this object while it is locked down. } - else if (!Owner.From.PlaceInBackpack(fish)) + else if (!from.PlaceInBackpack(fish)) { - Owner.From.SendLocalizedMessage(1074496); // There is no room in your pack for the creature. + from.SendLocalizedMessage(1074496); // There is no room in your pack for the creature. } else { - Owner.From.SendLocalizedMessage(1074495); // The creature has been removed from the fish bowl. + from.SendLocalizedMessage(1074495); // The creature has been removed from the fish bowl. fish.StartTimer(); - m_Bowl.InvalidateProperties(); + bowl.InvalidateProperties(); } } } diff --git a/Projects/UOContent/Items/Books/BaseBook.cs b/Projects/UOContent/Items/Books/BaseBook.cs index a2f79607c..b70dcf854 100644 --- a/Projects/UOContent/Items/Books/BaseBook.cs +++ b/Projects/UOContent/Items/Books/BaseBook.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using ModernUO.Serialization; +using Server.Collections; using Server.ContextMenus; using Server.Gumps; using Server.Multis; @@ -151,10 +152,10 @@ namespace Server.Items } } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); - SetSecureLevelEntry.AddTo(from, this, list); + base.GetContextMenuEntries(from, ref list); + SetSecureLevelEntry.AddTo(from, this, ref list); } private void Deserialize(IGenericReader reader, int version) diff --git a/Projects/UOContent/Items/Construction/Ankhs.cs b/Projects/UOContent/Items/Construction/Ankhs.cs index 8266898ca..de5fd58f8 100644 --- a/Projects/UOContent/Items/Construction/Ankhs.cs +++ b/Projects/UOContent/Items/Construction/Ankhs.cs @@ -1,5 +1,5 @@ -using System.Collections.Generic; using ModernUO.Serialization; +using Server.Collections; using Server.ContextMenus; using Server.Gumps; using Server.Mobiles; @@ -12,18 +12,18 @@ namespace Server.Items public const int TitheRange = 2; public const int LockRange = 2; - public static void GetContextMenuEntries(Mobile from, Item item, List list) + public static void GetContextMenuEntries(Mobile from, Item item, ref PooledRefList list) { if (from is PlayerMobile mobile) { - list.Add(new LockKarmaEntry(mobile)); + list.Add(new LockKarmaEntry(mobile.KarmaLocked)); } - list.Add(new ResurrectEntry(from, item)); + list.Add(new ResurrectEntry(from.Alive)); if (Core.AOS) { - list.Add(new TitheEntry(from)); + list.Add(new TitheEntry(from.Alive)); } } @@ -51,62 +51,58 @@ namespace Server.Items private class ResurrectEntry : ContextMenuEntry { - private readonly Item _item; - private readonly Mobile _mobile; + public ResurrectEntry(bool enabled) : base(6195, ResurrectRange) => Enabled = enabled; - public ResurrectEntry(Mobile mobile, Item item) : base(6195, ResurrectRange) + public override void OnClick(Mobile from, IEntity target) { - _mobile = mobile; - _item = item; - - Enabled = !_mobile.Alive; - } - - public override void OnClick() - { - Resurrect(_mobile, _item); + if (target is Item item) + { + Resurrect(from, item); + } } } - private class LockKarmaEntry : ContextMenuEntry + public class LockKarmaEntry : ContextMenuEntry { - private readonly PlayerMobile _mobile; - - public LockKarmaEntry(PlayerMobile mobile) : base(mobile.KarmaLocked ? 6197 : 6196, LockRange) => - _mobile = mobile; - - public override void OnClick() + public LockKarmaEntry(bool karmaLocked) : base(karmaLocked ? 6197 : 6196, LockRange) { - _mobile.KarmaLocked = !_mobile.KarmaLocked; + } - if (_mobile.KarmaLocked) + public override void OnClick(Mobile from, IEntity target) + { + if (from is not PlayerMobile pm || target is not Item item) + { + return; + } + + if (!from.InRange(item.GetWorldLocation(), 2)) + { + from.SendLocalizedMessage(500446); // That is too far away. + } + + pm.KarmaLocked = !pm.KarmaLocked; + + if (pm.KarmaLocked) { // Your karma has been locked. Your karma can no longer be raised. - _mobile.SendLocalizedMessage(1060192); + pm.SendLocalizedMessage(1060192); } else { - _mobile.SendLocalizedMessage(1060191); // Your karma has been unlocked. Your karma can be raised again. + pm.SendLocalizedMessage(1060191); // Your karma has been unlocked. Your karma can be raised again. } } } private class TitheEntry : ContextMenuEntry { - private readonly Mobile _mobile; + public TitheEntry(bool enabled) : base(6198, TitheRange) => Enabled = enabled; - public TitheEntry(Mobile mobile) : base(6198, TitheRange) + public override void OnClick(Mobile from, IEntity target) { - _mobile = mobile; - - Enabled = _mobile.Alive; - } - - public override void OnClick() - { - if (_mobile.CheckAlive()) + if (from.CheckAlive()) { - _mobile.SendGump(new TithingGump(_mobile)); + from.SendGump(new TithingGump(from)); } } } @@ -150,10 +146,10 @@ namespace Server.Items } } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); - Ankhs.GetContextMenuEntries(from, this, list); + base.GetContextMenuEntries(from, ref list); + Ankhs.GetContextMenuEntries(from, this, ref list); } public override void OnDoubleClickDead(Mobile m) @@ -244,10 +240,10 @@ namespace Server.Items } } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); - Ankhs.GetContextMenuEntries(from, this, list); + base.GetContextMenuEntries(from, ref list); + Ankhs.GetContextMenuEntries(from, this, ref list); } public override void OnDoubleClickDead(Mobile m) @@ -297,10 +293,10 @@ namespace Server.Items } } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); - Ankhs.GetContextMenuEntries(from, this, list); + base.GetContextMenuEntries(from, ref list); + Ankhs.GetContextMenuEntries(from, this, ref list); } public override void OnDoubleClickDead(Mobile m) @@ -393,10 +389,10 @@ namespace Server.Items } } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); - Ankhs.GetContextMenuEntries(from, this, list); + base.GetContextMenuEntries(from, ref list); + Ankhs.GetContextMenuEntries(from, this, ref list); } public override void OnDoubleClickDead(Mobile m) diff --git a/Projects/UOContent/Items/Construction/Doors/HouseDoors.cs b/Projects/UOContent/Items/Construction/Doors/HouseDoors.cs index 0661ff346..788b958d2 100644 --- a/Projects/UOContent/Items/Construction/Doors/HouseDoors.cs +++ b/Projects/UOContent/Items/Construction/Doors/HouseDoors.cs @@ -1,5 +1,5 @@ -using System.Collections.Generic; using ModernUO.Serialization; +using Server.Collections; using Server.ContextMenus; using Server.Gumps; using Server.Multis; @@ -74,10 +74,10 @@ public abstract partial class BaseHouseDoor : BaseDoor, ISecurable _level = SecureLevel.Anyone; } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); - SetSecureLevelEntry.AddTo(from, this, list); + base.GetContextMenuEntries(from, ref list); + SetSecureLevelEntry.AddTo(from, this, ref list); } public BaseHouse FindHouse() diff --git a/Projects/UOContent/Items/Containers/Container.cs b/Projects/UOContent/Items/Containers/Container.cs index 25db2ec11..6afb9105f 100644 --- a/Projects/UOContent/Items/Containers/Container.cs +++ b/Projects/UOContent/Items/Containers/Container.cs @@ -1,5 +1,5 @@ -using System.Collections.Generic; using ModernUO.Serialization; +using Server.Collections; using Server.ContextMenus; using Server.Mobiles; using Server.Multis; @@ -41,10 +41,10 @@ public abstract class BaseContainer : Container return base.CheckItemUse(from, item); } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); - SetSecureLevelEntry.AddTo(from, this, list); + base.GetContextMenuEntries(from, ref list); + SetSecureLevelEntry.AddTo(from, this, ref list); } public override bool TryDropItem(Mobile from, Item dropped, bool sendFullMessage) diff --git a/Projects/UOContent/Items/Containers/SalvageBag.cs b/Projects/UOContent/Items/Containers/SalvageBag.cs index ab9121093..173a4d2e6 100644 --- a/Projects/UOContent/Items/Containers/SalvageBag.cs +++ b/Projects/UOContent/Items/Containers/SalvageBag.cs @@ -1,9 +1,8 @@ using System; -using System.Collections.Generic; using ModernUO.Serialization; +using Server.Collections; using Server.ContextMenus; using Server.Engines.Craft; -using Server.Network; namespace Server.Items; @@ -27,18 +26,18 @@ public partial class SalvageBag : Bag public override int LabelNumber => 1079931; // Salvage Bag - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); if (from.Alive) { var inBackpack = IsChildOf(from.Backpack); var resmeltables = inBackpack && Resmeltables(); var scissorables = inBackpack && Scissorables(); - list.Add(new SalvageIngotsEntry(this, resmeltables)); - list.Add(new SalvageClothEntry(this, scissorables)); - list.Add(new SalvageAllEntry(this, resmeltables && scissorables)); + list.Add(new SalvageIngotsEntry(resmeltables)); + list.Add(new SalvageClothEntry(scissorables)); + list.Add(new SalvageAllEntry(resmeltables && scissorables)); } } @@ -287,90 +286,39 @@ public partial class SalvageBag : Bag private class SalvageAllEntry : ContextMenuEntry { - private readonly SalvageBag m_Bag; + public SalvageAllEntry(bool enabled) : base(6276) => Enabled = enabled; - public SalvageAllEntry(SalvageBag bag, bool enabled) : base(6276) + public override void OnClick(Mobile from, IEntity target) { - m_Bag = bag; - - if (!enabled) + if (from.CheckAlive() && target is SalvageBag { Deleted: false } bag) { - Flags |= CMEFlags.Disabled; - } - } - - public override void OnClick() - { - if (m_Bag.Deleted) - { - return; - } - - var from = Owner.From; - - if (from.CheckAlive()) - { - m_Bag.SalvageAll(from); + bag.SalvageAll(from); } } } private class SalvageIngotsEntry : ContextMenuEntry { - private readonly SalvageBag m_Bag; + public SalvageIngotsEntry(bool enabled) : base(6277) => Enabled = enabled; - public SalvageIngotsEntry(SalvageBag bag, bool enabled) : base(6277) + public override void OnClick(Mobile from, IEntity target) { - m_Bag = bag; - - if (!enabled) + if (from.CheckAlive() && target is SalvageBag { Deleted: false } bag) { - Flags |= CMEFlags.Disabled; - } - } - - public override void OnClick() - { - if (m_Bag.Deleted) - { - return; - } - - var from = Owner.From; - - if (from.CheckAlive()) - { - m_Bag.SalvageIngots(from); + bag.SalvageIngots(from); } } } private class SalvageClothEntry : ContextMenuEntry { - private readonly SalvageBag m_Bag; + public SalvageClothEntry(bool enabled) : base(6278) => Enabled = enabled; - public SalvageClothEntry(SalvageBag bag, bool enabled) : base(6278) + public override void OnClick(Mobile from, IEntity target) { - m_Bag = bag; - - if (!enabled) + if (from.CheckAlive() && target is SalvageBag { Deleted: false } bag) { - Flags |= CMEFlags.Disabled; - } - } - - public override void OnClick() - { - if (m_Bag.Deleted) - { - return; - } - - var from = Owner.From; - - if (from.CheckAlive()) - { - m_Bag.SalvageCloth(from); + bag.SalvageCloth(from); } } } diff --git a/Projects/UOContent/Items/Containers/TreasureMapChest.cs b/Projects/UOContent/Items/Containers/TreasureMapChest.cs index 81211c0da..f230ee897 100644 --- a/Projects/UOContent/Items/Containers/TreasureMapChest.cs +++ b/Projects/UOContent/Items/Containers/TreasureMapChest.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using ModernUO.Serialization; +using Server.Collections; using Server.ContextMenus; using Server.Engines.PartySystem; using Server.Gumps; @@ -415,13 +416,13 @@ public partial class TreasureMapChest : LockableContainer base.OnAfterDelete(); } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); if (from.Alive) { - list.Add(new RemoveEntry(from, this)); + list.Add(new RemoveEntry(from == _owner)); } } @@ -487,25 +488,16 @@ public partial class TreasureMapChest : LockableContainer private class RemoveEntry : ContextMenuEntry { - private readonly TreasureMapChest _chest; - private readonly Mobile _from; + public RemoveEntry(bool enabled) : base(6149, 3) => Enabled = enabled; - public RemoveEntry(Mobile from, TreasureMapChest chest) : base(6149, 3) + public override void OnClick(Mobile from, IEntity target) { - _from = from; - _chest = chest; - - Enabled = from == chest._owner; - } - - public override void OnClick() - { - if (_chest.Deleted || _from != _chest._owner || !_from.CheckAlive()) + if (!from.CheckAlive() || target is not TreasureMapChest chest || chest.Deleted || from != chest._owner) { return; } - _chest.BeginRemove(_from); + chest.BeginRemove(from); } } } diff --git a/Projects/UOContent/Items/Deeds/VendorRentalContract.cs b/Projects/UOContent/Items/Deeds/VendorRentalContract.cs index 203c0b415..a99bd3173 100644 --- a/Projects/UOContent/Items/Deeds/VendorRentalContract.cs +++ b/Projects/UOContent/Items/Deeds/VendorRentalContract.cs @@ -1,6 +1,6 @@ using System; -using System.Collections.Generic; using ModernUO.Serialization; +using Server.Collections; using Server.ContextMenus; using Server.Gumps; using Server.Mobiles; @@ -205,13 +205,13 @@ public partial class VendorRentalContract : Item } } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); if (IsUsableBy(from, true, true, true, false)) { - list.Add(new ContractOptionEntry(this)); + list.Add(new ContractOptionEntry()); } } @@ -224,18 +224,16 @@ public partial class VendorRentalContract : Item private class ContractOptionEntry : ContextMenuEntry { - private readonly VendorRentalContract m_Contract; - - public ContractOptionEntry(VendorRentalContract contract) : base(6209) => m_Contract = contract; - - public override void OnClick() + public ContractOptionEntry() : base(6209) { - var from = Owner.From; + } - if (m_Contract.IsUsableBy(from, true, true, true, true)) + public override void OnClick(Mobile from, IEntity target) + { + if (target is VendorRentalContract contract && contract.IsUsableBy(from, true, true, true, true)) { from.CloseGump(); - from.SendGump(new VendorRentalContractGump(m_Contract, from)); + from.SendGump(new VendorRentalContractGump(contract, from)); } } } diff --git a/Projects/UOContent/Items/Food/Food.cs b/Projects/UOContent/Items/Food/Food.cs index 9ef6beb8d..35c3b4e5b 100644 --- a/Projects/UOContent/Items/Food/Food.cs +++ b/Projects/UOContent/Items/Food/Food.cs @@ -1,5 +1,5 @@ -using System.Collections.Generic; using ModernUO.Serialization; +using Server.Collections; using Server.ContextMenus; namespace Server.Items; @@ -26,13 +26,13 @@ public abstract partial class Food : Item FillFactor = 1; } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); if (from.Alive) { - list.Add(new EatEntry(from, this)); + list.Add(new EatEntry()); } } diff --git a/Projects/UOContent/Items/Games/BaseBoard.cs b/Projects/UOContent/Items/Games/BaseBoard.cs index fe493c587..123f700dc 100644 --- a/Projects/UOContent/Items/Games/BaseBoard.cs +++ b/Projects/UOContent/Items/Games/BaseBoard.cs @@ -1,6 +1,6 @@ using System; -using System.Collections.Generic; using ModernUO.Serialization; +using Server.Collections; using Server.ContextMenus; using Server.Gumps; using Server.Multis; @@ -86,16 +86,16 @@ public abstract partial class BaseBoard : Container, ISecurable return false; } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); if (ValidateDefault(from, this)) { - list.Add(new DefaultEntry(from, this)); + list.Add(new DefaultEntry(from.AccessLevel >= AccessLevel.GameMaster ? -1 : 1)); } - SetSecureLevelEntry.AddTo(from, this, list); + SetSecureLevelEntry.AddTo(from, this, ref list); } public static bool ValidateDefault(Mobile from, BaseBoard board) => @@ -106,23 +106,15 @@ public abstract partial class BaseBoard : Container, ISecurable public class DefaultEntry : ContextMenuEntry { - private readonly BaseBoard m_Board; - private readonly Mobile m_From; - - public DefaultEntry(Mobile from, BaseBoard board) : base( - 6162, - from.AccessLevel >= AccessLevel.GameMaster ? -1 : 1 - ) + public DefaultEntry(int range) : base(6162, range) { - m_From = from; - m_Board = board; } - public override void OnClick() + public override void OnClick(Mobile from, IEntity target) { - if (ValidateDefault(m_From, m_Board)) + if (target is BaseBoard board && ValidateDefault(from, board)) { - m_Board.Reset(); + board.Reset(); } } } diff --git a/Projects/UOContent/Items/Games/Mahjong/MahjongGame.cs b/Projects/UOContent/Items/Games/Mahjong/MahjongGame.cs index 4bf19d996..a4be5c613 100644 --- a/Projects/UOContent/Items/Games/Mahjong/MahjongGame.cs +++ b/Projects/UOContent/Items/Games/Mahjong/MahjongGame.cs @@ -1,6 +1,6 @@ using System; -using System.Collections.Generic; using ModernUO.Serialization; +using Server.Collections; using Server.ContextMenus; using Server.Gumps; using Server.Multis; @@ -187,18 +187,18 @@ public partial class MahjongGame : Item, ISecurable } } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); _players.CheckPlayers(); if (from.Alive && IsAccessibleTo(from) && _players.GetInGameMobiles(true, false).Count == 0) { - list.Add(new ResetGameEntry(this)); + list.Add(new ResetGameEntry()); } - SetSecureLevelEntry.AddTo(from, this, list); + SetSecureLevelEntry.AddTo(from, this, ref list); } public override void OnDoubleClick(Mobile from) @@ -299,18 +299,16 @@ public partial class MahjongGame : Item, ISecurable private class ResetGameEntry : ContextMenuEntry { - private readonly MahjongGame _game; - - public ResetGameEntry(MahjongGame game) : base(6162) => _game = game; - - public override void OnClick() + public ResetGameEntry() : base(6162) { - var from = Owner.From; + } - if (from.CheckAlive() && !_game.Deleted && _game.IsAccessibleTo(from) && - _game.Players.GetInGameMobiles(true, false).Count == 0) + public override void OnClick(Mobile from, IEntity target) + { + if (from.CheckAlive() && target is MahjongGame { Deleted: false } game && game.IsAccessibleTo(from) && + game.Players.GetInGameMobiles(true, false).Count == 0) { - _game.ResetGame(from); + game.ResetGame(from); } } } diff --git a/Projects/UOContent/Items/Maps/TreasureMap.cs b/Projects/UOContent/Items/Maps/TreasureMap.cs index 823474938..e8c853dd6 100644 --- a/Projects/UOContent/Items/Maps/TreasureMap.cs +++ b/Projects/UOContent/Items/Maps/TreasureMap.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.IO; using ModernUO.Serialization; +using Server.Collections; using Server.ContextMenus; using Server.Engines.Harvest; using Server.Mobiles; @@ -454,22 +455,20 @@ public partial class TreasureMap : MapItem base.DisplayTo(from); } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); if (!_completed) { if (_decoder == null) { - list.Add(new DecodeMapEntry(this)); + list.Add(new DecodeMapEntry()); } else { - var digTool = HasDiggingTool(from); - - list.Add(new OpenMapEntry(this)); - list.Add(new DigEntry(this, digTool)); + list.Add(new OpenMapEntry()); + list.Add(new DigEntry(HasDiggingTool(from))); } } } @@ -842,65 +841,52 @@ public partial class TreasureMap : MapItem private class DecodeMapEntry : ContextMenuEntry { - private readonly TreasureMap m_Map; - - public DecodeMapEntry(TreasureMap map) : base(6147, 2) => m_Map = map; - - public override void OnClick() + public DecodeMapEntry() : base(6147, 2) { - if (!m_Map.Deleted) + } + + public override void OnClick(Mobile from, IEntity target) + { + if (target is TreasureMap { Deleted: false } map) { - m_Map.Decode(Owner.From); + map.Decode(from); } } } private class OpenMapEntry : ContextMenuEntry { - private readonly TreasureMap m_Map; - - public OpenMapEntry(TreasureMap map) : base(6150, 2) => m_Map = map; - - public override void OnClick() + public OpenMapEntry() : base(6150, 2) { - if (!m_Map.Deleted) + } + + public override void OnClick(Mobile from, IEntity target) + { + if (target is TreasureMap { Deleted: false } map) { - m_Map.DisplayTo(Owner.From); + map.DisplayTo(from); } } } private class DigEntry : ContextMenuEntry { - private readonly TreasureMap m_Map; + public DigEntry(bool enabled) : base(6148, 2) => Enabled = enabled; - public DigEntry(TreasureMap map, bool enabled) : base(6148, 2) + public override void OnClick(Mobile from, IEntity target) { - m_Map = map; - - if (!enabled) - { - Flags |= CMEFlags.Disabled; - } - } - - public override void OnClick() - { - if (m_Map.Deleted) + if (target is not TreasureMap { Deleted: false } map) { return; } - var from = Owner.From; - - if (HasDiggingTool(from)) - { - m_Map.OnBeginDig(from); - } - else + if (!HasDiggingTool(from)) { from.SendLocalizedMessage(1114416); // You must have a digging tool to dig for treasure. + return; } + + map.OnBeginDig(from); } } } diff --git a/Projects/UOContent/Items/Misc/Corpses/Corpse.cs b/Projects/UOContent/Items/Misc/Corpses/Corpse.cs index e0db281df..1be063325 100644 --- a/Projects/UOContent/Items/Misc/Corpses/Corpse.cs +++ b/Projects/UOContent/Items/Misc/Corpses/Corpse.cs @@ -696,9 +696,9 @@ public partial class Corpse : Container, ICarvable _instancedItems?.Remove(item); } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); if (Core.AOS && _owner == from && from.Alive) { @@ -1050,11 +1050,11 @@ public partial class Corpse : Container, ICarvable { } - public override void OnClick() + public override void OnClick(Mobile from, IEntity target) { - if (Owner.Target is Corpse corpse && Owner.From.CheckAlive()) + if (from.CheckAlive() && target is Corpse corpse) { - corpse.Open(Owner.From, false); + corpse.Open(from, false); } } } diff --git a/Projects/UOContent/Items/Misc/PlayerBulletinBoards.cs b/Projects/UOContent/Items/Misc/PlayerBulletinBoards.cs index 6652dc2ee..24a17d289 100644 --- a/Projects/UOContent/Items/Misc/PlayerBulletinBoards.cs +++ b/Projects/UOContent/Items/Misc/PlayerBulletinBoards.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using ModernUO.Serialization; +using Server.Collections; using Server.ContextMenus; using Server.Gumps; using Server.Mobiles; @@ -75,10 +76,10 @@ public abstract partial class BasePlayerBB : Item, ISecurable } } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); - SetSecureLevelEntry.AddTo(from, this, list); + base.GetContextMenuEntries(from, ref list); + SetSecureLevelEntry.AddTo(from, this, ref list); } public static bool CheckAccess(BaseHouse house, Mobile from) diff --git a/Projects/UOContent/Items/Skill Items/Fishing/FishingPole.cs b/Projects/UOContent/Items/Skill Items/Fishing/FishingPole.cs index 1db953b47..76334722e 100644 --- a/Projects/UOContent/Items/Skill Items/Fishing/FishingPole.cs +++ b/Projects/UOContent/Items/Skill Items/Fishing/FishingPole.cs @@ -1,5 +1,5 @@ -using System.Collections.Generic; using ModernUO.Serialization; +using Server.Collections; using Server.ContextMenus; using Server.Engines.Harvest; @@ -29,11 +29,11 @@ public partial class FishingPole : Item } } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); - BaseHarvestTool.AddContextMenuEntries(from, this, list, Fishing.System); + BaseHarvestTool.AddContextMenuEntries(from, this, ref list, Fishing.System); } public override bool CheckConflictingLayer(Mobile m, Item item, Layer layer) diff --git a/Projects/UOContent/Items/Skill Items/Harvest Tools/BaseHarvestTool.cs b/Projects/UOContent/Items/Skill Items/Harvest Tools/BaseHarvestTool.cs index 565fec925..9dee7be23 100644 --- a/Projects/UOContent/Items/Skill Items/Harvest Tools/BaseHarvestTool.cs +++ b/Projects/UOContent/Items/Skill Items/Harvest Tools/BaseHarvestTool.cs @@ -1,6 +1,6 @@ using System; -using System.Collections.Generic; using ModernUO.Serialization; +using Server.Collections; using Server.ContextMenus; using Server.Engines.Craft; using Server.Engines.Harvest; @@ -125,14 +125,14 @@ public abstract partial class BaseHarvestTool : Item, IUsesRemaining, ICraftable } } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); - AddContextMenuEntries(from, this, list, HarvestSystem); + AddContextMenuEntries(from, this, ref list, HarvestSystem); } - public static void AddContextMenuEntries(Mobile from, Item item, List list, HarvestSystem system) + public static void AddContextMenuEntries(Mobile from, Item item, ref PooledRefList list, HarvestSystem system) { if (system != Mining.System) { @@ -149,12 +149,14 @@ public abstract partial class BaseHarvestTool : Item, IUsesRemaining, ICraftable return; } - var miningEntry = new ContextMenuEntry(pm.ToggleMiningStone ? 6179 : 6178); - miningEntry.Color = 0x421F; - list.Add(miningEntry); + list.Add(new ContextMenuEntry(pm.ToggleMiningStone ? 6179 : 6178) + { + Color = 0x421F + }); - list.Add(new ToggleMiningStoneEntry(pm, false, 6176)); - list.Add(new ToggleMiningStoneEntry(pm, true, 6177)); + var stoneMining = pm.StoneMining && pm.Skills.Mining.Base >= 100.0; + list.Add(new ToggleMiningStoneEntry(false, pm.ToggleMiningStone, 6176)); + list.Add(new ToggleMiningStoneEntry(true, !pm.ToggleMiningStone && stoneMining, 6177)); } private void Deserialize(IGenericReader reader, int version) @@ -178,51 +180,48 @@ public abstract partial class BaseHarvestTool : Item, IUsesRemaining, ICraftable private class ToggleMiningStoneEntry : ContextMenuEntry { - private PlayerMobile _mobile; - private bool _value; + private readonly bool _value; - public ToggleMiningStoneEntry(PlayerMobile mobile, bool value, int number) : base(number) + public ToggleMiningStoneEntry(bool value, bool enabled, int number) : base(number) { - _mobile = mobile; _value = value; - - var stoneMining = mobile.StoneMining && mobile.Skills.Mining.Base >= 100.0; - - if (mobile.ToggleMiningStone == value || value && !stoneMining) - { - Flags |= CMEFlags.Disabled; - } + Enabled = enabled; } - public override void OnClick() + public override void OnClick(Mobile from, IEntity target) { - var oldValue = _mobile.ToggleMiningStone; + if (from is not PlayerMobile pm) + { + return; + } + + var oldValue = pm.ToggleMiningStone; if (_value) { if (oldValue) { - _mobile.SendLocalizedMessage(1054023); // You are already set to mine both ore and stone! + pm.SendLocalizedMessage(1054023); // You are already set to mine both ore and stone! } - else if (!_mobile.StoneMining || _mobile.Skills.Mining.Base < 100.0) + else if (!pm.StoneMining || pm.Skills.Mining.Base < 100.0) { // You have not learned how to mine stone or you do not have enough skill! - _mobile.SendLocalizedMessage(1054024); + pm.SendLocalizedMessage(1054024); } else { - _mobile.ToggleMiningStone = true; - _mobile.SendLocalizedMessage(1054022); // You are now set to mine both ore and stone. + pm.ToggleMiningStone = true; + pm.SendLocalizedMessage(1054022); // You are now set to mine both ore and stone. } } else if (oldValue) { - _mobile.ToggleMiningStone = false; - _mobile.SendLocalizedMessage(1054020); // You are now set to mine only ore. + pm.ToggleMiningStone = false; + pm.SendLocalizedMessage(1054020); // You are now set to mine only ore. } else { - _mobile.SendLocalizedMessage(1054021); // You are already set to mine only ore! + pm.SendLocalizedMessage(1054021); // You are already set to mine only ore! } } } diff --git a/Projects/UOContent/Items/Skill Items/Magical/Runebook.cs b/Projects/UOContent/Items/Skill Items/Magical/Runebook.cs index 3a9007ec6..622988d96 100644 --- a/Projects/UOContent/Items/Skill Items/Magical/Runebook.cs +++ b/Projects/UOContent/Items/Skill Items/Magical/Runebook.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using ModernUO.Serialization; +using Server.Collections; using Server.ContextMenus; using Server.Engines.Craft; using Server.Gumps; @@ -113,10 +114,10 @@ public partial class Runebook : Item, ISecurable, ICraftable public override bool AllowEquippedCast(Mobile from) => true; - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); - SetSecureLevelEntry.AddTo(from, this, list); + base.GetContextMenuEntries(from, ref list); + SetSecureLevelEntry.AddTo(from, this, ref list); } private void Deserialize(IGenericReader reader, int version) diff --git a/Projects/UOContent/Items/Skill Items/Magical/Scrolls/SpellScroll.cs b/Projects/UOContent/Items/Skill Items/Magical/Scrolls/SpellScroll.cs index 09a031f94..097a0a22d 100644 --- a/Projects/UOContent/Items/Skill Items/Magical/Scrolls/SpellScroll.cs +++ b/Projects/UOContent/Items/Skill Items/Magical/Scrolls/SpellScroll.cs @@ -1,5 +1,5 @@ -using System.Collections.Generic; using ModernUO.Serialization; +using Server.Collections; using Server.ContextMenus; using Server.Multis; using Server.Spells; @@ -25,9 +25,9 @@ public partial class SpellScroll : Item, ICommodity int ICommodity.DescriptionNumber => LabelNumber; bool ICommodity.IsDeedable => Core.ML; - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); if (from.Alive && Movable) { diff --git a/Projects/UOContent/Items/Skill Items/Ninjitsu/Fukiya.cs b/Projects/UOContent/Items/Skill Items/Ninjitsu/Fukiya.cs index 75b5ee33e..6b80d40da 100644 --- a/Projects/UOContent/Items/Skill Items/Ninjitsu/Fukiya.cs +++ b/Projects/UOContent/Items/Skill Items/Ninjitsu/Fukiya.cs @@ -1,6 +1,6 @@ using System; -using System.Collections.Generic; using ModernUO.Serialization; +using Server.Collections; using Server.ContextMenus; using Server.Mobiles; @@ -79,14 +79,14 @@ public partial class Fukiya : Item, INinjaWeapon NinjaWeapon.AttemptShoot((PlayerMobile)from, this); } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); if (IsChildOf(from)) { - list.Add(new NinjaWeapon.LoadEntry(this, 6224)); - list.Add(new NinjaWeapon.UnloadEntry(this, 6225)); + list.Add(new NinjaWeapon.LoadEntry(6224)); + list.Add(new NinjaWeapon.UnloadEntry(6225, UsesRemaining > 0)); } } } diff --git a/Projects/UOContent/Items/Skill Items/Ninjitsu/LeatherNinjaBelt.cs b/Projects/UOContent/Items/Skill Items/Ninjitsu/LeatherNinjaBelt.cs index e9ba47270..a62d7ad51 100644 --- a/Projects/UOContent/Items/Skill Items/Ninjitsu/LeatherNinjaBelt.cs +++ b/Projects/UOContent/Items/Skill Items/Ninjitsu/LeatherNinjaBelt.cs @@ -1,6 +1,6 @@ using System; -using System.Collections.Generic; using ModernUO.Serialization; +using Server.Collections; using Server.ContextMenus; using Server.Mobiles; @@ -92,14 +92,14 @@ public partial class LeatherNinjaBelt : BaseWaist, INinjaWeapon NinjaWeapon.AttemptShoot((PlayerMobile)from, this); } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); if (IsChildOf(from)) { - list.Add(new NinjaWeapon.LoadEntry(this, 6222)); - list.Add(new NinjaWeapon.UnloadEntry(this, 6223)); + list.Add(new NinjaWeapon.LoadEntry(6222)); + list.Add(new NinjaWeapon.UnloadEntry(6223, UsesRemaining > 0)); } } } diff --git a/Projects/UOContent/Items/Skill Items/Ninjitsu/NinjaWeapons.cs b/Projects/UOContent/Items/Skill Items/Ninjitsu/NinjaWeapons.cs index d9c0daaa2..498cd8c02 100644 --- a/Projects/UOContent/Items/Skill Items/Ninjitsu/NinjaWeapons.cs +++ b/Projects/UOContent/Items/Skill Items/Ninjitsu/NinjaWeapons.cs @@ -329,39 +329,29 @@ public static class NinjaWeapon public class LoadEntry : ContextMenuEntry { - private readonly INinjaWeapon weapon; - - public LoadEntry(INinjaWeapon wep, int entry) - : base(entry, 0) => - weapon = wep; - - public override void OnClick() + public LoadEntry(int entry) : base(entry, 0) { - if (WeaponIsValid(weapon, Owner.From)) + } + + public override void OnClick(Mobile from, IEntity target) + { + if (target is INinjaWeapon weapon && WeaponIsValid(weapon, from)) { - Owner.From.BeginTarget(10, false, TargetFlags.Harmful, OnTarget, weapon); + from.BeginTarget(10, false, TargetFlags.Harmful, OnTarget, weapon); } } } public class UnloadEntry : ContextMenuEntry { - private readonly INinjaWeapon weapon; + public UnloadEntry(int entry, bool enabled) : base(entry, 0) => Enabled = enabled; - public UnloadEntry(INinjaWeapon wep, int entry) - : base(entry, 0) + public override void OnClick(Mobile from, IEntity target) { - weapon = wep; - - Enabled = weapon.UsesRemaining > 0; - } - - public override void OnClick() - { - if (WeaponIsValid(weapon, Owner.From)) + if (target is INinjaWeapon weapon && WeaponIsValid(weapon, from)) { - Unload(Owner.From, weapon); + Unload(from, weapon); } } } -} \ No newline at end of file +} diff --git a/Projects/UOContent/Items/Skill Items/Tailor Items/Dyetubs/DyeTub.cs b/Projects/UOContent/Items/Skill Items/Tailor Items/Dyetubs/DyeTub.cs index 2f1f1a303..6ee0aa0cf 100644 --- a/Projects/UOContent/Items/Skill Items/Tailor Items/Dyetubs/DyeTub.cs +++ b/Projects/UOContent/Items/Skill Items/Tailor Items/Dyetubs/DyeTub.cs @@ -1,5 +1,5 @@ -using System.Collections.Generic; using ModernUO.Serialization; +using Server.Collections; using Server.ContextMenus; using Server.Gumps; using Server.Multis; @@ -86,10 +86,10 @@ namespace Server.Items } } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); - SetSecureLevelEntry.AddTo(from, this, list); + base.GetContextMenuEntries(from, ref list); + SetSecureLevelEntry.AddTo(from, this, ref list); } public override void OnDoubleClick(Mobile from) diff --git a/Projects/UOContent/Items/Special/8th Anniversary Items/Dawn's Music Box/DawnsMusicBox.cs b/Projects/UOContent/Items/Special/8th Anniversary Items/Dawn's Music Box/DawnsMusicBox.cs index 262f85f73..d84724425 100644 --- a/Projects/UOContent/Items/Special/8th Anniversary Items/Dawn's Music Box/DawnsMusicBox.cs +++ b/Projects/UOContent/Items/Special/8th Anniversary Items/Dawn's Music Box/DawnsMusicBox.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Runtime.CompilerServices; using ModernUO.Serialization; +using Server.Collections; using Server.ContextMenus; using Server.Gumps; using Server.Multis; @@ -191,11 +192,11 @@ public partial class DawnsMusicBox : Item, ISecurable } } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); - SetSecureLevelEntry.AddTo(from, this, list); // Set secure level + SetSecureLevelEntry.AddTo(from, this, ref list); // Set secure level } public override void OnDoubleClick(Mobile from) diff --git a/Projects/UOContent/Items/Special/Gifts/RoseOfTrinsic.cs b/Projects/UOContent/Items/Special/Gifts/RoseOfTrinsic.cs index 3131288b8..2faee7f5f 100644 --- a/Projects/UOContent/Items/Special/Gifts/RoseOfTrinsic.cs +++ b/Projects/UOContent/Items/Special/Gifts/RoseOfTrinsic.cs @@ -1,6 +1,6 @@ using System; -using System.Collections.Generic; using ModernUO.Serialization; +using Server.Collections; using Server.ContextMenus; using Server.Gumps; using Server.Multis; @@ -77,11 +77,11 @@ public partial class RoseOfTrinsic : Item, ISecurable list.Add(1062925, Petals); // Petals: ~1_COUNT~ } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); - SetSecureLevelEntry.AddTo(from, this, list); + SetSecureLevelEntry.AddTo(from, this, ref list); } private void StartSpawnTimer(TimeSpan delay) diff --git a/Projects/UOContent/Items/Special/Gifts/TapestryOfSosaria.cs b/Projects/UOContent/Items/Special/Gifts/TapestryOfSosaria.cs index 53281154b..b834cfa80 100644 --- a/Projects/UOContent/Items/Special/Gifts/TapestryOfSosaria.cs +++ b/Projects/UOContent/Items/Special/Gifts/TapestryOfSosaria.cs @@ -1,5 +1,5 @@ -using System.Collections.Generic; using ModernUO.Serialization; +using Server.Collections; using Server.ContextMenus; using Server.Gumps; using Server.Multis; @@ -24,11 +24,11 @@ public partial class TapestryOfSosaria : Item, ISecurable public override int LabelNumber => 1062917; // The Tapestry of Sosaria - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); - SetSecureLevelEntry.AddTo(from, this, list); + SetSecureLevelEntry.AddTo(from, this, ref list); } public override void OnDoubleClick(Mobile from) diff --git a/Projects/UOContent/Items/Special/House Raffle/HouseRaffleStone.cs b/Projects/UOContent/Items/Special/House Raffle/HouseRaffleStone.cs index b42128a9e..628d09457 100644 --- a/Projects/UOContent/Items/Special/House Raffle/HouseRaffleStone.cs +++ b/Projects/UOContent/Items/Special/House Raffle/HouseRaffleStone.cs @@ -4,10 +4,10 @@ using System.Net; using System.Runtime.CompilerServices; using ModernUO.Serialization; using Server.Accounting; +using Server.Collections; using Server.ContextMenus; using Server.Gumps; using Server.Mobiles; -using Server.Network; using Server.Regions; using Server.Text; @@ -394,21 +394,21 @@ public partial class HouseRaffleStone : Item } } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); if (from.AccessLevel >= AccessLevel.Seer) { - list.Add(new EditEntry(from, this)); + list.Add(new EditEntry()); if (_currentState == HouseRaffleState.Inactive) { - list.Add(new ActivateEntry(from, this)); + list.Add(new ActivateEntry(ValidLocation(_plotBounds, _plotFacet))); } else { - list.Add(new ManagementEntry(from, this)); + list.Add(new ManagementEntry()); } } } @@ -597,70 +597,49 @@ public partial class HouseRaffleStone : Item } } - private class RaffleContextMenuEntry : ContextMenuEntry + private class EditEntry : ContextMenuEntry { - protected readonly Mobile _from; - protected readonly HouseRaffleStone _stone; - - public RaffleContextMenuEntry(Mobile from, HouseRaffleStone stone, int label) : base(label) - { - _from = from; - _stone = stone; - } - } - - private class EditEntry : RaffleContextMenuEntry - { - public EditEntry(Mobile from, HouseRaffleStone stone) : base(from, stone, 5101) // Edit + public EditEntry() : base(5101) { } - public override void OnClick() + public override void OnClick(Mobile from, IEntity target) { - if (_stone.Deleted || _from.AccessLevel < AccessLevel.Seer) + if (from.AccessLevel < AccessLevel.Seer || target is not HouseRaffleStone stone || stone.Deleted) { return; } - _from.SendGump(new PropertiesGump(_from, _stone)); + from.SendGump(new PropertiesGump(from, stone)); } } - private class ActivateEntry : RaffleContextMenuEntry + private class ActivateEntry : ContextMenuEntry { - public ActivateEntry(Mobile from, HouseRaffleStone stone) : base(from, stone, 5113) // Start - { - if (!ValidLocation(stone._plotBounds, stone._plotFacet)) - { - Flags |= CMEFlags.Disabled; - } - } + public ActivateEntry(bool enabled) : base(5113) => Enabled = enabled; - public override void OnClick() + public override void OnClick(Mobile from, IEntity target) { - if (_stone.Deleted || _from.AccessLevel < AccessLevel.Seer || !ValidLocation(_stone._plotBounds, _stone._plotFacet)) + if (from.AccessLevel >= AccessLevel.Seer && target is HouseRaffleStone { Deleted: false } stone && + ValidLocation(stone._plotBounds, stone._plotFacet)) { - return; + stone.CurrentState = HouseRaffleState.Active; } - - _stone.CurrentState = HouseRaffleState.Active; } } - private class ManagementEntry : RaffleContextMenuEntry + private class ManagementEntry : ContextMenuEntry { - public ManagementEntry(Mobile from, HouseRaffleStone stone) : base(from, stone, 5032) // Game Monitor + public ManagementEntry() : base(5032) { } - public override void OnClick() + public override void OnClick(Mobile from, IEntity target) { - if (_stone.Deleted || _from.AccessLevel < AccessLevel.Seer) + if (from.AccessLevel >= AccessLevel.Seer && target is HouseRaffleStone { Deleted: false } stone) { - return; + from.SendGump(new HouseRaffleManagementGump(stone)); } - - _from.SendGump(new HouseRaffleManagementGump(_stone)); } } diff --git a/Projects/UOContent/Items/Special/Solen Items/BagOfSending.cs b/Projects/UOContent/Items/Special/Solen Items/BagOfSending.cs index c8dcbc616..a57c2d282 100644 --- a/Projects/UOContent/Items/Special/Solen Items/BagOfSending.cs +++ b/Projects/UOContent/Items/Special/Solen Items/BagOfSending.cs @@ -1,9 +1,8 @@ using System; -using System.Collections.Generic; using ModernUO.Serialization; +using Server.Collections; using Server.ContextMenus; using Server.Engines.Quests; -using Server.Network; using Server.Regions; using Server.Spells; using Server.Targeting; @@ -116,13 +115,13 @@ public partial class BagOfSending : Item, TranslocationItem LabelTo(from, 1060741, _charges.ToString()); // charges: ~1_val~ } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); if (from.Alive) { - list.Add(new UseBagEntry(this, Charges > 0 && IsChildOf(from.Backpack))); + list.Add(new UseBagEntry(Charges > 0 && IsChildOf(from.Backpack))); } } @@ -156,30 +155,13 @@ public partial class BagOfSending : Item, TranslocationItem private class UseBagEntry : ContextMenuEntry { - private readonly BagOfSending _bag; + public UseBagEntry(bool enabled) : base(6189) => Enabled = enabled; - public UseBagEntry(BagOfSending bag, bool enabled) : base(6189) + public override void OnClick(Mobile from, IEntity target) { - _bag = bag; - - if (!enabled) + if (from.CheckAlive() && target is BagOfSending bag && !bag.Deleted) { - Flags |= CMEFlags.Disabled; - } - } - - public override void OnClick() - { - if (_bag.Deleted) - { - return; - } - - var from = Owner.From; - - if (from.CheckAlive()) - { - _bag.OnDoubleClick(from); + bag.OnDoubleClick(from); } } } diff --git a/Projects/UOContent/Items/Special/Solen Items/BallOfSummoning.cs b/Projects/UOContent/Items/Special/Solen Items/BallOfSummoning.cs index 3e367c040..a9db9ec33 100644 --- a/Projects/UOContent/Items/Special/Solen Items/BallOfSummoning.cs +++ b/Projects/UOContent/Items/Special/Solen Items/BallOfSummoning.cs @@ -1,6 +1,6 @@ using System; -using System.Collections.Generic; using ModernUO.Serialization; +using Server.Collections; using Server.ContextMenus; using Server.Engines.ConPVP; using Server.Mobiles; @@ -97,9 +97,9 @@ public partial class BallOfSummoning : Item, TranslocationItem LabelTo(from, 1054131, $"{_charges}\t{_petName.DefaultIfNullOrEmpty(" ")}"); } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); if (!from.Alive || RootParent != from) { @@ -299,10 +299,8 @@ public partial class BallOfSummoning : Item, TranslocationItem public BallEntry(BallCallback callback, int number) : base(number, 2) => _callback = callback; - public override void OnClick() + public override void OnClick(Mobile from, IEntity target) { - var from = Owner.From; - if (from.CheckAlive()) { _callback(from); diff --git a/Projects/UOContent/Items/Special/Solen Items/BraceletOfBinding.cs b/Projects/UOContent/Items/Special/Solen Items/BraceletOfBinding.cs index 78a8a791a..8a8ce5d32 100644 --- a/Projects/UOContent/Items/Special/Solen Items/BraceletOfBinding.cs +++ b/Projects/UOContent/Items/Special/Solen Items/BraceletOfBinding.cs @@ -1,11 +1,10 @@ using System; -using System.Collections.Generic; using ModernUO.Serialization; +using Server.Collections; using Server.ContextMenus; using Server.Factions; using Server.Misc; using Server.Mobiles; -using Server.Network; using Server.Prompts; using Server.Regions; using Server.Spells; @@ -93,9 +92,9 @@ public partial class BraceletOfBinding : BaseBracelet, TranslocationItem LabelTo(from, 1054000, $"{_charges}\t{_inscription.DefaultIfNullOrEmpty(" ")}"); } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); if (from.Alive && IsChildOf(from)) { @@ -326,17 +325,11 @@ public partial class BraceletOfBinding : BaseBracelet, TranslocationItem public BraceletEntry(BraceletCallback callback, int number, bool enabled) : base(number) { _callback = callback; - - if (!enabled) - { - Flags |= CMEFlags.Disabled; - } + Enabled = enabled; } - public override void OnClick() + public override void OnClick(Mobile from, IEntity target) { - var from = Owner.From; - if (from.CheckAlive()) { _callback(from); diff --git a/Projects/UOContent/Items/Special/Veteran Rewards/AnkhOfSacrifice.cs b/Projects/UOContent/Items/Special/Veteran Rewards/AnkhOfSacrifice.cs index a1ca2465e..5f34b2c5b 100644 --- a/Projects/UOContent/Items/Special/Veteran Rewards/AnkhOfSacrifice.cs +++ b/Projects/UOContent/Items/Special/Veteran Rewards/AnkhOfSacrifice.cs @@ -1,6 +1,6 @@ using System; -using System.Collections.Generic; using ModernUO.Serialization; +using Server.Collections; using Server.ContextMenus; using Server.Engines.VeteranRewards; using Server.Gumps; @@ -19,16 +19,16 @@ public partial class AnkhOfSacrificeComponent : AddonComponent public override bool ForceShowProperties => ObjectPropertyList.Enabled; public override int LabelNumber => 1027772; // Ankh of Sacrifice - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); if (from is PlayerMobile mobile) { - list.Add(new LockKarmaEntry(mobile, Addon as AnkhOfSacrificeAddon)); + list.Add(new Ankhs.LockKarmaEntry(mobile.KarmaLocked)); } - list.Add(new ResurrectEntry(from, Addon as AnkhOfSacrificeAddon)); + list.Add(new ResurrectEntry()); } public static void Resurrect(PlayerMobile m, AnkhOfSacrificeAddon ankh) @@ -68,57 +68,15 @@ public partial class AnkhOfSacrificeComponent : AddonComponent private class ResurrectEntry : ContextMenuEntry { - private readonly AnkhOfSacrificeAddon _ankh; - private readonly Mobile _mobile; - - public ResurrectEntry(Mobile mobile, AnkhOfSacrificeAddon ankh) : base(6195, 2) + public ResurrectEntry() : base(6195, 2) { - _mobile = mobile; - _ankh = ankh; } - public override void OnClick() + public override void OnClick(Mobile from, IEntity target) { - if (_ankh?.Deleted != false) + if (target is AnkhOfSacrificeAddon { Deleted: false } ankh) { - return; - } - - Resurrect(_mobile as PlayerMobile, _ankh); - } - } - - private class LockKarmaEntry : ContextMenuEntry - { - private readonly AnkhOfSacrificeAddon _ankh; - private readonly PlayerMobile _mobile; - - public LockKarmaEntry(PlayerMobile mobile, AnkhOfSacrificeAddon ankh) : base(mobile.KarmaLocked ? 6197 : 6196, 2) - { - _mobile = mobile; - _ankh = ankh; - } - - public override void OnClick() - { - if (!_mobile.InRange(_ankh.GetWorldLocation(), 2)) - { - _mobile.SendLocalizedMessage(500446); // That is too far away. - } - else - { - _mobile.KarmaLocked = !_mobile.KarmaLocked; - - if (_mobile.KarmaLocked) - { - // Your karma has been locked. Your karma can no longer be raised. - _mobile.SendLocalizedMessage(1060192); - } - else - { - // Your karma has been unlocked. Your karma can be raised again. - _mobile.SendLocalizedMessage(1060191); - } + Resurrect(from as PlayerMobile, ankh); } } } diff --git a/Projects/UOContent/Items/Talismans/TalismanSummons.cs b/Projects/UOContent/Items/Talismans/TalismanSummons.cs index 9ca06f0d9..07b6e1acd 100644 --- a/Projects/UOContent/Items/Talismans/TalismanSummons.cs +++ b/Projects/UOContent/Items/Talismans/TalismanSummons.cs @@ -1,6 +1,6 @@ using System; -using System.Collections.Generic; using ModernUO.Serialization; +using Server.Collections; using Server.ContextMenus; using Server.Items; @@ -19,33 +19,33 @@ public partial class BaseTalismanSummon : BaseCreature public override bool Commandable => false; public override bool InitialInnocent => true; - public override void AddCustomContextEntries(Mobile from, List list) + public override void AddCustomContextEntries(Mobile from, ref PooledRefList list) { if (from.Alive && ControlMaster == from) { - list.Add(new TalismanReleaseEntry(this)); + list.Add(new TalismanReleaseEntry()); } } private class TalismanReleaseEntry : ContextMenuEntry { - private readonly Mobile m_Mobile; + public TalismanReleaseEntry() : base(6118, 3) + { + } - public TalismanReleaseEntry(Mobile m) : base(6118, 3) => m_Mobile = m; - - public override void OnClick() + public override void OnClick(Mobile from, IEntity target) { Effects.SendLocationParticles( - EffectItem.Create(m_Mobile.Location, m_Mobile.Map, EffectItem.DefaultDuration), + EffectItem.Create(from.Location, from.Map, EffectItem.DefaultDuration), 0x3728, 8, 20, 5042 ); - Effects.PlaySound(m_Mobile,0x201); + Effects.PlaySound(from,0x201); - m_Mobile.Delete(); + from.Delete(); } } } diff --git a/Projects/UOContent/Items/Weapons/Axes/BaseAxe.cs b/Projects/UOContent/Items/Weapons/Axes/BaseAxe.cs index 64b19aa89..3fb291bed 100644 --- a/Projects/UOContent/Items/Weapons/Axes/BaseAxe.cs +++ b/Projects/UOContent/Items/Weapons/Axes/BaseAxe.cs @@ -1,6 +1,6 @@ using System; -using System.Collections.Generic; using ModernUO.Serialization; +using Server.Collections; using Server.ContextMenus; using Server.Engines.ConPVP; using Server.Engines.Harvest; @@ -95,13 +95,13 @@ namespace Server.Items HarvestSystem.BeginHarvesting(from, this); } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); if (HarvestSystem != null) { - BaseHarvestTool.AddContextMenuEntries(from, this, list, HarvestSystem); + BaseHarvestTool.AddContextMenuEntries(from, this, ref list, HarvestSystem); } } diff --git a/Projects/UOContent/Items/Weapons/PoleArms/BasePoleArm.cs b/Projects/UOContent/Items/Weapons/PoleArms/BasePoleArm.cs index cc535befd..6ee681593 100644 --- a/Projects/UOContent/Items/Weapons/PoleArms/BasePoleArm.cs +++ b/Projects/UOContent/Items/Weapons/PoleArms/BasePoleArm.cs @@ -1,6 +1,6 @@ using System; -using System.Collections.Generic; using ModernUO.Serialization; +using Server.Collections; using Server.ContextMenus; using Server.Engines.ConPVP; using Server.Engines.Harvest; @@ -48,13 +48,13 @@ namespace Server.Items } } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); if (HarvestSystem != null) { - BaseHarvestTool.AddContextMenuEntries(from, this, list, HarvestSystem); + BaseHarvestTool.AddContextMenuEntries(from, this, ref list, HarvestSystem); } } diff --git a/Projects/UOContent/Mobiles/AI/BaseAI.cs b/Projects/UOContent/Mobiles/AI/BaseAI.cs index 5f0fdd0ec..5ce7ba5a7 100644 --- a/Projects/UOContent/Mobiles/AI/BaseAI.cs +++ b/Projects/UOContent/Mobiles/AI/BaseAI.cs @@ -160,40 +160,44 @@ public abstract class BaseAI return name != null && speech.InsensitiveStartsWith(name); } - public virtual void GetContextMenuEntries(Mobile from, List list) + public virtual void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - if (from.Alive && m_Mobile.Controlled && from.InRange(m_Mobile, 14)) + if (!from.Alive || !m_Mobile.Controlled || !from.InRange(m_Mobile, 14)) { - if (from == m_Mobile.ControlMaster) + return; + } + + var isDeadPet = m_Mobile.IsDeadPet; + + if (from == m_Mobile.ControlMaster) + { + list.Add(new InternalEntry(6107, 14, OrderType.Guard, !isDeadPet)); // Command: Guard + list.Add(new InternalEntry(6108, 14, OrderType.Follow, true)); // Command: Follow + + if (m_Mobile.CanDrop) { - list.Add(new InternalEntry(from, 6107, 14, m_Mobile, this, OrderType.Guard)); // Command: Guard - list.Add(new InternalEntry(from, 6108, 14, m_Mobile, this, OrderType.Follow)); // Command: Follow - - if (m_Mobile.CanDrop) - { - list.Add(new InternalEntry(from, 6109, 14, m_Mobile, this, OrderType.Drop)); // Command: Drop - } - - list.Add(new InternalEntry(from, 6111, 14, m_Mobile, this, OrderType.Attack)); // Command: Kill - - list.Add(new InternalEntry(from, 6112, 14, m_Mobile, this, OrderType.Stop)); // Command: Stop - list.Add(new InternalEntry(from, 6114, 14, m_Mobile, this, OrderType.Stay)); // Command: Stay - - if (!m_Mobile.Summoned && m_Mobile is not GrizzledMare) - { - list.Add(new InternalEntry(from, 6110, 14, m_Mobile, this, OrderType.Friend)); // Add Friend - list.Add(new InternalEntry(from, 6099, 14, m_Mobile, this, OrderType.Unfriend)); // Remove Friend - list.Add(new InternalEntry(from, 6113, 14, m_Mobile, this, OrderType.Transfer)); // Transfer - } - - list.Add(new InternalEntry(from, 6118, 14, m_Mobile, this, OrderType.Release)); // Release + list.Add(new InternalEntry(6109, 14, OrderType.Drop, !isDeadPet)); // Command: Drop } - else if (m_Mobile.IsPetFriend(from)) + + list.Add(new InternalEntry(6111, 14, OrderType.Attack, !isDeadPet)); // Command: Kill + + list.Add(new InternalEntry(6112, 14, OrderType.Stop, true)); // Command: Stop + list.Add(new InternalEntry(6114, 14, OrderType.Stay, true)); // Command: Stay + + if (!m_Mobile.Summoned && m_Mobile is not GrizzledMare) { - list.Add(new InternalEntry(from, 6108, 14, m_Mobile, this, OrderType.Follow)); // Command: Follow - list.Add(new InternalEntry(from, 6112, 14, m_Mobile, this, OrderType.Stop)); // Command: Stop - list.Add(new InternalEntry(from, 6114, 14, m_Mobile, this, OrderType.Stay)); // Command: Stay + list.Add(new InternalEntry(6110, 14, OrderType.Friend, true)); // Add Friend + list.Add(new InternalEntry(6099, 14, OrderType.Unfriend, true)); // Remove Friend + list.Add(new InternalEntry(6113, 14, OrderType.Transfer, !isDeadPet)); // Transfer } + + list.Add(new InternalEntry(6118, 14, OrderType.Release, true)); // Release + } + else if (m_Mobile.IsPetFriend(from)) + { + list.Add(new InternalEntry(6108, 14, OrderType.Follow, true)); // Command: Follow + list.Add(new InternalEntry(6112, 14, OrderType.Stop, !isDeadPet)); // Command: Stop + list.Add(new InternalEntry(6114, 14, OrderType.Stay, true)); // Command: Stay } } @@ -2910,51 +2914,41 @@ public abstract class BaseAI private class InternalEntry : ContextMenuEntry { - private readonly BaseAI m_AI; - private readonly Mobile m_From; - private readonly BaseCreature m_Mobile; - private readonly OrderType m_Order; + private readonly OrderType _order; - public InternalEntry(Mobile from, int number, int range, BaseCreature mobile, BaseAI ai, OrderType order) - : base(number, range) + public InternalEntry(int number, int range, OrderType order, bool enabled) : base(number, range) { - m_From = from; - m_Mobile = mobile; - m_AI = ai; - m_Order = order; - - if (mobile.IsDeadPet && order is OrderType.Guard or OrderType.Attack or OrderType.Transfer or OrderType.Drop) - { - Enabled = false; - } + _order = order; + Enabled = enabled; } - public override void OnClick() + public override void OnClick(Mobile from, IEntity target) { - if (m_Mobile.Deleted || !m_Mobile.Controlled || !m_From.CheckAlive()) + if (!from.CheckAlive() || target is not BaseCreature { Deleted: not true, Controlled: true } bc) { return; } - if (m_Mobile.IsDeadPet && m_Order is OrderType.Guard or OrderType.Attack or OrderType.Transfer or OrderType.Drop) + // Just in case + if (bc.IsDeadPet && _order is OrderType.Guard or OrderType.Attack or OrderType.Transfer or OrderType.Drop) { return; } - var isOwner = m_From == m_Mobile.ControlMaster; - var isFriend = !isOwner && m_Mobile.IsPetFriend(m_From); + var isOwner = from == bc.ControlMaster; + var isFriend = !isOwner && bc.IsPetFriend(from); if (!isOwner && !isFriend) { return; } - if (isFriend && m_Order != OrderType.Follow && m_Order != OrderType.Stay && m_Order != OrderType.Stop) + if (isFriend && _order != OrderType.Follow && _order != OrderType.Stay && _order != OrderType.Stop) { return; } - switch (m_Order) + switch (_order) { case OrderType.Follow: case OrderType.Attack: @@ -2962,37 +2956,37 @@ public abstract class BaseAI case OrderType.Friend: case OrderType.Unfriend: { - if (m_Order == OrderType.Transfer && m_From.HasTrade) + if (_order == OrderType.Transfer && from.HasTrade) { - m_From.SendLocalizedMessage(1010507); // You cannot transfer a pet with a trade pending + from.SendLocalizedMessage(1010507); // You cannot transfer a pet with a trade pending } - else if (m_Order == OrderType.Friend && m_From.HasTrade) + else if (_order == OrderType.Friend && from.HasTrade) { - m_From.SendLocalizedMessage(1070947); // You cannot friend a pet with a trade pending + from.SendLocalizedMessage(1070947); // You cannot friend a pet with a trade pending } else { - m_AI.BeginPickTarget(m_From, m_Order); + bc.AIObject.BeginPickTarget(from, _order); } break; } case OrderType.Release: { - if (m_Mobile.Summoned) + if (bc.Summoned) { goto default; } - m_From.SendGump(new ConfirmReleaseGump(m_From, m_Mobile)); + from.SendGump(new ConfirmReleaseGump(from, bc)); break; } default: { - if (m_Mobile.CheckControlChance(m_From)) + if (bc.CheckControlChance(from)) { - m_Mobile.ControlOrder = m_Order; + bc.ControlOrder = _order; } break; diff --git a/Projects/UOContent/Mobiles/Animals/Misc/PackHorse.cs b/Projects/UOContent/Mobiles/Animals/Misc/PackHorse.cs index fad36b42d..ab111f166 100644 --- a/Projects/UOContent/Mobiles/Animals/Misc/PackHorse.cs +++ b/Projects/UOContent/Mobiles/Animals/Misc/PackHorse.cs @@ -1,5 +1,5 @@ using ModernUO.Serialization; -using System.Collections.Generic; +using Server.Collections; using Server.ContextMenus; using Server.Items; @@ -103,43 +103,34 @@ namespace Server.Mobiles PackAnimal.TryPackOpen(this, from); } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); - PackAnimal.GetContextMenuEntries(this, from, list); + PackAnimal.GetContextMenuEntries(this, from, ref list); } } public class PackAnimalBackpackEntry : ContextMenuEntry { - private readonly BaseCreature m_Animal; - private readonly Mobile m_From; + public PackAnimalBackpackEntry(bool enabled) : base(6145, 3) => Enabled = enabled; - public PackAnimalBackpackEntry(BaseCreature animal, Mobile from) : base(6145, 3) + public override void OnClick(Mobile from, IEntity target) { - m_Animal = animal; - m_From = from; - - if (animal.IsDeadPet) + if (target is BaseCreature bc) { - Enabled = false; + PackAnimal.TryPackOpen(bc, from); } } - - public override void OnClick() - { - PackAnimal.TryPackOpen(m_Animal, m_From); - } } public static class PackAnimal { - public static void GetContextMenuEntries(BaseCreature animal, Mobile from, List list) + public static void GetContextMenuEntries(BaseCreature animal, Mobile from, ref PooledRefList list) { if (CheckAccess(animal, from)) { - list.Add(new PackAnimalBackpackEntry(animal, from)); + list.Add(new PackAnimalBackpackEntry(!animal.IsDeadPet)); } } diff --git a/Projects/UOContent/Mobiles/Animals/Misc/PackLlama.cs b/Projects/UOContent/Mobiles/Animals/Misc/PackLlama.cs index 557086811..4ea5c718a 100644 --- a/Projects/UOContent/Mobiles/Animals/Misc/PackLlama.cs +++ b/Projects/UOContent/Mobiles/Animals/Misc/PackLlama.cs @@ -1,5 +1,5 @@ using ModernUO.Serialization; -using System.Collections.Generic; +using Server.Collections; using Server.ContextMenus; using Server.Items; @@ -110,11 +110,11 @@ namespace Server.Mobiles PackAnimal.TryPackOpen(this, from); } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); - PackAnimal.GetContextMenuEntries(this, from, list); + PackAnimal.GetContextMenuEntries(this, from, ref list); } } } diff --git a/Projects/UOContent/Mobiles/Animals/Mounts/Beetle.cs b/Projects/UOContent/Mobiles/Animals/Mounts/Beetle.cs index ba9959d25..bba194d3d 100644 --- a/Projects/UOContent/Mobiles/Animals/Mounts/Beetle.cs +++ b/Projects/UOContent/Mobiles/Animals/Mounts/Beetle.cs @@ -1,5 +1,5 @@ using ModernUO.Serialization; -using System.Collections.Generic; +using Server.Collections; using Server.ContextMenus; using Server.Items; @@ -129,11 +129,11 @@ namespace Server.Mobiles public override bool CheckNonlocalLift(Mobile from, Item item) => PackAnimal.CheckAccess(this, from); - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); - PackAnimal.GetContextMenuEntries(this, from, list); + PackAnimal.GetContextMenuEntries(this, from, ref list); } } } diff --git a/Projects/UOContent/Mobiles/BaseCreature.cs b/Projects/UOContent/Mobiles/BaseCreature.cs index 643a7d34f..c8f8114ea 100644 --- a/Projects/UOContent/Mobiles/BaseCreature.cs +++ b/Projects/UOContent/Mobiles/BaseCreature.cs @@ -2546,25 +2546,25 @@ namespace Server.Mobiles return base.OnMoveOver(m); } - public virtual void AddCustomContextEntries(Mobile from, List list) + public virtual void AddCustomContextEntries(Mobile from, ref PooledRefList list) { } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); if (Commandable) { - AIObject?.GetContextMenuEntries(from, list); + AIObject?.GetContextMenuEntries(from, ref list); } if (m_bTamable && !m_Controlled && from.Alive) { - list.Add(new TameEntry(from, this)); + list.Add(new TameEntry(from.Female ? AllowFemaleTamer : AllowMaleTamer)); } - AddCustomContextEntries(from, list); + AddCustomContextEntries(from, ref list); if (CanTeach && from.Alive) { @@ -2585,7 +2585,7 @@ namespace Server.Mobiles toTeach = 420; } - list.Add(new TeachEntry((SkillName)i, this, from, toTeach > theirSkill.BaseFixedPoint)); + list.Add(new TeachEntry((SkillName)i, toTeach > theirSkill.BaseFixedPoint)); } } } @@ -5505,32 +5505,25 @@ namespace Server.Mobiles private class TameEntry : ContextMenuEntry { - private readonly BaseCreature m_Mobile; + public TameEntry(bool enabled) : base(6130, 6) => Enabled = enabled; - public TameEntry(Mobile from, BaseCreature creature) : base(6130, 6) + public override void OnClick(Mobile from, IEntity target) { - m_Mobile = creature; - - Enabled = Enabled && (from.Female ? creature.AllowFemaleTamer : creature.AllowMaleTamer); - } - - public override void OnClick() - { - if (!Owner.From.CheckAlive()) + if (!from.CheckAlive() || target is not BaseCreature bc) { return; } - Owner.From.TargetLocked = true; + from.TargetLocked = true; AnimalTaming.DisableMessage = true; - if (Owner.From.UseSkill(SkillName.AnimalTaming)) + if (from.UseSkill(SkillName.AnimalTaming)) { - Owner.From.Target.Invoke(Owner.From, m_Mobile); + from.Target.Invoke(from, bc); } AnimalTaming.DisableMessage = false; - Owner.From.TargetLocked = false; + from.TargetLocked = false; } } diff --git a/Projects/UOContent/Mobiles/Familiars/BaseFamiliar.cs b/Projects/UOContent/Mobiles/Familiars/BaseFamiliar.cs index 7990663af..3997a3856 100644 --- a/Projects/UOContent/Mobiles/Familiars/BaseFamiliar.cs +++ b/Projects/UOContent/Mobiles/Familiars/BaseFamiliar.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using ModernUO.Serialization; +using Server.Collections; using Server.ContextMenus; using Server.Items; @@ -108,13 +109,13 @@ public abstract partial class BaseFamiliar : BaseCreature } } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); if (from.Alive && Controlled && from == ControlMaster && from.InRange(this, 14)) { - list.Add(new ReleaseEntry(from, this)); + list.Add(new ReleaseEntry()); } } @@ -170,21 +171,16 @@ public abstract partial class BaseFamiliar : BaseCreature private class ReleaseEntry : ContextMenuEntry { - private readonly BaseFamiliar m_Familiar; - private readonly Mobile m_From; - - public ReleaseEntry(Mobile from, BaseFamiliar familiar) : base(6118, 14) + public ReleaseEntry() : base(6118, 14) { - m_From = from; - m_Familiar = familiar; } - public override void OnClick() + public override void OnClick(Mobile from, IEntity target) { - if (!m_Familiar.Deleted && m_Familiar.Controlled && m_From == m_Familiar.ControlMaster && - m_From.CheckAlive()) + if (from.CheckAlive() && target is BaseFamiliar { Deleted: false, Controlled: true } familiar && + from == familiar.ControlMaster) { - m_Familiar.BeginRelease(m_From); + familiar.BeginRelease(from); } } } diff --git a/Projects/UOContent/Mobiles/Familiars/HordeMinion.cs b/Projects/UOContent/Mobiles/Familiars/HordeMinion.cs index 00d4e3d73..23750daef 100644 --- a/Projects/UOContent/Mobiles/Familiars/HordeMinion.cs +++ b/Projects/UOContent/Mobiles/Familiars/HordeMinion.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using ModernUO.Serialization; using Server.Collections; using Server.ContextMenus; @@ -179,11 +178,11 @@ public partial class HordeMinionFamiliar : BaseFamiliar PackAnimal.TryPackOpen(this, from); } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); - PackAnimal.GetContextMenuEntries(this, from, list); + PackAnimal.GetContextMenuEntries(this, from, ref list); } private class ReleaseFamiliarWarningGump : StaticWarningGump diff --git a/Projects/UOContent/Mobiles/Hireables/BaseHire.cs b/Projects/UOContent/Mobiles/Hireables/BaseHire.cs index d7c3d29fc..06c569e25 100644 --- a/Projects/UOContent/Mobiles/Hireables/BaseHire.cs +++ b/Projects/UOContent/Mobiles/Hireables/BaseHire.cs @@ -219,7 +219,7 @@ public partial class BaseHire : BaseCreature base.OnSpeech(e); } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { if (Deleted) { @@ -230,14 +230,14 @@ public partial class BaseHire : BaseCreature { if (CanPaperdollBeOpenedBy(from)) { - list.Add(new PaperdollEntry(this)); + list.Add(new PaperdollEntry()); } - list.Add(new HireEntry(this)); + list.Add(new HireEntry()); } else { - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); } } @@ -309,13 +309,13 @@ public partial class BaseHire : BaseCreature public class HireEntry : ContextMenuEntry { - private readonly BaseHire _hire; - - public HireEntry(BaseHire hire) : base(6120, 3) => _hire = hire; - - public override void OnClick() + public HireEntry() : base(6120, 3) { - _hire.SayHireCost(); + } + + public override void OnClick(Mobile from, IEntity target) + { + (target as BaseHire)?.SayHireCost(); } } } diff --git a/Projects/UOContent/Mobiles/Monsters/Humanoid/Melee/RestlessSoul.cs b/Projects/UOContent/Mobiles/Monsters/Humanoid/Melee/RestlessSoul.cs index b69117530..1a2f3b10b 100644 --- a/Projects/UOContent/Mobiles/Monsters/Humanoid/Melee/RestlessSoul.cs +++ b/Projects/UOContent/Mobiles/Monsters/Humanoid/Melee/RestlessSoul.cs @@ -1,5 +1,5 @@ using ModernUO.Serialization; -using System.Collections.Generic; +using Server.Collections; using Server.ContextMenus; using Server.Engines.Quests.Haven; @@ -56,9 +56,9 @@ namespace Server.Mobiles { } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); for (var i = 0; i < list.Count; ++i) { diff --git a/Projects/UOContent/Mobiles/Monsters/Misc/Melee/PlagueSpawn.cs b/Projects/UOContent/Mobiles/Monsters/Misc/Melee/PlagueSpawn.cs index 2dee205b7..c57d56f60 100644 --- a/Projects/UOContent/Mobiles/Monsters/Misc/Melee/PlagueSpawn.cs +++ b/Projects/UOContent/Mobiles/Monsters/Misc/Melee/PlagueSpawn.cs @@ -1,6 +1,6 @@ using ModernUO.Serialization; using System; -using System.Collections.Generic; +using Server.Collections; using Server.ContextMenus; namespace Server.Mobiles @@ -85,9 +85,9 @@ namespace Server.Mobiles { } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); for (var i = 0; i < list.Count; ++i) { diff --git a/Projects/UOContent/Mobiles/PlayerMobile.cs b/Projects/UOContent/Mobiles/PlayerMobile.cs index 806cb8cd2..92dc09ae9 100644 --- a/Projects/UOContent/Mobiles/PlayerMobile.cs +++ b/Projects/UOContent/Mobiles/PlayerMobile.cs @@ -1855,13 +1855,18 @@ namespace Server.Mobiles } } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); if (from == this) { - Quest?.GetContextMenuEntries(list); + if (Alive && Backpack != null && CanSee(Backpack)) + { + list.Add(new OpenBackpackEntry()); + } + + Quest?.GetContextMenuEntries(ref list); if (Alive) { @@ -1945,17 +1950,17 @@ namespace Server.Mobiles if (theirParty == null && ourParty == null) { - list.Add(new AddToPartyEntry(from, this)); + list.Add(new AddToPartyEntry()); } else if (theirParty != null && theirParty.Leader == from) { if (ourParty == null) { - list.Add(new AddToPartyEntry(from, this)); + list.Add(new AddToPartyEntry()); } else if (ourParty == theirParty) { - list.Add(new RemoveFromPartyEntry(from, this)); + list.Add(new RemoveFromPartyEntry()); } } } @@ -1965,7 +1970,7 @@ namespace Server.Mobiles if (curhouse != null && Alive && Core.Expansion >= Expansion.AOS && curhouse.IsAosRules && curhouse.IsFriend(from)) { - list.Add(new EjectPlayerEntry(from, this)); + list.Add(new EjectPlayerEntry()); } } } @@ -4649,7 +4654,7 @@ namespace Server.Mobiles public CallbackEntry(int number, int range, ContextCallback callback) : base(number, range) => m_Callback = callback; - public override void OnClick() + public override void OnClick(Mobile from, IEntity target) { m_Callback?.Invoke(); } diff --git a/Projects/UOContent/Mobiles/Townfolk/Banker.cs b/Projects/UOContent/Mobiles/Townfolk/Banker.cs index b9f149463..78b11de96 100644 --- a/Projects/UOContent/Mobiles/Townfolk/Banker.cs +++ b/Projects/UOContent/Mobiles/Townfolk/Banker.cs @@ -137,7 +137,7 @@ public partial class Banker : BaseVendor } checks = PooledRefList.Create(); - + foreach (var bc in bank.FindItemsByType()) { balance += bc.Worth; @@ -507,13 +507,13 @@ public partial class Banker : BaseVendor base.OnSpeech(e); } - public override void AddCustomContextEntries(Mobile from, List list) + public override void AddCustomContextEntries(Mobile from, ref PooledRefList list) { if (from.Alive) { - list.Add(new OpenBankEntry(this)); + list.Add(new OpenBankEntry()); } - base.AddCustomContextEntries(from, list); + base.AddCustomContextEntries(from, ref list); } } diff --git a/Projects/UOContent/Mobiles/Townfolk/BaseEscortable.cs b/Projects/UOContent/Mobiles/Townfolk/BaseEscortable.cs index 056e24963..04c6e9311 100644 --- a/Projects/UOContent/Mobiles/Townfolk/BaseEscortable.cs +++ b/Projects/UOContent/Mobiles/Townfolk/BaseEscortable.cs @@ -3,6 +3,7 @@ using System.Collections; using System.Collections.Generic; using ModernUO.Serialization; using Server.Buffers; +using Server.Collections; using Server.ContextMenus; using Server.Engines.MLQuests; using Server.Engines.MLQuests.Definitions; @@ -738,7 +739,7 @@ public partial class BaseEscortable : BaseCreature public override bool CanBeRenamedBy(Mobile from) => from.AccessLevel >= AccessLevel.GameMaster; - public override void AddCustomContextEntries(Mobile from, List list) + public override void AddCustomContextEntries(Mobile from, ref PooledRefList list) { if (from.Alive) { @@ -748,22 +749,22 @@ public partial class BaseEscortable : BaseCreature { if (escorter == null || escorter == from) { - list.Add(new AskDestinationEntry(this, from)); + list.Add(new AskDestinationEntry()); } if (escorter == null) { - list.Add(new AcceptEscortEntry(this, from)); + list.Add(new AcceptEscortEntry()); } } if (escorter == from) { - list.Add(new AbandonEscortEntry(this)); + list.Add(new AbandonEscortEntry()); } } - base.AddCustomContextEntries(from, list); + base.AddCustomContextEntries(from, ref list); } public virtual string[] GetPossibleDestinations() => Core.ML ? MlTownNames : TownNames; @@ -901,46 +902,36 @@ public class EscortDestinationInfo public class AskDestinationEntry : ContextMenuEntry { - private readonly Mobile _from; - private readonly BaseEscortable _mobile; - - public AskDestinationEntry(BaseEscortable m, Mobile from) : base(6100, 3) + public AskDestinationEntry() : base(6100, 3) { - _mobile = m; - _from = from; } - public override void OnClick() + public override void OnClick(Mobile from, IEntity target) { - _mobile.SayDestinationTo(_from); + (target as BaseEscortable)?.SayDestinationTo(from); } } public class AcceptEscortEntry : ContextMenuEntry { - private readonly Mobile _from; - private readonly BaseEscortable _mobile; - - public AcceptEscortEntry(BaseEscortable m, Mobile from) : base(6101, 3) + public AcceptEscortEntry() : base(6101, 3) { - _mobile = m; - _from = from; } - public override void OnClick() + public override void OnClick(Mobile from, IEntity target) { - _mobile.AcceptEscorter(_from); + (target as BaseEscortable)?.AcceptEscorter(from); } } public class AbandonEscortEntry : ContextMenuEntry { - private readonly BaseEscortable _mobile; - - public AbandonEscortEntry(BaseEscortable m) : base(6102, 3) => _mobile = m; - - public override void OnClick() + public AbandonEscortEntry() : base(6102, 3) { - _mobile.Delete(); // OSI just seems to delete instantly + } + + public override void OnClick(Mobile from, IEntity target) + { + (target as BaseEscortable)?.Delete(); // OSI just seems to delete instantly } } diff --git a/Projects/UOContent/Mobiles/Vendors/BaseVendor.cs b/Projects/UOContent/Mobiles/Vendors/BaseVendor.cs index e8e9835c5..bbc9667ab 100644 --- a/Projects/UOContent/Mobiles/Vendors/BaseVendor.cs +++ b/Projects/UOContent/Mobiles/Vendors/BaseVendor.cs @@ -1398,27 +1398,27 @@ namespace Server.Mobiles } } - public override void AddCustomContextEntries(Mobile from, List list) + public override void AddCustomContextEntries(Mobile from, ref PooledRefList list) { if (from.Alive && IsActiveVendor) { if (SupportsBulkOrders(from)) { - list.Add(new BulkOrderInfoEntry(from, this)); + list.Add(new BulkOrderInfoEntry()); } if (IsActiveSeller) { - list.Add(new VendorBuyEntry(from, this)); + list.Add(new VendorBuyEntry(CheckVendorAccess(from))); } if (IsActiveBuyer) { - list.Add(new VendorSellEntry(from, this)); + list.Add(new VendorSellEntry(CheckVendorAccess(from))); } } - base.AddCustomContextEntries(from, list); + base.AddCustomContextEntries(from, ref list); } public virtual IShopSellInfo[] GetSellInfo() => _sellInfo.ToArray(); @@ -1439,63 +1439,57 @@ namespace Server.Mobiles private class BulkOrderInfoEntry : ContextMenuEntry { - private readonly Mobile m_From; - private readonly BaseVendor m_Vendor; - - public BulkOrderInfoEntry(Mobile from, BaseVendor vendor) - : base(6152) + public BulkOrderInfoEntry() : base(6152) { - m_From = from; - m_Vendor = vendor; } - public override void OnClick() + public override void OnClick(Mobile from, IEntity target) { - if (!m_Vendor.SupportsBulkOrders(m_From)) + if (target is not BaseVendor vendor || !vendor.SupportsBulkOrders(from)) { return; } - var ts = m_Vendor.GetNextBulkOrder(m_From); + var ts = vendor.GetNextBulkOrder(from); var totalSeconds = ts.TotalSeconds; // Let them get a bulk order if they are within 1 second. if (totalSeconds < 1) { - m_From.SendLocalizedMessage(1049038); // You can get an order now. + from.SendLocalizedMessage(1049038); // You can get an order now. if (Core.AOS) { - var bulkOrder = m_Vendor.CreateBulkOrder(m_From, true); + var bulkOrder = vendor.CreateBulkOrder(from, true); if (bulkOrder is LargeBOD bod) { - m_From.SendGump(new LargeBODAcceptGump(m_From, bod)); + from.SendGump(new LargeBODAcceptGump(from, bod)); } else if (bulkOrder is SmallBOD smallBod) { - m_From.SendGump(new SmallBODAcceptGump(m_From, smallBod)); + from.SendGump(new SmallBODAcceptGump(from, smallBod)); } } } else { - var oldSpeechHue = m_Vendor.SpeechHue; - m_Vendor.SpeechHue = 0x3B2; + var oldSpeechHue = vendor.SpeechHue; + vendor.SpeechHue = 0x3B2; if (Core.SE) { // An offer may be available in about ~1_minutes~ minutes. - m_Vendor.SayTo(m_From, 1072058, $"{Math.Ceiling(totalSeconds / 60):F0}"); + vendor.SayTo(from, 1072058, $"{Math.Ceiling(totalSeconds / 60):F0}"); } else { // An offer may be available in about ~1_hours~ hours. - m_Vendor.SayTo(m_From, 1049039, $"{Math.Ceiling(totalSeconds / 3600):F0}"); + vendor.SayTo(vendor, 1049039, $"{Math.Ceiling(totalSeconds / 3600):F0}"); } - m_Vendor.SpeechHue = oldSpeechHue; + vendor.SpeechHue = oldSpeechHue; } } } @@ -1506,35 +1500,21 @@ namespace Server.ContextMenus { public class VendorBuyEntry : ContextMenuEntry { - private readonly BaseVendor m_Vendor; + public VendorBuyEntry(bool enabled) : base(6103, 8) => Enabled = enabled; - public VendorBuyEntry(Mobile from, BaseVendor vendor) - : base(6103, 8) + public override void OnClick(Mobile from, IEntity target) { - m_Vendor = vendor; - Enabled = vendor.CheckVendorAccess(from); - } - - public override void OnClick() - { - m_Vendor.VendorBuy(Owner.From); + (target as BaseVendor)?.VendorBuy(from); } } public class VendorSellEntry : ContextMenuEntry { - private readonly BaseVendor m_Vendor; + public VendorSellEntry(bool enabled) : base(6104, 8) => Enabled = enabled; - public VendorSellEntry(Mobile from, BaseVendor vendor) - : base(6104, 8) + public override void OnClick(Mobile from, IEntity target) { - m_Vendor = vendor; - Enabled = vendor.CheckVendorAccess(from); - } - - public override void OnClick() - { - m_Vendor.VendorSell(Owner.From); + (target as BaseVendor)?.VendorSell(from); } } } diff --git a/Projects/UOContent/Mobiles/Vendors/NPC/AnimalTrainer.cs b/Projects/UOContent/Mobiles/Vendors/NPC/AnimalTrainer.cs index 5ac411aed..855ecf1bc 100644 --- a/Projects/UOContent/Mobiles/Vendors/NPC/AnimalTrainer.cs +++ b/Projects/UOContent/Mobiles/Vendors/NPC/AnimalTrainer.cs @@ -40,19 +40,19 @@ namespace Server.Mobiles AddItem(Utility.RandomBool() ? new QuarterStaff() : new ShepherdsCrook()); } - public override void AddCustomContextEntries(Mobile from, List list) + public override void AddCustomContextEntries(Mobile from, ref PooledRefList list) { if (from is PlayerMobile { Alive: true } pm) { - list.Add(new StableEntry(this, from)); + list.Add(new StableEntry()); if (pm.Stabled?.Count > 0) { - list.Add(new ClaimAllEntry(this, from)); + list.Add(new ClaimAllEntry()); } } - base.AddCustomContextEntries(from, list); + base.AddCustomContextEntries(from, ref list); } public static int GetMaxStabled(Mobile from) @@ -411,18 +411,13 @@ namespace Server.Mobiles private class StableEntry : ContextMenuEntry { - private readonly Mobile m_From; - private readonly AnimalTrainer m_Trainer; - - public StableEntry(AnimalTrainer trainer, Mobile from) : base(6126, 12) + public StableEntry() : base(6126, 12) { - m_Trainer = trainer; - m_From = from; } - public override void OnClick() + public override void OnClick(Mobile from, IEntity target) { - m_Trainer.BeginStable(m_From); + (target as AnimalTrainer)?.BeginStable(from); } } @@ -474,18 +469,13 @@ namespace Server.Mobiles private class ClaimAllEntry : ContextMenuEntry { - private readonly Mobile m_From; - private readonly AnimalTrainer m_Trainer; - - public ClaimAllEntry(AnimalTrainer trainer, Mobile from) : base(6127, 12) + public ClaimAllEntry() : base(6127, 12) { - m_Trainer = trainer; - m_From = from; } - public override void OnClick() + public override void OnClick(Mobile from, IEntity target) { - m_Trainer.Claim(m_From); + (target as AnimalTrainer)?.Claim(from); } } diff --git a/Projects/UOContent/Mobiles/Vendors/NPC/Guildmasters/TinkerGuildmaster.cs b/Projects/UOContent/Mobiles/Vendors/NPC/Guildmasters/TinkerGuildmaster.cs index 01331944e..eb28ed806 100644 --- a/Projects/UOContent/Mobiles/Vendors/NPC/Guildmasters/TinkerGuildmaster.cs +++ b/Projects/UOContent/Mobiles/Vendors/NPC/Guildmasters/TinkerGuildmaster.cs @@ -1,5 +1,5 @@ using ModernUO.Serialization; -using System.Collections.Generic; +using Server.Collections; using Server.ContextMenus; using Server.Items; @@ -18,11 +18,11 @@ namespace Server.Mobiles public override NpcGuild NpcGuild => NpcGuild.TinkersGuild; - public override void AddCustomContextEntries(Mobile from, List list) + public override void AddCustomContextEntries(Mobile from, ref PooledRefList list) { if (Core.ML && from.Alive) { - var entry = new RechargeEntry(from, this); + var entry = new RechargeEntry(); if (WeaponEngravingTool.Find(from) == null) { @@ -32,45 +32,38 @@ namespace Server.Mobiles list.Add(entry); } - base.AddCustomContextEntries(from, list); + base.AddCustomContextEntries(from, ref list); } private class RechargeEntry : ContextMenuEntry { - private readonly Mobile m_From; - private readonly Mobile m_Vendor; - - public RechargeEntry(Mobile from, Mobile vendor) : base(6271, 6) + public RechargeEntry() : base(6271, 6) { - m_From = from; - m_Vendor = vendor; } - public override void OnClick() + public override void OnClick(Mobile from, IEntity target) { - if (!Core.ML || m_Vendor?.Deleted != false) + if (!Core.ML || target is not Mobile vendor || vendor.Deleted) { return; } - var tool = WeaponEngravingTool.Find(m_From); + var tool = WeaponEngravingTool.Find(from); - if (tool?.UsesRemaining <= 0) + if (!(tool?.UsesRemaining <= 0)) { - if (Banker.GetBalance(m_From) >= 100000) - { - m_From.SendGump(new WeaponEngravingTool.ConfirmGump(tool, m_Vendor)); - } - else - { - m_Vendor.Say(1076167); // You need a 100,000 gold and a blue diamond to recharge the weapon engraver. - } + // I can only help with this if you are carrying an engraving tool that needs repair. + vendor.Say(1076164); + return; + } + + if (Banker.GetBalance(from) >= 100000) + { + from.SendGump(new WeaponEngravingTool.ConfirmGump(tool, vendor)); } else { - m_Vendor.Say( - 1076164 - ); // I can only help with this if you are carrying an engraving tool that needs repair. + vendor.Say(1076167); // You need a 100,000 gold and a blue diamond to recharge the weapon engraver. } } } diff --git a/Projects/UOContent/Mobiles/Vendors/PlayerBarkeeper.cs b/Projects/UOContent/Mobiles/Vendors/PlayerBarkeeper.cs index 4260bc9db..90da5bd2d 100644 --- a/Projects/UOContent/Mobiles/Vendors/PlayerBarkeeper.cs +++ b/Projects/UOContent/Mobiles/Vendors/PlayerBarkeeper.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using Server.Collections; using Server.ContextMenus; using Server.Gumps; using Server.Items; @@ -124,18 +125,13 @@ namespace Server.Mobiles public class ManageBarkeeperEntry : ContextMenuEntry { - private readonly PlayerBarkeeper m_Barkeeper; - private readonly Mobile m_From; - - public ManageBarkeeperEntry(Mobile from, PlayerBarkeeper barkeeper) : base(6151, 12) + public ManageBarkeeperEntry() : base(6151, 12) { - m_From = from; - m_Barkeeper = barkeeper; } - public override void OnClick() + public override void OnClick(Mobile from, IEntity target) { - m_Barkeeper.BeginManagement(m_From); + (target as PlayerBarkeeper)?.BeginManagement(from); } } @@ -372,13 +368,13 @@ namespace Server.Mobiles return Owner == from; } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); if (IsOwner(from) && from.InLOS(this)) { - list.Add(new ManageBarkeeperEntry(from, this)); + list.Add(new ManageBarkeeperEntry()); } } diff --git a/Projects/UOContent/Mobiles/Vendors/PlayerVendor.cs b/Projects/UOContent/Mobiles/Vendors/PlayerVendor.cs index b8a304b6d..82c614d17 100644 --- a/Projects/UOContent/Mobiles/Vendors/PlayerVendor.cs +++ b/Projects/UOContent/Mobiles/Vendors/PlayerVendor.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using ModernUO.Serialization; +using Server.Collections; using Server.ContextMenus; using Server.Engines.BulkOrders; using Server.Gumps; @@ -869,14 +870,14 @@ public partial class PlayerVendor : Mobile Placeholder?.Delete(); } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { if (from.Alive && Placeholder != null && IsOwner(from)) { - list.Add(new ReturnVendorEntry(this)); + list.Add(new ReturnVendorEntry()); } - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); } public override bool HandlesOnSpeech(Mobile from) => from.Alive && from.GetDistanceToSqrt(this) <= 3; @@ -978,17 +979,15 @@ public partial class PlayerVendor : Mobile private class ReturnVendorEntry : ContextMenuEntry { - private readonly PlayerVendor m_Vendor; - - public ReturnVendorEntry(PlayerVendor vendor) : base(6214) => m_Vendor = vendor; - - public override void OnClick() + public ReturnVendorEntry() : base(6214) { - var from = Owner.From; + } - if (!m_Vendor.Deleted && m_Vendor.IsOwner(from) && from.CheckAlive()) + public override void OnClick(Mobile from, IEntity target) + { + if (from.CheckAlive() && target is PlayerVendor { Deleted: false } vendor && vendor.IsOwner(from)) { - m_Vendor.Return(); + vendor.Return(); } } } diff --git a/Projects/UOContent/Mobiles/Vendors/RentedVendor.cs b/Projects/UOContent/Mobiles/Vendors/RentedVendor.cs index 8dec4fad0..1fb0a4b07 100644 --- a/Projects/UOContent/Mobiles/Vendors/RentedVendor.cs +++ b/Projects/UOContent/Mobiles/Vendors/RentedVendor.cs @@ -1,6 +1,6 @@ using System; -using System.Collections.Generic; using ModernUO.Serialization; +using Server.Collections; using Server.ContextMenus; using Server.Gumps; using Server.Misc; @@ -155,27 +155,27 @@ public partial class RentedVendor : PlayerVendor base.Destroy(toBackpack); } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { if (from.Alive) { if (IsOwner(from)) { - list.Add(new ContractOptionsEntry(this)); + list.Add(new ContractOptionsEntry()); } else if (IsLandlord(from)) { if (RentalGold > 0) { - list.Add(new CollectRentEntry(this)); + list.Add(new CollectRentEntry()); } - list.Add(new TerminateContractEntry(this)); - list.Add(new ContractOptionsEntry(this)); + list.Add(new TerminateContractEntry()); + list.Add(new ContractOptionsEntry()); } } - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); } [AfterDeserialization] @@ -190,65 +190,59 @@ public partial class RentedVendor : PlayerVendor private class ContractOptionsEntry : ContextMenuEntry { - private readonly RentedVendor m_Vendor; - - public ContractOptionsEntry(RentedVendor vendor) : base(6209) => m_Vendor = vendor; - - public override void OnClick() + public ContractOptionsEntry() : base(6209) { - var from = Owner.From; + } - if (m_Vendor.Deleted || !from.CheckAlive()) + public override void OnClick(Mobile from, IEntity target) + { + if (!from.CheckAlive() || target is not RentedVendor vendor || vendor.Deleted) { return; } - if (m_Vendor.IsOwner(from)) + if (vendor.IsOwner(from)) { from.CloseGump(); - from.SendGump(new RenterVendorRentalGump(m_Vendor)); + from.SendGump(new RenterVendorRentalGump(vendor)); - m_Vendor.SendRentalExpireMessage(from); + vendor.SendRentalExpireMessage(from); } - else if (m_Vendor.IsLandlord(from)) + else if (vendor.IsLandlord(from)) { from.CloseGump(); - from.SendGump(new LandlordVendorRentalGump(m_Vendor)); + from.SendGump(new LandlordVendorRentalGump(vendor)); - m_Vendor.SendRentalExpireMessage(from); + vendor.SendRentalExpireMessage(from); } } } private class CollectRentEntry : ContextMenuEntry { - private readonly RentedVendor m_Vendor; - - public CollectRentEntry(RentedVendor vendor) : base(6212) => m_Vendor = vendor; - - public override void OnClick() + public CollectRentEntry() : base(6212) { - var from = Owner.From; + } - if (m_Vendor.Deleted || !from.CheckAlive() || !m_Vendor.IsLandlord(from)) + public override void OnClick(Mobile from, IEntity target) + { + if (!from.CheckAlive() || target is not RentedVendor vendor || vendor.Deleted || !vendor.IsLandlord(from)) { return; } - if (m_Vendor.RentalGold > 0) + if (vendor.RentalGold > 0) { - var depositedGold = Banker.DepositUpTo(from, m_Vendor.RentalGold); - m_Vendor.RentalGold -= depositedGold; + var depositedGold = Banker.DepositUpTo(from, vendor.RentalGold); + vendor.RentalGold -= depositedGold; if (depositedGold > 0) { - from.SendLocalizedMessage( - 1060397, - depositedGold.ToString() - ); // ~1_AMOUNT~ gold has been deposited into your bank box. + // ~1_AMOUNT~ gold has been deposited into your bank box. + from.SendLocalizedMessage(1060397, depositedGold.ToString()); } - if (m_Vendor.RentalGold > 0) + if (vendor.RentalGold > 0) { from.SendLocalizedMessage(500390); // Your bank box is full. } @@ -258,23 +252,20 @@ public partial class RentedVendor : PlayerVendor private class TerminateContractEntry : ContextMenuEntry { - private readonly RentedVendor m_Vendor; - - public TerminateContractEntry(RentedVendor vendor) : base(6218) => m_Vendor = vendor; - - public override void OnClick() + public TerminateContractEntry() : base(6218) { - var from = Owner.From; + } - if (m_Vendor.Deleted || !from.CheckAlive() || !m_Vendor.IsLandlord(from)) + public override void OnClick(Mobile from, IEntity target) + { + if (!from.CheckAlive() || target is not RentedVendor vendor || vendor.Deleted || !vendor.IsLandlord(from)) { return; } - from.SendLocalizedMessage( - 1062503 - ); // Enter the amount of gold you wish to offer the renter in exchange for immediate termination of this contract? - from.Prompt = new RefundOfferPrompt(m_Vendor); + // Enter the amount of gold you wish to offer the renter in exchange for immediate termination of this contract? + from.SendLocalizedMessage(1062503); + from.Prompt = new RefundOfferPrompt(vendor); } } diff --git a/Projects/UOContent/Mobiles/Vendors/VendorBackpack.cs b/Projects/UOContent/Mobiles/Vendors/VendorBackpack.cs index 4d628bccf..267fbcd1a 100644 --- a/Projects/UOContent/Mobiles/Vendors/VendorBackpack.cs +++ b/Projects/UOContent/Mobiles/Vendors/VendorBackpack.cs @@ -1,5 +1,5 @@ -using System.Collections.Generic; using ModernUO.Serialization; +using Server.Collections; using Server.ContextMenus; using Server.Engines.BulkOrders; using Server.Ethics; @@ -78,9 +78,9 @@ public partial class VendorBackpack : Backpack (from.AccessLevel >= AccessLevel.GameMaster || targ.GetType().IsDefined(typeof(PlayerVendorTargetAttribute), false)); - public override void GetChildContextMenuEntries(Mobile from, List list, Item item) + public override void GetChildContextMenuEntries(Mobile from, ref PooledRefList list, Item item) { - base.GetChildContextMenuEntries(from, list, item); + base.GetChildContextMenuEntries(from, ref list, item); if (RootParent is not PlayerVendor pv || pv.IsOwner(from)) { @@ -91,7 +91,7 @@ public partial class VendorBackpack : Backpack if (vi != null) { - list.Add(new BuyEntry(item)); + list.Add(new BuyEntry()); } } @@ -169,20 +169,18 @@ public partial class VendorBackpack : Backpack private class BuyEntry : ContextMenuEntry { - private readonly Item m_Item; - - public BuyEntry(Item item) : base(6103) => m_Item = item; + public BuyEntry() : base(6103) + { + } public override bool NonLocalUse => true; - public override void OnClick() + public override void OnClick(Mobile from, IEntity target) { - if (m_Item.Deleted) + if (target is Item { Deleted: false } item) { - return; + PlayerVendor.TryToBuy(item, from); } - - PlayerVendor.TryToBuy(m_Item, Owner.From); } } } diff --git a/Projects/UOContent/Multis/Houses/BaseHouse.cs b/Projects/UOContent/Multis/Houses/BaseHouse.cs index b7e911f42..d86ac4a50 100644 --- a/Projects/UOContent/Multis/Houses/BaseHouse.cs +++ b/Projects/UOContent/Multis/Houses/BaseHouse.cs @@ -4296,13 +4296,8 @@ namespace Server.Multis public class SetSecureLevelEntry : ContextMenuEntry { - private readonly Item m_Item; - private ISecurable m_Securable; - - public SetSecureLevelEntry(Item item, ISecurable securable) : base(6203, 6) + public SetSecureLevelEntry() : base(6203, 6) { - m_Item = item; - m_Securable = securable; } public static ISecurable GetSecurable(Mobile from, Item item) @@ -4314,8 +4309,6 @@ namespace Server.Multis return null; } - ISecurable sec = null; - if (item is ISecurable securable) { var isOwned = item is BaseDoor door && house.Doors.Contains(door); @@ -4332,45 +4325,50 @@ namespace Server.Multis if (isOwned) { - sec = securable; + return securable; } } else { var list = house.Secures; - for (var i = 0; sec == null && i < list?.Count; ++i) + for (var i = 0; i < list?.Count; ++i) { var si = list[i]; if (si.Item == item) { - sec = si; + return si; } } } - return sec; + return null; } - public static void AddTo(Mobile from, Item item, List list) + public static void AddTo(Mobile from, Item item, ref PooledRefList list) { var sec = GetSecurable(from, item); if (sec != null) { - list.Add(new SetSecureLevelEntry(item, sec)); + list.Add(new SetSecureLevelEntry()); } } - public override void OnClick() + public override void OnClick(Mobile from, IEntity target) { - var sec = GetSecurable(Owner.From, m_Item); + if (target is not Item item) + { + return; + } + + var sec = GetSecurable(from, item); if (sec != null) { - Owner.From.CloseGump(); - Owner.From.SendGump(new SetSecureLevelGump(Owner.From, sec, BaseHouse.FindHouseAt(m_Item))); + from.CloseGump(); + from.SendGump(new SetSecureLevelGump(from, sec, BaseHouse.FindHouseAt(item))); } } } diff --git a/Projects/UOContent/Multis/Houses/HouseSign.cs b/Projects/UOContent/Multis/Houses/HouseSign.cs index 2cacd3c5e..faa390cbd 100644 --- a/Projects/UOContent/Multis/Houses/HouseSign.cs +++ b/Projects/UOContent/Multis/Houses/HouseSign.cs @@ -1,6 +1,6 @@ using System; -using System.Collections.Generic; using ModernUO.Serialization; +using Server.Collections; using Server.ContextMenus; using Server.Gumps; @@ -197,9 +197,9 @@ public partial class HouseSign : Item } } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); + base.GetContextMenuEntries(from, ref list); if (!BaseHouse.NewVendorSystem || !from.Alive || Owner?.IsAosRules != true) { @@ -208,59 +208,55 @@ public partial class HouseSign : Item if (Owner.AreThereAvailableVendorsFor(from)) { - list.Add(new VendorsEntry(this)); + list.Add(new VendorsEntry()); } if (Owner.VendorInventories.Count > 0) { - list.Add(new ReclaimVendorInventoryEntry(this)); + list.Add(new ReclaimVendorInventoryEntry()); } } private class VendorsEntry : ContextMenuEntry { - private readonly HouseSign m_Sign; - - public VendorsEntry(HouseSign sign) : base(6211) => m_Sign = sign; - - public override void OnClick() + public VendorsEntry() : base(6211, 5) { - var from = Owner.From; + } - if (!from.CheckAlive() || m_Sign.Deleted || m_Sign.Owner?.AreThereAvailableVendorsFor(from) != true) + public override void OnClick(Mobile from, IEntity target) + { + if (!from.CheckAlive() || target is not HouseSign sign || sign.Deleted || sign.Owner?.AreThereAvailableVendorsFor(from) != true) { return; } - if (from.Map != m_Sign.Map || !from.InRange(m_Sign, 5)) + if (from.Map != sign.Map) { // You must be within five paces of the house sign to use this option. from.SendLocalizedMessage(1062429); } else { - from.SendGump(new HouseGumpAOS(HouseGumpPageAOS.Vendors, from, m_Sign.Owner)); + from.SendGump(new HouseGumpAOS(HouseGumpPageAOS.Vendors, from, sign.Owner)); } } } private class ReclaimVendorInventoryEntry : ContextMenuEntry { - private readonly HouseSign m_Sign; - - public ReclaimVendorInventoryEntry(HouseSign sign) : base(6213) => m_Sign = sign; - - public override void OnClick() + public ReclaimVendorInventoryEntry() : base(6213, 5) { - var from = Owner.From; + } - if (m_Sign.Deleted || m_Sign.Owner == null || m_Sign.Owner.VendorInventories.Count == 0 || - !from.CheckAlive()) + public override void OnClick(Mobile from, IEntity target) + { + if (!from.CheckAlive() || target is not HouseSign sign || sign.Deleted || sign.Owner == null || + sign.Owner.VendorInventories.Count == 0) { return; } - if (from.Map != m_Sign.Map || !from.InRange(m_Sign, 5)) + if (from.Map != sign.Map) { // You must be within five paces of the house sign to use this option. from.SendLocalizedMessage(1062429); @@ -268,7 +264,7 @@ public partial class HouseSign : Item else { from.CloseGump(); - from.SendGump(new VendorInventoryGump(m_Sign.Owner, from)); + from.SendGump(new VendorInventoryGump(sign.Owner, from)); } } } diff --git a/Projects/UOContent/Multis/Houses/HouseTeleporter.cs b/Projects/UOContent/Multis/Houses/HouseTeleporter.cs index 17a2d9be8..6c5c5d9fc 100644 --- a/Projects/UOContent/Multis/Houses/HouseTeleporter.cs +++ b/Projects/UOContent/Multis/Houses/HouseTeleporter.cs @@ -1,6 +1,6 @@ using System; -using System.Collections.Generic; using ModernUO.Serialization; +using Server.Collections; using Server.ContextMenus; using Server.Gumps; using Server.Mobiles; @@ -57,10 +57,10 @@ public partial class HouseTeleporter : Item, ISecurable return true; } - public override void GetContextMenuEntries(Mobile from, List list) + public override void GetContextMenuEntries(Mobile from, ref PooledRefList list) { - base.GetContextMenuEntries(from, list); - SetSecureLevelEntry.AddTo(from, this, list); + base.GetContextMenuEntries(from, ref list); + SetSecureLevelEntry.AddTo(from, this, ref list); } private void Deserialize(IGenericReader reader, int version) diff --git a/Projects/UOContent/Network/Packets/IncomingExtendedCommandPackets.cs b/Projects/UOContent/Network/Packets/IncomingExtendedCommandPackets.cs index 4e8afed42..00216857c 100644 --- a/Projects/UOContent/Network/Packets/IncomingExtendedCommandPackets.cs +++ b/Projects/UOContent/Network/Packets/IncomingExtendedCommandPackets.cs @@ -15,7 +15,6 @@ using System.Buffers; using System.Runtime.CompilerServices; -using Server.ContextMenus; using Server.Items; using Server.Mobiles; @@ -51,8 +50,6 @@ public static class IncomingExtendedCommandPackets RegisterExtended(0x0E, true, &Animate); RegisterExtended(0x0F, false, &Empty); // What's this? RegisterExtended(0x10, true, &QueryProperties); - RegisterExtended(0x13, true, &ContextMenuRequest); - RegisterExtended(0x15, true, &ContextMenuResponse); RegisterExtended(0x1A, true, &StatLockChange); RegisterExtended(0x1C, true, &CastSpell); RegisterExtended(0x24, false, &UnhandledBF); @@ -386,102 +383,6 @@ public static class IncomingExtendedCommandPackets } } - public static void ContextMenuResponse(NetState state, SpanReader reader) - { - var from = state.Mobile; - - if (from == null) - { - return; - } - - var menu = from.ContextMenu; - - from.ContextMenu = null; - - if (menu != null && from == menu.From) - { - var entity = World.FindEntity((Serial)reader.ReadUInt32()); - - if (entity != null && entity == menu.Target && from.CanSee(entity)) - { - Point3D p; - - if (entity is Mobile) - { - p = entity.Location; - } - else if (entity is Item item) - { - p = item.GetWorldLocation(); - } - else - { - return; - } - - int index = reader.ReadUInt16(); - - if (index < menu.Entries.Length) - { - var e = menu.Entries[index]; - - var range = e.Range; - - if (range == -1) - { - range = 18; - } - - if (e.Enabled && from.InRange(p, range)) - { - e.OnClick(); - } - } - } - } - } - - public static void ContextMenuRequest(NetState state, SpanReader reader) - { - var from = state.Mobile; - var target = World.FindEntity((Serial)reader.ReadUInt32()); - - if (from == null || target == null || from.Map != target.Map || !from.CanSee(target)) - { - return; - } - - var item = target as Item; - - var checkLocation = item?.GetWorldLocation() ?? target.Location; - if (!(Utility.InUpdateRange(from.Location, checkLocation) && from.CheckContextMenuDisplay(target))) - { - return; - } - - var c = new ContextMenu(from, target); - - if (c.Entries.Length <= 0) - { - return; - } - - if (item?.RootParent is Mobile mobile && mobile != from && mobile.AccessLevel >= from.AccessLevel) - { - for (var i = 0; i < c.Entries.Length; ++i) - { - var entry = c.Entries[i]; - if (!entry.NonLocalUse) - { - entry.Enabled = false; - } - } - } - - from.ContextMenu = c; - } - public static void BandageTarget(NetState state, SpanReader reader) { var from = state.Mobile;