diff options
| author | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-09-14 10:41:08 -0300 |
|---|---|---|
| committer | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-09-14 10:41:08 -0300 |
| commit | 1e17a31e3eeed8ccf76982534002513cee6593f1 (patch) | |
| tree | 74d8e4fbf706b1008edcd699b0ba7af2d6bb34ea | |
| parent | 5958d9c071915ab71aea5a5c08d79e88024f6c58 (diff) | |
Magicas
30 files changed, 435 insertions, 12 deletions
diff --git a/assets/definitions/Items/mana_bolt_grimoire.tres b/assets/definitions/Items/mana_bolt_grimoire.tres new file mode 100644 index 0000000..b134ea1 --- /dev/null +++ b/assets/definitions/Items/mana_bolt_grimoire.tres @@ -0,0 +1,14 @@ +[gd_resource type="Resource" script_class="GrimoireConsumableDefinition" load_steps=4 format=3 uid="uid://coeyeuyren2vi"] + +[ext_resource type="Resource" uid="uid://boi8svlb0e8l" path="res://assets/definitions/spells/mana_bolt.tres" id="1_dnjm5"] +[ext_resource type="Script" uid="uid://blkth0in1fp74" path="res://scripts/Entities/Items/GrimoireConsumableDefinition.cs" id="1_tv46f"] +[ext_resource type="Texture2D" uid="uid://lgxlsnp626j8" path="res://assets/sprites/items/grimoire.png" id="3_degcq"] + +[resource] +script = ExtResource("1_tv46f") +Spell = ExtResource("1_dnjm5") +name = "Grimório de flecha de mana." +texture = ExtResource("3_degcq") +Type = 1 +blocksMovement = false +metadata/_custom_type_script = "uid://blkth0in1fp74" diff --git a/assets/definitions/spells/mana_bolt.tres b/assets/definitions/spells/mana_bolt.tres index da209fb..13a2329 100644 --- a/assets/definitions/spells/mana_bolt.tres +++ b/assets/definitions/spells/mana_bolt.tres @@ -1,11 +1,13 @@ -[gd_resource type="Resource" script_class="SpellResource" load_steps=4 format=3 uid="uid://boi8svlb0e8l"] +[gd_resource type="Resource" script_class="SpellResource" load_steps=5 format=3 uid="uid://boi8svlb0e8l"] [ext_resource type="Script" uid="uid://brhihikhjtc6e" path="res://scripts/Magic/SpellEffect.cs" id="1_ux3o7"] [ext_resource type="Script" uid="uid://bi6jdrduu76de" path="res://scripts/Magic/SpellResource.cs" id="2_uq8o1"] [ext_resource type="Resource" uid="uid://2121t34hbxck" path="res://assets/definitions/spells/little_damage.tres" id="2_yltt7"] +[ext_resource type="Texture2D" uid="uid://c16x1hbiqkulw" path="res://assets/sprites/spells/mana_bolt.png" id="3_yltt7"] [resource] script = ExtResource("2_uq8o1") +Icon = ExtResource("3_yltt7") SpellName = "Flecha de mana" Cost = 8 Type = 0 diff --git a/assets/sprites/items/grimoire.png b/assets/sprites/items/grimoire.png Binary files differnew file mode 100644 index 0000000..7bf651d --- /dev/null +++ b/assets/sprites/items/grimoire.png diff --git a/assets/sprites/items/grimoire.png.import b/assets/sprites/items/grimoire.png.import new file mode 100644 index 0000000..7c8eda7 --- /dev/null +++ b/assets/sprites/items/grimoire.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://lgxlsnp626j8" +path="res://.godot/imported/grimoire.png-4de28a716ac941c013123c4aa4154d33.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/sprites/items/grimoire.png" +dest_files=["res://.godot/imported/grimoire.png-4de28a716ac941c013123c4aa4154d33.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/assets/sprites/items/grimoire.pxo b/assets/sprites/items/grimoire.pxo Binary files differnew file mode 100644 index 0000000..ccd1a31 --- /dev/null +++ b/assets/sprites/items/grimoire.pxo diff --git a/assets/sprites/spells/mana_bolt.png b/assets/sprites/spells/mana_bolt.png Binary files differnew file mode 100644 index 0000000..7a70b37 --- /dev/null +++ b/assets/sprites/spells/mana_bolt.png diff --git a/assets/sprites/spells/mana_bolt.png.import b/assets/sprites/spells/mana_bolt.png.import new file mode 100644 index 0000000..8d3e68a --- /dev/null +++ b/assets/sprites/spells/mana_bolt.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://c16x1hbiqkulw" +path="res://.godot/imported/mana_bolt.png-39a02e84aea4be3e6247b407ba4fefb6.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/sprites/spells/mana_bolt.png" +dest_files=["res://.godot/imported/mana_bolt.png-39a02e84aea4be3e6247b407ba4fefb6.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/assets/sprites/spells/mana_bolt.pxo b/assets/sprites/spells/mana_bolt.pxo Binary files differnew file mode 100644 index 0000000..fd99e97 --- /dev/null +++ b/assets/sprites/spells/mana_bolt.pxo diff --git a/project.godot b/project.godot index 5d0052e..ccb3ac6 100644 --- a/project.godot +++ b/project.godot @@ -109,6 +109,11 @@ open-inventory={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":73,"physical_keycode":0,"key_label":0,"unicode":105,"location":0,"echo":false,"script":null) ] } +open-spellbook={ +"deadzone": 0.2, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":90,"physical_keycode":0,"key_label":0,"unicode":122,"location":0,"echo":false,"script":null) +] +} [rendering] diff --git a/scenes/GUI/spell_menu_entry.tscn b/scenes/GUI/spell_menu_entry.tscn new file mode 100644 index 0000000..d50b5cd --- /dev/null +++ b/scenes/GUI/spell_menu_entry.tscn @@ -0,0 +1,31 @@ +[gd_scene load_steps=3 format=3 uid="uid://boioo6c5yu8to"] + +[ext_resource type="Script" uid="uid://bg766ly1f747t" path="res://scripts/GUI/SpellMenuEntry.cs" id="1_kcgob"] +[ext_resource type="Texture2D" uid="uid://dwky8qc2y602k" path="res://assets/sprites/actors/player.png" id="2_7wscr"] + +[node name="SpellMenuEntry" type="HBoxContainer"] +offset_right = 8.0 +offset_bottom = 8.0 +size_flags_horizontal = 3 +script = ExtResource("1_kcgob") + +[node name="Icon" type="TextureRect" parent="."] +layout_mode = 2 +texture = ExtResource("2_7wscr") +expand_mode = 3 + +[node name="Shortcut" type="Label" parent="."] +layout_mode = 2 +text = "Atalho" + +[node name="VSeparator" type="VSeparator" parent="."] +layout_mode = 2 + +[node name="SpellName" type="Label" parent="."] +layout_mode = 2 +size_flags_horizontal = 3 +text = "Nome" + +[node name="CastButton" type="Button" parent="."] +layout_mode = 2 +text = "Usar" diff --git a/scenes/GUI/spellbook_menu.tscn b/scenes/GUI/spellbook_menu.tscn new file mode 100644 index 0000000..5b11d97 --- /dev/null +++ b/scenes/GUI/spellbook_menu.tscn @@ -0,0 +1,36 @@ +[gd_scene load_steps=3 format=3 uid="uid://bdxnfkx6nq0gr"] + +[ext_resource type="Script" uid="uid://7y0q058tvq7y" path="res://scripts/GUI/SpellBookMenu.cs" id="1_27g5s"] + +[sub_resource type="LabelSettings" id="LabelSettings_mo078"] +font_size = 32 + +[node name="SpellbookMenu" type="CanvasLayer"] +layer = 2 +script = ExtResource("1_27g5s") + +[node name="CenterContainer" type="CenterContainer" parent="."] +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="PanelContainer" type="PanelContainer" parent="CenterContainer"] +layout_mode = 2 + +[node name="VBoxContainer" type="VBoxContainer" parent="CenterContainer/PanelContainer"] +layout_mode = 2 + +[node name="Title" type="Label" parent="CenterContainer/PanelContainer/VBoxContainer"] +layout_mode = 2 +text = "Feitiços" +label_settings = SubResource("LabelSettings_mo078") +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="HSeparator" type="HSeparator" parent="CenterContainer/PanelContainer/VBoxContainer"] +layout_mode = 2 + +[node name="Spells" type="VBoxContainer" parent="CenterContainer/PanelContainer/VBoxContainer"] +layout_mode = 2 diff --git a/scenes/Game.tscn b/scenes/Game.tscn index d25c3b5..96ba3c0 100644 --- a/scenes/Game.tscn +++ b/scenes/Game.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=14 format=3 uid="uid://u5h6iqyi8wd0"] +[gd_scene load_steps=15 format=3 uid="uid://u5h6iqyi8wd0"] [ext_resource type="Script" uid="uid://dwubb28wt4bhe" path="res://scripts/Game.cs" id="1_cpr0p"] [ext_resource type="Script" uid="uid://ejqmdbc0524i" path="res://scripts/InputHandling/MainGameInputHandler.cs" id="3_400sg"] @@ -13,6 +13,7 @@ [ext_resource type="Script" uid="uid://dspqgdxg5jji0" path="res://scripts/InputHandling/PickupInputHandler.cs" id="10_3xj3m"] [ext_resource type="Script" uid="uid://bjcjktvyrdh10" path="res://scripts/InputHandling/InventoryInputHandler.cs" id="11_mcffj"] [ext_resource type="Script" uid="uid://ceck6d5tjpgwf" path="res://scripts/InputHandling/CastSpellInputHandler.cs" id="12_2rd6h"] +[ext_resource type="Script" uid="uid://bllj3j2wa4ebm" path="res://scripts/InputHandling/SpellMenuInputHandler.cs" id="13_7ua8r"] [node name="Game" type="Node"] script = ExtResource("1_cpr0p") @@ -59,6 +60,10 @@ Map = NodePath("../../Map") script = ExtResource("12_2rd6h") map = NodePath("../../Map") +[node name="SpellMenuInputHandler" type="Node" parent="InputHandler" node_paths=PackedStringArray("map")] +script = ExtResource("13_7ua8r") +map = NodePath("../../Map") + [node name="Camera2D" type="Camera2D" parent="."] offset = Vector2(8, 8) zoom = Vector2(2, 2) 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); } } } |
