mirror of
https://github.com/Steffo99/octogem.git
synced 2024-11-21 20:44:19 +00:00
69 lines
2 KiB
C#
69 lines
2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class Unit : MonoBehaviour
|
|
{
|
|
public UnitPosition position;
|
|
public UnitHealth health;
|
|
public UnitStats stats;
|
|
private List<GenericEffect> activeEffects;
|
|
|
|
void Awake()
|
|
{
|
|
position = GetComponent<UnitPosition>();
|
|
health = GetComponent<UnitHealth>();
|
|
stats = GetComponent<UnitStats>();
|
|
}
|
|
|
|
public void Heal(int amount)
|
|
{
|
|
activeEffects.ForEach(delegate (GenericEffect effect) { effect.BeforeHeal(this, amount); });
|
|
if (health != null)
|
|
{
|
|
health.Heal(amount);
|
|
}
|
|
activeEffects.ForEach(delegate (GenericEffect effect) { effect.AfterHeal(this, amount); });
|
|
}
|
|
|
|
public void Damage(int amount)
|
|
{
|
|
activeEffects.ForEach(delegate (GenericEffect effect) { effect.BeforeDamage(this, amount); });
|
|
if (health != null)
|
|
{
|
|
health.Damage(amount);
|
|
if (health.currentHealth == 0)
|
|
{
|
|
Kill();
|
|
}
|
|
}
|
|
activeEffects.ForEach(delegate (GenericEffect effect) { effect.AfterDamage(this, amount); });
|
|
}
|
|
|
|
public void Kill()
|
|
{
|
|
bool deathPrevented = activeEffects.TrueForAll(delegate (GenericEffect effect) { return effect.BeforeDeath(this); });
|
|
if(deathPrevented)
|
|
{
|
|
if(health.currentHealth <= 0)
|
|
{
|
|
health.currentHealth = 1;
|
|
}
|
|
return;
|
|
}
|
|
//Die. For real.
|
|
}
|
|
|
|
public void StepTo(MapPosition mapPosition)
|
|
{
|
|
position.StepTo(mapPosition);
|
|
//TODO
|
|
}
|
|
|
|
public void ApplyNewEffect(GenericEffect newEffect)
|
|
{
|
|
activeEffects.ForEach(delegate (GenericEffect existingEffect) { existingEffect.BeforeNewEffect(this, newEffect); });
|
|
activeEffects.Add(newEffect);
|
|
activeEffects.ForEach(delegate (GenericEffect existingEffect) { existingEffect.AfterNewEffect(this, newEffect); });
|
|
}
|
|
}
|