Resource System (Health/Energy/Beans)
The resources system has been built from an initial health system into a an extendable resource system.
Any type of resource can be modeled with a simple wrapper around a resource system. Health systems implement IHealable
, Shield systems implement IShieldable
, and both systems implement the IDamageable
interface.
public interface IHealable {
int CurrentHealth { get; }
float CurrentHealthPercent { get; }
bool IsDead { get; }
bool IsHealthRegenerating { get; }
void ResetValues();
void DisableHealth();
void EnableHealth();
void GiveHealth(int value);
void GiveHealthRegen(int value, int ticks);
}
public interface IShieldable {
int CurrentShield { get; }
bool IsShielded { get; }
bool IsShieldRegenerating { get; }
...
}
public interface IDamageable {
bool IsDead { get;}
bool TakeDamage(int damage, Vector2 location);
}
public interface IKillable {
void Die(Vector2 lastHitLocation);
}
The IDamageable
and IKillable
interfaces allow for a many different classes to implement their own ways to deal with damage. Any component that implements IDamageable
can recieve damage from the games damage systems without extra wiring. All damage done in the game runs through an IDamageable
interface. In this case, a basic enemy implements the IKillable
interface directly, but passes off the implementation of IDamageable
to BaseHealthSystem
public class Enemy : MonoBehaviour, IKillable, IDamageable, IHealable
{
...
protected BaseHealthSystem health;
public void Die(Vector2 lastHitLocation)
{
StartCoroutine(Death(lastHitLocation));
}
...
}
public class BaseHealthSystem : MonoBehaviour, IDamageable, IHealable{...}