54 lines
984 B
C#
54 lines
984 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;
|
|
public int Hp => _hp;
|
|
public int MaxHp => _maxHP;
|
|
public int Line {get; set;}
|
|
public PlantResource Resource;
|
|
|
|
[Signal]
|
|
public delegate void OnHPChangedEventHandler(int amount);
|
|
|
|
public override void _Ready()
|
|
{
|
|
_hp = _maxHP;
|
|
}
|
|
|
|
public void Heal(int amount)
|
|
{
|
|
_hp += amount;
|
|
|
|
EmitSignal(SignalName.OnHPChanged,amount);
|
|
|
|
if (MaxHp > 0)
|
|
{
|
|
_hp = MaxHp;
|
|
}
|
|
}
|
|
|
|
public void TakeDamage(int amount)
|
|
{
|
|
_hp -= amount;
|
|
|
|
EmitSignal(SignalName.OnHPChanged,-amount);
|
|
|
|
if (_hp <= 0)
|
|
{
|
|
Kill();
|
|
}
|
|
}
|
|
public void Kill()
|
|
{
|
|
PoolContainer.Instance.EntityField[Resource.Layer].Remove(GlobalPosition);
|
|
QueueFree();
|
|
}
|
|
}
|