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:
parent
bb24b330e1
commit
f58117a877
88 changed files with 1206 additions and 1483 deletions
|
|
@ -15,7 +15,6 @@
|
|||
|
||||
using System.Buffers;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Server.ContextMenus;
|
||||
using Server.Items;
|
||||
using Server.Mobiles;
|
||||
|
||||
|
|
@ -51,8 +50,6 @@ public static class IncomingExtendedCommandPackets
|
|||
RegisterExtended(0x0E, true, &Animate);
|
||||
RegisterExtended(0x0F, false, &Empty); // What's this?
|
||||
RegisterExtended(0x10, true, &QueryProperties);
|
||||
RegisterExtended(0x13, true, &ContextMenuRequest);
|
||||
RegisterExtended(0x15, true, &ContextMenuResponse);
|
||||
RegisterExtended(0x1A, true, &StatLockChange);
|
||||
RegisterExtended(0x1C, true, &CastSpell);
|
||||
RegisterExtended(0x24, false, &UnhandledBF);
|
||||
|
|
@ -386,102 +383,6 @@ public static class IncomingExtendedCommandPackets
|
|||
}
|
||||
}
|
||||
|
||||
public static void ContextMenuResponse(NetState state, SpanReader reader)
|
||||
{
|
||||
var from = state.Mobile;
|
||||
|
||||
if (from == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var menu = from.ContextMenu;
|
||||
|
||||
from.ContextMenu = null;
|
||||
|
||||
if (menu != null && from == menu.From)
|
||||
{
|
||||
var entity = World.FindEntity((Serial)reader.ReadUInt32());
|
||||
|
||||
if (entity != null && entity == menu.Target && from.CanSee(entity))
|
||||
{
|
||||
Point3D p;
|
||||
|
||||
if (entity is Mobile)
|
||||
{
|
||||
p = entity.Location;
|
||||
}
|
||||
else if (entity is Item item)
|
||||
{
|
||||
p = item.GetWorldLocation();
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int index = reader.ReadUInt16();
|
||||
|
||||
if (index < menu.Entries.Length)
|
||||
{
|
||||
var e = menu.Entries[index];
|
||||
|
||||
var range = e.Range;
|
||||
|
||||
if (range == -1)
|
||||
{
|
||||
range = 18;
|
||||
}
|
||||
|
||||
if (e.Enabled && from.InRange(p, range))
|
||||
{
|
||||
e.OnClick();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void ContextMenuRequest(NetState state, SpanReader reader)
|
||||
{
|
||||
var from = state.Mobile;
|
||||
var target = World.FindEntity((Serial)reader.ReadUInt32());
|
||||
|
||||
if (from == null || target == null || from.Map != target.Map || !from.CanSee(target))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var item = target as Item;
|
||||
|
||||
var checkLocation = item?.GetWorldLocation() ?? target.Location;
|
||||
if (!(Utility.InUpdateRange(from.Location, checkLocation) && from.CheckContextMenuDisplay(target)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var c = new ContextMenu(from, target);
|
||||
|
||||
if (c.Entries.Length <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (item?.RootParent is Mobile mobile && mobile != from && mobile.AccessLevel >= from.AccessLevel)
|
||||
{
|
||||
for (var i = 0; i < c.Entries.Length; ++i)
|
||||
{
|
||||
var entry = c.Entries[i];
|
||||
if (!entry.NonLocalUse)
|
||||
{
|
||||
entry.Enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
from.ContextMenu = c;
|
||||
}
|
||||
|
||||
public static void BandageTarget(NetState state, SpanReader reader)
|
||||
{
|
||||
var from = state.Mobile;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue