2022-04-14 16:17:34 +12:00
using Content.Shared.Hands ;
using Content.Shared.Inventory ;
using Content.Shared.Inventory.Events ;
2022-02-26 18:24:08 +13:00
using Robust.Shared.Map ;
using Robust.Shared.Serialization ;
namespace Content.Shared.Actions ;
2022-04-14 16:17:34 +12:00
/// <summary>
/// Event raised directed at items or clothing when they are equipped or held. In order for an item to grant actions some
2022-09-11 21:30:11 -07:00
/// system can subscribe to this event and add actions to the <see cref="Actions"/> list.
2022-04-14 16:17:34 +12:00
/// </summary>
/// <remarks>
/// Note that a system could also just manually add actions as a result of a <see cref="GotEquippedEvent"/> or <see
/// cref="GotEquippedHandEvent"/>. This exists mostly as a convenience event, while also helping to keep
/// action-granting logic separate from general equipment behavior.
/// </remarks>
public sealed class GetItemActionsEvent : EntityEventArgs
2022-02-26 18:24:08 +13:00
{
2023-09-23 04:49:39 -04:00
private readonly ActionContainerSystem _system ;
2023-09-08 18:16:05 -07:00
public readonly SortedSet < EntityUid > Actions = new ( ) ;
2022-04-14 16:17:34 +12:00
2023-08-30 03:34:58 +01:00
/// <summary>
/// User equipping the item.
/// </summary>
public EntityUid User ;
2023-09-23 04:49:39 -04:00
/// <summary>
/// The entity that is being asked to provide the actions. This is used as a default argument to <see cref="AddAction(ref System.Nullable{Robust.Shared.GameObjects.EntityUid},string,Robust.Shared.GameObjects.EntityUid)"/>.
/// I.e., if a new action needs to be spawned, then it will be inserted into this entity unless otherwise specified.
/// </summary>
public EntityUid Provider ;
2022-04-14 16:17:34 +12:00
/// <summary>
/// Slot flags for the inventory slot that this item got equipped to. Null if not in a slot (i.e., if equipped to hands).
/// </summary>
public SlotFlags ? SlotFlags ;
/// <summary>
/// If true, the item was equipped to a users hands.
/// </summary>
public bool InHands = > SlotFlags = = null ;
2023-09-23 04:49:39 -04:00
public GetItemActionsEvent ( ActionContainerSystem system , EntityUid user , EntityUid provider , SlotFlags ? slotFlags = null )
2022-04-14 16:17:34 +12:00
{
2023-09-23 04:49:39 -04:00
_system = system ;
2023-08-30 03:34:58 +01:00
User = user ;
2023-09-23 04:49:39 -04:00
Provider = provider ;
2022-04-14 16:17:34 +12:00
SlotFlags = slotFlags ;
}
2023-09-08 18:16:05 -07:00
2023-09-23 04:49:39 -04:00
/// <summary>
/// Grant the given action. If the EntityUid does not refer to a valid action entity, it will create a new action and
/// store it in <see cref="container"/>.
/// </summary>
public void AddAction ( ref EntityUid ? actionId , string prototypeId , EntityUid container )
2023-09-08 18:16:05 -07:00
{
2023-09-23 04:49:39 -04:00
if ( _system . EnsureAction ( container , ref actionId , prototypeId ) )
Actions . Add ( actionId . Value ) ;
}
2023-09-08 18:16:05 -07:00
2023-09-23 04:49:39 -04:00
/// <summary>
/// Grant the given action. If the EntityUid does not refer to a valid action entity, it will create a new action and
/// store it in <see cref="Provider"/>.
/// </summary>
public void AddAction ( ref EntityUid ? actionId , string prototypeId )
{
AddAction ( ref actionId , prototypeId , Provider ) ;
}
2023-09-08 18:16:05 -07:00
2024-04-29 15:22:11 +12:00
public void AddAction ( EntityUid ? actionId )
2023-09-23 04:49:39 -04:00
{
2024-04-29 15:22:11 +12:00
if ( actionId ! = null )
Actions . Add ( actionId . Value ) ;
2023-09-08 18:16:05 -07:00
}
2022-02-26 18:24:08 +13:00
}
/// <summary>
2022-04-14 16:17:34 +12:00
/// Event used to communicate with the server that a client wishes to perform some action.
2022-02-26 18:24:08 +13:00
/// </summary>
[Serializable, NetSerializable]
public sealed class RequestPerformActionEvent : EntityEventArgs
{
2023-09-11 09:42:41 +10:00
public readonly NetEntity Action ;
public readonly NetEntity ? EntityTarget ;
public readonly NetCoordinates ? EntityCoordinatesTarget ;
2022-02-26 18:24:08 +13:00
2023-09-11 09:42:41 +10:00
public RequestPerformActionEvent ( NetEntity action )
2022-02-26 18:24:08 +13:00
{
Action = action ;
}
2023-09-11 09:42:41 +10:00
public RequestPerformActionEvent ( NetEntity action , NetEntity entityTarget )
2022-02-26 18:24:08 +13:00
{
Action = action ;
EntityTarget = entityTarget ;
}
2023-09-11 09:42:41 +10:00
public RequestPerformActionEvent ( NetEntity action , NetCoordinates entityCoordinatesTarget )
2022-02-26 18:24:08 +13:00
{
Action = action ;
2022-12-06 18:03:20 -05:00
EntityCoordinatesTarget = entityCoordinatesTarget ;
2022-02-26 18:24:08 +13:00
}
2024-08-08 02:47:08 -07:00
public RequestPerformActionEvent ( NetEntity action , NetEntity entityTarget , NetCoordinates entityCoordinatesTarget )
{
Action = action ;
EntityTarget = entityTarget ;
EntityCoordinatesTarget = entityCoordinatesTarget ;
}
2022-02-26 18:24:08 +13:00
}
2022-04-14 16:17:34 +12:00
/// <summary>
/// This is the type of event that gets raised when an <see cref="InstantAction"/> is performed. The <see
/// cref="Performer"/> field is automatically filled out by the <see cref="SharedActionsSystem"/>.
/// </summary>
/// <remarks>
/// To define a new action for some system, you need to create an event that inherits from this class.
/// </remarks>
2023-08-22 18:14:33 -07:00
public abstract partial class InstantActionEvent : BaseActionEvent { }
2022-04-14 16:17:34 +12:00
/// <summary>
/// This is the type of event that gets raised when an <see cref="EntityTargetAction"/> is performed. The <see
/// cref="Performer"/> and <see cref="Target"/> fields will automatically be filled out by the <see
/// cref="SharedActionsSystem"/>.
/// </summary>
/// <remarks>
/// To define a new action for some system, you need to create an event that inherits from this class.
/// </remarks>
2023-08-22 18:14:33 -07:00
public abstract partial class EntityTargetActionEvent : BaseActionEvent
2022-02-26 18:24:08 +13:00
{
/// <summary>
2022-04-14 16:17:34 +12:00
/// The entity that the user targeted.
2022-02-26 18:24:08 +13:00
/// </summary>
2022-04-14 16:17:34 +12:00
public EntityUid Target ;
2022-02-26 18:24:08 +13:00
}
2022-04-14 16:17:34 +12:00
/// <summary>
/// This is the type of event that gets raised when an <see cref="WorldTargetAction"/> is performed. The <see
/// cref="Performer"/> and <see cref="Target"/> fields will automatically be filled out by the <see
/// cref="SharedActionsSystem"/>.
/// </summary>
/// <remarks>
/// To define a new action for some system, you need to create an event that inherits from this class.
/// </remarks>
2023-08-22 18:14:33 -07:00
public abstract partial class WorldTargetActionEvent : BaseActionEvent
2022-02-26 18:24:08 +13:00
{
2022-04-14 16:17:34 +12:00
/// <summary>
/// The coordinates of the location that the user targeted.
/// </summary>
2022-12-06 18:03:20 -05:00
public EntityCoordinates Target ;
2022-02-26 18:24:08 +13:00
}
2024-08-08 02:47:08 -07:00
/// <summary>
/// This is the type of event that gets raised when an <see cref="EntityWorldTargetActionComponent"/> is performed.
/// The <see cref="BaseActionEvent.Performer"/>, <see cref="Entity"/>, and <see cref="Coords"/>
/// fields will automatically be filled out by the <see cref="SharedActionsSystem"/>.
/// </summary>
/// <remarks>
/// To define a new action for some system, you need to create an event that inherits from this class.
/// </remarks>
public abstract partial class EntityWorldTargetActionEvent : BaseActionEvent
{
/// <summary>
/// The entity that the user targeted.
/// </summary>
public EntityUid ? Entity ;
/// <summary>
/// The coordinates of the location that the user targeted.
/// </summary>
public EntityCoordinates ? Coords ;
}
2022-04-14 16:17:34 +12:00
/// <summary>
/// Base class for events that are raised when an action gets performed. This should not generally be used outside of the action
/// system.
/// </summary>
[ImplicitDataDefinitionForInheritors]
2023-08-22 18:14:33 -07:00
public abstract partial class BaseActionEvent : HandledEntityEventArgs
2022-02-26 18:24:08 +13:00
{
2022-04-14 16:17:34 +12:00
/// <summary>
/// The user performing the action.
/// </summary>
public EntityUid Performer ;
2024-05-10 17:04:01 -07:00
/// <summary>
Magic Refactor + Wizard Grimoire (#22568)
* Brings over changes from the original magic refactor PR
* Adds Master Spellbook, spellbook categories, WizCoin currency, and locale
* Wiz€oin™
* Adds currency whitelist to Spellbook preset, grants contained actions on action added.
* Adds grant contained action and remove provided action.
* adds a way for actions to be upgraded to the store
* Adds Fireball 3 and fixes action upgrade logic so that it checks if the action can level or if the action can upgrade separately
* Fixes upgrade logic in ActionUpgradeSystem to allow for level ups without an actual upgrade. Fixed action upgrade logic in store system as well
* Removes current action entity from the bought entities list and adds new or old action entity
* Removes Current Entity
* Removes old comments, fixes TransferAllActionsWithNewAttached
* Removes TODO
* Removes Product Action Upgrade Event
* reverts changes to immovablerodrule
* Removes stale event reference
* fixes mind action grant logic
* reverts shared gun system change to projectile anomaly system
* forgor to remove the using
* Reverts unintended changes to action container
* Adds refund button to the store
* Refreshes store back to origin.
* Refund with correct currency
* Init refund
* Check for terminating and update interface
* Disables refund button
* Removes preset allow refund
* dont refund if map changed
* adds refunds to stores
* Adds method to check for starting map
* comments, datafields, some requested changes
* turns event into ref event
* Adds datafields
* Switches to entity terminating event
* Changes store entity to be nullable and checks if store is terminating to remove reference.
* Tryadd instead of containskey
* Adds a refund disable method, disables refund on bought ent container changes if not an action
* Removes duplicate refundcomp
* Removes unintended merges
* Removed another unintended change from merge
* removes extra using statement
* readds using statement
* might as well just remove both usings since it won't leave the PR
* Fixes Action upgrades from stores
* Changes to non obsolete method uses
* Shares spawn code between instant and world
* Adds action entity to action event, adds beforecastspellevent, adds spell requirements to magic component
* puts prereq check in spell methods, sets up template code for before cast event
* checks for required wizard clothes
* Networks Magic Comp and Wizard Clothes Comp. Renames MagicSpawnData to MagicInstantSpawnData.
* Removes posdata from projectiles
* Speech > RequiresSpeech
* Fixes ActionOnInteract
* checks for muted
* popup for missing reqs
* Validate click loc for blink spell
* Checks if doors are in range and not obstructed before opening
* Check ents by map coords
* Adds speak event
* Comments spellbooks
* Removes comments
* Unobsoletes smite spell
* Invert if
* Requirements loc
* Fixes spell reqs
* Inverts an if
* Comment updates
* Starts doafter work
* Removes doafter references
* Balances fireball upgrades to be more reasonable
* Enables refund on master spellbooks
* Spells to do
* update spellbook doafter
* knock toggles bolts
* Touch Spell comments
* Comments for pending spells
* more comments
* adds spider polymorph to spellbook
* TODOs for spells
* reorganizes spellbook categories and adds wands
* fixes spacing and adds limited conditions
* commented owner only for future store PR
* reenables owner only for the grimoire
* fixes grimoire sprite
* Adds wizard rod polymorph
* summon ghosts event
* Moves rod form to offensive category
* Adds charge spell and loc for rod polymorph
* Oops forgor the actual chages
* Item Recall comment
* Fixes UI
* removes extra field for wizard rod
* Cleanup
* New Condition (INCOMPLETE)
* Fix linter
* Fix linter (for real)
* fixed some descriptions
* adds regions to magic
* Adds a non-refund wizard grimoire, fixes blink to deselect after teleporting, reduces force wall despawn time to 12 seconds
* removes limited upgrade condition
---------
Co-authored-by: AJCM <AJCM@tutanota.com>
2024-05-11 19:06:49 -04:00
/// The action the event belongs to.
2024-05-10 17:04:01 -07:00
/// </summary>
2024-08-25 22:43:31 +10:00
public Entity < BaseActionComponent > Action ;
/// <summary>
/// Should we toggle the action entity?
/// </summary>
public bool Toggle ;
2022-02-26 18:24:08 +13:00
}