Files
Red 930caa30b3 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

101 lines
3.5 KiB
C#

using Content.Shared._CP14.MagicSpell.Spells;
using Content.Shared.CombatMode.Pacification;
using Content.Shared.Throwing;
using Content.Shared.Weapons.Melee.Events;
using Content.Shared.Whitelist;
using Robust.Shared.Physics.Events;
using Robust.Shared.Random;
namespace Content.Server._CP14.MagicSpell;
public sealed class CP14MagicSystem : EntitySystem
{
[Dependency] private readonly EntityLookupSystem _lookup = default!;
[Dependency] private readonly EntityWhitelistSystem _whitelist = default!;
[Dependency] private readonly IRobustRandom _random = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<CP14AreaEntityEffectComponent, MapInitEvent>(OnAoEMapInit);
SubscribeLocalEvent<CP14SpellEffectOnHitComponent, MeleeHitEvent>(OnMeleeHit);
SubscribeLocalEvent<CP14SpellEffectOnHitComponent, ThrowDoHitEvent>(OnProjectileHit);
SubscribeLocalEvent<CP14SpellEffectOnCollideComponent, StartCollideEvent>(OnStartCollide);
}
private void OnStartCollide(Entity<CP14SpellEffectOnCollideComponent> ent, ref StartCollideEvent args)
{
if (!_random.Prob(ent.Comp.Prob))
return;
if (ent.Comp.Whitelist is not null && !_whitelist.IsValid(ent.Comp.Whitelist, args.OtherEntity))
return;
foreach (var effect in ent.Comp.Effects)
{
effect.Effect(EntityManager, new CP14SpellEffectBaseArgs(null, ent, args.OtherEntity, Transform(args.OtherEntity).Coordinates));
}
}
private void OnProjectileHit(Entity<CP14SpellEffectOnHitComponent> ent, ref ThrowDoHitEvent args)
{
if (!_random.Prob(ent.Comp.Prob))
return;
if (ent.Comp.Whitelist is not null && !_whitelist.IsValid(ent.Comp.Whitelist, args.Target))
return;
foreach (var effect in ent.Comp.Effects)
{
effect.Effect(EntityManager, new CP14SpellEffectBaseArgs(args.Thrown, ent, args.Target, Transform(args.Target).Coordinates));
}
}
private void OnMeleeHit(Entity<CP14SpellEffectOnHitComponent> ent, ref MeleeHitEvent args)
{
if (HasComp<PacifiedComponent>(args.User)) //IDK how to check if the user is pacified in a better way
return;
if (!args.IsHit)
return;
if (!_random.Prob(ent.Comp.Prob))
return;
foreach (var entity in args.HitEntities)
{
if (ent.Comp.Whitelist is not null && !_whitelist.IsValid(ent.Comp.Whitelist, entity))
continue;
foreach (var effect in ent.Comp.Effects)
{
effect.Effect(EntityManager, new CP14SpellEffectBaseArgs(args.User, ent, entity, Transform(entity).Coordinates));
}
}
}
private void OnAoEMapInit(Entity<CP14AreaEntityEffectComponent> ent, ref MapInitEvent args)
{
var entitiesAround = _lookup.GetEntitiesInRange(ent, ent.Comp.Range, LookupFlags.Uncontained);
var count = 0;
foreach (var entity in entitiesAround)
{
if (ent.Comp.Whitelist is not null && !_whitelist.IsValid(ent.Comp.Whitelist, entity))
continue;
foreach (var effect in ent.Comp.Effects)
{
effect.Effect(EntityManager, new CP14SpellEffectBaseArgs(ent, null, entity, Transform(entity).Coordinates));
}
count++;
if (ent.Comp.MaxTargets > 0 && count >= ent.Comp.MaxTargets)
break;
}
}
}