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
|
|
|
using System.Linq;
|
2023-01-02 13:01:40 +13:00
|
|
|
using Content.Shared.Actions;
|
2025-05-28 19:52:11 +00:00
|
|
|
using Content.Shared.Actions.Components;
|
2025-04-29 15:40:49 -04:00
|
|
|
using Content.Shared.Charges.Components;
|
|
|
|
|
using Content.Shared.Charges.Systems;
|
2023-01-02 13:01:40 +13:00
|
|
|
using Content.Shared.Interaction;
|
|
|
|
|
using Robust.Shared.Random;
|
|
|
|
|
using Robust.Shared.Timing;
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.Actions;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// This System handled interactions for the <see cref="ActionOnInteractComponent"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public sealed class ActionOnInteractSystem : EntitySystem
|
|
|
|
|
{
|
|
|
|
|
[Dependency] private readonly IRobustRandom _random = default!;
|
|
|
|
|
[Dependency] private readonly SharedActionsSystem _actions = default!;
|
2023-09-23 04:49:39 -04:00
|
|
|
[Dependency] private readonly ActionContainerSystem _actionContainer = default!;
|
2025-04-29 15:40:49 -04:00
|
|
|
[Dependency] private readonly SharedChargesSystem _charges = default!;
|
2023-01-02 13:01:40 +13:00
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
SubscribeLocalEvent<ActionOnInteractComponent, ActivateInWorldEvent>(OnActivate);
|
|
|
|
|
SubscribeLocalEvent<ActionOnInteractComponent, AfterInteractEvent>(OnAfterInteract);
|
2023-09-23 04:49:39 -04:00
|
|
|
SubscribeLocalEvent<ActionOnInteractComponent, MapInitEvent>(OnMapInit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnMapInit(EntityUid uid, ActionOnInteractComponent component, MapInitEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (component.Actions == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var comp = EnsureComp<ActionsContainerComponent>(uid);
|
|
|
|
|
foreach (var id in component.Actions)
|
|
|
|
|
{
|
|
|
|
|
_actionContainer.AddAction(uid, id, comp);
|
|
|
|
|
}
|
2023-01-02 13:01:40 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnActivate(EntityUid uid, ActionOnInteractComponent component, ActivateInWorldEvent args)
|
|
|
|
|
{
|
2024-05-31 16:26:19 -04:00
|
|
|
if (args.Handled || !args.Complex)
|
2023-01-02 13:01:40 +13:00
|
|
|
return;
|
|
|
|
|
|
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
|
|
|
if (component.ActionEntities is not {} actionEnts)
|
|
|
|
|
{
|
|
|
|
|
if (!TryComp<ActionsContainerComponent>(uid, out var actionsContainerComponent))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
actionEnts = actionsContainerComponent.Container.ContainedEntities.ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var options = GetValidActions<InstantActionComponent>(actionEnts);
|
2023-01-02 13:01:40 +13:00
|
|
|
if (options.Count == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2025-04-29 15:40:49 -04:00
|
|
|
if (!TryUseCharge((uid, component)))
|
|
|
|
|
return;
|
|
|
|
|
|
2025-05-28 19:52:11 +00:00
|
|
|
// not predicted as this is in server due to random
|
|
|
|
|
// TODO: use predicted random and move to shared?
|
|
|
|
|
var (actId, action, comp) = _random.Pick(options);
|
|
|
|
|
_actions.PerformAction(args.User, (actId, action), predicted: false);
|
2023-01-02 13:01:40 +13:00
|
|
|
args.Handled = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnAfterInteract(EntityUid uid, ActionOnInteractComponent component, AfterInteractEvent args)
|
|
|
|
|
{
|
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
|
|
|
if (args.Handled)
|
2023-01-02 13:01:40 +13:00
|
|
|
return;
|
|
|
|
|
|
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
|
|
|
if (component.ActionEntities is not {} actionEnts)
|
|
|
|
|
{
|
|
|
|
|
if (!TryComp<ActionsContainerComponent>(uid, out var actionsContainerComponent))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
actionEnts = actionsContainerComponent.Container.ContainedEntities.ToList();
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-02 13:01:40 +13:00
|
|
|
// First, try entity target actions
|
2025-05-28 19:52:11 +00:00
|
|
|
if (args.Target is {} target)
|
2023-01-02 13:01:40 +13:00
|
|
|
{
|
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
|
|
|
var entOptions = GetValidActions<EntityTargetActionComponent>(actionEnts, args.CanReach);
|
2023-09-08 18:16:05 -07:00
|
|
|
for (var i = entOptions.Count - 1; i >= 0; i--)
|
2023-01-02 13:01:40 +13:00
|
|
|
{
|
2024-04-22 01:39:50 -07:00
|
|
|
var action = entOptions[i];
|
2025-05-28 19:52:11 +00:00
|
|
|
if (!_actions.ValidateEntityTarget(args.User, target, (action, action.Comp2)))
|
2023-09-08 18:16:05 -07:00
|
|
|
entOptions.RemoveAt(i);
|
2023-01-02 13:01:40 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (entOptions.Count > 0)
|
|
|
|
|
{
|
2025-04-29 15:40:49 -04:00
|
|
|
if (!TryUseCharge((uid, component)))
|
|
|
|
|
return;
|
|
|
|
|
|
2025-05-28 19:52:11 +00:00
|
|
|
var (actionId, action, _) = _random.Pick(entOptions);
|
|
|
|
|
_actions.SetEventTarget(actionId, target);
|
|
|
|
|
_actions.PerformAction(args.User, (actionId, action), predicted: false);
|
2023-01-02 13:01:40 +13:00
|
|
|
args.Handled = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// else: try world target actions
|
2023-09-08 18:16:05 -07:00
|
|
|
var options = GetValidActions<WorldTargetActionComponent>(component.ActionEntities, args.CanReach);
|
|
|
|
|
for (var i = options.Count - 1; i >= 0; i--)
|
2023-01-02 13:01:40 +13:00
|
|
|
{
|
2024-04-22 01:39:50 -07:00
|
|
|
var action = options[i];
|
2025-05-28 19:52:11 +00:00
|
|
|
if (!_actions.ValidateWorldTarget(args.User, args.ClickLocation, (action, action.Comp2)))
|
2023-09-08 18:16:05 -07:00
|
|
|
options.RemoveAt(i);
|
2023-01-02 13:01:40 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (options.Count == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2025-04-29 15:40:49 -04:00
|
|
|
if (!TryUseCharge((uid, component)))
|
|
|
|
|
return;
|
|
|
|
|
|
2025-05-28 19:52:11 +00:00
|
|
|
var (actId, comp, world) = _random.Pick(options);
|
|
|
|
|
if (world.Event is {} worldEv)
|
2023-01-02 13:01:40 +13:00
|
|
|
{
|
2025-05-28 19:52:11 +00:00
|
|
|
worldEv.Target = args.ClickLocation;
|
|
|
|
|
worldEv.Entity = HasComp<EntityTargetActionComponent>(actId) ? args.Target : null;
|
2023-01-02 13:01:40 +13:00
|
|
|
}
|
|
|
|
|
|
2025-05-28 19:52:11 +00:00
|
|
|
_actions.PerformAction(args.User, (actId, comp), world.Event, predicted: false);
|
2023-01-02 13:01:40 +13:00
|
|
|
args.Handled = true;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-28 19:52:11 +00:00
|
|
|
private List<Entity<ActionComponent, T>> GetValidActions<T>(List<EntityUid>? actions, bool canReach = true) where T: Component
|
2023-09-08 18:16:05 -07:00
|
|
|
{
|
2025-05-28 19:52:11 +00:00
|
|
|
var valid = new List<Entity<ActionComponent, T>>();
|
2023-09-08 18:16:05 -07:00
|
|
|
|
|
|
|
|
if (actions == null)
|
|
|
|
|
return valid;
|
|
|
|
|
|
|
|
|
|
foreach (var id in actions)
|
|
|
|
|
{
|
2025-05-28 19:52:11 +00:00
|
|
|
if (_actions.GetAction(id) is not {} action ||
|
|
|
|
|
!TryComp<T>(id, out var comp) ||
|
2024-08-18 12:22:36 -04:00
|
|
|
!_actions.ValidAction(action, canReach))
|
2023-09-08 18:16:05 -07:00
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-28 19:52:11 +00:00
|
|
|
valid.Add((id, action, comp));
|
2023-09-08 18:16:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return valid;
|
2023-01-02 13:01:40 +13:00
|
|
|
}
|
2025-04-29 15:40:49 -04:00
|
|
|
|
|
|
|
|
private bool TryUseCharge(Entity<ActionOnInteractComponent> ent)
|
|
|
|
|
{
|
|
|
|
|
if (!ent.Comp.RequiresCharge)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
Entity<LimitedChargesComponent?> charges = ent.Owner;
|
|
|
|
|
if (_charges.IsEmpty(charges))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
_charges.TryUseCharge(charges);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2023-01-02 13:01:40 +13:00
|
|
|
}
|