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

@ -11,7 +11,7 @@ public partial class RuntimePlantData : Node2D, IEntity
{
[Export]
private int _maxHP;
private int _hp;
[Export]private int _hp;
public int Hp => _hp;
public int MaxHp => _maxHP;
public int Line {get; set;}

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");
}
}

View file

@ -14,6 +14,7 @@ public partial class WallnutBehaviour : Node
public void OnHPChanged(int amount)
{
if(_data.Hp <= _data.MaxHp*2.0/3.0 && _data.Hp > _data.MaxHp/3.0)
{
_player.Play("idle_mid");
@ -22,5 +23,9 @@ public partial class WallnutBehaviour : Node
{
_player.Play("idle_low");
}
else
{
_player.Play("idle_full");
}
}
}