summaryrefslogtreecommitdiff
path: root/scripts/Entities
diff options
context:
space:
mode:
authorMatheus <matheus.guedes.mg.m@gmail.com>2025-09-14 10:41:08 -0300
committerMatheus <matheus.guedes.mg.m@gmail.com>2025-09-14 10:41:08 -0300
commit1e17a31e3eeed8ccf76982534002513cee6593f1 (patch)
tree74d8e4fbf706b1008edcd699b0ba7af2d6bb34ea /scripts/Entities
parent5958d9c071915ab71aea5a5c08d79e88024f6c58 (diff)
Magicas
Diffstat (limited to 'scripts/Entities')
-rw-r--r--scripts/Entities/Actions/SpellAction.cs2
-rw-r--r--scripts/Entities/Actors/Actor.cs36
-rw-r--r--scripts/Entities/Items/GrimoireConsumable.cs22
-rw-r--r--scripts/Entities/Items/GrimoireConsumable.cs.uid1
-rw-r--r--scripts/Entities/Items/GrimoireConsumableDefinition.cs11
-rw-r--r--scripts/Entities/Items/GrimoireConsumableDefinition.cs.uid1
6 files changed, 71 insertions, 2 deletions
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
@@ -35,6 +35,14 @@ public partial class Actor : Entity
public delegate void HealthChangedEventHandler(int hp, int maxHp);
/// <summary>
+ /// Sinal emitido toda vez que a mana mudar.
+ /// </summary>
+ /// <param name="mp">Nova mana</param>
+ /// <param name="maxMp">Quantidade máxima de mana</param>
+ [Signal]
+ public delegate void ManaChangedEventHandler(int mp, int maxMp);
+
+ /// <summary>
/// Sinal emitido se o ator morrer.
/// </summary>
[Signal]
@@ -106,6 +114,7 @@ public partial class Actor : Entity
set
{
mp = int.Clamp(value, 0, MaxMp);
+ EmitSignal(SignalName.ManaChanged, Mp, MaxMp);
}
}
@@ -125,6 +134,15 @@ public partial class Actor : Entity
public int Men { get; private set; }
/// <summary>
+ /// Quantos turnos para recarregar a mana.
+ /// </summary>
+ public int MpRegenRate { get; private set; } = 2;
+ /// <summary>
+ /// Quanto de mana para recarregar.
+ /// </summary>
+ public int MpRegenPerTurn { get; private set; } = 5;
+
+ /// <summary>
/// A definição do ator possui caracterísitcas padrões que definem
/// o ator em questão.
/// </summary>
@@ -139,14 +157,28 @@ public partial class Actor : Entity
#region Methods
/// <summary>
- /// Executado uma vez por turno,
+ /// Recarrega a energia do ator.
/// </summary>
- public void RechargeEnergy()
+ private void RechargeEnergy()
{
Energy += Speed;
}
/// <summary>
+ /// Executado uma vez por
+ /// </summary>
+ /// <param name="turn">Número do turno.</param>
+ public void OnTurnStart(int turn)
+ {
+ RechargeEnergy();
+
+ if (turn % MpRegenRate == 0 && Mp < MaxMp)
+ {
+ Mp += MpRegenPerTurn;
+ }
+ }
+
+ /// <summary>
/// Move o ator para uma localização. Veja MovementAction.
/// </summary>
/// <param name="offset">Vetor que parte da posição do ator até o seu destino.</param>
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