ModernUO/Projects/UOContent/Context Menus/AddToParty.cs
Kamron Batman f58117a877
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)
> ```
2024-07-20 21:33:23 -07:00

51 lines
1.6 KiB
C#

using Server.Engines.PartySystem;
namespace Server.ContextMenus
{
public class AddToPartyEntry : ContextMenuEntry
{
public AddToPartyEntry() : base(0197, 12)
{
}
public override void OnClick(Mobile from, IEntity target)
{
if (target is not Mobile targetMobile)
{
return;
}
var p = Party.Get(from);
var mp = Party.Get(targetMobile);
if (from == targetMobile)
{
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)
{
from.SendLocalizedMessage(1008095); // You may only have 10 in your party (this includes candidates).
}
else if (!targetMobile.Player)
{
from.SendLocalizedMessage(1005444); // The creature ignores your offer.
}
else if (mp != null && mp == p)
{
from.SendLocalizedMessage(1005440); // This person is already in your party!
}
else if (mp != null)
{
from.SendLocalizedMessage(1005441); // This person is already in a party!
}
else
{
Party.Invite(from, targetMobile);
}
}
}
}