2025-02-14 16:19:33 +03:00
|
|
|
using Content.Shared._CP14.MagicSpell.Components;
|
|
|
|
|
using Content.Shared._CP14.MagicSpell.Events;
|
|
|
|
|
using Content.Shared._CP14.MagicSpell.Spells;
|
|
|
|
|
|
|
|
|
|
namespace Content.Shared._CP14.MagicSpell;
|
|
|
|
|
|
|
|
|
|
public abstract partial class CP14SharedMagicSystem
|
|
|
|
|
{
|
|
|
|
|
private void InitializeInstantActions()
|
|
|
|
|
{
|
|
|
|
|
SubscribeLocalEvent<CP14InstantActionEvent>(OnMagicInstantAction);
|
|
|
|
|
SubscribeLocalEvent<CP14EntityWorldTargetActionEvent>(OnMagicEntityWorldTargetAction);
|
|
|
|
|
SubscribeLocalEvent<CP14EntityTargetActionEvent>(OnMagicEntityTargetAction);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnMagicInstantAction(CP14InstantActionEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (args.Handled)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!TryComp<CP14MagicEffectComponent>(args.Action, out var magicEffect))
|
|
|
|
|
return;
|
|
|
|
|
|
2025-05-01 00:25:10 +10:00
|
|
|
var spellArgs = new CP14SpellEffectBaseArgs(args.Performer, magicEffect.SpellStorage, args.Performer, Transform(args.Performer).Coordinates);
|
2025-02-14 16:19:33 +03:00
|
|
|
|
2025-05-01 00:25:10 +10:00
|
|
|
if (!CanCastSpell((args.Action, magicEffect), spellArgs))
|
|
|
|
|
return;
|
2025-02-14 16:19:33 +03:00
|
|
|
|
|
|
|
|
CastSpell((args.Action, magicEffect), spellArgs);
|
|
|
|
|
_action.CP14StartCustomDelay(args.Action, args.Cooldown);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnMagicEntityWorldTargetAction(CP14EntityWorldTargetActionEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (args.Handled)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!TryComp<CP14MagicEffectComponent>(args.Action, out var magicEffect))
|
|
|
|
|
return;
|
|
|
|
|
|
2025-05-01 00:25:10 +10:00
|
|
|
var spellArgs = new CP14SpellEffectBaseArgs(args.Performer, magicEffect.SpellStorage, args.Entity, args.Coords);
|
2025-02-14 16:19:33 +03:00
|
|
|
|
2025-05-01 00:25:10 +10:00
|
|
|
if (!CanCastSpell((args.Action, magicEffect), spellArgs))
|
|
|
|
|
return;
|
2025-02-14 16:19:33 +03:00
|
|
|
|
|
|
|
|
CastSpell((args.Action, magicEffect), spellArgs);
|
|
|
|
|
_action.CP14StartCustomDelay(args.Action, args.Cooldown);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnMagicEntityTargetAction(CP14EntityTargetActionEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (args.Handled)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!TryComp<CP14MagicEffectComponent>(args.Action, out var magicEffect))
|
|
|
|
|
return;
|
|
|
|
|
|
2025-05-01 00:25:10 +10:00
|
|
|
var spellArgs = new CP14SpellEffectBaseArgs(args.Performer, magicEffect.SpellStorage, args.Target, Transform(args.Target).Coordinates);
|
2025-02-14 16:19:33 +03:00
|
|
|
|
2025-05-01 00:25:10 +10:00
|
|
|
if (!CanCastSpell((args.Action, magicEffect), spellArgs))
|
|
|
|
|
return;
|
2025-02-14 16:19:33 +03:00
|
|
|
|
|
|
|
|
CastSpell((args.Action, magicEffect), spellArgs);
|
|
|
|
|
_action.CP14StartCustomDelay(args.Action, args.Cooldown);
|
|
|
|
|
}
|
|
|
|
|
}
|