summaryrefslogtreecommitdiff
path: root/scripts/Entities/Actors/Inventory.cs
blob: 5ae61b475262417427e893417427570d853c218e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using Godot;
using TheLegendOfGustav.Entities.Items;
using TheLegendOfGustav.Map;
using TheLegendOfGustav.Utils;

namespace TheLegendOfGustav.Entities.Actors;

public partial class Inventory(int capacity) : Node
{
	private Player player;
	public int Capacity { get; private set; } = capacity;
	public Godot.Collections.Array<Item> Items { get; private set; } = [];

	public override void _Ready()
	{
		base._Ready();
		player = GetParent<Player>();
	}

	public void Drop(Item item)
	{
		Items.Remove(item);

		MapData data = player.MapData;

		ItemEntity itemEnt = new(player.GridPosition, data, item);

		data.InsertEntity(itemEnt);
		data.EmitSignal(MapData.SignalName.EntityPlaced, itemEnt);
		
		MessageLogData.Instance.AddMessage($"Você descarta {item.Definition.DisplayName}.");
	}

	public void Add(Item item)
	{
		if (Items.Count >= Capacity) return;

		Items.Add(item);
	}

	public void RemoveItem(Item item)
	{
		Items.Remove(item);
	}
}