summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorMatheus <matheus.guedes.mg.m@gmail.com>2025-09-13 11:06:46 -0300
committerMatheus <matheus.guedes.mg.m@gmail.com>2025-09-13 11:06:46 -0300
commit539fd4820f37aa54df8878091db9680d89ee027a (patch)
tree41f9f5d6aa123058e3549c1baba4155fa5a85279 /scripts
parentb8962990ddb75b874a49c83d8eeaba7b7e45c196 (diff)
pergaminho
Diffstat (limited to 'scripts')
-rw-r--r--scripts/Entities/Actions/SpellAction.cs33
-rw-r--r--scripts/Entities/Actions/SpellAction.cs.uid1
-rw-r--r--scripts/Entities/Actors/Actor.cs3
-rw-r--r--scripts/Entities/Items/ConsumableItem.cs2
-rw-r--r--scripts/Entities/Items/ScrollConsumable.cs25
-rw-r--r--scripts/Entities/Items/ScrollConsumable.cs.uid1
-rw-r--r--scripts/Entities/Items/ScrollConsumableDefinition.cs11
-rw-r--r--scripts/Entities/Items/ScrollConsumableDefinition.cs.uid1
-rw-r--r--scripts/Magic/DamageEffect.cs18
-rw-r--r--scripts/Magic/DamageEffect.cs.uid1
-rw-r--r--scripts/Magic/Spell.cs.uid1
-rw-r--r--scripts/Magic/SpellBook.cs20
-rw-r--r--scripts/Magic/SpellBook.cs.uid1
-rw-r--r--scripts/Magic/SpellEffect.cs10
-rw-r--r--scripts/Magic/SpellEffect.cs.uid1
-rw-r--r--scripts/Magic/SpellResource.cs36
-rw-r--r--scripts/Magic/SpellResource.cs.uid1
-rw-r--r--scripts/Map/DungeonGenerator.cs8
18 files changed, 171 insertions, 3 deletions
diff --git a/scripts/Entities/Actions/SpellAction.cs b/scripts/Entities/Actions/SpellAction.cs
new file mode 100644
index 0000000..086a52a
--- /dev/null
+++ b/scripts/Entities/Actions/SpellAction.cs
@@ -0,0 +1,33 @@
+using Godot;
+using TheLegendOfGustav.Entities.Actors;
+using TheLegendOfGustav.Magic;
+
+namespace TheLegendOfGustav.Entities.Actions;
+
+public partial class SpellCommand(Actor actor, Vector2I offset, SpellResource spell) : DirectionalAction(actor, offset)
+{
+ private SpellResource spell = spell;
+
+ public override bool Perform()
+ {
+ Actor target = null;
+
+ if (GetTarget() is Actor actor)
+ {
+ target = actor;
+ }
+
+ if (spell.Type == SpellType.Ranged && target == null) return false;
+
+ if (Actor.Mp < spell.Cost)
+ {
+ return false;
+ }
+
+ foreach (SpellEffect effect in spell.Effects)
+ {
+ effect.Apply(Actor, target);
+ }
+ return true;
+ }
+}
diff --git a/scripts/Entities/Actions/SpellAction.cs.uid b/scripts/Entities/Actions/SpellAction.cs.uid
new file mode 100644
index 0000000..6f85025
--- /dev/null
+++ b/scripts/Entities/Actions/SpellAction.cs.uid
@@ -0,0 +1 @@
+uid://b18wblvggpev0
diff --git a/scripts/Entities/Actors/Actor.cs b/scripts/Entities/Actors/Actor.cs
index 7e6685f..8eee4e2 100644
--- a/scripts/Entities/Actors/Actor.cs
+++ b/scripts/Entities/Actors/Actor.cs
@@ -1,4 +1,5 @@
using Godot;
+using TheLegendOfGustav.Magic;
using TheLegendOfGustav.Map;
using TheLegendOfGustav.Utils;
@@ -132,6 +133,8 @@ public partial class Actor : Entity
get;
set;
}
+
+ public SpellBook SpellBook { get; private set; } = new();
#endregion
#region Methods
diff --git a/scripts/Entities/Items/ConsumableItem.cs b/scripts/Entities/Items/ConsumableItem.cs
index f70983a..4078bd3 100644
--- a/scripts/Entities/Items/ConsumableItem.cs
+++ b/scripts/Entities/Items/ConsumableItem.cs
@@ -9,7 +9,7 @@ namespace TheLegendOfGustav.Entities.Items;
/// Classe para itens consumíveis.
/// Itens consumíveis são itens de uso limitado.
/// </summary>
-public abstract partial class ConsumableItem(Vector2I initialPosition, MapData map, EntityDefinition definition) : Entity(initialPosition, map, definition)
+public abstract partial class ConsumableItem(Vector2I initialPosition, MapData map, ConsumableItemDefinition definition) : Entity(initialPosition, map, definition)
{
/// <summary>
diff --git a/scripts/Entities/Items/ScrollConsumable.cs b/scripts/Entities/Items/ScrollConsumable.cs
new file mode 100644
index 0000000..d260263
--- /dev/null
+++ b/scripts/Entities/Items/ScrollConsumable.cs
@@ -0,0 +1,25 @@
+using Godot;
+using TheLegendOfGustav.Entities.Actions;
+using TheLegendOfGustav.Entities.Actors;
+using TheLegendOfGustav.Magic;
+using TheLegendOfGustav.Map;
+using TheLegendOfGustav.Utils;
+
+namespace TheLegendOfGustav.Entities.Items;
+
+public partial class ScrollConsumable(Vector2I initialPosition, MapData map, ScrollConsumableDefinition definition) : ConsumableItem(initialPosition, map, definition)
+{
+ private ScrollConsumableDefinition definition = definition;
+
+ public SpellResource Spell { get; private set; } = definition.Spell;
+
+
+ public override bool Activate(ItemAction action)
+ {
+ Player consumer = action.Player;
+
+ MessageLogData.Instance.AddMessage("Foste cuckado");
+ ConsumedBy(consumer);
+ return true;
+ }
+} \ No newline at end of file
diff --git a/scripts/Entities/Items/ScrollConsumable.cs.uid b/scripts/Entities/Items/ScrollConsumable.cs.uid
new file mode 100644
index 0000000..ba79f47
--- /dev/null
+++ b/scripts/Entities/Items/ScrollConsumable.cs.uid
@@ -0,0 +1 @@
+uid://dsp0ryh6fctv1
diff --git a/scripts/Entities/Items/ScrollConsumableDefinition.cs b/scripts/Entities/Items/ScrollConsumableDefinition.cs
new file mode 100644
index 0000000..c9f50a5
--- /dev/null
+++ b/scripts/Entities/Items/ScrollConsumableDefinition.cs
@@ -0,0 +1,11 @@
+using Godot;
+using TheLegendOfGustav.Magic;
+
+namespace TheLegendOfGustav.Entities.Items;
+
+[GlobalClass]
+public partial class ScrollConsumableDefinition : ConsumableItemDefinition
+{
+ [Export]
+ public SpellResource Spell { get; set; }
+} \ No newline at end of file
diff --git a/scripts/Entities/Items/ScrollConsumableDefinition.cs.uid b/scripts/Entities/Items/ScrollConsumableDefinition.cs.uid
new file mode 100644
index 0000000..8cadd79
--- /dev/null
+++ b/scripts/Entities/Items/ScrollConsumableDefinition.cs.uid
@@ -0,0 +1 @@
+uid://2lk5w2po81gy
diff --git a/scripts/Magic/DamageEffect.cs b/scripts/Magic/DamageEffect.cs
new file mode 100644
index 0000000..abd2cca
--- /dev/null
+++ b/scripts/Magic/DamageEffect.cs
@@ -0,0 +1,18 @@
+using Godot;
+using TheLegendOfGustav.Entities.Actors;
+
+namespace TheLegendOfGustav.Magic;
+
+[GlobalClass]
+public partial class DamageEffect : SpellEffect
+{
+ [Export]
+ public int Damage { get; set; }
+
+ public override void Apply(Actor caster, Actor target)
+ {
+ int damageDealt = Damage - target.Men;
+
+ target.Hp -= damageDealt;
+ }
+} \ No newline at end of file
diff --git a/scripts/Magic/DamageEffect.cs.uid b/scripts/Magic/DamageEffect.cs.uid
new file mode 100644
index 0000000..be2d36b
--- /dev/null
+++ b/scripts/Magic/DamageEffect.cs.uid
@@ -0,0 +1 @@
+uid://cmgtdh2kdo1rq
diff --git a/scripts/Magic/Spell.cs.uid b/scripts/Magic/Spell.cs.uid
new file mode 100644
index 0000000..78c0570
--- /dev/null
+++ b/scripts/Magic/Spell.cs.uid
@@ -0,0 +1 @@
+uid://byo6rbhx6nlgh
diff --git a/scripts/Magic/SpellBook.cs b/scripts/Magic/SpellBook.cs
new file mode 100644
index 0000000..8ccba71
--- /dev/null
+++ b/scripts/Magic/SpellBook.cs
@@ -0,0 +1,20 @@
+using Godot;
+
+namespace TheLegendOfGustav.Magic;
+
+public partial class SpellBook : Node
+{
+ public Godot.Collections.Array<SpellResource> KnownSpells { get; private set; } = [];
+
+ public bool KnowsSpell(SpellResource spell) => KnownSpells.Contains(spell);
+
+ public void LearnSpell(SpellResource spell) {
+ if (!KnownSpells.Contains(spell)) {
+ KnownSpells.Add(spell);
+ }
+ }
+
+ public void ForgetSpell(SpellResource spell) {
+ KnownSpells.Remove(spell);
+ }
+} \ No newline at end of file
diff --git a/scripts/Magic/SpellBook.cs.uid b/scripts/Magic/SpellBook.cs.uid
new file mode 100644
index 0000000..d18055c
--- /dev/null
+++ b/scripts/Magic/SpellBook.cs.uid
@@ -0,0 +1 @@
+uid://bn3q4xypi2ogf
diff --git a/scripts/Magic/SpellEffect.cs b/scripts/Magic/SpellEffect.cs
new file mode 100644
index 0000000..482a64f
--- /dev/null
+++ b/scripts/Magic/SpellEffect.cs
@@ -0,0 +1,10 @@
+using Godot;
+using TheLegendOfGustav.Entities.Actors;
+
+namespace TheLegendOfGustav.Magic;
+
+[GlobalClass]
+public abstract partial class SpellEffect : Resource
+{
+ public abstract void Apply(Actor caster, Actor target);
+} \ No newline at end of file
diff --git a/scripts/Magic/SpellEffect.cs.uid b/scripts/Magic/SpellEffect.cs.uid
new file mode 100644
index 0000000..4fc1573
--- /dev/null
+++ b/scripts/Magic/SpellEffect.cs.uid
@@ -0,0 +1 @@
+uid://brhihikhjtc6e
diff --git a/scripts/Magic/SpellResource.cs b/scripts/Magic/SpellResource.cs
new file mode 100644
index 0000000..bb3fd15
--- /dev/null
+++ b/scripts/Magic/SpellResource.cs
@@ -0,0 +1,36 @@
+using Godot;
+using TheLegendOfGustav.Entities.Actions;
+using TheLegendOfGustav.Entities.Actors;
+
+namespace TheLegendOfGustav.Magic;
+
+public enum SpellType
+{
+ Ranged,
+ Self
+}
+[GlobalClass]
+public partial class SpellResource : Resource
+{
+ /// <summary>
+ /// Ícone do feitiço na interface gráfica.
+ /// </summary>
+ [ExportCategory("Visuals")]
+ [Export]
+ public Texture2D Icon { get; set; }
+ /// <summary>
+ /// Nome do feitiço na interface gráfica.
+ /// </summary>
+ [Export]
+ public string SpellName { get; set; } = "unnamed spell";
+
+ [ExportCategory("Mechanics")]
+ [Export]
+ public int Cost { get; set; }
+ [Export]
+ public SpellType Type { get; set; }
+ [Export]
+ public int Range { get; set; }
+ [Export]
+ public Godot.Collections.Array<SpellEffect> Effects { get; set; } = [];
+} \ No newline at end of file
diff --git a/scripts/Magic/SpellResource.cs.uid b/scripts/Magic/SpellResource.cs.uid
new file mode 100644
index 0000000..7472e6b
--- /dev/null
+++ b/scripts/Magic/SpellResource.cs.uid
@@ -0,0 +1 @@
+uid://bi6jdrduu76de
diff --git a/scripts/Map/DungeonGenerator.cs b/scripts/Map/DungeonGenerator.cs
index 9a44d33..6f239ac 100644
--- a/scripts/Map/DungeonGenerator.cs
+++ b/scripts/Map/DungeonGenerator.cs
@@ -22,7 +22,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<HealingConsumableDefinition>("res://assets/definitions/Items/small_healing_potion.tres"),
+ GD.Load<ScrollConsumableDefinition>("res://assets/definitions/Items/mana_bolt_scroll.tres")
];
#endregion
@@ -274,7 +275,6 @@ public partial class DungeonGenerator : Node
Rng.RandiRange(room.Position.Y, room.End.Y - 1)
);
- // Só podemos colocar um ator por ponto no espaço.
bool canPlace = true;
foreach (Entity entity in data.Entities)
{
@@ -293,6 +293,10 @@ public partial class DungeonGenerator : Node
{
HealingConsumable item = new(position, data, hcDefinition);
data.InsertEntity(item);
+ } else if (definition is ScrollConsumableDefinition scroll)
+ {
+ ScrollConsumable item = new(position, data, scroll);
+ data.InsertEntity(item);
}
}
}