diff options
Diffstat (limited to 'scripts/entities/actors')
| -rw-r--r-- | scripts/entities/actors/Inventory.cs | 35 | ||||
| -rw-r--r-- | scripts/entities/actors/Inventory.cs.uid | 1 | ||||
| -rw-r--r-- | scripts/entities/actors/Player.cs | 11 | ||||
| -rw-r--r-- | scripts/entities/actors/PlayerDefinition.cs | 8 | ||||
| -rw-r--r-- | scripts/entities/actors/PlayerDefinition.cs.uid | 1 |
5 files changed, 55 insertions, 1 deletions
diff --git a/scripts/entities/actors/Inventory.cs b/scripts/entities/actors/Inventory.cs new file mode 100644 index 0000000..ea9569f --- /dev/null +++ b/scripts/entities/actors/Inventory.cs @@ -0,0 +1,35 @@ +using Godot; + +public partial class Inventory : Node { + private Player player; + + public Godot.Collections.Array<ConsumableItem> Items { get; private set; } = []; + + public int Capacity { get; private set; } + + public Inventory(int capacity) { + Capacity = capacity; + } + + public override void _Ready() { + base._Ready(); + player = GetParent<Player>(); + } + + public void Drop(ConsumableItem item) { + Items.Remove(item); + MapData data = player.Map_Data; + data.InsertEntity(item); + data.EmitSignal(MapData.SignalName.EntityPlaced, item); + item.Map_Data = data; + item.GridPosition = player.GridPosition; + + MessageLogData.Instance.AddMessage($"VocĂȘ descarta {item.DisplayName}."); + } + + public void Add(ConsumableItem item) { + if (Items.Count >= Capacity) return; + + Items.Add(item); + } +}
\ No newline at end of file diff --git a/scripts/entities/actors/Inventory.cs.uid b/scripts/entities/actors/Inventory.cs.uid new file mode 100644 index 0000000..05c2beb --- /dev/null +++ b/scripts/entities/actors/Inventory.cs.uid @@ -0,0 +1 @@ +uid://isaqxdpou22h diff --git a/scripts/entities/actors/Player.cs b/scripts/entities/actors/Player.cs index 324e67a..d1c4c7f 100644 --- a/scripts/entities/actors/Player.cs +++ b/scripts/entities/actors/Player.cs @@ -7,7 +7,16 @@ using System; [GlobalClass] public partial class Player : Actor { - public Player(Vector2I initialPosition, MapData map, ActorDefinition definition) : base(initialPosition, map, definition) + public Inventory inventory; + + public Player(Vector2I initialPosition, MapData map, PlayerDefinition definition) : base(initialPosition, map, definition) { + SetDefinition(definition); + } + + public void SetDefinition(PlayerDefinition definition) { + inventory = new(definition.InventoryCapacity); + + AddChild(inventory); } } diff --git a/scripts/entities/actors/PlayerDefinition.cs b/scripts/entities/actors/PlayerDefinition.cs new file mode 100644 index 0000000..aca07e1 --- /dev/null +++ b/scripts/entities/actors/PlayerDefinition.cs @@ -0,0 +1,8 @@ +using Godot; + +[GlobalClass] +public partial class PlayerDefinition : ActorDefinition { + [ExportCategory("Player Mechanics")] + [Export] + public int InventoryCapacity = 0; +}
\ No newline at end of file diff --git a/scripts/entities/actors/PlayerDefinition.cs.uid b/scripts/entities/actors/PlayerDefinition.cs.uid new file mode 100644 index 0000000..9d01ab9 --- /dev/null +++ b/scripts/entities/actors/PlayerDefinition.cs.uid @@ -0,0 +1 @@ +uid://bd78nfh1tsjq6 |
