summaryrefslogtreecommitdiff
path: root/scripts/Entities/Actions/PickUpAction.cs
blob: 0dbd6724a0354dd1bdb0caca66e6f3b46b7c5075 (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
46
47
48
49
50
51
using Godot;
using TheLegendOfGustav.Entities.Actors;
using TheLegendOfGustav.Utils;
using TheLegendOfGustav.Entities.Items;
using TheLegendOfGustav.Map;

namespace TheLegendOfGustav.Entities.Actions;

public partial class PickupAction : DirectionalAction
{
	private Player player;

	public PickupAction(Player player, Vector2I offset) : base(player, offset)
	{
		Player = player;
		// Pegar itens requer um tempo menor.
		Cost = 2;
	}

	protected Player Player
	{
		get => player;
		private set
		{
			player = value;
		}
	}

	public override bool Perform()
	{
		ConsumableItem item = MapData.GetFirstItemAtPosition(Destination);

		if (item == null)
		{
			MessageLogData.Instance.AddMessage("Não tem item aqui.");
			return false;
		}

		if (player.Inventory.Items.Count >= player.Inventory.Capacity)
		{
			MessageLogData.Instance.AddMessage("Seu inventário está cheio");
			return false;
		}

		MapData.RemoveEntity(item);
		player.Inventory.Add(item);

		player.Energy -= Cost;
		return true;
	}
}