Files
crystall-punk-14/Content.Shared/_CP14/Actions/CP14SharedActionSystem.ModularEffects.cs

146 lines
5.2 KiB
C#
Raw Permalink Normal View History

Magic spell refactor part 2 (#1757) * DoAfter support for Actions (#38253) * Adds Action DoAfter Events * Adds DoAfterArgs fields to DoAfterComp * Adds a base doafter action * Adds Attempt action doafter logic * Adds doafter logic to actions * Changes Action Attempt Doafter and action doafter to take in Performer and the original use delay. Use delay now triggers when a repeated action is cancelled. * Readds the TryPerformAction method and readds request perform action into the action doafter events * Adds a force skip to DoAfter Cancel so we can skip the complete check * Adds a Delay Reduction field to the comp and to the comp state * Fixes doafter mispredict, changes doafter comp check to a guard clause, sets delay reduction if it exists. * Cancels ActionDoAfter if charges is 0 * Serializes Attempt Frequency * Comment for rework * Changes todo into a comment * Moves doafterargs to doafterargscomp * Adds DoAfterArgs comp to BaseDoAfterAction * Removes unused trycomp with actionDoAfter * Replaces DoAfterRepateUseDelay const with timespan.zero * Removes unused usings * Makes SharedActionsSystem partial, adds DoAfter partial class to ActionSystem, moves ActionDoAfter logic to the SharedActionsSystem.DoAfter class * Cleanup and prediction * Renames OnActionDoAfterAttempt to OnActionDoAfter, moves both to Shared Action DoAfter * Removes ActionAttemptDoAfterEvent and moves its summaries to ActionDoAfterEvent. Converts OnActionDoAfterAttempt into TryStartActionDoAfter * Removes Extra check for charges and actiondoafters * Sloptimization * Cleanup * Cleanup * Adds param descs --------- Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com> * Refactor CP14 action emote and speech handling Moved emote and speech logic from magic spell components to dedicated CP14 action components and systems. Removed CP14MagicEffectEmotingComponent and related event handling, introducing CP14ActionEmotingComponent and updating event subscriptions. Updated resource consumption and performed logic to use new action-based components. Adjusted affected prototypes and removed obsolete code. * kicking in * Refactor athletic spell actions and remove mana cost calc Reworked dash and sprint spell YAMLs to use modular effect events and updated their action properties. Removed the unused CalculateManacost method from CP14SharedMagicSystem.cs. Also removed the startDelay property from the kick action. * fix cooldown and resource cost * casting visuals adapt * telegraphy adapt * slowdown adaption * Remove Lumera and Merkas demigod spells and skills Deleted all spell and skill prototypes related to the Lumera and Merkas demigods, including their actions, effects, and skill trees. Updated athletic sprint and second wind spells, and refactored portal_to_city spell to use modular effects. Also added a debug category to the admin skill reset verb. * fuck... * done * some refactor hell * light + lurker process * meta process * mobs process * vampire * finish * no clientside * Update water_creation.yml * fixes * Update ice_ghost.yml * а * viator review * fix lurker --------- Co-authored-by: keronshb <54602815+keronshb@users.noreply.github.com> Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com>
2025-09-17 22:13:10 +03:00
using Content.Shared._CP14.MagicSpell.Spells;
using Content.Shared.Actions;
using Content.Shared.Actions.Components;
namespace Content.Shared._CP14.Actions;
public abstract partial class CP14SharedActionSystem
{
private void InitializeModularEffects()
{
SubscribeLocalEvent<TransformComponent, CP14ActionStartDoAfterEvent>(OnActionTelegraphy);
SubscribeLocalEvent<TransformComponent, CP14InstantModularEffectEvent>(OnInstantCast);
SubscribeLocalEvent<TransformComponent, CP14WorldTargetModularEffectEvent>(OnWorldTargetCast);
SubscribeLocalEvent<TransformComponent, CP14EntityTargetModularEffectEvent>(OnEntityTargetCast);
}
private void OnActionTelegraphy(Entity<TransformComponent> ent, ref CP14ActionStartDoAfterEvent args)
{
if (!_timing.IsFirstTimePredicted)
return;
var performer = GetEntity(args.Performer);
var action = GetEntity(args.Input.Action);
var target = GetEntity(args.Input.EntityTarget);
var targetPosition = GetCoordinates(args.Input.EntityCoordinatesTarget);
if (!TryComp<ActionComponent>(action, out var actionComp))
return;
//Instant
if (TryComp<InstantActionComponent>(action, out var instant) && instant.Event is CP14InstantModularEffectEvent instantModular)
{
var spellArgs = new CP14SpellEffectBaseArgs(performer, actionComp.Container, performer, Transform(performer).Coordinates);
foreach (var effect in instantModular.TelegraphyEffects)
{
effect.Effect(EntityManager, spellArgs);
}
}
//World Target
if (TryComp<WorldTargetActionComponent>(action, out var worldTarget) && worldTarget.Event is CP14WorldTargetModularEffectEvent worldModular && targetPosition is not null)
{
var spellArgs = new CP14SpellEffectBaseArgs(performer, actionComp.Container, null, targetPosition.Value);
foreach (var effect in worldModular.TelegraphyEffects)
{
effect.Effect(EntityManager, spellArgs);
}
}
//Entity Target
if (TryComp<EntityTargetActionComponent>(action, out var entityTarget) && entityTarget.Event is CP14EntityTargetModularEffectEvent entityModular && target is not null)
{
var spellArgs = new CP14SpellEffectBaseArgs(performer, actionComp.Container, target, Transform(target.Value).Coordinates);
foreach (var effect in entityModular.TelegraphyEffects)
{
effect.Effect(EntityManager, spellArgs);
}
}
}
private void OnInstantCast(Entity<TransformComponent> ent, ref CP14InstantModularEffectEvent args)
{
if (!_timing.IsFirstTimePredicted)
return;
var spellArgs = new CP14SpellEffectBaseArgs(args.Performer, args.Action.Comp.Container, args.Performer, Transform(args.Performer).Coordinates);
foreach (var effect in args.Effects)
{
effect.Effect(EntityManager, spellArgs);
}
args.Handled = true;
}
private void OnWorldTargetCast(Entity<TransformComponent> ent, ref CP14WorldTargetModularEffectEvent args)
{
if (!_timing.IsFirstTimePredicted)
return;
var spellArgs = new CP14SpellEffectBaseArgs(args.Performer, args.Action.Comp.Container, null, args.Target);
foreach (var effect in args.Effects)
{
effect.Effect(EntityManager, spellArgs);
}
args.Handled = true;
}
private void OnEntityTargetCast(Entity<TransformComponent> ent, ref CP14EntityTargetModularEffectEvent args)
{
if (!_timing.IsFirstTimePredicted)
return;
var spellArgs = new CP14SpellEffectBaseArgs(args.Performer, args.Action.Comp.Container, args.Target, Transform(args.Target).Coordinates);
foreach (var effect in args.Effects)
{
effect.Effect(EntityManager, spellArgs);
}
args.Handled = true;
}
}
public sealed partial class CP14InstantModularEffectEvent : InstantActionEvent
{
/// <summary>
/// Effects that will trigger at the beginning of the cast, before mana is spent. Should have no gameplay importance, just special effects, popups and sounds.
/// </summary>
[DataField]
public List<CP14SpellEffect> TelegraphyEffects = new();
[DataField]
public List<CP14SpellEffect> Effects = new();
}
public sealed partial class CP14WorldTargetModularEffectEvent : WorldTargetActionEvent
{
/// <summary>
/// Effects that will trigger at the beginning of the cast, before mana is spent. Should have no gameplay importance, just special effects, popups and sounds.
/// </summary>
[DataField]
public List<CP14SpellEffect> TelegraphyEffects = new();
[DataField]
public List<CP14SpellEffect> Effects = new();
}
public sealed partial class CP14EntityTargetModularEffectEvent : EntityTargetActionEvent
{
/// <summary>
/// Effects that will trigger at the beginning of the cast, before mana is spent. Should have no gameplay importance, just special effects, popups and sounds.
/// </summary>
[DataField]
public List<CP14SpellEffect> TelegraphyEffects = new();
[DataField]
public List<CP14SpellEffect> Effects = new();
}