From c6bbb834f7758027c0df338f1520f34fad3befea Mon Sep 17 00:00:00 2001 From: Matheus Date: Tue, 9 Sep 2025 19:09:34 -0300 Subject: Organização MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/Entities/Items/ConsumableItem.cs | 40 ++++++++++++++++++++++ scripts/Entities/Items/ConsumableItem.cs.uid | 1 + scripts/Entities/Items/ConsumableItemDefinition.cs | 9 +++++ .../Entities/Items/ConsumableItemDefinition.cs.uid | 1 + scripts/Entities/Items/HealingConsumable.cs | 30 ++++++++++++++++ scripts/Entities/Items/HealingConsumable.cs.uid | 1 + .../Entities/Items/HealingConsumableDefinition.cs | 14 ++++++++ .../Items/HealingConsumableDefinition.cs.uid | 1 + 8 files changed, 97 insertions(+) create mode 100644 scripts/Entities/Items/ConsumableItem.cs create mode 100644 scripts/Entities/Items/ConsumableItem.cs.uid create mode 100644 scripts/Entities/Items/ConsumableItemDefinition.cs create mode 100644 scripts/Entities/Items/ConsumableItemDefinition.cs.uid create mode 100644 scripts/Entities/Items/HealingConsumable.cs create mode 100644 scripts/Entities/Items/HealingConsumable.cs.uid create mode 100644 scripts/Entities/Items/HealingConsumableDefinition.cs create mode 100644 scripts/Entities/Items/HealingConsumableDefinition.cs.uid (limited to 'scripts/Entities/Items') diff --git a/scripts/Entities/Items/ConsumableItem.cs b/scripts/Entities/Items/ConsumableItem.cs new file mode 100644 index 0000000..f70983a --- /dev/null +++ b/scripts/Entities/Items/ConsumableItem.cs @@ -0,0 +1,40 @@ +using Godot; +using TheLegendOfGustav.Entities.Actions; +using TheLegendOfGustav.Entities.Actors; +using TheLegendOfGustav.Map; + +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) +{ + + /// + /// Gera uma ação onde o ator consome o item. + /// + /// + /// + public Action GetAction(Player consumer) + { + return new ItemAction(consumer, this); + } + + /// + /// Ativa a função deste item. + /// Este método é chamado pela ação gerada por ele mesmo. + /// Este método permite definir condições para a sua ativação. + /// + /// Ação gerada pelo item. + /// Se a ação foi realizada ou não. + public abstract bool Activate(ItemAction action); + + public void ConsumedBy(Player consumer) + { + Inventory inventory = consumer.Inventory; + inventory.RemoveItem(this); + QueueFree(); + } +} \ No newline at end of file diff --git a/scripts/Entities/Items/ConsumableItem.cs.uid b/scripts/Entities/Items/ConsumableItem.cs.uid new file mode 100644 index 0000000..e6c452a --- /dev/null +++ b/scripts/Entities/Items/ConsumableItem.cs.uid @@ -0,0 +1 @@ +uid://hpppt5k743x diff --git a/scripts/Entities/Items/ConsumableItemDefinition.cs b/scripts/Entities/Items/ConsumableItemDefinition.cs new file mode 100644 index 0000000..9cadc0b --- /dev/null +++ b/scripts/Entities/Items/ConsumableItemDefinition.cs @@ -0,0 +1,9 @@ +using Godot; + +namespace TheLegendOfGustav.Entities.Items; + +/// +/// Esta classe só existe para agrupar seus descendentes. +/// +[GlobalClass] +public abstract partial class ConsumableItemDefinition : EntityDefinition; \ No newline at end of file diff --git a/scripts/Entities/Items/ConsumableItemDefinition.cs.uid b/scripts/Entities/Items/ConsumableItemDefinition.cs.uid new file mode 100644 index 0000000..9ddc0f6 --- /dev/null +++ b/scripts/Entities/Items/ConsumableItemDefinition.cs.uid @@ -0,0 +1 @@ +uid://dpdju2ucehsb0 diff --git a/scripts/Entities/Items/HealingConsumable.cs b/scripts/Entities/Items/HealingConsumable.cs new file mode 100644 index 0000000..32f76a6 --- /dev/null +++ b/scripts/Entities/Items/HealingConsumable.cs @@ -0,0 +1,30 @@ +using Godot; +using TheLegendOfGustav.Entities.Actors; +using TheLegendOfGustav.Utils; +using TheLegendOfGustav.Entities.Actions; +using TheLegendOfGustav.Map; + +namespace TheLegendOfGustav.Entities.Items; + +public partial class HealingConsumable(Vector2I initialPosition, MapData map, HealingConsumableDefinition definition) : ConsumableItem(initialPosition, map, definition) +{ + private HealingConsumableDefinition Definition { get; set; } = definition; + public float HealingPercentage { get; private set; } = definition.healingPercentage; + + public override bool Activate(ItemAction action) + { + Player consumer = action.Player; + int intendedAmount = (int)(HealingPercentage / 100 * consumer.MaxHp); + int recovered = consumer.Heal(intendedAmount); + + // Se não tinha o que curar, a ativação falhou. + if (recovered == 0) + { + MessageLogData.Instance.AddMessage("Você já está saudável."); + return false; + } + MessageLogData.Instance.AddMessage($"Você consome {DisplayName} e recupera {recovered} de HP"); + ConsumedBy(consumer); + return true; + } +} \ No newline at end of file diff --git a/scripts/Entities/Items/HealingConsumable.cs.uid b/scripts/Entities/Items/HealingConsumable.cs.uid new file mode 100644 index 0000000..8f8f942 --- /dev/null +++ b/scripts/Entities/Items/HealingConsumable.cs.uid @@ -0,0 +1 @@ +uid://ct20rmjhaukge diff --git a/scripts/Entities/Items/HealingConsumableDefinition.cs b/scripts/Entities/Items/HealingConsumableDefinition.cs new file mode 100644 index 0000000..d0e5850 --- /dev/null +++ b/scripts/Entities/Items/HealingConsumableDefinition.cs @@ -0,0 +1,14 @@ +using Godot; + +namespace TheLegendOfGustav.Entities.Items; + +[GlobalClass] +public partial class HealingConsumableDefinition : ConsumableItemDefinition +{ + /// + /// Porcentagem da vida do ator para restaurar. + /// + [ExportCategory("Item Mechanics")] + [Export] + public float healingPercentage = 10; +} \ No newline at end of file diff --git a/scripts/Entities/Items/HealingConsumableDefinition.cs.uid b/scripts/Entities/Items/HealingConsumableDefinition.cs.uid new file mode 100644 index 0000000..2fd311d --- /dev/null +++ b/scripts/Entities/Items/HealingConsumableDefinition.cs.uid @@ -0,0 +1 @@ +uid://b3qy4gtjfci14 -- cgit v1.2.3