Atrocities
This commit is contained in:
parent
8e0f90ae3d
commit
9680b21792
90 changed files with 324 additions and 69 deletions
54
scripts/components/Armor.cs
Normal file
54
scripts/components/Armor.cs
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
using Godot;
|
||||
|
||||
namespace Newlon.Components;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class Armor : Node
|
||||
{
|
||||
[Signal]
|
||||
public delegate void ArmorDamagedEventHandler(int hp);
|
||||
[Signal]
|
||||
public delegate void ArmorLostEventHandler();
|
||||
|
||||
[Export]
|
||||
private int _maxHP;
|
||||
private int _hp;
|
||||
private bool _lost = false;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_hp = _maxHP;
|
||||
}
|
||||
|
||||
public int RecieveDamage(int damage)
|
||||
{
|
||||
if(_lost)
|
||||
return damage;
|
||||
int returnAmount = 0;
|
||||
_hp -= damage;
|
||||
if(_hp <= 0)
|
||||
{
|
||||
returnAmount = _hp;
|
||||
_hp = 0;
|
||||
EmitSignal(SignalName.ArmorLost);
|
||||
_lost = true;
|
||||
}
|
||||
EmitSignal(SignalName.ArmorDamaged,_hp);
|
||||
return returnAmount;
|
||||
}
|
||||
|
||||
public int Heal(int amount)
|
||||
{
|
||||
if(_lost)
|
||||
return amount;
|
||||
int returnAmount = 0;
|
||||
_hp += amount;
|
||||
if (_hp >= _maxHP)
|
||||
{
|
||||
returnAmount = _hp-_maxHP;
|
||||
_hp = _maxHP;
|
||||
}
|
||||
EmitSignal(SignalName.ArmorDamaged,_hp);
|
||||
return returnAmount;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue