summaryrefslogtreecommitdiff
path: root/scripts/Entities/Items/HealingConsumable.cs
blob: 85377d3facbedc53cf1f2a967b6a304dc5eedfab (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
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 = 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;
	}
}