From 1e17a31e3eeed8ccf76982534002513cee6593f1 Mon Sep 17 00:00:00 2001 From: Matheus Date: Sun, 14 Sep 2025 10:41:08 -0300 Subject: Magicas --- scripts/Entities/Actions/SpellAction.cs | 2 ++ scripts/Entities/Actors/Actor.cs | 36 ++++++++++++++++++++-- scripts/Entities/Items/GrimoireConsumable.cs | 22 +++++++++++++ scripts/Entities/Items/GrimoireConsumable.cs.uid | 1 + .../Entities/Items/GrimoireConsumableDefinition.cs | 11 +++++++ .../Items/GrimoireConsumableDefinition.cs.uid | 1 + 6 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 scripts/Entities/Items/GrimoireConsumable.cs create mode 100644 scripts/Entities/Items/GrimoireConsumable.cs.uid create mode 100644 scripts/Entities/Items/GrimoireConsumableDefinition.cs create mode 100644 scripts/Entities/Items/GrimoireConsumableDefinition.cs.uid (limited to 'scripts/Entities') diff --git a/scripts/Entities/Actions/SpellAction.cs b/scripts/Entities/Actions/SpellAction.cs index f8819b9..d9e9952 100644 --- a/scripts/Entities/Actions/SpellAction.cs +++ b/scripts/Entities/Actions/SpellAction.cs @@ -46,6 +46,8 @@ public partial class SpellAction : DirectionalAction return false; } + Actor.Mp -= spell.Cost; + foreach (SpellEffect effect in spell.Effects) { effect.Apply(Actor, target); diff --git a/scripts/Entities/Actors/Actor.cs b/scripts/Entities/Actors/Actor.cs index 8eee4e2..7e228f8 100644 --- a/scripts/Entities/Actors/Actor.cs +++ b/scripts/Entities/Actors/Actor.cs @@ -34,6 +34,14 @@ public partial class Actor : Entity [Signal] public delegate void HealthChangedEventHandler(int hp, int maxHp); + /// + /// Sinal emitido toda vez que a mana mudar. + /// + /// Nova mana + /// Quantidade máxima de mana + [Signal] + public delegate void ManaChangedEventHandler(int mp, int maxMp); + /// /// Sinal emitido se o ator morrer. /// @@ -106,6 +114,7 @@ public partial class Actor : Entity set { mp = int.Clamp(value, 0, MaxMp); + EmitSignal(SignalName.ManaChanged, Mp, MaxMp); } } @@ -124,6 +133,15 @@ public partial class Actor : Entity /// public int Men { get; private set; } + /// + /// Quantos turnos para recarregar a mana. + /// + public int MpRegenRate { get; private set; } = 2; + /// + /// Quanto de mana para recarregar. + /// + public int MpRegenPerTurn { get; private set; } = 5; + /// /// A definição do ator possui caracterísitcas padrões que definem /// o ator em questão. @@ -139,13 +157,27 @@ public partial class Actor : Entity #region Methods /// - /// Executado uma vez por turno, + /// Recarrega a energia do ator. /// - public void RechargeEnergy() + private void RechargeEnergy() { Energy += Speed; } + /// + /// Executado uma vez por + /// + /// Número do turno. + public void OnTurnStart(int turn) + { + RechargeEnergy(); + + if (turn % MpRegenRate == 0 && Mp < MaxMp) + { + Mp += MpRegenPerTurn; + } + } + /// /// Move o ator para uma localização. Veja MovementAction. /// diff --git a/scripts/Entities/Items/GrimoireConsumable.cs b/scripts/Entities/Items/GrimoireConsumable.cs new file mode 100644 index 0000000..e5157a7 --- /dev/null +++ b/scripts/Entities/Items/GrimoireConsumable.cs @@ -0,0 +1,22 @@ +using Godot; +using TheLegendOfGustav.Entities.Actions; +using TheLegendOfGustav.Entities.Actors; +using TheLegendOfGustav.Magic; +using TheLegendOfGustav.Map; + +namespace TheLegendOfGustav.Entities.Items; + +public partial class GrimoireConsumable(Vector2I initialPosition, MapData map, GrimoireConsumableDefinition definition) : ConsumableItem(initialPosition, map, definition) +{ + private SpellResource spell = definition.Spell; + + public override bool Activate(ItemAction action) + { + Player consumer = action.Player; + + consumer.SpellBook.LearnSpell(spell); + + ConsumedBy(consumer); + return true; + } +} \ No newline at end of file diff --git a/scripts/Entities/Items/GrimoireConsumable.cs.uid b/scripts/Entities/Items/GrimoireConsumable.cs.uid new file mode 100644 index 0000000..2d56832 --- /dev/null +++ b/scripts/Entities/Items/GrimoireConsumable.cs.uid @@ -0,0 +1 @@ +uid://cdk0yd56njql0 diff --git a/scripts/Entities/Items/GrimoireConsumableDefinition.cs b/scripts/Entities/Items/GrimoireConsumableDefinition.cs new file mode 100644 index 0000000..4b041c1 --- /dev/null +++ b/scripts/Entities/Items/GrimoireConsumableDefinition.cs @@ -0,0 +1,11 @@ +using Godot; +using TheLegendOfGustav.Magic; + +namespace TheLegendOfGustav.Entities.Items; + +[GlobalClass] +public partial class GrimoireConsumableDefinition : ConsumableItemDefinition +{ + [Export] + public SpellResource Spell { get; set; } +} \ No newline at end of file diff --git a/scripts/Entities/Items/GrimoireConsumableDefinition.cs.uid b/scripts/Entities/Items/GrimoireConsumableDefinition.cs.uid new file mode 100644 index 0000000..97ad272 --- /dev/null +++ b/scripts/Entities/Items/GrimoireConsumableDefinition.cs.uid @@ -0,0 +1 @@ +uid://blkth0in1fp74 -- cgit v1.2.3