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 + scripts/GUI/Hud.cs | 17 ++++-- scripts/GUI/SpellBookMenu.cs | 55 +++++++++++++++++ scripts/GUI/SpellBookMenu.cs.uid | 1 + scripts/GUI/SpellMenuEntry.cs | 43 ++++++++++++++ scripts/GUI/SpellMenuEntry.cs.uid | 1 + scripts/Game.cs | 1 + scripts/InputHandling/InputHandler.cs | 5 +- scripts/InputHandling/MainGameInputHandler.cs | 5 ++ scripts/InputHandling/SpellMenuInputHandler.cs | 68 ++++++++++++++++++++++ scripts/InputHandling/SpellMenuInputHandler.cs.uid | 1 + scripts/Map/DungeonGenerator.cs | 10 +++- scripts/Time/TurnManager.cs | 2 +- 18 files changed, 272 insertions(+), 10 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 create mode 100644 scripts/GUI/SpellBookMenu.cs create mode 100644 scripts/GUI/SpellBookMenu.cs.uid create mode 100644 scripts/GUI/SpellMenuEntry.cs create mode 100644 scripts/GUI/SpellMenuEntry.cs.uid create mode 100644 scripts/InputHandling/SpellMenuInputHandler.cs create mode 100644 scripts/InputHandling/SpellMenuInputHandler.cs.uid (limited to 'scripts') 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 diff --git a/scripts/GUI/Hud.cs b/scripts/GUI/Hud.cs index 1149728..227ca32 100644 --- a/scripts/GUI/Hud.cs +++ b/scripts/GUI/Hud.cs @@ -1,20 +1,29 @@ +using System.Runtime.InteropServices; using Godot; namespace TheLegendOfGustav.GUI; public partial class Hud : Node { - private TextureProgressBar HpBar { get; set; } + private TextureProgressBar hpBar; + private TextureProgressBar mpBar; public override void _Ready() { base._Ready(); - HpBar = GetNode("VBoxContainer/InfoBar/Stats/MarginContainer/HBoxContainer/AspectRatioContainer/HPbar"); + hpBar = GetNode("VBoxContainer/InfoBar/Stats/MarginContainer/HBoxContainer/AspectRatioContainer/HPbar"); + mpBar = GetNode("VBoxContainer/InfoBar/Stats/MarginContainer/HBoxContainer/AspectRatioContainer2/MPbar"); } public void OnHealthChanged(int hp, int maxHp) { - HpBar.Value = hp; - HpBar.MaxValue = maxHp; + hpBar.Value = hp; + hpBar.MaxValue = maxHp; + } + + public void OnManaChanged(int mp, int maxMp) + { + mpBar.Value = mp; + mpBar.MaxValue = maxMp; } } diff --git a/scripts/GUI/SpellBookMenu.cs b/scripts/GUI/SpellBookMenu.cs new file mode 100644 index 0000000..ecd89a3 --- /dev/null +++ b/scripts/GUI/SpellBookMenu.cs @@ -0,0 +1,55 @@ +using Godot; +using System; +using TheLegendOfGustav.Magic; + +namespace TheLegendOfGustav.GUI; + +public partial class SpellBookMenu : CanvasLayer +{ + private static readonly PackedScene spellMenuEntryScene = GD.Load("res://scenes/GUI/spell_menu_entry.tscn"); + + private VBoxContainer spellsNode; + + [Signal] + public delegate void SpellSelectedEventHandler(SpellResource spell); + + public override void _Ready() + { + base._Ready(); + + spellsNode = GetNode("CenterContainer/PanelContainer/VBoxContainer/Spells"); + Hide(); + } + + public void OnCast(SpellResource spell) + { + EmitSignal(SignalName.SpellSelected, spell); + } + + public void Initialize(SpellBook spellBook) + { + for (int i = 0; i < spellBook.KnownSpells.Count; i++) + { + RegisterSpell(i, spellBook.KnownSpells[i]); + } + + Show(); + } + + private void RegisterSpell(int index, SpellResource spell) + { + char? shortcut = null; + + // Só terá atalho para as letras do alfabeto. + if (index < 26) + { + shortcut = (char)('a' + index); + } + + SpellMenuEntry spellEntry = spellMenuEntryScene.Instantiate(); + + spellsNode.AddChild(spellEntry); + spellEntry.Initialize(spell, shortcut); + spellEntry.Cast += OnCast; + } +} diff --git a/scripts/GUI/SpellBookMenu.cs.uid b/scripts/GUI/SpellBookMenu.cs.uid new file mode 100644 index 0000000..d4100bc --- /dev/null +++ b/scripts/GUI/SpellBookMenu.cs.uid @@ -0,0 +1 @@ +uid://7y0q058tvq7y diff --git a/scripts/GUI/SpellMenuEntry.cs b/scripts/GUI/SpellMenuEntry.cs new file mode 100644 index 0000000..2be0fcc --- /dev/null +++ b/scripts/GUI/SpellMenuEntry.cs @@ -0,0 +1,43 @@ +using Godot; +using System; +using TheLegendOfGustav.Magic; + +namespace TheLegendOfGustav.GUI; + +public partial class SpellMenuEntry : HBoxContainer +{ + private TextureRect icon; + private Label shortcutLabel; + private Label nameLabel; + private Button castBtn; + private SpellResource spell; + + [Signal] + public delegate void CastEventHandler(SpellResource Item); + + public override void _Ready() + { + base._Ready(); + icon = GetNode("Icon"); + shortcutLabel = GetNode