using System.Collections.Generic;
namespace Server.ContextMenus
{
///
/// Represents the state of an active context menu. This includes who opened the menu, the menu's focus object, and a list
/// of
/// entries that the menu is composed of.
///
///
public class ContextMenu
{
///
/// Instantiates a new ContextMenu instance.
///
///
/// The who opened this ContextMenu.
///
///
///
/// The or for which this ContextMenu is on.
///
///
public ContextMenu(Mobile from, IEntity target)
{
From = from;
Target = target;
var list = new List();
if (target is Mobile mobile)
{
mobile.GetContextMenuEntries(from, list);
}
else if (target is Item item)
{
item.GetContextMenuEntries(from, list);
}
Entries = list.ToArray();
for (var i = 0; i < Entries.Length; ++i)
{
Entries[i].Owner = this;
}
}
///
/// Gets the who opened this ContextMenu.
///
public Mobile From { get; }
///
/// Gets an object of the or for which this ContextMenu is on.
///
public IEntity Target { get; }
///
/// Gets the list of entries contained in this ContextMenu.
///
public ContextMenuEntry[] Entries { get; }
///
/// Returns true if this ContextMenu requires packet version 2.
///
public bool RequiresNewPacket
{
get
{
for (var i = 0; i < Entries.Length; ++i)
{
var number = Entries[i].Number;
if (number is < 3000000 or > 3032767)
{
return true;
}
}
return false;
}
}
}
}