2025-05-28 19:52:11 +00:00
using Content.Shared.Actions ;
using Robust.Shared.Audio ;
using Robust.Shared.GameStates ;
2024-06-02 16:08:15 +12:00
using Robust.Shared.Prototypes ;
2023-09-08 18:16:05 -07:00
using Robust.Shared.Serialization ;
2025-05-28 19:52:11 +00:00
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom ;
2023-09-08 18:16:05 -07:00
using Robust.Shared.Utility ;
2025-05-28 19:52:11 +00:00
namespace Content.Shared.Actions.Components ;
2023-09-08 18:16:05 -07:00
2025-05-28 19:52:11 +00:00
/// <summary>
/// Component all actions are required to have.
/// </summary>
[RegisterComponent, NetworkedComponent, Access(typeof(SharedActionsSystem))]
[AutoGenerateComponentState(true, true)]
2024-06-02 16:08:15 +12:00
[EntityCategory("Actions")]
2025-05-28 19:52:11 +00:00
public sealed partial class ActionComponent : Component
2023-09-08 18:16:05 -07:00
{
/// <summary>
/// Icon representing this action in the UI.
/// </summary>
2025-05-28 19:52:11 +00:00
[DataField, AutoNetworkedField]
public SpriteSpecifier ? Icon ;
2023-09-08 18:16:05 -07:00
/// <summary>
/// For toggle actions only, icon to show when toggled on. If omitted, the action will simply be highlighted
/// when turned on.
/// </summary>
2025-05-28 19:52:11 +00:00
[DataField, AutoNetworkedField]
public SpriteSpecifier ? IconOn ;
2023-09-08 18:16:05 -07:00
2024-05-10 17:04:01 -07:00
/// <summary>
/// For toggle actions only, background to show when toggled on.
/// </summary>
2025-05-28 19:52:11 +00:00
[DataField]
public SpriteSpecifier ? BackgroundOn ;
2024-05-10 17:04:01 -07:00
2023-09-08 18:16:05 -07:00
/// <summary>
/// If not null, this color will modulate the action icon color.
/// </summary>
/// <remarks>
/// This currently only exists for decal-placement actions, so that the action icons correspond to the color of
/// the decal. But this is probably useful for other actions, including maybe changing color on toggle.
/// </remarks>
2025-05-28 19:52:11 +00:00
[DataField, AutoNetworkedField]
public Color IconColor = Color . White ;
2023-09-08 18:16:05 -07:00
2024-09-25 10:27:28 -04:00
/// <summary>
/// The original <see cref="IconColor"/> this action was.
/// </summary>
2025-05-28 19:52:11 +00:00
[DataField, AutoNetworkedField]
public Color OriginalIconColor ;
2024-09-25 10:27:28 -04:00
/// <summary>
/// The color the action should turn to when disabled
/// </summary>
[DataField] public Color DisabledIconColor = Color . DimGray ;
2023-09-08 18:16:05 -07:00
/// <summary>
/// Keywords that can be used to search for this action in the action menu.
/// </summary>
2025-05-28 19:52:11 +00:00
[DataField, AutoNetworkedField]
public HashSet < string > Keywords = new ( ) ;
2023-09-08 18:16:05 -07:00
/// <summary>
/// Whether this action is currently enabled. If not enabled, this action cannot be performed.
/// </summary>
2025-05-28 19:52:11 +00:00
[DataField, AutoNetworkedField]
public bool Enabled = true ;
2023-09-08 18:16:05 -07:00
/// <summary>
/// The toggle state of this action. Toggling switches the currently displayed icon, see <see cref="Icon"/> and <see cref="IconOn"/>.
/// </summary>
/// <remarks>
/// The toggle can set directly via <see cref="SharedActionsSystem.SetToggled"/>, but it will also be
/// automatically toggled for targeted-actions while selecting a target.
/// </remarks>
2025-05-28 19:52:11 +00:00
[DataField, AutoNetworkedField]
2023-09-08 18:16:05 -07:00
public bool Toggled ;
/// <summary>
/// The current cooldown on the action.
/// </summary>
2025-05-28 19:52:11 +00:00
[DataField, AutoNetworkedField]
public ActionCooldown ? Cooldown ;
2023-09-08 18:16:05 -07:00
2024-10-28 23:21:14 +01:00
/// <summary>
/// If true, the action will have an initial cooldown applied upon addition.
/// </summary>
[DataField] public bool StartDelay = false ;
2023-09-08 18:16:05 -07:00
/// <summary>
/// Time interval between action uses.
/// </summary>
2025-05-28 19:52:11 +00:00
[DataField, AutoNetworkedField]
public TimeSpan ? UseDelay ;
2023-09-08 18:16:05 -07:00
/// <summary>
2023-09-23 04:49:39 -04:00
/// The entity that contains this action. If the action is innate, this may be the user themselves.
/// This should almost always be non-null.
2023-09-08 18:16:05 -07:00
/// </summary>
2023-09-23 04:49:39 -04:00
[Access(typeof(ActionContainerSystem), typeof(SharedActionsSystem))]
2025-05-28 19:52:11 +00:00
[DataField, AutoNetworkedField]
2023-09-23 04:49:39 -04:00
public EntityUid ? Container ;
2023-09-08 18:16:05 -07:00
/// <summary>
2023-09-23 04:49:39 -04:00
/// Entity to use for the action icon. If no entity is provided and the <see cref="Container"/> differs from
/// <see cref="AttachedEntity"/>, then it will default to using <see cref="Container"/>
2023-09-08 18:16:05 -07:00
/// </summary>
public EntityUid ? EntityIcon
{
2023-09-23 04:49:39 -04:00
get
{
if ( EntIcon ! = null )
return EntIcon ;
if ( AttachedEntity ! = Container )
return Container ;
return null ;
}
set = > EntIcon = value ;
2023-09-08 18:16:05 -07:00
}
2025-05-28 19:52:11 +00:00
[DataField, AutoNetworkedField]
2023-09-23 04:49:39 -04:00
public EntityUid ? EntIcon ;
2023-09-08 18:16:05 -07:00
/// <summary>
/// Whether the action system should block this action if the user cannot currently interact. Some spells or
/// abilities may want to disable this and implement their own checks.
/// </summary>
2025-05-28 19:52:11 +00:00
[DataField, AutoNetworkedField]
public bool CheckCanInteract = true ;
2023-09-08 18:16:05 -07:00
2024-03-19 00:35:46 +02:00
/// <summary>
/// Whether to check if the user is conscious or not. Can be used instead of <see cref="CheckCanInteract"/>
/// for a more permissive check.
/// </summary>
2025-05-28 19:52:11 +00:00
[DataField, AutoNetworkedField]
public bool CheckConsciousness = true ;
2024-03-19 00:35:46 +02:00
2023-09-08 18:16:05 -07:00
/// <summary>
2023-09-23 04:49:39 -04:00
/// If true, this will cause the action to only execute locally without ever notifying the server.
2023-09-08 18:16:05 -07:00
/// </summary>
2025-05-28 19:52:11 +00:00
[DataField, AutoNetworkedField]
public bool ClientExclusive ;
2023-09-08 18:16:05 -07:00
/// <summary>
/// Determines the order in which actions are automatically added the action bar.
/// </summary>
2025-05-28 19:52:11 +00:00
[DataField, AutoNetworkedField]
public int Priority = 0 ;
2023-09-08 18:16:05 -07:00
/// <summary>
/// What entity, if any, currently has this action in the actions component?
/// </summary>
2025-05-28 19:52:11 +00:00
[DataField, AutoNetworkedField]
public EntityUid ? AttachedEntity ;
2023-09-08 18:16:05 -07:00
2023-11-03 19:55:32 -04:00
/// <summary>
/// If true, this will cause the the action event to always be raised directed at the action performer/user instead of the action's container/provider.
/// </summary>
2025-05-28 19:52:11 +00:00
[DataField, AutoNetworkedField]
2023-11-03 19:55:32 -04:00
public bool RaiseOnUser ;
2025-02-08 22:56:08 +01:00
/// <summary>
/// If true, this will cause the the action event to always be raised directed at the action itself instead of the action's container/provider.
/// Takes priority over RaiseOnUser.
/// </summary>
[DataField]
[Obsolete("This datafield will be reworked in an upcoming action refactor")]
public bool RaiseOnAction ;
2023-09-08 18:16:05 -07:00
/// <summary>
/// Whether or not to automatically add this action to the action bar when it becomes available.
/// </summary>
2025-05-28 19:52:11 +00:00
[DataField, AutoNetworkedField]
public bool AutoPopulate = true ;
2023-09-08 18:16:05 -07:00
/// <summary>
2023-09-23 04:49:39 -04:00
/// Temporary actions are deleted when they get removed a <see cref="ActionsComponent"/>.
2023-09-08 18:16:05 -07:00
/// </summary>
2025-05-28 19:52:11 +00:00
[DataField, AutoNetworkedField]
public bool Temporary ;
2023-09-08 18:16:05 -07:00
/// <summary>
/// Determines the appearance of the entity-icon for actions that are enabled via some entity.
/// </summary>
2025-05-28 19:52:11 +00:00
[DataField, AutoNetworkedField]
public ItemActionIconStyle ItemIconStyle ;
2023-09-08 18:16:05 -07:00
/// <summary>
/// If not null, this sound will be played when performing this action.
/// </summary>
2025-05-28 19:52:11 +00:00
[DataField, AutoNetworkedField]
public SoundSpecifier ? Sound ;
2023-09-08 18:16:05 -07:00
}
2025-05-28 19:52:11 +00:00
[DataRecord, Serializable, NetSerializable]
public record struct ActionCooldown
2023-09-08 18:16:05 -07:00
{
2025-05-28 19:52:11 +00:00
[DataField(required: true, customTypeSerializer: typeof(TimeOffsetSerializer))]
public TimeSpan Start ;
2023-09-08 18:16:05 -07:00
2025-05-28 19:52:11 +00:00
[DataField(required: true, customTypeSerializer: typeof(TimeOffsetSerializer))]
public TimeSpan End ;
2023-09-08 18:16:05 -07:00
}