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);
|
2025-06-14 02:11:36 +03:00
|
|
|
SubscribeLocalEvent<CP14WorldTargetActionEvent>(OnMagicWorldTargetAction);
|
2025-02-14 16:19:33 +03:00
|
|
|
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);
|
2025-06-10 11:49:35 +03:00
|
|
|
_action.SetCooldown(args.Action.Owner, args.Cooldown);
|
2025-02-14 16:19:33 +03:00
|
|
|
}
|
|
|
|
|
|
2025-06-14 02:11:36 +03:00
|
|
|
private void OnMagicWorldTargetAction(CP14WorldTargetActionEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (args.Handled)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!TryComp<CP14MagicEffectComponent>(args.Action, out var magicEffect))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var spellArgs = new CP14SpellEffectBaseArgs(args.Performer, magicEffect.SpellStorage, null, args.Target);
|
|
|
|
|
|
|
|
|
|
if (!CanCastSpell((args.Action, magicEffect), spellArgs))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
CastSpell((args.Action, magicEffect), spellArgs);
|
2025-06-15 21:48:20 +03:00
|
|
|
_action.SetCooldown(args.Action.Owner, args.Cooldown);
|
2025-06-14 02:11:36 +03:00
|
|
|
}
|
|
|
|
|
|
2025-02-14 16:19:33 +03:00
|
|
|
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);
|
2025-06-10 11:49:35 +03:00
|
|
|
_action.SetCooldown(args.Action.Owner, args.Cooldown);
|
2025-02-14 16:19:33 +03:00
|
|
|
}
|
|
|
|
|
}
|