summaryrefslogtreecommitdiff
path: root/scripts
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
parent5958d9c071915ab71aea5a5c08d79e88024f6c58 (diff)
Magicas
Diffstat (limited to 'scripts')
-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
-rw-r--r--scripts/GUI/Hud.cs17
-rw-r--r--scripts/GUI/SpellBookMenu.cs55
-rw-r--r--scripts/GUI/SpellBookMenu.cs.uid1
-rw-r--r--scripts/GUI/SpellMenuEntry.cs43
-rw-r--r--scripts/GUI/SpellMenuEntry.cs.uid1
-rw-r--r--scripts/Game.cs1
-rw-r--r--scripts/InputHandling/InputHandler.cs5
-rw-r--r--scripts/InputHandling/MainGameInputHandler.cs5
-rw-r--r--scripts/InputHandling/SpellMenuInputHandler.cs68
-rw-r--r--scripts/InputHandling/SpellMenuInputHandler.cs.uid1
-rw-r--r--scripts/Map/DungeonGenerator.cs10
-rw-r--r--scripts/Time/TurnManager.cs2
18 files changed, 272 insertions, 10 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
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<TextureProgressBar>("VBoxContainer/InfoBar/Stats/MarginContainer/HBoxContainer/AspectRatioContainer/HPbar");
+ hpBar = GetNode<TextureProgressBar>("VBoxContainer/InfoBar/Stats/MarginContainer/HBoxContainer/AspectRatioContainer/HPbar");
+ mpBar = GetNode<TextureProgressBar>("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<PackedScene>("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<VBoxContainer>("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<SpellMenuEntry>();
+
+ 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<TextureRect>("Icon");
+ shortcutLabel = GetNode<Label>("Shortcut");
+ nameLabel = GetNode<Label>("SpellName");
+ castBtn = GetNode<Button>("CastButton");
+
+ castBtn.Pressed += () => EmitSignal(SignalName.Cast, spell);
+ }
+
+ public void Initialize(SpellResource spell, char? shortcut)
+ {
+ this.spell = spell;
+ nameLabel.Text = spell.SpellName;
+ if (shortcut != null)
+ {
+ shortcutLabel.Text = $"{shortcut}";
+ }
+ else
+ {
+ shortcutLabel.Text = "";
+ }
+ icon.Texture = spell.Icon;
+ }
+}
diff --git a/scripts/GUI/SpellMenuEntry.cs.uid b/scripts/GUI/SpellMenuEntry.cs.uid
new file mode 100644
index 0000000..eb17e04
--- /dev/null
+++ b/scripts/GUI/SpellMenuEntry.cs.uid
@@ -0,0 +1 @@
+uid://bg766ly1f747t
diff --git a/scripts/Game.cs b/scripts/Game.cs
index ff10eea..5c1b634 100644
--- a/scripts/Game.cs
+++ b/scripts/Game.cs
@@ -47,6 +47,7 @@ public partial class Game : Node
Camera2D camera = GetNode<Camera2D>("Camera2D");
RemoveChild(camera);
player.HealthChanged += (int hp, int maxHp) => hud.OnHealthChanged(hp, maxHp);
+ player.ManaChanged += hud.OnManaChanged;
player.Died += () => InputHandler.SetInputHandler(InputHandlers.GameOver);
player.AddChild(camera);
diff --git a/scripts/InputHandling/InputHandler.cs b/scripts/InputHandling/InputHandler.cs
index a1e9b03..ce265a1 100644
--- a/scripts/InputHandling/InputHandler.cs
+++ b/scripts/InputHandling/InputHandler.cs
@@ -13,7 +13,8 @@ public enum InputHandlers
Inspect,
Pickup,
Inventory,
- CastSpell
+ CastSpell,
+ SpellMenu
}
/// <summary>
@@ -43,6 +44,8 @@ public partial class InputHandler : Node
InputHandlerDict.Add(InputHandlers.Inventory, GetNode<InventoryInputHandler>("InventoryInputHandler"));
// Controles para quando o jogador precisar escolher um alvo de feitiço.
InputHandlerDict.Add(InputHandlers.CastSpell, GetNode<CastSpellInputHandler>("CastSpellInputHandler"));
+ // Controles para quando o menu de feitiços for aberto.
+ InputHandlerDict.Add(InputHandlers.SpellMenu, GetNode<SpellMenuInputHandler>("SpellMenuInputHandler"));
SetInputHandler(StartingInputHandler);
diff --git a/scripts/InputHandling/MainGameInputHandler.cs b/scripts/InputHandling/MainGameInputHandler.cs
index fe8e573..6a110d7 100644
--- a/scripts/InputHandling/MainGameInputHandler.cs
+++ b/scripts/InputHandling/MainGameInputHandler.cs
@@ -48,6 +48,11 @@ public partial class MainGameInputHandler : BaseInputHandler
GetParent<InputHandler>().SetInputHandler(InputHandlers.Inspect);
}
+ if (Input.IsActionJustPressed("open-spellbook"))
+ {
+ GetParent<InputHandler>().SetInputHandler(InputHandlers.SpellMenu);
+ }
+
if (Input.IsActionJustPressed("skip-turn"))
{
action = new WaitAction(player);
diff --git a/scripts/InputHandling/SpellMenuInputHandler.cs b/scripts/InputHandling/SpellMenuInputHandler.cs
new file mode 100644
index 0000000..ba9c128
--- /dev/null
+++ b/scripts/InputHandling/SpellMenuInputHandler.cs
@@ -0,0 +1,68 @@
+using Godot;
+using TheLegendOfGustav.Entities.Actions;
+using TheLegendOfGustav.Entities.Actors;
+using TheLegendOfGustav.GUI;
+using TheLegendOfGustav.Magic;
+using TheLegendOfGustav.Utils;
+
+namespace TheLegendOfGustav.InputHandling;
+
+public partial class SpellMenuInputHandler : BaseInputHandler
+{
+ private static readonly PackedScene spellMenuScene = GD.Load<PackedScene>("res://scenes/GUI/spellbook_menu.tscn");
+
+ [Export]
+ private Map.Map map;
+
+ private SpellBookMenu spellBookMenu;
+ private SpellResource spellCast = null;
+
+ public override void Enter()
+ {
+ spellBookMenu = spellMenuScene.Instantiate<SpellBookMenu>();
+ map.MapData.Player.AddChild(spellBookMenu);
+ spellBookMenu.Initialize(map.MapData.Player.SpellBook);
+ spellBookMenu.SpellSelected += OnSpellCast;
+ }
+
+ public override void Exit()
+ {
+ spellCast = null;
+ spellBookMenu.QueueFree();
+ }
+
+ public override Action GetAction(Player player)
+ {
+ Action action = null;
+
+ if (spellCast != null)
+ {
+ if (spellCast.Type == SpellType.Ranged)
+ {
+ SignalBus.Instance.EmitSignal(SignalBus.SignalName.PlayerSpellChooseLocation, spellCast);
+ GetParent<InputHandler>().SetInputHandler(InputHandlers.CastSpell);
+ return action;
+ }
+ action = new SpellAction(player, Vector2I.Zero, spellCast);
+ Close();
+ return action;
+ }
+
+ if (Input.IsActionJustPressed("quit"))
+ {
+ Close();
+ }
+
+ return action;
+ }
+
+ private void Close()
+ {
+ GetParent<InputHandler>().SetInputHandler(InputHandlers.MainGame);
+ }
+
+ private void OnSpellCast(SpellResource spell)
+ {
+ spellCast = spell;
+ }
+} \ No newline at end of file
diff --git a/scripts/InputHandling/SpellMenuInputHandler.cs.uid b/scripts/InputHandling/SpellMenuInputHandler.cs.uid
new file mode 100644
index 0000000..443ac59
--- /dev/null
+++ b/scripts/InputHandling/SpellMenuInputHandler.cs.uid
@@ -0,0 +1 @@
+uid://bllj3j2wa4ebm
diff --git a/scripts/Map/DungeonGenerator.cs b/scripts/Map/DungeonGenerator.cs
index 6f239ac..f2f00a9 100644
--- a/scripts/Map/DungeonGenerator.cs
+++ b/scripts/Map/DungeonGenerator.cs
@@ -23,7 +23,8 @@ public partial class DungeonGenerator : Node
private static readonly Godot.Collections.Array<ConsumableItemDefinition> items = [
GD.Load<HealingConsumableDefinition>("res://assets/definitions/Items/small_healing_potion.tres"),
- GD.Load<ScrollConsumableDefinition>("res://assets/definitions/Items/mana_bolt_scroll.tres")
+ GD.Load<ScrollConsumableDefinition>("res://assets/definitions/Items/mana_bolt_scroll.tres"),
+ GD.Load<GrimoireConsumableDefinition>("res://assets/definitions/Items/mana_bolt_grimoire.tres")
];
#endregion
@@ -293,10 +294,15 @@ public partial class DungeonGenerator : Node
{
HealingConsumable item = new(position, data, hcDefinition);
data.InsertEntity(item);
- } else if (definition is ScrollConsumableDefinition scroll)
+ }
+ else if (definition is ScrollConsumableDefinition scroll)
{
ScrollConsumable item = new(position, data, scroll);
data.InsertEntity(item);
+ } else if (definition is GrimoireConsumableDefinition grimoire)
+ {
+ GrimoireConsumable item = new(position, data, grimoire);
+ data.InsertEntity(item);
}
}
}
diff --git a/scripts/Time/TurnManager.cs b/scripts/Time/TurnManager.cs
index 3937aa0..e8f2db9 100644
--- a/scripts/Time/TurnManager.cs
+++ b/scripts/Time/TurnManager.cs
@@ -101,7 +101,7 @@ public partial class TurnManager(Map.Map map) : RefCounted
{
if (entity is Actor actor && actor.IsAlive)
{
- actor.RechargeEnergy();
+ actor.OnTurnStart(TurnCount);
}
}
}