Plants now based on entity class
This commit is contained in:
parent
6c9909df30
commit
08d593175b
14 changed files with 38 additions and 65 deletions
|
|
@ -7,64 +7,19 @@ namespace Newlon.Components.Plants;
|
|||
// Data that plant stores during runtime
|
||||
//
|
||||
|
||||
public partial class RuntimePlantData : Node2D, IEntity
|
||||
public partial class RuntimePlantData : Entity
|
||||
{
|
||||
[Export]
|
||||
private int _maxHP;
|
||||
private int _hp;
|
||||
public int Hp => _hp;
|
||||
public int MaxHp => _maxHP;
|
||||
public int Line { get; set; }
|
||||
public PlantResource Resource;
|
||||
|
||||
private AudioStream eatenSound;
|
||||
|
||||
[Signal]
|
||||
public delegate void OnHPChangedEventHandler(int amount, Node origin);
|
||||
|
||||
public override void _Ready()
|
||||
private AudioStream eatenSound = ResourceLoader.Load<AudioStream>("res://assets/audio/sfx/gulp.mp3");
|
||||
public override void KillByDamage()
|
||||
{
|
||||
_hp = _maxHP;
|
||||
eatenSound = ResourceLoader.Load<AudioStream>("res://assets/audio/sfx/gulp.mp3");
|
||||
AudioSequencer.Play("plant_eaten", eatenSound);
|
||||
base.KillByDamage();
|
||||
}
|
||||
|
||||
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();
|
||||
AudioSequencer.Play("plant_eaten", eatenSound);
|
||||
}
|
||||
}
|
||||
public virtual void Kill()
|
||||
public override 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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue