Plants now based on entity class
This commit is contained in:
parent
6c9909df30
commit
08d593175b
14 changed files with 38 additions and 65 deletions
|
|
@ -19,7 +19,7 @@ public partial class Entity : Node2D
|
|||
EmitSignal(SignalName.OnDamaged);
|
||||
if (HP <= 0)
|
||||
{
|
||||
Kill();
|
||||
KillByDamage();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -29,6 +29,11 @@ public partial class Entity : Node2D
|
|||
HP += amount;
|
||||
}
|
||||
|
||||
public virtual void KillByDamage()
|
||||
{
|
||||
Kill();
|
||||
}
|
||||
|
||||
public virtual void Kill()
|
||||
{
|
||||
QueueFree();
|
||||
|
|
|
|||
|
|
@ -23,12 +23,12 @@ public partial class PoolContainer : Node2D
|
|||
|
||||
public static PoolContainer Instance { get; private set; }
|
||||
|
||||
public Dictionary<Vector2, IEntity>[] EntityField = { new(), new(), new() };
|
||||
public Dictionary<Vector2, Entity>[] EntityField = { new(), new(), new() };
|
||||
public override void _Ready()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
public bool TryGetEntity(Vector2 key, out IEntity result, int layer = 1)
|
||||
public bool TryGetEntity(Vector2 key, out Entity result, int layer = 1)
|
||||
{
|
||||
if (EntityField[layer].ContainsKey(key))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,10 +4,11 @@ namespace Newlon.Components.Plants;
|
|||
|
||||
public partial class LoseZone : RuntimePlantData
|
||||
{
|
||||
public override void TakeDamage(int amount, Node origin, Utility.DamageTypes damageType = Utility.DamageTypes.PHYSICAL)
|
||||
{
|
||||
public override void TakeDamage(float amount, Node origin)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override void Kill()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ public partial class ReturnEffect : Node
|
|||
|
||||
public void OnDamageRecieved(int delta,Node origin)
|
||||
{
|
||||
if (delta >= 0) return;
|
||||
if (origin is RuntimeZombieData zombie)
|
||||
{
|
||||
zombie.GiveEffect(_effectToReturn);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ public partial class AloeBehaviour : BaseBehaviour
|
|||
var checkPos = GetParent<Node2D>().GlobalPosition + Vector2.Right * Utility.TileWidth;
|
||||
if(_charge && PoolContainer.Instance.TryGetEntity(checkPos, out RuntimePlantData plantData))
|
||||
{
|
||||
if((float)plantData.Hp / (float)plantData.MaxHp < _hpTreshold)
|
||||
if((float)plantData.HP / (float)plantData.MaxHP < _hpTreshold)
|
||||
{
|
||||
_charge = false;
|
||||
_tree.Set("parameters/conditions/heal",true);
|
||||
|
|
@ -36,7 +36,7 @@ public partial class AloeBehaviour : BaseBehaviour
|
|||
var checkPos = GetParent<Node2D>().GlobalPosition + Vector2.Right * Utility.TileWidth;
|
||||
if (PoolContainer.Instance.TryGetEntity(checkPos, out RuntimePlantData plantData))
|
||||
{
|
||||
plantData.Heal(3000 + 25 * plantData.MaxHp, GetParent());
|
||||
plantData.Heal(3000 + 25 * plantData.MaxHP, GetParent());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,6 @@ public partial class HpBasedBehaviour : BaseBehaviour
|
|||
|
||||
public void OnHPChanged(int amount,Node origin)
|
||||
{
|
||||
_tree.Set("parameters/blend_position",(float)_data.Hp/_data.MaxHp);
|
||||
_tree.Set("parameters/blend_position",(float)_data.HP/_data.MaxHP);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue