This commit is contained in:
Фёдор Веселов 2024-10-03 00:25:57 +05:00
commit 8fdc2a3ed9
7 changed files with 127 additions and 1 deletions

View file

@ -0,0 +1,42 @@
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);
_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");
}
}