42 lines
1 KiB
C#
42 lines
1 KiB
C#
using Godot;
|
|
using Newlon.Components.Level;
|
|
|
|
namespace Newlon.Components.Plants.Behaviours;
|
|
|
|
public partial class AloeBehaviour : Node
|
|
{
|
|
[Export] private AnimationPlayer _player;
|
|
[Export] private float _hpTreshold = 0.25f;
|
|
private Timer _timer;
|
|
private bool _charge = true;
|
|
|
|
public override void _Ready()
|
|
{
|
|
_timer = GetNode<Timer>("Timer");
|
|
}
|
|
|
|
|
|
|
|
public override void _Process(double delta)
|
|
{
|
|
var checkPos = GetParent<Node2D>().GlobalPosition + Vector2.Right * Utility.TileWidth;
|
|
if(_charge && PoolContainer.Instance.EntityField[1].ContainsKey(checkPos) && PoolContainer.Instance.EntityField[1][checkPos] is RuntimePlantData plantData)
|
|
{
|
|
if((float)plantData.Hp / (float)plantData.MaxHp < _hpTreshold)
|
|
{
|
|
plantData.Heal(3000 + 25 * plantData.MaxHp,GetParent());
|
|
_charge = false;
|
|
_player.Play("aloe/heal");
|
|
_player.Queue("aloe/idle_used");
|
|
_timer.Start();
|
|
}
|
|
}
|
|
}
|
|
|
|
public void OnTimeout()
|
|
{
|
|
_charge = true;
|
|
_player.Play("aloe/recharge");
|
|
_player.Queue("aloe/idle");
|
|
}
|
|
}
|