From 1e17a31e3eeed8ccf76982534002513cee6593f1 Mon Sep 17 00:00:00 2001 From: Matheus Date: Sun, 14 Sep 2025 10:41:08 -0300 Subject: Magicas --- assets/definitions/Items/mana_bolt_grimoire.tres | 14 +++++ assets/definitions/spells/mana_bolt.tres | 4 +- assets/sprites/items/grimoire.png | Bin 0 -> 238 bytes assets/sprites/items/grimoire.png.import | 34 +++++++++++ assets/sprites/items/grimoire.pxo | Bin 0 -> 850 bytes assets/sprites/spells/mana_bolt.png | Bin 0 -> 350 bytes assets/sprites/spells/mana_bolt.png.import | 34 +++++++++++ assets/sprites/spells/mana_bolt.pxo | Bin 0 -> 955 bytes project.godot | 5 ++ scenes/GUI/spell_menu_entry.tscn | 31 ++++++++++ scenes/GUI/spellbook_menu.tscn | 36 +++++++++++ scenes/Game.tscn | 7 ++- 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 +- 30 files changed, 435 insertions(+), 12 deletions(-) create mode 100644 assets/definitions/Items/mana_bolt_grimoire.tres create mode 100644 assets/sprites/items/grimoire.png create mode 100644 assets/sprites/items/grimoire.png.import create mode 100644 assets/sprites/items/grimoire.pxo create mode 100644 assets/sprites/spells/mana_bolt.png create mode 100644 assets/sprites/spells/mana_bolt.png.import create mode 100644 assets/sprites/spells/mana_bolt.pxo create mode 100644 scenes/GUI/spell_menu_entry.tscn create mode 100644 scenes/GUI/spellbook_menu.tscn 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 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 new file mode 100644 index 0000000..7bf651d Binary files /dev/null and b/assets/sprites/items/grimoire.png differ 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 new file mode 100644 index 0000000..ccd1a31 Binary files /dev/null and b/assets/sprites/items/grimoire.pxo differ diff --git a/assets/sprites/spells/mana_bolt.png b/assets/sprites/spells/mana_bolt.png new file mode 100644 index 0000000..7a70b37 Binary files /dev/null and b/assets/sprites/spells/mana_bolt.png differ 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 new file mode 100644 index 0000000..fd99e97 Binary files /dev/null and b/assets/sprites/spells/mana_bolt.pxo differ 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 @@ -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