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

@ -2546,25 +2546,25 @@ namespace Server.Mobiles
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)
{
AIObject?.GetContextMenuEntries(from, list);
AIObject?.GetContextMenuEntries(from, ref list);
}
if (m_bTamable && !m_Controlled && from.Alive)
{
list.Add(new TameEntry(from, this));
list.Add(new TameEntry(from.Female ? AllowFemaleTamer : AllowMaleTamer));
}
AddCustomContextEntries(from, list);
AddCustomContextEntries(from, ref list);
if (CanTeach && from.Alive)
{
@ -2585,7 +2585,7 @@ namespace Server.Mobiles
toTeach = 420;
}
list.Add(new TeachEntry((SkillName)i, this, from, toTeach > theirSkill.BaseFixedPoint));
list.Add(new TeachEntry((SkillName)i, toTeach > theirSkill.BaseFixedPoint));
}
}
}
@ -5505,32 +5505,25 @@ namespace Server.Mobiles
private class TameEntry : ContextMenuEntry
{
private readonly BaseCreature m_Mobile;
public TameEntry(bool enabled) : base(6130, 6) => Enabled = enabled;
public TameEntry(Mobile from, BaseCreature creature) : base(6130, 6)
public override void OnClick(Mobile from, IEntity target)
{
m_Mobile = creature;
Enabled = Enabled && (from.Female ? creature.AllowFemaleTamer : creature.AllowMaleTamer);
}
public override void OnClick()
{
if (!Owner.From.CheckAlive())
if (!from.CheckAlive() || target is not BaseCreature bc)
{
return;
}
Owner.From.TargetLocked = true;
from.TargetLocked = true;
AnimalTaming.DisableMessage = true;
if (Owner.From.UseSkill(SkillName.AnimalTaming))
if (from.UseSkill(SkillName.AnimalTaming))
{
Owner.From.Target.Invoke(Owner.From, m_Mobile);
from.Target.Invoke(from, bc);
}
AnimalTaming.DisableMessage = false;
Owner.From.TargetLocked = false;
from.TargetLocked = false;
}
}