From 539fd4820f37aa54df8878091db9680d89ee027a Mon Sep 17 00:00:00 2001 From: Matheus Date: Sat, 13 Sep 2025 11:06:46 -0300 Subject: pergaminho --- scripts/Entities/Actions/SpellAction.cs | 33 ++++++++++++++++++++ scripts/Entities/Actions/SpellAction.cs.uid | 1 + scripts/Entities/Actors/Actor.cs | 3 ++ scripts/Entities/Items/ConsumableItem.cs | 2 +- scripts/Entities/Items/ScrollConsumable.cs | 25 +++++++++++++++ scripts/Entities/Items/ScrollConsumable.cs.uid | 1 + .../Entities/Items/ScrollConsumableDefinition.cs | 11 +++++++ .../Items/ScrollConsumableDefinition.cs.uid | 1 + scripts/Magic/DamageEffect.cs | 18 +++++++++++ scripts/Magic/DamageEffect.cs.uid | 1 + scripts/Magic/Spell.cs.uid | 1 + scripts/Magic/SpellBook.cs | 20 ++++++++++++ scripts/Magic/SpellBook.cs.uid | 1 + scripts/Magic/SpellEffect.cs | 10 ++++++ scripts/Magic/SpellEffect.cs.uid | 1 + scripts/Magic/SpellResource.cs | 36 ++++++++++++++++++++++ scripts/Magic/SpellResource.cs.uid | 1 + scripts/Map/DungeonGenerator.cs | 8 +++-- 18 files changed, 171 insertions(+), 3 deletions(-) create mode 100644 scripts/Entities/Actions/SpellAction.cs create mode 100644 scripts/Entities/Actions/SpellAction.cs.uid create mode 100644 scripts/Entities/Items/ScrollConsumable.cs create mode 100644 scripts/Entities/Items/ScrollConsumable.cs.uid create mode 100644 scripts/Entities/Items/ScrollConsumableDefinition.cs create mode 100644 scripts/Entities/Items/ScrollConsumableDefinition.cs.uid create mode 100644 scripts/Magic/DamageEffect.cs create mode 100644 scripts/Magic/DamageEffect.cs.uid create mode 100644 scripts/Magic/Spell.cs.uid create mode 100644 scripts/Magic/SpellBook.cs create mode 100644 scripts/Magic/SpellBook.cs.uid create mode 100644 scripts/Magic/SpellEffect.cs create mode 100644 scripts/Magic/SpellEffect.cs.uid create mode 100644 scripts/Magic/SpellResource.cs create mode 100644 scripts/Magic/SpellResource.cs.uid (limited to 'scripts') 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. /// -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) { /// 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 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 +{ + /// + /// Ícone do feitiço na interface gráfica. + /// + [ExportCategory("Visuals")] + [Export] + public Texture2D Icon { get; set; } + /// + /// Nome do feitiço na interface gráfica. + /// + [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 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 items = [ - GD.Load("res://assets/definitions/Items/small_healing_potion.tres") + GD.Load("res://assets/definitions/Items/small_healing_potion.tres"), + GD.Load("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); } } } -- cgit v1.2.3