56 lines
1.1 KiB
C#
56 lines
1.1 KiB
C#
using Godot;
|
|
using Newlon.Components.Level;
|
|
|
|
namespace Newlon.Components.Plants;
|
|
|
|
//
|
|
// Data that plant stores during runtime
|
|
//
|
|
|
|
public partial class RuntimePlantData : Node2D, IEntity
|
|
{
|
|
[Export]
|
|
private int _maxHP;
|
|
[Export]private int _hp;
|
|
public int Hp => _hp;
|
|
public int MaxHp => _maxHP;
|
|
public int Line {get; set;}
|
|
public PlantResource Resource;
|
|
|
|
[Signal]
|
|
public delegate void OnHPChangedEventHandler(int amount,Node origin);
|
|
|
|
public override void _Ready()
|
|
{
|
|
_hp = _maxHP;
|
|
}
|
|
|
|
public void Heal(int amount,Node origin)
|
|
{
|
|
_hp += amount;
|
|
|
|
EmitSignal(SignalName.OnHPChanged,amount,origin);
|
|
|
|
if (MaxHp > 0)
|
|
{
|
|
_hp = MaxHp;
|
|
}
|
|
}
|
|
|
|
public void TakeDamage(int amount,Node origin, Utility.DamageTypes damageType = Utility.DamageTypes.PHYSICAL)
|
|
{
|
|
_hp -= amount;
|
|
|
|
EmitSignal(SignalName.OnHPChanged,-amount, origin);
|
|
|
|
if (_hp <= 0)
|
|
{
|
|
Kill();
|
|
}
|
|
}
|
|
public void Kill()
|
|
{
|
|
PoolContainer.Instance.EntityField[Resource.Layer].Remove(GlobalPosition);
|
|
QueueFree();
|
|
}
|
|
}
|