newlon/scripts/components/plants/RuntimePlantData.cs

45 lines
776 B
C#

using Godot;
using System;
//
// Data that plant stores during runtime
//
public partial class RuntimePlantData : Node2D, IEntity
{
[Export]
private int _maxHP;
private int _hp;
[Export]
private int _line;
public int Hp => _hp;
public int MaxHp => _maxHP;
public int Line => _line;
public int Layer;
public override void _Ready()
{
_hp = _maxHP;
}
public void Heal(int amount)
{
_hp += amount;
if (MaxHp > 0)
{
_hp = MaxHp;
}
}
public void TakeDamage(int amount)
{
_hp -= amount;
if (_hp <= 0)
{
LevelController.Instance.Pools.EntityField[Layer].Remove(GlobalPosition);
QueueFree();
}
}
}