summaryrefslogtreecommitdiff
path: root/scripts/Entities/Items
diff options
context:
space:
mode:
authorMatheus <matheus.guedes.mg.m@gmail.com>2025-09-09 19:09:34 -0300
committerMatheus <matheus.guedes.mg.m@gmail.com>2025-09-09 19:09:34 -0300
commitc6bbb834f7758027c0df338f1520f34fad3befea (patch)
tree1818cd23c24be16fbe19b16dd0a510874d440d83 /scripts/Entities/Items
parentf1b51bed52ffbd90b5b7cc8dcfc6f0484bbbeb3c (diff)
Organização
Diffstat (limited to 'scripts/Entities/Items')
-rw-r--r--scripts/Entities/Items/ConsumableItem.cs40
-rw-r--r--scripts/Entities/Items/ConsumableItem.cs.uid1
-rw-r--r--scripts/Entities/Items/ConsumableItemDefinition.cs9
-rw-r--r--scripts/Entities/Items/ConsumableItemDefinition.cs.uid1
-rw-r--r--scripts/Entities/Items/HealingConsumable.cs30
-rw-r--r--scripts/Entities/Items/HealingConsumable.cs.uid1
-rw-r--r--scripts/Entities/Items/HealingConsumableDefinition.cs14
-rw-r--r--scripts/Entities/Items/HealingConsumableDefinition.cs.uid1
8 files changed, 97 insertions, 0 deletions
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;
+
+/// <summary>
+/// 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)
+{
+
+ /// <summary>
+ /// Gera uma ação onde o ator consome o item.
+ /// </summary>
+ /// <param name="consumer"></param>
+ /// <returns></returns>
+ public Action GetAction(Player consumer)
+ {
+ return new ItemAction(consumer, this);
+ }
+
+ /// <summary>
+ /// 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.
+ /// </summary>
+ /// <param name="action">Ação gerada pelo item.</param>
+ /// <returns>Se a ação foi realizada ou não.</returns>
+ 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;
+
+/// <summary>
+/// Esta classe só existe para agrupar seus descendentes.
+/// </summary>
+[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
+{
+ ///<summary>
+ /// Porcentagem da vida do ator para restaurar.
+ ///</summary>
+ [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