using Content.Shared.Hands;
using Content.Shared.Inventory;
using Content.Shared.Inventory.Events;
using Robust.Shared.Map;
using Robust.Shared.Network;
using Robust.Shared.Serialization;
namespace Content.Shared.Actions;
///
/// Event raised directed at items or clothing when they are equipped or held. In order for an item to grant actions some
/// system can subscribe to this event and add actions to the list.
///
///
/// Note that a system could also just manually add actions as a result of a or . This exists mostly as a convenience event, while also helping to keep
/// action-granting logic separate from general equipment behavior.
///
public sealed class GetItemActionsEvent : EntityEventArgs
{
private readonly IEntityManager _entities;
private readonly INetManager _net;
public readonly SortedSet Actions = new();
///
/// User equipping the item.
///
public EntityUid User;
///
/// Slot flags for the inventory slot that this item got equipped to. Null if not in a slot (i.e., if equipped to hands).
///
public SlotFlags? SlotFlags;
///
/// If true, the item was equipped to a users hands.
///
public bool InHands => SlotFlags == null;
public GetItemActionsEvent(IEntityManager entities, INetManager net, EntityUid user, SlotFlags? slotFlags = null)
{
_entities = entities;
_net = net;
User = user;
SlotFlags = slotFlags;
}
public void AddAction(ref EntityUid? actionId, string? prototypeId)
{
if (_entities.Deleted(actionId))
{
if (string.IsNullOrWhiteSpace(prototypeId) || _net.IsClient)
return;
actionId = _entities.Spawn(prototypeId);
}
Actions.Add(actionId.Value);
}
}
///
/// Event used to communicate with the server that a client wishes to perform some action.
///
[Serializable, NetSerializable]
public sealed class RequestPerformActionEvent : EntityEventArgs
{
public readonly EntityUid Action;
public readonly EntityUid? EntityTarget;
public readonly EntityCoordinates? EntityCoordinatesTarget;
public RequestPerformActionEvent(EntityUid action)
{
Action = action;
}
public RequestPerformActionEvent(EntityUid action, EntityUid entityTarget)
{
Action = action;
EntityTarget = entityTarget;
}
public RequestPerformActionEvent(EntityUid action, EntityCoordinates entityCoordinatesTarget)
{
Action = action;
EntityCoordinatesTarget = entityCoordinatesTarget;
}
}
///
/// This is the type of event that gets raised when an is performed. The field is automatically filled out by the .
///
///
/// To define a new action for some system, you need to create an event that inherits from this class.
///
public abstract partial class InstantActionEvent : BaseActionEvent { }
///
/// This is the type of event that gets raised when an is performed. The and fields will automatically be filled out by the .
///
///
/// To define a new action for some system, you need to create an event that inherits from this class.
///
public abstract partial class EntityTargetActionEvent : BaseActionEvent
{
///
/// The entity that the user targeted.
///
public EntityUid Target;
}
///
/// This is the type of event that gets raised when an is performed. The and fields will automatically be filled out by the .
///
///
/// To define a new action for some system, you need to create an event that inherits from this class.
///
public abstract partial class WorldTargetActionEvent : BaseActionEvent
{
///
/// The coordinates of the location that the user targeted.
///
public EntityCoordinates Target;
}
///
/// Base class for events that are raised when an action gets performed. This should not generally be used outside of the action
/// system.
///
[ImplicitDataDefinitionForInheritors]
public abstract partial class BaseActionEvent : HandledEntityEventArgs
{
///
/// The user performing the action.
///
public EntityUid Performer;
}