diff options
Diffstat (limited to 'scripts/entities')
| -rw-r--r-- | scripts/entities/actions/DropAction.cs | 13 | ||||
| -rw-r--r-- | scripts/entities/actions/DropAction.cs.uid | 1 | ||||
| -rw-r--r-- | scripts/entities/actions/ItemAction.cs | 6 | ||||
| -rw-r--r-- | scripts/entities/actors/Actor.cs | 2 | ||||
| -rw-r--r-- | scripts/entities/actors/Inventory.cs | 4 | ||||
| -rw-r--r-- | scripts/entities/actors/Player.cs | 2 | ||||
| -rw-r--r-- | scripts/entities/items/ConsumableItem.cs | 8 | ||||
| -rw-r--r-- | scripts/entities/items/HealingConsumable.cs | 3 |
8 files changed, 34 insertions, 5 deletions
diff --git a/scripts/entities/actions/DropAction.cs b/scripts/entities/actions/DropAction.cs new file mode 100644 index 0000000..e5bd929 --- /dev/null +++ b/scripts/entities/actions/DropAction.cs @@ -0,0 +1,13 @@ +using Godot; + +public partial class DropAction : ItemAction +{ + public DropAction(Player player, ConsumableItem item) : base(player, item) + { + } + + public override bool Perform() { + player.inventory.Drop(item); + return true; + } +}
\ No newline at end of file diff --git a/scripts/entities/actions/DropAction.cs.uid b/scripts/entities/actions/DropAction.cs.uid new file mode 100644 index 0000000..98ed82f --- /dev/null +++ b/scripts/entities/actions/DropAction.cs.uid @@ -0,0 +1 @@ +uid://by48a3a3gbvfa diff --git a/scripts/entities/actions/ItemAction.cs b/scripts/entities/actions/ItemAction.cs index 54ff207..d5247df 100644 --- a/scripts/entities/actions/ItemAction.cs +++ b/scripts/entities/actions/ItemAction.cs @@ -2,10 +2,12 @@ using Godot; public partial class ItemAction : Action { - private ConsumableItem item; - public ItemAction(Actor actor, ConsumableItem item) : base(actor) + protected ConsumableItem item; + protected Player player; + public ItemAction(Player player, ConsumableItem item) : base(player) { this.item = item; + this.player = player; } public override bool Perform() diff --git a/scripts/entities/actors/Actor.cs b/scripts/entities/actors/Actor.cs index 1717cfa..1cb1f37 100644 --- a/scripts/entities/actors/Actor.cs +++ b/scripts/entities/actors/Actor.cs @@ -139,7 +139,7 @@ public partial class Actor : Entity public int Heal(int amount) { int neoHp = Hp + amount; - if (amount > MaxHp) neoHp = MaxHp; + if (neoHp > MaxHp) neoHp = MaxHp; int recovered = neoHp - Hp; Hp = neoHp; diff --git a/scripts/entities/actors/Inventory.cs b/scripts/entities/actors/Inventory.cs index ea9569f..f1cff2a 100644 --- a/scripts/entities/actors/Inventory.cs +++ b/scripts/entities/actors/Inventory.cs @@ -32,4 +32,8 @@ public partial class Inventory : Node { Items.Add(item); } + + public void RemoveItem(ConsumableItem item) { + Items.Remove(item); + } }
\ No newline at end of file diff --git a/scripts/entities/actors/Player.cs b/scripts/entities/actors/Player.cs index d1c4c7f..71812e8 100644 --- a/scripts/entities/actors/Player.cs +++ b/scripts/entities/actors/Player.cs @@ -7,10 +7,12 @@ using System; [GlobalClass] public partial class Player : Actor { + private PlayerDefinition definition; public Inventory inventory; public Player(Vector2I initialPosition, MapData map, PlayerDefinition definition) : base(initialPosition, map, definition) { + this.definition = definition; SetDefinition(definition); } diff --git a/scripts/entities/items/ConsumableItem.cs b/scripts/entities/items/ConsumableItem.cs index 8c862da..82fab49 100644 --- a/scripts/entities/items/ConsumableItem.cs +++ b/scripts/entities/items/ConsumableItem.cs @@ -15,7 +15,7 @@ public abstract partial class ConsumableItem : Entity /// </summary> /// <param name="consumer"></param> /// <returns></returns> - public Action GetAction(Actor consumer) + public Action GetAction(Player consumer) { return new ItemAction(consumer, this); } @@ -28,4 +28,10 @@ public abstract partial class ConsumableItem : Entity /// <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/HealingConsumable.cs b/scripts/entities/items/HealingConsumable.cs index 3d8df51..2104693 100644 --- a/scripts/entities/items/HealingConsumable.cs +++ b/scripts/entities/items/HealingConsumable.cs @@ -12,7 +12,7 @@ public partial class HealingConsumable : ConsumableItem public override bool Activate(ItemAction action) { - Actor consumer = action.ThisActor; + Player consumer = (Player) action.ThisActor; int intendedAmount = (int)(HealingPercentage / 100 * consumer.MaxHp); int recovered = consumer.Heal(intendedAmount); @@ -22,6 +22,7 @@ public partial class HealingConsumable : ConsumableItem return false; } MessageLogData.Instance.AddMessage($"Você consome {DisplayName} e recupera {recovered} de HP"); + ConsumedBy(consumer); return true; } }
\ No newline at end of file |
