This repository has been archived on 2023-04-11. You can view files and clone it, but cannot push or open issues or pull requests.
dungeon-crawler-demo/scripts/Stats/Health.cs
2020-10-26 00:50:16 -04:00

39 lines
751 B
C#

using System;
public class Health : IStat
{
public int value { get { return hp; }}
public int max { get { return 100; }}
public int min { get {return 0; }}
private int hp = 100;
public event StatUpdatedHandler statUpdated;
public void Heal(int heal_amount)
{
int new_val = hp - heal_amount;
if(new_val > max)
hp = max;
else
hp = new_val;
}
public void Damage(int damange_amount)
{
int new_val = hp - damange_amount;
if(new_val < min)
hp = min;
else
hp = new_val;
OnStatUpdated();
}
protected void OnStatUpdated()
{
if(statUpdated != null)
statUpdated(hp);
}
}