Magic spells code expansion (#692)
* split manacost in separate component * stamina spells * toggleable actions * swap activeCasting on ActiveDoAfter * remove dublication * Update CP14SharedMagicSystem.ToggleableActions.cs * EntityWoldTarget * mana glove done * fix spell scrolls interrupting * fix cooldown problem * clean up, edit stamina system
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using Content.Server._CP14.MagicEnergy;
|
||||
using Content.Server.Chat.Systems;
|
||||
using Content.Shared._CP14.MagicEnergy.Components;
|
||||
using Content.Shared._CP14.MagicSpell;
|
||||
using Content.Shared._CP14.MagicSpell.Components;
|
||||
using Content.Shared._CP14.MagicSpell.Events;
|
||||
@@ -10,6 +12,7 @@ public sealed partial class CP14MagicSystem : CP14SharedMagicSystem
|
||||
{
|
||||
[Dependency] private readonly ChatSystem _chat = default!;
|
||||
[Dependency] private readonly TransformSystem _transform = default!;
|
||||
[Dependency] private readonly CP14MagicEnergySystem _magicEnergy = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -19,6 +22,8 @@ public sealed partial class CP14MagicSystem : CP14SharedMagicSystem
|
||||
|
||||
SubscribeLocalEvent<CP14MagicEffectCastingVisualComponent, CP14StartCastMagicEffectEvent>(OnSpawnMagicVisualEffect);
|
||||
SubscribeLocalEvent<CP14MagicEffectCastingVisualComponent, CP14EndCastMagicEffectEvent>(OnDespawnMagicVisualEffect);
|
||||
|
||||
SubscribeLocalEvent<CP14MagicEffectManaCostComponent, CP14MagicEffectConsumeResourceEvent>(OnManaConsume);
|
||||
}
|
||||
|
||||
private void OnSpellSpoken(Entity<CP14MagicEffectVerbalAspectComponent> ent, ref CP14VerbalAspectSpeechEvent args)
|
||||
@@ -39,4 +44,33 @@ public sealed partial class CP14MagicSystem : CP14SharedMagicSystem
|
||||
QueueDel(ent.Comp.SpawnedEntity);
|
||||
ent.Comp.SpawnedEntity = null;
|
||||
}
|
||||
|
||||
private void OnManaConsume(Entity<CP14MagicEffectManaCostComponent> ent, ref CP14MagicEffectConsumeResourceEvent args)
|
||||
{
|
||||
if (!TryComp<CP14MagicEffectComponent>(ent, out var magicEffect))
|
||||
return;
|
||||
|
||||
var requiredMana = CalculateManacost(ent, args.Performer);
|
||||
|
||||
if (magicEffect.SpellStorage is not null &&
|
||||
TryComp<CP14MagicEnergyContainerComponent>(magicEffect.SpellStorage, out var magicStorage))
|
||||
{
|
||||
var spellEv = new CP14SpellFromSpellStorageUsedEvent(args.Performer, (ent, magicEffect), requiredMana);
|
||||
RaiseLocalEvent(magicEffect.SpellStorage.Value, ref spellEv);
|
||||
|
||||
if (magicStorage.Energy > 0)
|
||||
{
|
||||
//TODO: FIX THIS SHIT
|
||||
var cashedEnergy = magicStorage.Energy;
|
||||
_magicEnergy.TryConsumeEnergy(magicEffect.SpellStorage.Value, requiredMana, magicStorage, false);
|
||||
requiredMana = MathF.Max(0, (float)(requiredMana - cashedEnergy));
|
||||
}
|
||||
}
|
||||
|
||||
if (requiredMana > 0 &&
|
||||
TryComp<CP14MagicEnergyContainerComponent>(args.Performer, out var playerMana))
|
||||
{
|
||||
_magicEnergy.TryConsumeEnergy(args.Performer.Value, requiredMana, safe: false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user