66 lines
1.4 KiB
C#
66 lines
1.4 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;
|
|
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 virtual void Heal(int amount, Node origin)
|
|
{
|
|
_hp += amount;
|
|
|
|
EmitSignal(SignalName.OnHPChanged, amount, origin);
|
|
|
|
if (MaxHp > 0)
|
|
{
|
|
_hp = MaxHp;
|
|
}
|
|
}
|
|
|
|
public virtual void TakeDamage(int amount, Node origin, Utility.DamageTypes damageType = Utility.DamageTypes.PHYSICAL)
|
|
{
|
|
_hp -= amount;
|
|
|
|
EmitSignal(SignalName.OnHPChanged, -amount, origin);
|
|
|
|
if (_hp <= 0)
|
|
{
|
|
Kill();
|
|
}
|
|
}
|
|
public virtual void Kill()
|
|
{
|
|
PoolContainer.Instance.EntityField[Resource.Layer].Remove(GlobalPosition);
|
|
QueueFree();
|
|
}
|
|
|
|
public virtual void DisableBrain()
|
|
{
|
|
GetNode<Node>("Behaviour").ProcessMode = ProcessModeEnum.Disabled;
|
|
}
|
|
|
|
public virtual void EnableBrain()
|
|
{
|
|
GetNode<Node>("Behaviour").ProcessMode = ProcessModeEnum.Inherit;
|
|
}
|
|
}
|