2018-09-26 22:38:49 +00:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public class Unit : MonoBehaviour
|
|
|
|
|
{
|
2018-09-30 14:35:17 +00:00
|
|
|
|
public UnitPosition position;
|
|
|
|
|
public UnitHealth health;
|
|
|
|
|
public UnitStats stats;
|
2018-09-26 22:38:49 +00:00
|
|
|
|
private List<GenericEffect> activeEffects;
|
|
|
|
|
|
2018-09-30 14:35:17 +00:00
|
|
|
|
void Awake()
|
2018-09-26 22:38:49 +00:00
|
|
|
|
{
|
|
|
|
|
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); });
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-30 14:35:17 +00:00
|
|
|
|
public void Damage(int amount)
|
2018-09-26 22:38:49 +00:00
|
|
|
|
{
|
|
|
|
|
activeEffects.ForEach(delegate (GenericEffect effect) { effect.BeforeDamage(this, amount); });
|
|
|
|
|
if (health != null)
|
|
|
|
|
{
|
|
|
|
|
health.Damage(amount);
|
|
|
|
|
if (health.currentHealth == 0)
|
|
|
|
|
{
|
2018-09-30 14:35:17 +00:00
|
|
|
|
Kill();
|
2018-09-26 22:38:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
activeEffects.ForEach(delegate (GenericEffect effect) { effect.AfterDamage(this, amount); });
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-30 14:35:17 +00:00
|
|
|
|
public void Kill()
|
2018-09-26 22:38:49 +00:00
|
|
|
|
{
|
|
|
|
|
bool deathPrevented = activeEffects.TrueForAll(delegate (GenericEffect effect) { return effect.BeforeDeath(this); });
|
|
|
|
|
if(deathPrevented)
|
|
|
|
|
{
|
|
|
|
|
if(health.currentHealth <= 0)
|
|
|
|
|
{
|
|
|
|
|
health.currentHealth = 1;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//Die. For real.
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-30 14:35:17 +00:00
|
|
|
|
public void StepTo(MapPosition mapPosition)
|
|
|
|
|
{
|
|
|
|
|
position.StepTo(mapPosition);
|
|
|
|
|
//TODO
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ApplyNewEffect(GenericEffect newEffect)
|
2018-09-26 22:38:49 +00:00
|
|
|
|
{
|
|
|
|
|
activeEffects.ForEach(delegate (GenericEffect existingEffect) { existingEffect.BeforeNewEffect(this, newEffect); });
|
|
|
|
|
activeEffects.Add(newEffect);
|
|
|
|
|
activeEffects.ForEach(delegate (GenericEffect existingEffect) { existingEffect.AfterNewEffect(this, newEffect); });
|
|
|
|
|
}
|
|
|
|
|
}
|