fix: Moves ContextMenu out of core, streamlines code, fixes bugs (#1873)

## Summary
- Removes allocation of a `List<ContextMenuEntry>` every time a context menu is created.
- Moves packet/context menu creation logic out of the core
- Fixes tame entry

## BREAKING CHANGE
> [!Important]
> **Developer Note**
> ```cs
> public virtual void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list)
> ```
> and similar functions changed to
> ```cs
> public virtual void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
> ```
This commit is contained in:
Kamron Batman 2024-07-20 21:33:23 -07:00 • committed by GitHub
parent bb24b330e1
commit f58117a877
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
88 changed files with 1206 additions and 1483 deletions

View file

@ -1,4 +1,4 @@
using System.Collections.Generic; using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Menus.ItemLists; using Server.Menus.ItemLists;
using Server.Menus.Questions; using Server.Menus.Questions;
@ -9,13 +9,13 @@ namespace Server.Tests.Network
{ {
internal class ContextMenuItem : Item internal class ContextMenuItem : Item
{ {
private bool _requiresNewPacket; private readonly bool _requiresNewPacket;
public ContextMenuItem(Serial serial, bool requiresNewPacket) : base(serial) => public ContextMenuItem(Serial serial, bool requiresNewPacket) : base(serial) =>
_requiresNewPacket = requiresNewPacket; _requiresNewPacket = requiresNewPacket;
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
list.Add(new ContextMenuEntry(3000001)); list.Add(new ContextMenuEntry(3000001));
list.Add(new ContextMenuEntry(3000002)); list.Add(new ContextMenuEntry(3000002));
@ -35,12 +35,11 @@ namespace Server.Tests.Network
{ {
var menu = new ItemListMenu( var menu = new ItemListMenu(
"Which item would you choose?", "Which item would you choose?",
new[] [
{
new ItemListEntry("Item 1", 0x01), new ItemListEntry("Item 1", 0x01),
new ItemListEntry("Item 2", 0x100), new ItemListEntry("Item 2", 0x100),
new ItemListEntry("Item 3", 0x1000, 250) new ItemListEntry("Item 3", 0x1000, 250)
} ]
); );
var expected = new DisplayItemListMenu(menu).Compile(); var expected = new DisplayItemListMenu(menu).Compile();
@ -57,12 +56,11 @@ namespace Server.Tests.Network
{ {
var menu = new QuestionMenu( var menu = new QuestionMenu(
"Which option would you choose?", "Which option would you choose?",
new[] [
{
"Option 1", "Option 1",
"Option 2", "Option 2",
"Option 3" "Option 3"
} ]
); );
var expected = new DisplayQuestionMenu(menu).Compile(); var expected = new DisplayQuestionMenu(menu).Compile();
@ -84,7 +82,7 @@ namespace Server.Tests.Network
m.DefaultMobileInit(); m.DefaultMobileInit();
var item = new ContextMenuItem(World.NewItem, newPacket); 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 packet = newHaven && newPacket ? (Packet)new DisplayContextMenu(menu) : new DisplayContextMenuOld(menu);
var expected = packet.Compile(); var expected = packet.Compile();

View file

@ -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 <http://www.gnu.org/licenses/>. *
*************************************************************************/
namespace Server.ContextMenus; namespace Server.ContextMenus;
@ -18,30 +31,28 @@ public class ContextMenu
/// <seealso cref="From" /> /// <seealso cref="From" />
/// </param> /// </param>
/// <param name="target"> /// <param name="target">
/// The <see cref="Mobile" /> or <see cref="Item" /> for which this ContextMenu is on. /// The <see cref="Mobile" /> or <see cref="Item" /> to execute the ContextMenu on.
/// <seealso cref="Target" /> /// <seealso cref="Target" />
/// </param> /// </param>
public ContextMenu(Mobile from, IEntity target) /// <param name="entries">
/// An array of <see cref="ContextMenuEntry">entries</see> contained in this ContextMenu.
/// <seealso cref="Entries" />
/// </param>
public ContextMenu(Mobile from, IEntity target, ContextMenuEntry[] entries)
{ {
From = from; From = from;
Target = target; Target = target;
Entries = entries;
var list = new List<ContextMenuEntry>(); for (var i = 0; i < Entries.Length; i++)
if (target is Mobile mobile)
{ {
mobile.GetContextMenuEntries(from, list); var entry = Entries[i];
}
else if (target is Item item)
{
item.GetContextMenuEntries(from, list);
}
Entries = list.ToArray(); if (entry.Number is < 3000000 or > 3032767)
{
for (var i = 0; i < Entries.Length; ++i) RequiresNewPacket = true;
{ break;
Entries[i].Owner = this; }
} }
} }
@ -63,20 +74,5 @@ public class ContextMenu
/// <summary> /// <summary>
/// Returns true if this ContextMenu requires packet version 2. /// Returns true if this ContextMenu requires packet version 2.
/// </summary> /// </summary>
public bool RequiresNewPacket public bool RequiresNewPacket { get; }
{
get
{
for (var i = 0; i < Entries.Length; ++i)
{
var number = Entries[i].Number;
if (number is < 3000000 or > 3032767)
{
return true;
}
}
return false;
}
}
} }

View file

@ -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 <http://www.gnu.org/licenses/>. *
*************************************************************************/
using Server.Network; using Server.Network;
namespace Server.ContextMenus; namespace Server.ContextMenus;
@ -42,11 +57,6 @@ public class ContextMenuEntry
/// </summary> /// </summary>
public CMEFlags Flags { get; set; } public CMEFlags Flags { get; set; }
/// <summary>
/// Gets or sets the <see cref="ContextMenu" /> that owns this entry.
/// </summary>
public ContextMenu Owner { get; set; }
/// <summary> /// <summary>
/// Gets or sets the localization number containing the name of this entry. /// Gets or sets the localization number containing the name of this entry.
/// </summary> /// </summary>
@ -76,7 +86,7 @@ public class ContextMenuEntry
/// <summary> /// <summary>
/// Overridable. Virtual event invoked when the entry is clicked. /// Overridable. Virtual event invoked when the entry is clicked.
/// </summary> /// </summary>
public virtual void OnClick() public virtual void OnClick(Mobile from, IEntity target)
{ {
} }
} }

View file

@ -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);
}
}

View file

@ -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);
}
}
}

View file

@ -2131,27 +2131,27 @@ public class Item : IHued, IComparable<Item>, ISpawnable, IObjectPropertyListEnt
public virtual bool CanEquip(Mobile m) => m_Layer != Layer.Invalid && m.FindItemOnLayer(m_Layer) == null; public virtual bool CanEquip(Mobile m) => m_Layer != Layer.Invalid && m.FindItemOnLayer(m_Layer) == null;
public virtual void GetChildContextMenuEntries(Mobile from, List<ContextMenuEntry> list, Item item) public virtual void GetChildContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list, Item item)
{ {
if (m_Parent is Item parentItem) if (m_Parent is Item parentItem)
{ {
parentItem.GetChildContextMenuEntries(from, list, item); parentItem.GetChildContextMenuEntries(from, ref list, item);
} }
else if (m_Parent is Mobile parentMobile) 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<ContextMenuEntry> list) public virtual void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
if (m_Parent is Item item) if (m_Parent is Item item)
{ {
item.GetChildContextMenuEntries(from, list, this); item.GetChildContextMenuEntries(from, ref list, this);
} }
else if (m_Parent is Mobile mobile) else if (m_Parent is Mobile mobile)
{ {
mobile.GetChildContextMenuEntries(from, list, this); mobile.GetChildContextMenuEntries(from, ref list, this);
} }
} }

View file

@ -264,7 +264,6 @@ public partial class Mobile : IHued, IComparable<Mobile>, ISpawnable, IObjectPro
private int m_ChangingCombatant; private int m_ChangingCombatant;
private Mobile m_Combatant; private Mobile m_Combatant;
private TimerExecutionToken _combatTimerToken; private TimerExecutionToken _combatTimerToken;
private ContextMenu m_ContextMenu;
private bool m_Criminal; private bool m_Criminal;
private MobileDelta m_DeltaFlags; private MobileDelta m_DeltaFlags;
@ -870,16 +869,6 @@ public partial class Mobile : IHued, IComparable<Mobile>, ISpawnable, IObjectPro
} }
} }
public ContextMenu ContextMenu
{
get => m_ContextMenu;
set
{
m_ContextMenu = value;
m_NetState.SendDisplayContextMenu(m_ContextMenu);
}
}
[IgnoreDupe] [IgnoreDupe]
public bool Pushing { get; set; } public bool Pushing { get; set; }
@ -6521,26 +6510,12 @@ public partial class Mobile : IHued, IComparable<Mobile>, ISpawnable, IObjectPro
public virtual bool CanPaperdollBeOpenedBy(Mobile from) => Body.IsHuman || Body.IsGhost || IsBodyMod; public virtual bool CanPaperdollBeOpenedBy(Mobile from) => Body.IsHuman || Body.IsGhost || IsBodyMod;
public virtual void GetChildContextMenuEntries(Mobile from, List<ContextMenuEntry> list, Item item) public virtual void GetChildContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list, Item item)
{ {
} }
public virtual void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public virtual void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> 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() public void Internalize()

View file

@ -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 <http://www.gnu.org/licenses/>. *
*************************************************************************/
using System; using System;
using System.Buffers; using System.Buffers;
using System.IO; using System.IO;
using Server.ContextMenus;
using Server.Menus.ItemLists; using Server.Menus.ItemLists;
using Server.Menus.Questions; using Server.Menus.Questions;
@ -132,82 +146,4 @@ public static class OutgoingMenuPackets
writer.WritePacketLength(); writer.WritePacketLength();
ns.Send(writer.Span); 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);
}
} }

View file

@ -4,47 +4,47 @@ namespace Server.ContextMenus
{ {
public class AddToPartyEntry : ContextMenuEntry public class AddToPartyEntry : ContextMenuEntry
{ {
private readonly Mobile m_From; public AddToPartyEntry() : base(0197, 12)
private readonly Mobile m_Target;
public AddToPartyEntry(Mobile from, Mobile target) : 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); if (target is not Mobile targetMobile)
var mp = Party.Get(m_Target);
if (m_From == m_Target)
{ {
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) 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) 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) 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 else
{ {
Party.Invite(m_From, m_Target); Party.Invite(from, targetMobile);
} }
} }
} }

View file

@ -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);
} }
} }

View file

@ -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<Mobile, ContextMenu> _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<ContextMenuEntry>.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);
}
}

View file

@ -4,23 +4,16 @@ namespace Server.ContextMenus
{ {
public class EatEntry : ContextMenuEntry public class EatEntry : ContextMenuEntry
{ {
private readonly Food m_Food; public EatEntry() : base(6135, 1)
private readonly Mobile m_From;
public EatEntry(Mobile from, Food food) : 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);
} }
} }
} }

View file

@ -4,25 +4,25 @@ namespace Server.ContextMenus
{ {
public class EjectPlayerEntry : ContextMenuEntry public class EjectPlayerEntry : ContextMenuEntry
{ {
private readonly Mobile m_From; public EjectPlayerEntry() : base(6206, 12)
private readonly Mobile m_Target;
private readonly BaseHouse m_TargetHouse;
public EjectPlayerEntry(Mobile from, Mobile target) : 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; 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);
} }
} }
} }

View file

@ -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);
}
}

View file

@ -2,24 +2,24 @@ namespace Server.ContextMenus
{ {
public class OpenBankEntry : ContextMenuEntry public class OpenBankEntry : ContextMenuEntry
{ {
private readonly Mobile m_Banker; public OpenBankEntry() : base(6105, 12)
public OpenBankEntry(Mobile banker) : base(6105, 12) => m_Banker = banker;
public override void OnClick()
{ {
if (!Owner.From.CheckAlive()) }
public override void OnClick(Mobile from, IEntity target)
{
if (!from.CheckAlive() || target is not Mobile banker)
{ {
return; 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 else
{ {
Owner.From.BankBox.Open(); from.BankBox.Open();
} }
} }
} }

View file

@ -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);
}
}
}

View file

@ -1,34 +1,25 @@
using Server.Mobiles; using Server.Mobiles;
using Server.Network;
namespace Server.ContextMenus namespace Server.ContextMenus
{ {
public class TeachEntry : ContextMenuEntry public class TeachEntry : ContextMenuEntry
{ {
private readonly Mobile m_From; private readonly SkillName _skill;
private readonly BaseCreature m_Mobile;
private readonly SkillName m_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; _skill = skill;
m_Mobile = m; Enabled = enabled;
m_From = from;
if (!enabled)
{
Flags |= CMEFlags.Disabled;
}
} }
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; return;
} }
m_Mobile.Teach(m_Skill, m_From, 0, false); bc.Teach(_skill, from, 0, false);
} }
} }
} }

View file

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Gumps; using Server.Gumps;
using Server.Mobiles; using Server.Mobiles;
@ -277,36 +278,33 @@ public partial class BulkOrderBook : Item, ISecurable
} }
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
if (from.CheckAlive() && IsChildOf(from.Backpack)) 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 class NameBookEntry : ContextMenuEntry
{ {
private readonly BulkOrderBook m_Book; public NameBookEntry() : base(6216)
private readonly Mobile m_From;
public NameBookEntry(Mobile from, BulkOrderBook book) : 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); return;
m_From.SendLocalizedMessage(1062479); // Type in the new name of the book:
} }
from.Prompt = new NameBookPrompt(book);
from.SendLocalizedMessage(1062479); // Type in the new name of the book:
} }
} }

View file

@ -1,4 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Gumps; using Server.Gumps;
@ -46,17 +47,17 @@ namespace Server.Engines.ConPVP
public override string DefaultName => "tournament controller"; public override string DefaultName => "tournament controller";
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
if (from.AccessLevel >= AccessLevel.GameMaster && Tournament != null) if (from.AccessLevel >= AccessLevel.GameMaster && Tournament != null)
{ {
list.Add(new EditEntry(Tournament)); list.Add(new EditEntry());
if (Tournament.CurrentStage == TournamentStage.Inactive) 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 class EditEntry : ContextMenuEntry
{ {
private readonly Tournament m_Tournament; public EditEntry() : base(5101)
public EditEntry(Tournament tourney) : base(5101) => m_Tournament = tourney;
public override void OnClick()
{ {
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 class StartEntry : ContextMenuEntry
{ {
private readonly Tournament m_Tournament; public StartEntry() : base(5113)
public StartEntry(Tournament tourney) : base(5113) => m_Tournament = tourney;
public override void OnClick()
{ {
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; return;
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."
);
} }
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."
);
} }
} }
} }

View file

@ -4,31 +4,26 @@ namespace Server.ContextMenus
{ {
public class RemoveFromPartyEntry : ContextMenuEntry public class RemoveFromPartyEntry : ContextMenuEntry
{ {
private readonly Mobile m_From; public RemoveFromPartyEntry() : base(0198, 12)
private readonly Mobile m_Target;
public RemoveFromPartyEntry(Mobile from, Mobile target) : 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; 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 else
{ {
p.Remove(m_Target); p.Remove(mobile);
} }
} }
} }

View file

@ -1,5 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Gumps; using Server.Gumps;
using Server.Items; using Server.Items;
@ -221,10 +222,10 @@ public partial class PlantItem : Item, ISecurable
} }
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
SetSecureLevelEntry.AddTo(from, this, list); SetSecureLevelEntry.AddTo(from, this, ref list);
} }
public int GetLocalizedPlantStatus() public int GetLocalizedPlantStatus()

View file

@ -1,5 +1,5 @@
using System.Collections.Generic;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Network; using Server.Network;
using Server.Targeting; using Server.Targeting;
@ -153,13 +153,13 @@ public partial class Obsidian : Item
} }
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
if (from.Alive && _quantity is >= Partial and < Completed && IsChildOf(from.Backpack)) 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 class DisassembleEntry : ContextMenuEntry
{ {
private readonly Obsidian _obsidian; public DisassembleEntry() : base(6142)
public DisassembleEntry(Obsidian obsidian) : base(6142) => _obsidian = obsidian;
public override void OnClick()
{ {
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;
} }
} }

View file

@ -1,5 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Items; using Server.Items;
using Server.Mobiles; using Server.Mobiles;
@ -8,17 +9,15 @@ namespace Server.Engines.Quests;
public class TalkEntry : ContextMenuEntry public class TalkEntry : ContextMenuEntry
{ {
private readonly BaseQuester _quester; public TalkEntry(int talkNumber) : base(talkNumber)
public TalkEntry(BaseQuester quester) : base(quester.TalkNumber) => _quester = quester;
public override void OnClick()
{ {
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; return item;
} }
public override void AddCustomContextEntries(Mobile from, List<ContextMenuEntry> list) public override void AddCustomContextEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.AddCustomContextEntries(from, list); base.AddCustomContextEntries(from, ref list);
if (from.Alive && from is PlayerMobile mobile && TalkNumber > 0 && CanTalkTo(mobile)) if (from.Alive && from is PlayerMobile mobile && TalkNumber > 0 && CanTalkTo(mobile))
{ {
list.Add(new TalkEntry(this)); list.Add(new TalkEntry(TalkNumber));
} }
} }

View file

@ -13,7 +13,7 @@ namespace Server.Engines.Quests
public QuestCallbackEntry(int number, int range, QuestCallback callback) : base(number, range) => public QuestCallbackEntry(int number, int range, QuestCallback callback) : base(number, range) =>
m_Callback = callback; m_Callback = callback;
public override void OnClick() public override void OnClick(Mobile from, IEntity target)
{ {
m_Callback?.Invoke(); m_Callback?.Invoke();
} }

View file

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Engines.Quests.Ambitious; using Server.Engines.Quests.Ambitious;
using Server.Engines.Quests.Collector; using Server.Engines.Quests.Collector;
@ -246,7 +247,7 @@ namespace Server.Engines.Quests
From.SendGump(new QuestOfferGump(this)); From.SendGump(new QuestOfferGump(this));
} }
public virtual void GetContextMenuEntries(List<ContextMenuEntry> list) public virtual void GetContextMenuEntries(ref PooledRefList<ContextMenuEntry> list)
{ {
if (Objectives.Count > 0) if (Objectives.Count > 0)
{ {

View file

@ -1,9 +1,8 @@
using System.Collections.Generic;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Items; using Server.Items;
using Server.Mobiles; using Server.Mobiles;
using Server.Network;
namespace Server.Engines.Quests.Necro; namespace Server.Engines.Quests.Necro;
@ -115,9 +114,9 @@ public partial class Horus : BaseQuester
} }
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
if (!from.Alive || from is not PlayerMobile pm) if (!from.Alive || from is not PlayerMobile pm)
{ {
@ -131,7 +130,7 @@ public partial class Horus : BaseQuester
var obj = qs.FindObjective<SpeakCavePasswordObjective>(); var obj = qs.FindObjective<SpeakCavePasswordObjective>();
var enabled = obj?.Completed == false; 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 class SpeakPasswordEntry : ContextMenuEntry
{ {
private readonly PlayerMobile _from; public SpeakPasswordEntry(bool enabled) : base(6193, 3) => Enabled = enabled;
private readonly Horus _horus;
public SpeakPasswordEntry(Horus horus, PlayerMobile from, bool enabled) : base(6193, 3) public override void OnClick(Mobile from, IEntity target)
{ {
_horus = horus; if (from.Alive && from is PlayerMobile pm && target is Horus horus)
_from = from;
if (!enabled)
{ {
Flags |= CMEFlags.Disabled; horus.OnPasswordSpoken(pm);
}
}
public override void OnClick()
{
if (_from.Alive)
{
_horus.OnPasswordSpoken(_from);
} }
} }
} }

View file

@ -1,5 +1,5 @@
using System.Collections.Generic;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Engines.Plants; using Server.Engines.Plants;
using Server.Items; using Server.Items;
@ -141,14 +141,14 @@ public abstract partial class BaseSolenMatriarch : BaseQuester
return true; return true;
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> 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 && if (from.Alive && from is PlayerMobile pm && pm.Quest is SolenMatriarchQuest qs && qs.RedSolen == RedSolen &&
qs.IsObjectiveInProgress(typeof(ProcessFungiObjective))) 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 class ProcessZoogiFungusEntry : ContextMenuEntry
{ {
private readonly PlayerMobile _from; public ProcessZoogiFungusEntry() : base(6184)
private readonly BaseSolenMatriarch _matriarch;
public ProcessZoogiFungusEntry(BaseSolenMatriarch matriarch, PlayerMobile from) : 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);
} }
} }
} }

View file

@ -1,8 +1,8 @@
using System; using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Accounting; using Server.Accounting;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Engines.VeteranRewards; using Server.Engines.VeteranRewards;
using Server.Gumps; using Server.Gumps;
@ -135,9 +135,9 @@ public partial class CharacterStatue : Mobile, IRewardItem
} }
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
if (from.Alive && _sculptedBy != null) if (from.Alive && _sculptedBy != null)
{ {
@ -145,7 +145,7 @@ public partial class CharacterStatue : Mobile, IRewardItem
if (house?.IsCoOwner(from) == true || from.AccessLevel > AccessLevel.Counselor) 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 class DemolishEntry : ContextMenuEntry
{ {
private readonly CharacterStatue m_Statue; public DemolishEntry() : base(6275, 2)
public DemolishEntry(CharacterStatue statue) : base(6275, 2) => m_Statue = statue;
public override void OnClick()
{ {
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);
} }
} }
} }

View file

@ -162,7 +162,7 @@ namespace Server.Items
/* /*
public override void GetProperties(IPropertyList list) => _addon?.GetProperties(list); public override void GetProperties(IPropertyList list) => _addon?.GetProperties(list);
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) => public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list) =>
_addon?.GetContextMenuEntries(from, list); _addon?.GetContextMenuEntries(from, list);
*/ */
public override void OnAfterDelete() public override void OnAfterDelete()

View file

@ -1,7 +1,7 @@
using System; using System;
using System.Buffers.Binary; using System.Buffers.Binary;
using System.Collections.Generic;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Network; using Server.Network;
@ -79,8 +79,8 @@ namespace Server.Items
public override void GetProperties(IPropertyList list) => _addon?.GetProperties(list); public override void GetProperties(IPropertyList list) => _addon?.GetProperties(list);
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) => public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list) =>
_addon?.GetContextMenuEntries(from, list); _addon?.GetContextMenuEntries(from, ref list);
public override void OnAfterDelete() public override void OnAfterDelete()
{ {

View file

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Multis; using Server.Multis;
using Server.Network; using Server.Network;
@ -438,40 +439,40 @@ namespace Server.Items
} }
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
if (from.Alive) if (from.Alive)
{ {
list.Add(new ExamineEntry(this)); list.Add(new ExamineEntry());
if (HasAccess(from)) if (HasAccess(from))
{ {
if (_rewardAvailable) if (_rewardAvailable)
{ {
list.Add(new CollectRewardEntry(this)); list.Add(new CollectRewardEntry());
} }
if (_events.Count > 0) if (_events.Count > 0)
{ {
list.Add(new ViewEventEntry(this)); list.Add(new ViewEventEntry());
} }
if (_vacationLeft > 0) if (_vacationLeft > 0)
{ {
list.Add(new CancelVacationMode(this)); list.Add(new CancelVacationMode());
} }
} }
} }
if (from.AccessLevel >= AccessLevel.GameMaster) if (from.AccessLevel >= AccessLevel.GameMaster)
{ {
list.Add(new GMAddFood(this)); list.Add(new GMAddFood());
list.Add(new GMAddWater(this)); list.Add(new GMAddWater());
list.Add(new GMForceEvaluate(this)); list.Add(new GMForceEvaluate());
list.Add(new GMOpen(this)); list.Add(new GMOpen());
list.Add(new GMFill(this)); list.Add(new GMFill());
} }
} }
@ -982,177 +983,171 @@ namespace Server.Items
private class ExamineEntry : ContextMenuEntry private class ExamineEntry : ContextMenuEntry
{ {
private readonly Aquarium m_Aquarium; public ExamineEntry() : base(6235, 2)
public ExamineEntry(Aquarium aquarium) : base(6235, 2) // Examine Aquarium
=>
m_Aquarium = aquarium;
public override void OnClick()
{ {
if (m_Aquarium.Deleted) }
public override void OnClick(Mobile from, IEntity target)
{
if (!from.Alive || target is not Aquarium aquarium || aquarium.Deleted)
{ {
return; return;
} }
m_Aquarium.ExamineAquarium(Owner.From); aquarium.ExamineAquarium(from);
} }
} }
private class CollectRewardEntry : ContextMenuEntry private class CollectRewardEntry : ContextMenuEntry
{ {
private readonly Aquarium m_Aquarium; public CollectRewardEntry() : base(6237, 2)
public CollectRewardEntry(Aquarium aquarium) : base(6237, 2) // Collect Reward
=>
m_Aquarium = aquarium;
public override void OnClick()
{ {
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; return;
} }
m_Aquarium.GiveReward(Owner.From); aquarium.GiveReward(from);
} }
} }
private class ViewEventEntry : ContextMenuEntry private class ViewEventEntry : ContextMenuEntry
{ {
private readonly Aquarium m_Aquarium; public ViewEventEntry() : base(6239, 2)
public ViewEventEntry(Aquarium aquarium) : base(6239, 2) // View events
=>
m_Aquarium = aquarium;
public override void OnClick()
{ {
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; 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); aquarium.RemoveFromEventsAt(0);
m_Aquarium.InvalidateProperties(); aquarium.InvalidateProperties();
} }
} }
private class CancelVacationMode : ContextMenuEntry private class CancelVacationMode : ContextMenuEntry
{ {
private readonly Aquarium m_Aquarium; public CancelVacationMode() : base(6240, 2)
public CancelVacationMode(Aquarium aquarium) : base(6240, 2) // Cancel vacation mode
=>
m_Aquarium = aquarium;
public override void OnClick()
{ {
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; return;
} }
Owner.From.SendLocalizedMessage(1074429); // Vacation mode has been cancelled. from.SendLocalizedMessage(1074429); // Vacation mode has been cancelled.
m_Aquarium.VacationLeft = 0; aquarium.VacationLeft = 0;
m_Aquarium.InvalidateProperties(); aquarium.InvalidateProperties();
} }
} }
// GM context entries // GM context entries
private class GMAddFood : ContextMenuEntry private class GMAddFood : ContextMenuEntry
{ {
private readonly Aquarium m_Aquarium; public GMAddFood() : base(6231)
public GMAddFood(Aquarium aquarium) : base(6231) => m_Aquarium = aquarium;
public override void OnClick()
{ {
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; return;
} }
m_Aquarium.Food.Added += 1; aquarium.Food.Added += 1;
m_Aquarium.InvalidateProperties(); aquarium.InvalidateProperties();
} }
} }
private class GMAddWater : ContextMenuEntry private class GMAddWater : ContextMenuEntry
{ {
private readonly Aquarium m_Aquarium; public GMAddWater() : base(6232)
public GMAddWater(Aquarium aquarium) : base(6232) => m_Aquarium = aquarium;
public override void OnClick()
{ {
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; return;
} }
m_Aquarium.Water.Added += 1; aquarium.Water.Added += 1;
m_Aquarium.InvalidateProperties(); aquarium.InvalidateProperties();
} }
} }
private class GMForceEvaluate : ContextMenuEntry private class GMForceEvaluate : ContextMenuEntry
{ {
private readonly Aquarium m_Aquarium; public GMForceEvaluate() : base(6233)
public GMForceEvaluate(Aquarium aquarium) : base(6233) => m_Aquarium = aquarium;
public override void OnClick()
{ {
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; return;
} }
m_Aquarium.Evaluate(); aquarium.Evaluate();
} }
} }
private class GMOpen : ContextMenuEntry private class GMOpen : ContextMenuEntry
{ {
private readonly Aquarium m_Aquarium; public GMOpen() : base(6234)
public GMOpen(Aquarium aquarium) : base(6234) => m_Aquarium = aquarium;
public override void OnClick()
{ {
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; return;
} }
Owner.From.SendGump(new AquariumGump(m_Aquarium, true)); from.SendGump(new AquariumGump(aquarium, true));
} }
} }
private class GMFill : ContextMenuEntry private class GMFill : ContextMenuEntry
{ {
private readonly Aquarium m_Aquarium; public GMFill() : base(6236)
public GMFill(Aquarium aquarium) : base(6236) => m_Aquarium = aquarium;
public override void OnClick()
{ {
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; return;
} }
m_Aquarium.Food.Added = m_Aquarium.Food.Maintain; aquarium.Food.Added = aquarium.Food.Maintain;
m_Aquarium.Water.Added = m_Aquarium.Water.Maintain; aquarium.Water.Added = aquarium.Water.Maintain;
m_Aquarium.InvalidateProperties(); aquarium.InvalidateProperties();
} }
} }
} }

View file

@ -1,5 +1,5 @@
using System.Collections.Generic;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Network; using Server.Network;
@ -93,30 +93,30 @@ namespace Server.Items
} }
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
if (!Empty && IsAccessibleTo(from)) if (!Empty && IsAccessibleTo(from))
{ {
list.Add(new RemoveCreature(this)); list.Add(new RemoveCreature());
} }
} }
private class RemoveCreature : ContextMenuEntry private class RemoveCreature : ContextMenuEntry
{ {
private readonly FishBowl m_Bowl; public RemoveCreature() : base(6242, 3)
public RemoveCreature(FishBowl bowl) : base(6242, 3) => m_Bowl = bowl;
public override void OnClick()
{ {
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; return;
} }
var fish = m_Bowl.Fish; var fish = bowl.Fish;
if (fish == null) if (fish == null)
{ {
@ -125,17 +125,17 @@ namespace Server.Items
if (fish.IsLockedDown) // for legacy fish bowls 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 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(); fish.StartTimer();
m_Bowl.InvalidateProperties(); bowl.InvalidateProperties();
} }
} }
} }

View file

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Gumps; using Server.Gumps;
using Server.Multis; using Server.Multis;
@ -151,10 +152,10 @@ namespace Server.Items
} }
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
SetSecureLevelEntry.AddTo(from, this, list); SetSecureLevelEntry.AddTo(from, this, ref list);
} }
private void Deserialize(IGenericReader reader, int version) private void Deserialize(IGenericReader reader, int version)

View file

@ -1,5 +1,5 @@
using System.Collections.Generic;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Gumps; using Server.Gumps;
using Server.Mobiles; using Server.Mobiles;
@ -12,18 +12,18 @@ namespace Server.Items
public const int TitheRange = 2; public const int TitheRange = 2;
public const int LockRange = 2; public const int LockRange = 2;
public static void GetContextMenuEntries(Mobile from, Item item, List<ContextMenuEntry> list) public static void GetContextMenuEntries(Mobile from, Item item, ref PooledRefList<ContextMenuEntry> list)
{ {
if (from is PlayerMobile mobile) 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) 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 class ResurrectEntry : ContextMenuEntry
{ {
private readonly Item _item; public ResurrectEntry(bool enabled) : base(6195, ResurrectRange) => Enabled = enabled;
private readonly Mobile _mobile;
public ResurrectEntry(Mobile mobile, Item item) : base(6195, ResurrectRange) public override void OnClick(Mobile from, IEntity target)
{ {
_mobile = mobile; if (target is Item item)
_item = item; {
Resurrect(from, item);
Enabled = !_mobile.Alive; }
}
public override void OnClick()
{
Resurrect(_mobile, _item);
} }
} }
private class LockKarmaEntry : ContextMenuEntry public class LockKarmaEntry : ContextMenuEntry
{ {
private readonly PlayerMobile _mobile; public LockKarmaEntry(bool karmaLocked) : base(karmaLocked ? 6197 : 6196, LockRange)
public LockKarmaEntry(PlayerMobile mobile) : base(mobile.KarmaLocked ? 6197 : 6196, LockRange) =>
_mobile = mobile;
public override void OnClick()
{ {
_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. // Your karma has been locked. Your karma can no longer be raised.
_mobile.SendLocalizedMessage(1060192); pm.SendLocalizedMessage(1060192);
} }
else 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 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; if (from.CheckAlive())
Enabled = _mobile.Alive;
}
public override void OnClick()
{
if (_mobile.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<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
Ankhs.GetContextMenuEntries(from, this, list); Ankhs.GetContextMenuEntries(from, this, ref list);
} }
public override void OnDoubleClickDead(Mobile m) public override void OnDoubleClickDead(Mobile m)
@ -244,10 +240,10 @@ namespace Server.Items
} }
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
Ankhs.GetContextMenuEntries(from, this, list); Ankhs.GetContextMenuEntries(from, this, ref list);
} }
public override void OnDoubleClickDead(Mobile m) public override void OnDoubleClickDead(Mobile m)
@ -297,10 +293,10 @@ namespace Server.Items
} }
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
Ankhs.GetContextMenuEntries(from, this, list); Ankhs.GetContextMenuEntries(from, this, ref list);
} }
public override void OnDoubleClickDead(Mobile m) public override void OnDoubleClickDead(Mobile m)
@ -393,10 +389,10 @@ namespace Server.Items
} }
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
Ankhs.GetContextMenuEntries(from, this, list); Ankhs.GetContextMenuEntries(from, this, ref list);
} }
public override void OnDoubleClickDead(Mobile m) public override void OnDoubleClickDead(Mobile m)

View file

@ -1,5 +1,5 @@
using System.Collections.Generic;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Gumps; using Server.Gumps;
using Server.Multis; using Server.Multis;
@ -74,10 +74,10 @@ public abstract partial class BaseHouseDoor : BaseDoor, ISecurable
_level = SecureLevel.Anyone; _level = SecureLevel.Anyone;
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
SetSecureLevelEntry.AddTo(from, this, list); SetSecureLevelEntry.AddTo(from, this, ref list);
} }
public BaseHouse FindHouse() public BaseHouse FindHouse()

View file

@ -1,5 +1,5 @@
using System.Collections.Generic;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Mobiles; using Server.Mobiles;
using Server.Multis; using Server.Multis;
@ -41,10 +41,10 @@ public abstract class BaseContainer : Container
return base.CheckItemUse(from, item); return base.CheckItemUse(from, item);
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
SetSecureLevelEntry.AddTo(from, this, list); SetSecureLevelEntry.AddTo(from, this, ref list);
} }
public override bool TryDropItem(Mobile from, Item dropped, bool sendFullMessage) public override bool TryDropItem(Mobile from, Item dropped, bool sendFullMessage)

View file

@ -1,9 +1,8 @@
using System; using System;
using System.Collections.Generic;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Engines.Craft; using Server.Engines.Craft;
using Server.Network;
namespace Server.Items; namespace Server.Items;
@ -27,18 +26,18 @@ public partial class SalvageBag : Bag
public override int LabelNumber => 1079931; // Salvage Bag public override int LabelNumber => 1079931; // Salvage Bag
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
if (from.Alive) if (from.Alive)
{ {
var inBackpack = IsChildOf(from.Backpack); var inBackpack = IsChildOf(from.Backpack);
var resmeltables = inBackpack && Resmeltables(); var resmeltables = inBackpack && Resmeltables();
var scissorables = inBackpack && Scissorables(); var scissorables = inBackpack && Scissorables();
list.Add(new SalvageIngotsEntry(this, resmeltables)); list.Add(new SalvageIngotsEntry(resmeltables));
list.Add(new SalvageClothEntry(this, scissorables)); list.Add(new SalvageClothEntry(scissorables));
list.Add(new SalvageAllEntry(this, resmeltables && scissorables)); list.Add(new SalvageAllEntry(resmeltables && scissorables));
} }
} }
@ -287,90 +286,39 @@ public partial class SalvageBag : Bag
private class SalvageAllEntry : ContextMenuEntry 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 (from.CheckAlive() && target is SalvageBag { Deleted: false } bag)
if (!enabled)
{ {
Flags |= CMEFlags.Disabled; bag.SalvageAll(from);
}
}
public override void OnClick()
{
if (m_Bag.Deleted)
{
return;
}
var from = Owner.From;
if (from.CheckAlive())
{
m_Bag.SalvageAll(from);
} }
} }
} }
private class SalvageIngotsEntry : ContextMenuEntry 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 (from.CheckAlive() && target is SalvageBag { Deleted: false } bag)
if (!enabled)
{ {
Flags |= CMEFlags.Disabled; bag.SalvageIngots(from);
}
}
public override void OnClick()
{
if (m_Bag.Deleted)
{
return;
}
var from = Owner.From;
if (from.CheckAlive())
{
m_Bag.SalvageIngots(from);
} }
} }
} }
private class SalvageClothEntry : ContextMenuEntry 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 (from.CheckAlive() && target is SalvageBag { Deleted: false } bag)
if (!enabled)
{ {
Flags |= CMEFlags.Disabled; bag.SalvageCloth(from);
}
}
public override void OnClick()
{
if (m_Bag.Deleted)
{
return;
}
var from = Owner.From;
if (from.CheckAlive())
{
m_Bag.SalvageCloth(from);
} }
} }
} }

View file

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Engines.PartySystem; using Server.Engines.PartySystem;
using Server.Gumps; using Server.Gumps;
@ -415,13 +416,13 @@ public partial class TreasureMapChest : LockableContainer
base.OnAfterDelete(); base.OnAfterDelete();
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
if (from.Alive) 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 class RemoveEntry : ContextMenuEntry
{ {
private readonly TreasureMapChest _chest; public RemoveEntry(bool enabled) : base(6149, 3) => Enabled = enabled;
private readonly Mobile _from;
public RemoveEntry(Mobile from, TreasureMapChest chest) : base(6149, 3) public override void OnClick(Mobile from, IEntity target)
{ {
_from = from; if (!from.CheckAlive() || target is not TreasureMapChest chest || chest.Deleted || from != chest._owner)
_chest = chest;
Enabled = from == chest._owner;
}
public override void OnClick()
{
if (_chest.Deleted || _from != _chest._owner || !_from.CheckAlive())
{ {
return; return;
} }
_chest.BeginRemove(_from); chest.BeginRemove(from);
} }
} }
} }

View file

@ -1,6 +1,6 @@
using System; using System;
using System.Collections.Generic;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Gumps; using Server.Gumps;
using Server.Mobiles; using Server.Mobiles;
@ -205,13 +205,13 @@ public partial class VendorRentalContract : Item
} }
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
if (IsUsableBy(from, true, true, true, false)) 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 class ContractOptionEntry : ContextMenuEntry
{ {
private readonly VendorRentalContract m_Contract; public ContractOptionEntry() : base(6209)
public ContractOptionEntry(VendorRentalContract contract) : base(6209) => m_Contract = contract;
public override void OnClick()
{ {
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<VendorRentalContractGump>(); from.CloseGump<VendorRentalContractGump>();
from.SendGump(new VendorRentalContractGump(m_Contract, from)); from.SendGump(new VendorRentalContractGump(contract, from));
} }
} }
} }

View file

@ -1,5 +1,5 @@
using System.Collections.Generic;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
namespace Server.Items; namespace Server.Items;
@ -26,13 +26,13 @@ public abstract partial class Food : Item
FillFactor = 1; FillFactor = 1;
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
if (from.Alive) if (from.Alive)
{ {
list.Add(new EatEntry(from, this)); list.Add(new EatEntry());
} }
} }

View file

@ -1,6 +1,6 @@
using System; using System;
using System.Collections.Generic;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Gumps; using Server.Gumps;
using Server.Multis; using Server.Multis;
@ -86,16 +86,16 @@ public abstract partial class BaseBoard : Container, ISecurable
return false; return false;
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
if (ValidateDefault(from, this)) 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) => public static bool ValidateDefault(Mobile from, BaseBoard board) =>
@ -106,23 +106,15 @@ public abstract partial class BaseBoard : Container, ISecurable
public class DefaultEntry : ContextMenuEntry public class DefaultEntry : ContextMenuEntry
{ {
private readonly BaseBoard m_Board; public DefaultEntry(int range) : base(6162, range)
private readonly Mobile m_From;
public DefaultEntry(Mobile from, BaseBoard board) : base(
6162,
from.AccessLevel >= AccessLevel.GameMaster ? -1 : 1
)
{ {
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();
} }
} }
} }

View file

@ -1,6 +1,6 @@
using System; using System;
using System.Collections.Generic;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Gumps; using Server.Gumps;
using Server.Multis; using Server.Multis;
@ -187,18 +187,18 @@ public partial class MahjongGame : Item, ISecurable
} }
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
_players.CheckPlayers(); _players.CheckPlayers();
if (from.Alive && IsAccessibleTo(from) && _players.GetInGameMobiles(true, false).Count == 0) 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) public override void OnDoubleClick(Mobile from)
@ -299,18 +299,16 @@ public partial class MahjongGame : Item, ISecurable
private class ResetGameEntry : ContextMenuEntry private class ResetGameEntry : ContextMenuEntry
{ {
private readonly MahjongGame _game; public ResetGameEntry() : base(6162)
public ResetGameEntry(MahjongGame game) : base(6162) => _game = game;
public override void OnClick()
{ {
var from = Owner.From; }
if (from.CheckAlive() && !_game.Deleted && _game.IsAccessibleTo(from) && public override void OnClick(Mobile from, IEntity target)
_game.Players.GetInGameMobiles(true, false).Count == 0) {
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);
} }
} }
} }

View file

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Engines.Harvest; using Server.Engines.Harvest;
using Server.Mobiles; using Server.Mobiles;
@ -454,22 +455,20 @@ public partial class TreasureMap : MapItem
base.DisplayTo(from); base.DisplayTo(from);
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
if (!_completed) if (!_completed)
{ {
if (_decoder == null) if (_decoder == null)
{ {
list.Add(new DecodeMapEntry(this)); list.Add(new DecodeMapEntry());
} }
else else
{ {
var digTool = HasDiggingTool(from); list.Add(new OpenMapEntry());
list.Add(new DigEntry(HasDiggingTool(from)));
list.Add(new OpenMapEntry(this));
list.Add(new DigEntry(this, digTool));
} }
} }
} }
@ -842,65 +841,52 @@ public partial class TreasureMap : MapItem
private class DecodeMapEntry : ContextMenuEntry private class DecodeMapEntry : ContextMenuEntry
{ {
private readonly TreasureMap m_Map; public DecodeMapEntry() : base(6147, 2)
public DecodeMapEntry(TreasureMap map) : base(6147, 2) => m_Map = map;
public override void OnClick()
{ {
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 class OpenMapEntry : ContextMenuEntry
{ {
private readonly TreasureMap m_Map; public OpenMapEntry() : base(6150, 2)
public OpenMapEntry(TreasureMap map) : base(6150, 2) => m_Map = map;
public override void OnClick()
{ {
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 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 (target is not TreasureMap { Deleted: false } map)
if (!enabled)
{
Flags |= CMEFlags.Disabled;
}
}
public override void OnClick()
{
if (m_Map.Deleted)
{ {
return; return;
} }
var from = Owner.From; if (!HasDiggingTool(from))
if (HasDiggingTool(from))
{
m_Map.OnBeginDig(from);
}
else
{ {
from.SendLocalizedMessage(1114416); // You must have a digging tool to dig for treasure. from.SendLocalizedMessage(1114416); // You must have a digging tool to dig for treasure.
return;
} }
map.OnBeginDig(from);
} }
} }
} }

View file

@ -696,9 +696,9 @@ public partial class Corpse : Container, ICarvable
_instancedItems?.Remove(item); _instancedItems?.Remove(item);
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
if (Core.AOS && _owner == from && from.Alive) 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);
} }
} }
} }

View file

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Gumps; using Server.Gumps;
using Server.Mobiles; using Server.Mobiles;
@ -75,10 +76,10 @@ public abstract partial class BasePlayerBB : Item, ISecurable
} }
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
SetSecureLevelEntry.AddTo(from, this, list); SetSecureLevelEntry.AddTo(from, this, ref list);
} }
public static bool CheckAccess(BaseHouse house, Mobile from) public static bool CheckAccess(BaseHouse house, Mobile from)

View file

@ -1,5 +1,5 @@
using System.Collections.Generic;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Engines.Harvest; using Server.Engines.Harvest;
@ -29,11 +29,11 @@ public partial class FishingPole : Item
} }
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> 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) public override bool CheckConflictingLayer(Mobile m, Item item, Layer layer)

View file

@ -1,6 +1,6 @@
using System; using System;
using System.Collections.Generic;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Engines.Craft; using Server.Engines.Craft;
using Server.Engines.Harvest; using Server.Engines.Harvest;
@ -125,14 +125,14 @@ public abstract partial class BaseHarvestTool : Item, IUsesRemaining, ICraftable
} }
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> 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<ContextMenuEntry> list, HarvestSystem system) public static void AddContextMenuEntries(Mobile from, Item item, ref PooledRefList<ContextMenuEntry> list, HarvestSystem system)
{ {
if (system != Mining.System) if (system != Mining.System)
{ {
@ -149,12 +149,14 @@ public abstract partial class BaseHarvestTool : Item, IUsesRemaining, ICraftable
return; return;
} }
var miningEntry = new ContextMenuEntry(pm.ToggleMiningStone ? 6179 : 6178); list.Add(new ContextMenuEntry(pm.ToggleMiningStone ? 6179 : 6178)
miningEntry.Color = 0x421F; {
list.Add(miningEntry); Color = 0x421F
});
list.Add(new ToggleMiningStoneEntry(pm, false, 6176)); var stoneMining = pm.StoneMining && pm.Skills.Mining.Base >= 100.0;
list.Add(new ToggleMiningStoneEntry(pm, true, 6177)); list.Add(new ToggleMiningStoneEntry(false, pm.ToggleMiningStone, 6176));
list.Add(new ToggleMiningStoneEntry(true, !pm.ToggleMiningStone && stoneMining, 6177));
} }
private void Deserialize(IGenericReader reader, int version) private void Deserialize(IGenericReader reader, int version)
@ -178,51 +180,48 @@ public abstract partial class BaseHarvestTool : Item, IUsesRemaining, ICraftable
private class ToggleMiningStoneEntry : ContextMenuEntry private class ToggleMiningStoneEntry : ContextMenuEntry
{ {
private PlayerMobile _mobile; private readonly bool _value;
private 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; _value = value;
Enabled = enabled;
var stoneMining = mobile.StoneMining && mobile.Skills.Mining.Base >= 100.0;
if (mobile.ToggleMiningStone == value || value && !stoneMining)
{
Flags |= CMEFlags.Disabled;
}
} }
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 (_value)
{ {
if (oldValue) 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! // You have not learned how to mine stone or you do not have enough skill!
_mobile.SendLocalizedMessage(1054024); pm.SendLocalizedMessage(1054024);
} }
else else
{ {
_mobile.ToggleMiningStone = true; pm.ToggleMiningStone = true;
_mobile.SendLocalizedMessage(1054022); // You are now set to mine both ore and stone. pm.SendLocalizedMessage(1054022); // You are now set to mine both ore and stone.
} }
} }
else if (oldValue) else if (oldValue)
{ {
_mobile.ToggleMiningStone = false; pm.ToggleMiningStone = false;
_mobile.SendLocalizedMessage(1054020); // You are now set to mine only ore. pm.SendLocalizedMessage(1054020); // You are now set to mine only ore.
} }
else else
{ {
_mobile.SendLocalizedMessage(1054021); // You are already set to mine only ore! pm.SendLocalizedMessage(1054021); // You are already set to mine only ore!
} }
} }
} }

View file

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Engines.Craft; using Server.Engines.Craft;
using Server.Gumps; using Server.Gumps;
@ -113,10 +114,10 @@ public partial class Runebook : Item, ISecurable, ICraftable
public override bool AllowEquippedCast(Mobile from) => true; public override bool AllowEquippedCast(Mobile from) => true;
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
SetSecureLevelEntry.AddTo(from, this, list); SetSecureLevelEntry.AddTo(from, this, ref list);
} }
private void Deserialize(IGenericReader reader, int version) private void Deserialize(IGenericReader reader, int version)

View file

@ -1,5 +1,5 @@
using System.Collections.Generic;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Multis; using Server.Multis;
using Server.Spells; using Server.Spells;
@ -25,9 +25,9 @@ public partial class SpellScroll : Item, ICommodity
int ICommodity.DescriptionNumber => LabelNumber; int ICommodity.DescriptionNumber => LabelNumber;
bool ICommodity.IsDeedable => Core.ML; bool ICommodity.IsDeedable => Core.ML;
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
if (from.Alive && Movable) if (from.Alive && Movable)
{ {

View file

@ -1,6 +1,6 @@
using System; using System;
using System.Collections.Generic;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Mobiles; using Server.Mobiles;
@ -79,14 +79,14 @@ public partial class Fukiya : Item, INinjaWeapon
NinjaWeapon.AttemptShoot((PlayerMobile)from, this); NinjaWeapon.AttemptShoot((PlayerMobile)from, this);
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
if (IsChildOf(from)) if (IsChildOf(from))
{ {
list.Add(new NinjaWeapon.LoadEntry(this, 6224)); list.Add(new NinjaWeapon.LoadEntry(6224));
list.Add(new NinjaWeapon.UnloadEntry(this, 6225)); list.Add(new NinjaWeapon.UnloadEntry(6225, UsesRemaining > 0));
} }
} }
} }

View file

@ -1,6 +1,6 @@
using System; using System;
using System.Collections.Generic;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Mobiles; using Server.Mobiles;
@ -92,14 +92,14 @@ public partial class LeatherNinjaBelt : BaseWaist, INinjaWeapon
NinjaWeapon.AttemptShoot((PlayerMobile)from, this); NinjaWeapon.AttemptShoot((PlayerMobile)from, this);
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
if (IsChildOf(from)) if (IsChildOf(from))
{ {
list.Add(new NinjaWeapon.LoadEntry(this, 6222)); list.Add(new NinjaWeapon.LoadEntry(6222));
list.Add(new NinjaWeapon.UnloadEntry(this, 6223)); list.Add(new NinjaWeapon.UnloadEntry(6223, UsesRemaining > 0));
} }
} }
} }

View file

@ -329,39 +329,29 @@ public static class NinjaWeapon
public class LoadEntry : ContextMenuEntry public class LoadEntry : ContextMenuEntry
{ {
private readonly INinjaWeapon weapon; public LoadEntry(int entry) : base(entry, 0)
public LoadEntry(INinjaWeapon wep, int entry)
: base(entry, 0) =>
weapon = wep;
public override void OnClick()
{ {
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 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) public override void OnClick(Mobile from, IEntity target)
: base(entry, 0)
{ {
weapon = wep; if (target is INinjaWeapon weapon && WeaponIsValid(weapon, from))
Enabled = weapon.UsesRemaining > 0;
}
public override void OnClick()
{
if (WeaponIsValid(weapon, Owner.From))
{ {
Unload(Owner.From, weapon); Unload(from, weapon);
} }
} }
} }
} }

View file

@ -1,5 +1,5 @@
using System.Collections.Generic;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Gumps; using Server.Gumps;
using Server.Multis; using Server.Multis;
@ -86,10 +86,10 @@ namespace Server.Items
} }
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> 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) public override void OnDoubleClick(Mobile from)

View file

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Gumps; using Server.Gumps;
using Server.Multis; using Server.Multis;
@ -191,11 +192,11 @@ public partial class DawnsMusicBox : Item, ISecurable
} }
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> 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) public override void OnDoubleClick(Mobile from)

View file

@ -1,6 +1,6 @@
using System; using System;
using System.Collections.Generic;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Gumps; using Server.Gumps;
using Server.Multis; using Server.Multis;
@ -77,11 +77,11 @@ public partial class RoseOfTrinsic : Item, ISecurable
list.Add(1062925, Petals); // Petals: ~1_COUNT~ list.Add(1062925, Petals); // Petals: ~1_COUNT~
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> 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) private void StartSpawnTimer(TimeSpan delay)

View file

@ -1,5 +1,5 @@
using System.Collections.Generic;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Gumps; using Server.Gumps;
using Server.Multis; using Server.Multis;
@ -24,11 +24,11 @@ public partial class TapestryOfSosaria : Item, ISecurable
public override int LabelNumber => 1062917; // The Tapestry of Sosaria public override int LabelNumber => 1062917; // The Tapestry of Sosaria
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> 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) public override void OnDoubleClick(Mobile from)

View file

@ -4,10 +4,10 @@ using System.Net;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Accounting; using Server.Accounting;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Gumps; using Server.Gumps;
using Server.Mobiles; using Server.Mobiles;
using Server.Network;
using Server.Regions; using Server.Regions;
using Server.Text; using Server.Text;
@ -394,21 +394,21 @@ public partial class HouseRaffleStone : Item
} }
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
if (from.AccessLevel >= AccessLevel.Seer) if (from.AccessLevel >= AccessLevel.Seer)
{ {
list.Add(new EditEntry(from, this)); list.Add(new EditEntry());
if (_currentState == HouseRaffleState.Inactive) if (_currentState == HouseRaffleState.Inactive)
{ {
list.Add(new ActivateEntry(from, this)); list.Add(new ActivateEntry(ValidLocation(_plotBounds, _plotFacet)));
} }
else 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; public EditEntry() : base(5101)
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 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; 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 public ActivateEntry(bool enabled) : base(5113) => Enabled = enabled;
{
if (!ValidLocation(stone._plotBounds, stone._plotFacet))
{
Flags |= CMEFlags.Disabled;
}
}
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));
} }
} }

View file

@ -1,9 +1,8 @@
using System; using System;
using System.Collections.Generic;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Engines.Quests; using Server.Engines.Quests;
using Server.Network;
using Server.Regions; using Server.Regions;
using Server.Spells; using Server.Spells;
using Server.Targeting; using Server.Targeting;
@ -116,13 +115,13 @@ public partial class BagOfSending : Item, TranslocationItem
LabelTo(from, 1060741, _charges.ToString()); // charges: ~1_val~ LabelTo(from, 1060741, _charges.ToString()); // charges: ~1_val~
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
if (from.Alive) 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 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 (from.CheckAlive() && target is BagOfSending bag && !bag.Deleted)
if (!enabled)
{ {
Flags |= CMEFlags.Disabled; bag.OnDoubleClick(from);
}
}
public override void OnClick()
{
if (_bag.Deleted)
{
return;
}
var from = Owner.From;
if (from.CheckAlive())
{
_bag.OnDoubleClick(from);
} }
} }
} }

View file

@ -1,6 +1,6 @@
using System; using System;
using System.Collections.Generic;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Engines.ConPVP; using Server.Engines.ConPVP;
using Server.Mobiles; using Server.Mobiles;
@ -97,9 +97,9 @@ public partial class BallOfSummoning : Item, TranslocationItem
LabelTo(from, 1054131, $"{_charges}\t{_petName.DefaultIfNullOrEmpty(" ")}"); LabelTo(from, 1054131, $"{_charges}\t{_petName.DefaultIfNullOrEmpty(" ")}");
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
if (!from.Alive || RootParent != from) 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 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()) if (from.CheckAlive())
{ {
_callback(from); _callback(from);

View file

@ -1,11 +1,10 @@
using System; using System;
using System.Collections.Generic;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Factions; using Server.Factions;
using Server.Misc; using Server.Misc;
using Server.Mobiles; using Server.Mobiles;
using Server.Network;
using Server.Prompts; using Server.Prompts;
using Server.Regions; using Server.Regions;
using Server.Spells; using Server.Spells;
@ -93,9 +92,9 @@ public partial class BraceletOfBinding : BaseBracelet, TranslocationItem
LabelTo(from, 1054000, $"{_charges}\t{_inscription.DefaultIfNullOrEmpty(" ")}"); LabelTo(from, 1054000, $"{_charges}\t{_inscription.DefaultIfNullOrEmpty(" ")}");
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
if (from.Alive && IsChildOf(from)) 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) public BraceletEntry(BraceletCallback callback, int number, bool enabled) : base(number)
{ {
_callback = callback; _callback = callback;
Enabled = enabled;
if (!enabled)
{
Flags |= CMEFlags.Disabled;
}
} }
public override void OnClick() public override void OnClick(Mobile from, IEntity target)
{ {
var from = Owner.From;
if (from.CheckAlive()) if (from.CheckAlive())
{ {
_callback(from); _callback(from);

View file

@ -1,6 +1,6 @@
using System; using System;
using System.Collections.Generic;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Engines.VeteranRewards; using Server.Engines.VeteranRewards;
using Server.Gumps; using Server.Gumps;
@ -19,16 +19,16 @@ public partial class AnkhOfSacrificeComponent : AddonComponent
public override bool ForceShowProperties => ObjectPropertyList.Enabled; public override bool ForceShowProperties => ObjectPropertyList.Enabled;
public override int LabelNumber => 1027772; // Ankh of Sacrifice public override int LabelNumber => 1027772; // Ankh of Sacrifice
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
if (from is PlayerMobile mobile) 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) public static void Resurrect(PlayerMobile m, AnkhOfSacrificeAddon ankh)
@ -68,57 +68,15 @@ public partial class AnkhOfSacrificeComponent : AddonComponent
private class ResurrectEntry : ContextMenuEntry private class ResurrectEntry : ContextMenuEntry
{ {
private readonly AnkhOfSacrificeAddon _ankh; public ResurrectEntry() : base(6195, 2)
private readonly Mobile _mobile;
public ResurrectEntry(Mobile mobile, AnkhOfSacrificeAddon ankh) : 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(from as PlayerMobile, ankh);
}
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);
}
} }
} }
} }

View file

@ -1,6 +1,6 @@
using System; using System;
using System.Collections.Generic;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Items; using Server.Items;
@ -19,33 +19,33 @@ public partial class BaseTalismanSummon : BaseCreature
public override bool Commandable => false; public override bool Commandable => false;
public override bool InitialInnocent => true; public override bool InitialInnocent => true;
public override void AddCustomContextEntries(Mobile from, List<ContextMenuEntry> list) public override void AddCustomContextEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
if (from.Alive && ControlMaster == from) if (from.Alive && ControlMaster == from)
{ {
list.Add(new TalismanReleaseEntry(this)); list.Add(new TalismanReleaseEntry());
} }
} }
private class TalismanReleaseEntry : ContextMenuEntry 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(Mobile from, IEntity target)
public override void OnClick()
{ {
Effects.SendLocationParticles( Effects.SendLocationParticles(
EffectItem.Create(m_Mobile.Location, m_Mobile.Map, EffectItem.DefaultDuration), EffectItem.Create(from.Location, from.Map, EffectItem.DefaultDuration),
0x3728, 0x3728,
8, 8,
20, 20,
5042 5042
); );
Effects.PlaySound(m_Mobile,0x201); Effects.PlaySound(from,0x201);
m_Mobile.Delete(); from.Delete();
} }
} }
} }

View file

@ -1,6 +1,6 @@
using System; using System;
using System.Collections.Generic;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Engines.ConPVP; using Server.Engines.ConPVP;
using Server.Engines.Harvest; using Server.Engines.Harvest;
@ -95,13 +95,13 @@ namespace Server.Items
HarvestSystem.BeginHarvesting(from, this); HarvestSystem.BeginHarvesting(from, this);
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
if (HarvestSystem != null) if (HarvestSystem != null)
{ {
BaseHarvestTool.AddContextMenuEntries(from, this, list, HarvestSystem); BaseHarvestTool.AddContextMenuEntries(from, this, ref list, HarvestSystem);
} }
} }

View file

@ -1,6 +1,6 @@
using System; using System;
using System.Collections.Generic;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Engines.ConPVP; using Server.Engines.ConPVP;
using Server.Engines.Harvest; using Server.Engines.Harvest;
@ -48,13 +48,13 @@ namespace Server.Items
} }
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
if (HarvestSystem != null) if (HarvestSystem != null)
{ {
BaseHarvestTool.AddContextMenuEntries(from, this, list, HarvestSystem); BaseHarvestTool.AddContextMenuEntries(from, this, ref list, HarvestSystem);
} }
} }

View file

@ -160,40 +160,44 @@ public abstract class BaseAI
return name != null && speech.InsensitiveStartsWith(name); return name != null && speech.InsensitiveStartsWith(name);
} }
public virtual void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public virtual void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> 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(6109, 14, OrderType.Drop, !isDeadPet)); // Command: Drop
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
} }
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(6110, 14, OrderType.Friend, true)); // Add Friend
list.Add(new InternalEntry(from, 6112, 14, m_Mobile, this, OrderType.Stop)); // Command: Stop list.Add(new InternalEntry(6099, 14, OrderType.Unfriend, true)); // Remove Friend
list.Add(new InternalEntry(from, 6114, 14, m_Mobile, this, OrderType.Stay)); // Command: Stay 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 class InternalEntry : ContextMenuEntry
{ {
private readonly BaseAI m_AI; private readonly OrderType _order;
private readonly Mobile m_From;
private readonly BaseCreature m_Mobile;
private readonly OrderType m_Order;
public InternalEntry(Mobile from, int number, int range, BaseCreature mobile, BaseAI ai, OrderType order) public InternalEntry(int number, int range, OrderType order, bool enabled) : base(number, range)
: base(number, range)
{ {
m_From = from; _order = order;
m_Mobile = mobile; Enabled = enabled;
m_AI = ai;
m_Order = order;
if (mobile.IsDeadPet && order is OrderType.Guard or OrderType.Attack or OrderType.Transfer or OrderType.Drop)
{
Enabled = false;
}
} }
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; 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; return;
} }
var isOwner = m_From == m_Mobile.ControlMaster; var isOwner = from == bc.ControlMaster;
var isFriend = !isOwner && m_Mobile.IsPetFriend(m_From); var isFriend = !isOwner && bc.IsPetFriend(from);
if (!isOwner && !isFriend) if (!isOwner && !isFriend)
{ {
return; 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; return;
} }
switch (m_Order) switch (_order)
{ {
case OrderType.Follow: case OrderType.Follow:
case OrderType.Attack: case OrderType.Attack:
@ -2962,37 +2956,37 @@ public abstract class BaseAI
case OrderType.Friend: case OrderType.Friend:
case OrderType.Unfriend: 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 else
{ {
m_AI.BeginPickTarget(m_From, m_Order); bc.AIObject.BeginPickTarget(from, _order);
} }
break; break;
} }
case OrderType.Release: case OrderType.Release:
{ {
if (m_Mobile.Summoned) if (bc.Summoned)
{ {
goto default; goto default;
} }
m_From.SendGump(new ConfirmReleaseGump(m_From, m_Mobile)); from.SendGump(new ConfirmReleaseGump(from, bc));
break; break;
} }
default: default:
{ {
if (m_Mobile.CheckControlChance(m_From)) if (bc.CheckControlChance(from))
{ {
m_Mobile.ControlOrder = m_Order; bc.ControlOrder = _order;
} }
break; break;

View file

@ -1,5 +1,5 @@
using ModernUO.Serialization; using ModernUO.Serialization;
using System.Collections.Generic; using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Items; using Server.Items;
@ -103,43 +103,34 @@ namespace Server.Mobiles
PackAnimal.TryPackOpen(this, from); PackAnimal.TryPackOpen(this, from);
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> 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 public class PackAnimalBackpackEntry : ContextMenuEntry
{ {
private readonly BaseCreature m_Animal; public PackAnimalBackpackEntry(bool enabled) : base(6145, 3) => Enabled = enabled;
private readonly Mobile m_From;
public PackAnimalBackpackEntry(BaseCreature animal, Mobile from) : base(6145, 3) public override void OnClick(Mobile from, IEntity target)
{ {
m_Animal = animal; if (target is BaseCreature bc)
m_From = from;
if (animal.IsDeadPet)
{ {
Enabled = false; PackAnimal.TryPackOpen(bc, from);
} }
} }
public override void OnClick()
{
PackAnimal.TryPackOpen(m_Animal, m_From);
}
} }
public static class PackAnimal public static class PackAnimal
{ {
public static void GetContextMenuEntries(BaseCreature animal, Mobile from, List<ContextMenuEntry> list) public static void GetContextMenuEntries(BaseCreature animal, Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
if (CheckAccess(animal, from)) if (CheckAccess(animal, from))
{ {
list.Add(new PackAnimalBackpackEntry(animal, from)); list.Add(new PackAnimalBackpackEntry(!animal.IsDeadPet));
} }
} }

View file

@ -1,5 +1,5 @@
using ModernUO.Serialization; using ModernUO.Serialization;
using System.Collections.Generic; using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Items; using Server.Items;
@ -110,11 +110,11 @@ namespace Server.Mobiles
PackAnimal.TryPackOpen(this, from); PackAnimal.TryPackOpen(this, from);
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
PackAnimal.GetContextMenuEntries(this, from, list); PackAnimal.GetContextMenuEntries(this, from, ref list);
} }
} }
} }

View file

@ -1,5 +1,5 @@
using ModernUO.Serialization; using ModernUO.Serialization;
using System.Collections.Generic; using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Items; using Server.Items;
@ -129,11 +129,11 @@ namespace Server.Mobiles
public override bool CheckNonlocalLift(Mobile from, Item item) => PackAnimal.CheckAccess(this, from); public override bool CheckNonlocalLift(Mobile from, Item item) => PackAnimal.CheckAccess(this, from);
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
PackAnimal.GetContextMenuEntries(this, from, list); PackAnimal.GetContextMenuEntries(this, from, ref list);
} }
} }
} }

View file

@ -2546,25 +2546,25 @@ namespace Server.Mobiles
return base.OnMoveOver(m); return base.OnMoveOver(m);
} }
public virtual void AddCustomContextEntries(Mobile from, List<ContextMenuEntry> list) public virtual void AddCustomContextEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
if (Commandable) if (Commandable)
{ {
AIObject?.GetContextMenuEntries(from, list); AIObject?.GetContextMenuEntries(from, ref list);
} }
if (m_bTamable && !m_Controlled && from.Alive) 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) if (CanTeach && from.Alive)
{ {
@ -2585,7 +2585,7 @@ namespace Server.Mobiles
toTeach = 420; 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 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; if (!from.CheckAlive() || target is not BaseCreature bc)
Enabled = Enabled && (from.Female ? creature.AllowFemaleTamer : creature.AllowMaleTamer);
}
public override void OnClick()
{
if (!Owner.From.CheckAlive())
{ {
return; return;
} }
Owner.From.TargetLocked = true; from.TargetLocked = true;
AnimalTaming.DisableMessage = 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; AnimalTaming.DisableMessage = false;
Owner.From.TargetLocked = false; from.TargetLocked = false;
} }
} }

View file

@ -1,5 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Items; using Server.Items;
@ -108,13 +109,13 @@ public abstract partial class BaseFamiliar : BaseCreature
} }
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
if (from.Alive && Controlled && from == ControlMaster && from.InRange(this, 14)) 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 class ReleaseEntry : ContextMenuEntry
{ {
private readonly BaseFamiliar m_Familiar; public ReleaseEntry() : base(6118, 14)
private readonly Mobile m_From;
public ReleaseEntry(Mobile from, BaseFamiliar familiar) : 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 && if (from.CheckAlive() && target is BaseFamiliar { Deleted: false, Controlled: true } familiar &&
m_From.CheckAlive()) from == familiar.ControlMaster)
{ {
m_Familiar.BeginRelease(m_From); familiar.BeginRelease(from);
} }
} }
} }

View file

@ -1,5 +1,4 @@
using System; using System;
using System.Collections.Generic;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections; using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
@ -179,11 +178,11 @@ public partial class HordeMinionFamiliar : BaseFamiliar
PackAnimal.TryPackOpen(this, from); PackAnimal.TryPackOpen(this, from);
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> 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<ReleaseFamiliarWarningGump> private class ReleaseFamiliarWarningGump : StaticWarningGump<ReleaseFamiliarWarningGump>

View file

@ -219,7 +219,7 @@ public partial class BaseHire : BaseCreature
base.OnSpeech(e); base.OnSpeech(e);
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
if (Deleted) if (Deleted)
{ {
@ -230,14 +230,14 @@ public partial class BaseHire : BaseCreature
{ {
if (CanPaperdollBeOpenedBy(from)) if (CanPaperdollBeOpenedBy(from))
{ {
list.Add(new PaperdollEntry(this)); list.Add(new PaperdollEntry());
} }
list.Add(new HireEntry(this)); list.Add(new HireEntry());
} }
else else
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
} }
} }
@ -309,13 +309,13 @@ public partial class BaseHire : BaseCreature
public class HireEntry : ContextMenuEntry public class HireEntry : ContextMenuEntry
{ {
private readonly BaseHire _hire; public HireEntry() : base(6120, 3)
public HireEntry(BaseHire hire) : base(6120, 3) => _hire = hire;
public override void OnClick()
{ {
_hire.SayHireCost(); }
public override void OnClick(Mobile from, IEntity target)
{
(target as BaseHire)?.SayHireCost();
} }
} }
} }

View file

@ -1,5 +1,5 @@
using ModernUO.Serialization; using ModernUO.Serialization;
using System.Collections.Generic; using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Engines.Quests.Haven; using Server.Engines.Quests.Haven;
@ -56,9 +56,9 @@ namespace Server.Mobiles
{ {
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
for (var i = 0; i < list.Count; ++i) for (var i = 0; i < list.Count; ++i)
{ {

View file

@ -1,6 +1,6 @@
using ModernUO.Serialization; using ModernUO.Serialization;
using System; using System;
using System.Collections.Generic; using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
namespace Server.Mobiles namespace Server.Mobiles
@ -85,9 +85,9 @@ namespace Server.Mobiles
{ {
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
for (var i = 0; i < list.Count; ++i) for (var i = 0; i < list.Count; ++i)
{ {

View file

@ -1855,13 +1855,18 @@ namespace Server.Mobiles
} }
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
if (from == this) if (from == this)
{ {
Quest?.GetContextMenuEntries(list); if (Alive && Backpack != null && CanSee(Backpack))
{
list.Add(new OpenBackpackEntry());
}
Quest?.GetContextMenuEntries(ref list);
if (Alive) if (Alive)
{ {
@ -1945,17 +1950,17 @@ namespace Server.Mobiles
if (theirParty == null && ourParty == null) if (theirParty == null && ourParty == null)
{ {
list.Add(new AddToPartyEntry(from, this)); list.Add(new AddToPartyEntry());
} }
else if (theirParty != null && theirParty.Leader == from) else if (theirParty != null && theirParty.Leader == from)
{ {
if (ourParty == null) if (ourParty == null)
{ {
list.Add(new AddToPartyEntry(from, this)); list.Add(new AddToPartyEntry());
} }
else if (ourParty == theirParty) 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 && if (curhouse != null && Alive && Core.Expansion >= Expansion.AOS && curhouse.IsAosRules &&
curhouse.IsFriend(from)) 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) => public CallbackEntry(int number, int range, ContextCallback callback) : base(number, range) =>
m_Callback = callback; m_Callback = callback;
public override void OnClick() public override void OnClick(Mobile from, IEntity target)
{ {
m_Callback?.Invoke(); m_Callback?.Invoke();
} }

View file

@ -137,7 +137,7 @@ public partial class Banker : BaseVendor
} }
checks = PooledRefList<BankCheck>.Create(); checks = PooledRefList<BankCheck>.Create();
foreach (var bc in bank.FindItemsByType<BankCheck>()) foreach (var bc in bank.FindItemsByType<BankCheck>())
{ {
balance += bc.Worth; balance += bc.Worth;
@ -507,13 +507,13 @@ public partial class Banker : BaseVendor
base.OnSpeech(e); base.OnSpeech(e);
} }
public override void AddCustomContextEntries(Mobile from, List<ContextMenuEntry> list) public override void AddCustomContextEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
if (from.Alive) if (from.Alive)
{ {
list.Add(new OpenBankEntry(this)); list.Add(new OpenBankEntry());
} }
base.AddCustomContextEntries(from, list); base.AddCustomContextEntries(from, ref list);
} }
} }

View file

@ -3,6 +3,7 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Buffers; using Server.Buffers;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Engines.MLQuests; using Server.Engines.MLQuests;
using Server.Engines.MLQuests.Definitions; 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 bool CanBeRenamedBy(Mobile from) => from.AccessLevel >= AccessLevel.GameMaster;
public override void AddCustomContextEntries(Mobile from, List<ContextMenuEntry> list) public override void AddCustomContextEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
if (from.Alive) if (from.Alive)
{ {
@ -748,22 +749,22 @@ public partial class BaseEscortable : BaseCreature
{ {
if (escorter == null || escorter == from) if (escorter == null || escorter == from)
{ {
list.Add(new AskDestinationEntry(this, from)); list.Add(new AskDestinationEntry());
} }
if (escorter == null) if (escorter == null)
{ {
list.Add(new AcceptEscortEntry(this, from)); list.Add(new AcceptEscortEntry());
} }
} }
if (escorter == from) 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; public virtual string[] GetPossibleDestinations() => Core.ML ? MlTownNames : TownNames;
@ -901,46 +902,36 @@ public class EscortDestinationInfo
public class AskDestinationEntry : ContextMenuEntry public class AskDestinationEntry : ContextMenuEntry
{ {
private readonly Mobile _from; public AskDestinationEntry() : base(6100, 3)
private readonly BaseEscortable _mobile;
public AskDestinationEntry(BaseEscortable m, Mobile from) : 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 public class AcceptEscortEntry : ContextMenuEntry
{ {
private readonly Mobile _from; public AcceptEscortEntry() : base(6101, 3)
private readonly BaseEscortable _mobile;
public AcceptEscortEntry(BaseEscortable m, Mobile from) : 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 public class AbandonEscortEntry : ContextMenuEntry
{ {
private readonly BaseEscortable _mobile; public AbandonEscortEntry() : base(6102, 3)
public AbandonEscortEntry(BaseEscortable m) : base(6102, 3) => _mobile = m;
public override void OnClick()
{ {
_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
} }
} }

View file

@ -1398,27 +1398,27 @@ namespace Server.Mobiles
} }
} }
public override void AddCustomContextEntries(Mobile from, List<ContextMenuEntry> list) public override void AddCustomContextEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
if (from.Alive && IsActiveVendor) if (from.Alive && IsActiveVendor)
{ {
if (SupportsBulkOrders(from)) if (SupportsBulkOrders(from))
{ {
list.Add(new BulkOrderInfoEntry(from, this)); list.Add(new BulkOrderInfoEntry());
} }
if (IsActiveSeller) if (IsActiveSeller)
{ {
list.Add(new VendorBuyEntry(from, this)); list.Add(new VendorBuyEntry(CheckVendorAccess(from)));
} }
if (IsActiveBuyer) 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(); public virtual IShopSellInfo[] GetSellInfo() => _sellInfo.ToArray();
@ -1439,63 +1439,57 @@ namespace Server.Mobiles
private class BulkOrderInfoEntry : ContextMenuEntry private class BulkOrderInfoEntry : ContextMenuEntry
{ {
private readonly Mobile m_From; public BulkOrderInfoEntry() : base(6152)
private readonly BaseVendor m_Vendor;
public BulkOrderInfoEntry(Mobile from, BaseVendor vendor)
: 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; return;
} }
var ts = m_Vendor.GetNextBulkOrder(m_From); var ts = vendor.GetNextBulkOrder(from);
var totalSeconds = ts.TotalSeconds; var totalSeconds = ts.TotalSeconds;
// Let them get a bulk order if they are within 1 second. // Let them get a bulk order if they are within 1 second.
if (totalSeconds < 1) 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) if (Core.AOS)
{ {
var bulkOrder = m_Vendor.CreateBulkOrder(m_From, true); var bulkOrder = vendor.CreateBulkOrder(from, true);
if (bulkOrder is LargeBOD bod) 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) else if (bulkOrder is SmallBOD smallBod)
{ {
m_From.SendGump(new SmallBODAcceptGump(m_From, smallBod)); from.SendGump(new SmallBODAcceptGump(from, smallBod));
} }
} }
} }
else else
{ {
var oldSpeechHue = m_Vendor.SpeechHue; var oldSpeechHue = vendor.SpeechHue;
m_Vendor.SpeechHue = 0x3B2; vendor.SpeechHue = 0x3B2;
if (Core.SE) if (Core.SE)
{ {
// An offer may be available in about ~1_minutes~ minutes. // 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 else
{ {
// An offer may be available in about ~1_hours~ hours. // 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 public class VendorBuyEntry : ContextMenuEntry
{ {
private readonly BaseVendor m_Vendor; public VendorBuyEntry(bool enabled) : base(6103, 8) => Enabled = enabled;
public VendorBuyEntry(Mobile from, BaseVendor vendor) public override void OnClick(Mobile from, IEntity target)
: base(6103, 8)
{ {
m_Vendor = vendor; (target as BaseVendor)?.VendorBuy(from);
Enabled = vendor.CheckVendorAccess(from);
}
public override void OnClick()
{
m_Vendor.VendorBuy(Owner.From);
} }
} }
public class VendorSellEntry : ContextMenuEntry public class VendorSellEntry : ContextMenuEntry
{ {
private readonly BaseVendor m_Vendor; public VendorSellEntry(bool enabled) : base(6104, 8) => Enabled = enabled;
public VendorSellEntry(Mobile from, BaseVendor vendor) public override void OnClick(Mobile from, IEntity target)
: base(6104, 8)
{ {
m_Vendor = vendor; (target as BaseVendor)?.VendorSell(from);
Enabled = vendor.CheckVendorAccess(from);
}
public override void OnClick()
{
m_Vendor.VendorSell(Owner.From);
} }
} }
} }

View file

@ -40,19 +40,19 @@ namespace Server.Mobiles
AddItem(Utility.RandomBool() ? new QuarterStaff() : new ShepherdsCrook()); AddItem(Utility.RandomBool() ? new QuarterStaff() : new ShepherdsCrook());
} }
public override void AddCustomContextEntries(Mobile from, List<ContextMenuEntry> list) public override void AddCustomContextEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
if (from is PlayerMobile { Alive: true } pm) if (from is PlayerMobile { Alive: true } pm)
{ {
list.Add(new StableEntry(this, from)); list.Add(new StableEntry());
if (pm.Stabled?.Count > 0) 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) public static int GetMaxStabled(Mobile from)
@ -411,18 +411,13 @@ namespace Server.Mobiles
private class StableEntry : ContextMenuEntry private class StableEntry : ContextMenuEntry
{ {
private readonly Mobile m_From; public StableEntry() : base(6126, 12)
private readonly AnimalTrainer m_Trainer;
public StableEntry(AnimalTrainer trainer, Mobile from) : 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 class ClaimAllEntry : ContextMenuEntry
{ {
private readonly Mobile m_From; public ClaimAllEntry() : base(6127, 12)
private readonly AnimalTrainer m_Trainer;
public ClaimAllEntry(AnimalTrainer trainer, Mobile from) : 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);
} }
} }

View file

@ -1,5 +1,5 @@
using ModernUO.Serialization; using ModernUO.Serialization;
using System.Collections.Generic; using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Items; using Server.Items;
@ -18,11 +18,11 @@ namespace Server.Mobiles
public override NpcGuild NpcGuild => NpcGuild.TinkersGuild; public override NpcGuild NpcGuild => NpcGuild.TinkersGuild;
public override void AddCustomContextEntries(Mobile from, List<ContextMenuEntry> list) public override void AddCustomContextEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
if (Core.ML && from.Alive) if (Core.ML && from.Alive)
{ {
var entry = new RechargeEntry(from, this); var entry = new RechargeEntry();
if (WeaponEngravingTool.Find(from) == null) if (WeaponEngravingTool.Find(from) == null)
{ {
@ -32,45 +32,38 @@ namespace Server.Mobiles
list.Add(entry); list.Add(entry);
} }
base.AddCustomContextEntries(from, list); base.AddCustomContextEntries(from, ref list);
} }
private class RechargeEntry : ContextMenuEntry private class RechargeEntry : ContextMenuEntry
{ {
private readonly Mobile m_From; public RechargeEntry() : base(6271, 6)
private readonly Mobile m_Vendor;
public RechargeEntry(Mobile from, Mobile vendor) : 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; 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) // I can only help with this if you are carrying an engraving tool that needs repair.
{ vendor.Say(1076164);
m_From.SendGump(new WeaponEngravingTool.ConfirmGump(tool, m_Vendor)); return;
} }
else
{ if (Banker.GetBalance(from) >= 100000)
m_Vendor.Say(1076167); // You need a 100,000 gold and a blue diamond to recharge the weapon engraver. {
} from.SendGump(new WeaponEngravingTool.ConfirmGump(tool, vendor));
} }
else else
{ {
m_Vendor.Say( vendor.Say(1076167); // You need a 100,000 gold and a blue diamond to recharge the weapon engraver.
1076164
); // I can only help with this if you are carrying an engraving tool that needs repair.
} }
} }
} }

View file

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Gumps; using Server.Gumps;
using Server.Items; using Server.Items;
@ -124,18 +125,13 @@ namespace Server.Mobiles
public class ManageBarkeeperEntry : ContextMenuEntry public class ManageBarkeeperEntry : ContextMenuEntry
{ {
private readonly PlayerBarkeeper m_Barkeeper; public ManageBarkeeperEntry() : base(6151, 12)
private readonly Mobile m_From;
public ManageBarkeeperEntry(Mobile from, PlayerBarkeeper barkeeper) : 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; return Owner == from;
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
if (IsOwner(from) && from.InLOS(this)) if (IsOwner(from) && from.InLOS(this))
{ {
list.Add(new ManageBarkeeperEntry(from, this)); list.Add(new ManageBarkeeperEntry());
} }
} }

View file

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Engines.BulkOrders; using Server.Engines.BulkOrders;
using Server.Gumps; using Server.Gumps;
@ -869,14 +870,14 @@ public partial class PlayerVendor : Mobile
Placeholder?.Delete(); Placeholder?.Delete();
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
if (from.Alive && Placeholder != null && IsOwner(from)) 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; 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 class ReturnVendorEntry : ContextMenuEntry
{ {
private readonly PlayerVendor m_Vendor; public ReturnVendorEntry() : base(6214)
public ReturnVendorEntry(PlayerVendor vendor) : base(6214) => m_Vendor = vendor;
public override void OnClick()
{ {
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();
} }
} }
} }

View file

@ -1,6 +1,6 @@
using System; using System;
using System.Collections.Generic;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Gumps; using Server.Gumps;
using Server.Misc; using Server.Misc;
@ -155,27 +155,27 @@ public partial class RentedVendor : PlayerVendor
base.Destroy(toBackpack); base.Destroy(toBackpack);
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
if (from.Alive) if (from.Alive)
{ {
if (IsOwner(from)) if (IsOwner(from))
{ {
list.Add(new ContractOptionsEntry(this)); list.Add(new ContractOptionsEntry());
} }
else if (IsLandlord(from)) else if (IsLandlord(from))
{ {
if (RentalGold > 0) if (RentalGold > 0)
{ {
list.Add(new CollectRentEntry(this)); list.Add(new CollectRentEntry());
} }
list.Add(new TerminateContractEntry(this)); list.Add(new TerminateContractEntry());
list.Add(new ContractOptionsEntry(this)); list.Add(new ContractOptionsEntry());
} }
} }
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
} }
[AfterDeserialization] [AfterDeserialization]
@ -190,65 +190,59 @@ public partial class RentedVendor : PlayerVendor
private class ContractOptionsEntry : ContextMenuEntry private class ContractOptionsEntry : ContextMenuEntry
{ {
private readonly RentedVendor m_Vendor; public ContractOptionsEntry() : base(6209)
public ContractOptionsEntry(RentedVendor vendor) : base(6209) => m_Vendor = vendor;
public override void OnClick()
{ {
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; return;
} }
if (m_Vendor.IsOwner(from)) if (vendor.IsOwner(from))
{ {
from.CloseGump<RenterVendorRentalGump>(); from.CloseGump<RenterVendorRentalGump>();
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<LandlordVendorRentalGump>(); from.CloseGump<LandlordVendorRentalGump>();
from.SendGump(new LandlordVendorRentalGump(m_Vendor)); from.SendGump(new LandlordVendorRentalGump(vendor));
m_Vendor.SendRentalExpireMessage(from); vendor.SendRentalExpireMessage(from);
} }
} }
} }
private class CollectRentEntry : ContextMenuEntry private class CollectRentEntry : ContextMenuEntry
{ {
private readonly RentedVendor m_Vendor; public CollectRentEntry() : base(6212)
public CollectRentEntry(RentedVendor vendor) : base(6212) => m_Vendor = vendor;
public override void OnClick()
{ {
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; return;
} }
if (m_Vendor.RentalGold > 0) if (vendor.RentalGold > 0)
{ {
var depositedGold = Banker.DepositUpTo(from, m_Vendor.RentalGold); var depositedGold = Banker.DepositUpTo(from, vendor.RentalGold);
m_Vendor.RentalGold -= depositedGold; vendor.RentalGold -= depositedGold;
if (depositedGold > 0) if (depositedGold > 0)
{ {
from.SendLocalizedMessage( // ~1_AMOUNT~ gold has been deposited into your bank box.
1060397, from.SendLocalizedMessage(1060397, depositedGold.ToString());
depositedGold.ToString()
); // ~1_AMOUNT~ gold has been deposited into your bank box.
} }
if (m_Vendor.RentalGold > 0) if (vendor.RentalGold > 0)
{ {
from.SendLocalizedMessage(500390); // Your bank box is full. from.SendLocalizedMessage(500390); // Your bank box is full.
} }
@ -258,23 +252,20 @@ public partial class RentedVendor : PlayerVendor
private class TerminateContractEntry : ContextMenuEntry private class TerminateContractEntry : ContextMenuEntry
{ {
private readonly RentedVendor m_Vendor; public TerminateContractEntry() : base(6218)
public TerminateContractEntry(RentedVendor vendor) : base(6218) => m_Vendor = vendor;
public override void OnClick()
{ {
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; return;
} }
from.SendLocalizedMessage( // Enter the amount of gold you wish to offer the renter in exchange for immediate termination of this contract?
1062503 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(vendor);
from.Prompt = new RefundOfferPrompt(m_Vendor);
} }
} }

View file

@ -1,5 +1,5 @@
using System.Collections.Generic;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Engines.BulkOrders; using Server.Engines.BulkOrders;
using Server.Ethics; using Server.Ethics;
@ -78,9 +78,9 @@ public partial class VendorBackpack : Backpack
(from.AccessLevel >= AccessLevel.GameMaster || (from.AccessLevel >= AccessLevel.GameMaster ||
targ.GetType().IsDefined(typeof(PlayerVendorTargetAttribute), false)); targ.GetType().IsDefined(typeof(PlayerVendorTargetAttribute), false));
public override void GetChildContextMenuEntries(Mobile from, List<ContextMenuEntry> list, Item item) public override void GetChildContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list, Item item)
{ {
base.GetChildContextMenuEntries(from, list, item); base.GetChildContextMenuEntries(from, ref list, item);
if (RootParent is not PlayerVendor pv || pv.IsOwner(from)) if (RootParent is not PlayerVendor pv || pv.IsOwner(from))
{ {
@ -91,7 +91,7 @@ public partial class VendorBackpack : Backpack
if (vi != null) 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 class BuyEntry : ContextMenuEntry
{ {
private readonly Item m_Item; public BuyEntry() : base(6103)
{
public BuyEntry(Item item) : base(6103) => m_Item = item; }
public override bool NonLocalUse => true; 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);
} }
} }
} }

View file

@ -4296,13 +4296,8 @@ namespace Server.Multis
public class SetSecureLevelEntry : ContextMenuEntry public class SetSecureLevelEntry : ContextMenuEntry
{ {
private readonly Item m_Item; public SetSecureLevelEntry() : base(6203, 6)
private ISecurable m_Securable;
public SetSecureLevelEntry(Item item, ISecurable securable) : base(6203, 6)
{ {
m_Item = item;
m_Securable = securable;
} }
public static ISecurable GetSecurable(Mobile from, Item item) public static ISecurable GetSecurable(Mobile from, Item item)
@ -4314,8 +4309,6 @@ namespace Server.Multis
return null; return null;
} }
ISecurable sec = null;
if (item is ISecurable securable) if (item is ISecurable securable)
{ {
var isOwned = item is BaseDoor door && house.Doors.Contains(door); var isOwned = item is BaseDoor door && house.Doors.Contains(door);
@ -4332,45 +4325,50 @@ namespace Server.Multis
if (isOwned) if (isOwned)
{ {
sec = securable; return securable;
} }
} }
else else
{ {
var list = house.Secures; 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]; var si = list[i];
if (si.Item == item) if (si.Item == item)
{ {
sec = si; return si;
} }
} }
} }
return sec; return null;
} }
public static void AddTo(Mobile from, Item item, List<ContextMenuEntry> list) public static void AddTo(Mobile from, Item item, ref PooledRefList<ContextMenuEntry> list)
{ {
var sec = GetSecurable(from, item); var sec = GetSecurable(from, item);
if (sec != null) 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) if (sec != null)
{ {
Owner.From.CloseGump<SetSecureLevelGump>(); from.CloseGump<SetSecureLevelGump>();
Owner.From.SendGump(new SetSecureLevelGump(Owner.From, sec, BaseHouse.FindHouseAt(m_Item))); from.SendGump(new SetSecureLevelGump(from, sec, BaseHouse.FindHouseAt(item)));
} }
} }
} }

View file

@ -1,6 +1,6 @@
using System; using System;
using System.Collections.Generic;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Gumps; using Server.Gumps;
@ -197,9 +197,9 @@ public partial class HouseSign : Item
} }
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
if (!BaseHouse.NewVendorSystem || !from.Alive || Owner?.IsAosRules != true) if (!BaseHouse.NewVendorSystem || !from.Alive || Owner?.IsAosRules != true)
{ {
@ -208,59 +208,55 @@ public partial class HouseSign : Item
if (Owner.AreThereAvailableVendorsFor(from)) if (Owner.AreThereAvailableVendorsFor(from))
{ {
list.Add(new VendorsEntry(this)); list.Add(new VendorsEntry());
} }
if (Owner.VendorInventories.Count > 0) if (Owner.VendorInventories.Count > 0)
{ {
list.Add(new ReclaimVendorInventoryEntry(this)); list.Add(new ReclaimVendorInventoryEntry());
} }
} }
private class VendorsEntry : ContextMenuEntry private class VendorsEntry : ContextMenuEntry
{ {
private readonly HouseSign m_Sign; public VendorsEntry() : base(6211, 5)
public VendorsEntry(HouseSign sign) : base(6211) => m_Sign = sign;
public override void OnClick()
{ {
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; 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. // You must be within five paces of the house sign to use this option.
from.SendLocalizedMessage(1062429); from.SendLocalizedMessage(1062429);
} }
else 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 class ReclaimVendorInventoryEntry : ContextMenuEntry
{ {
private readonly HouseSign m_Sign; public ReclaimVendorInventoryEntry() : base(6213, 5)
public ReclaimVendorInventoryEntry(HouseSign sign) : base(6213) => m_Sign = sign;
public override void OnClick()
{ {
var from = Owner.From; }
if (m_Sign.Deleted || m_Sign.Owner == null || m_Sign.Owner.VendorInventories.Count == 0 || public override void OnClick(Mobile from, IEntity target)
!from.CheckAlive()) {
if (!from.CheckAlive() || target is not HouseSign sign || sign.Deleted || sign.Owner == null ||
sign.Owner.VendorInventories.Count == 0)
{ {
return; 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. // You must be within five paces of the house sign to use this option.
from.SendLocalizedMessage(1062429); from.SendLocalizedMessage(1062429);
@ -268,7 +264,7 @@ public partial class HouseSign : Item
else else
{ {
from.CloseGump<VendorInventoryGump>(); from.CloseGump<VendorInventoryGump>();
from.SendGump(new VendorInventoryGump(m_Sign.Owner, from)); from.SendGump(new VendorInventoryGump(sign.Owner, from));
} }
} }
} }

View file

@ -1,6 +1,6 @@
using System; using System;
using System.Collections.Generic;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Gumps; using Server.Gumps;
using Server.Mobiles; using Server.Mobiles;
@ -57,10 +57,10 @@ public partial class HouseTeleporter : Item, ISecurable
return true; return true;
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, ref list);
SetSecureLevelEntry.AddTo(from, this, list); SetSecureLevelEntry.AddTo(from, this, ref list);
} }
private void Deserialize(IGenericReader reader, int version) private void Deserialize(IGenericReader reader, int version)

View file

@ -15,7 +15,6 @@
using System.Buffers; using System.Buffers;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using Server.ContextMenus;
using Server.Items; using Server.Items;
using Server.Mobiles; using Server.Mobiles;
@ -51,8 +50,6 @@ public static class IncomingExtendedCommandPackets
RegisterExtended(0x0E, true, &Animate); RegisterExtended(0x0E, true, &Animate);
RegisterExtended(0x0F, false, &Empty); // What's this? RegisterExtended(0x0F, false, &Empty); // What's this?
RegisterExtended(0x10, true, &QueryProperties); RegisterExtended(0x10, true, &QueryProperties);
RegisterExtended(0x13, true, &ContextMenuRequest);
RegisterExtended(0x15, true, &ContextMenuResponse);
RegisterExtended(0x1A, true, &StatLockChange); RegisterExtended(0x1A, true, &StatLockChange);
RegisterExtended(0x1C, true, &CastSpell); RegisterExtended(0x1C, true, &CastSpell);
RegisterExtended(0x24, false, &UnhandledBF); 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) public static void BandageTarget(NetState state, SpanReader reader)
{ {
var from = state.Mobile; var from = state.Mobile;