using UnityEngine;
using System.Collections;
using Framework.Entities;

public class Health : CoreBehaviour
{
    public class ReviveAction : CoreAction
    {
    }

    public class DeadAction : CoreAction
    {
        public DeadAction(CoreBehaviour sender) : base(sender) { }
    }

    public class HurtAction : CoreAction
    {
        public int damage;

        public HurtAction(int damage)
        {
            this.damage = damage;
        }
    }

    public class HealAction : CoreAction
    {
        public int damage;

        public HealAction(int damage)
        {
            this.damage = damage;
        }
    }

    public int health;
    public int maxHealth;

    protected override void InnerAwake()
    {
        AddActionHandler<ReviveAction>(Revive);
        AddActionHandler<HurtAction>(Hurt);
        AddActionHandler<HealAction>(Heal);
    }

    protected override void InnerUpdate()
    {

    }

    private void Revive(ReviveAction action)
    {
        this.health = this.maxHealth;
    }

    private void Hurt(HurtAction action)
    {
        if (this.gameObject.name == "Player")
        {
            Announce(new CameraShake.ShakeAction());
        }
        this.health -= action.damage;
        if (this.health <= 0)
        {
            Interact(new DeadAction(this));
        }
    }

    private void Heal(HealAction action)
    {
        this.health += action.damage;
        if (this.health > this.maxHealth)
        {
            this.health = this.maxHealth;
        }
    }
}
