using UnityEngine;
using System.Collections;

public class Observer : MonoBehaviour
{
    #region application-level events
    public delegate void GameLoadedDelegate();
    public static event GameLoadedDelegate gameLoadedHandler;

    public static void OnGameLoaded()
    {
        if (gameLoadedHandler != null)
            gameLoadedHandler();
    }

    public delegate void GameTitleExitedDelegate();
    public static event GameTitleExitedDelegate gameTitleExitedHandler;

    public static void OnGameTitleExited()
    {
        if (gameTitleExitedHandler != null)
            gameTitleExitedHandler();
    }

    public delegate void GameInitiatedDelegate();
    public static event GameInitiatedDelegate gameInitiatedHandler;

    public static void OnGameInitiated()
    {
        if (gameInitiatedHandler != null)
            gameInitiatedHandler();
    }

    public delegate void GameOverDelegate();
    public static event GameOverDelegate gameOverHandler;

    public static void OnGameOver()
    {
        if (gameOverHandler != null)
            gameOverHandler();
    }

    public delegate void GameResetDelegate();
    public static event GameResetDelegate gameResetHandler;

    public static void OnGameReset()
    {
        if (gameResetHandler != null)
            gameResetHandler();
    }

    public delegate void ScoreChangeDelegate(int newScore);
    public static event ScoreChangeDelegate scoreChangeHandler;

    public static void OnScoreChange(int newScore)
    {
        if (scoreChangeHandler != null)
            scoreChangeHandler(newScore);
    }
    #endregion
    #region gameplay events
    public delegate void GrumpTouchedDelegate(NPC grumpTouched);
    public static GrumpTouchedDelegate grumpTouchedHandler;

    public static void OnGrumpTouched(NPC grumpTouched)
    {
        if (grumpTouchedHandler != null)
            grumpTouchedHandler(grumpTouched);
    }

    public delegate void ShotDelegate(Vector3 firePosition);
    public static ShotDelegate shotHandler;

    public static void OnShot(Vector3 firePosition)
    {
        if (shotHandler != null)
            shotHandler(firePosition);
    }

    public delegate void GrumpShotDelegate(Vector3 firePosition);
    public static GrumpShotDelegate grumpShotHandler;

    public static void OnGrumpShot(Vector3 firePosition)
    {
        if (grumpShotHandler != null)
            grumpShotHandler(firePosition);
    }

    public delegate void BonusTouchedDelegate(NPC bonusTouched);
    public static BonusTouchedDelegate bonusTouchedHandler;

    public static void OnBonusTouched(NPC bonusTouched)
    {
        if (bonusTouchedHandler != null)
            bonusTouchedHandler(bonusTouched);
    }

    public delegate void MouseUpDelegate();
    public static MouseUpDelegate mouseUpHandler;

    public static void OnMouseUp()
    {
        if (mouseUpHandler != null)
            mouseUpHandler();
    }

    public delegate void NeutralTouchedDelegate(NPC neutralTouched);
    public static NeutralTouchedDelegate neutralTouchedHandler;

    public static void OnNeutralTouched(NPC neutralTouched)
    {
        if (neutralTouchedHandler != null)
            neutralTouchedHandler(neutralTouched);
    }

    public delegate void ShotBarDelegate(float shotValue);
    public static ShotBarDelegate shotBarHandler;

    public static void OnShotBar(float shotValue)
    {
        if (shotBarHandler != null)
            shotBarHandler(shotValue);
    }

    public delegate void BossApproachesDelegate();
    public static BossApproachesDelegate bossApproachesHandler;

    public static void OnBossApproaches()
    {
        if (bossApproachesHandler != null)
            bossApproachesHandler();
    }

    public delegate void BossDeadDelegate();
    public static BossDeadDelegate bossDeadHandler;

    public static void OnBossDead()
    {
        if (bossDeadHandler != null)
            bossDeadHandler();
    }

    public delegate void WarningAnimationDelegate();
    public static WarningAnimationDelegate warningAnimationHandler;

    public static void OnWarningAnimation()
    {
        if (warningAnimationHandler != null)
            warningAnimationHandler();
    }

    public delegate void BossReadyDelegate();
    public static BossReadyDelegate bossReadyHandler;

    public static void OnBossReady()
    {
        if (bossReadyHandler != null)
            bossReadyHandler();
    }

    public delegate void BossDamageDelegate(int health);
    public static BossDamageDelegate bossDamageHandler;

    public static void OnBossDamage(int health)
    {
        if (bossDamageHandler != null)
            bossDamageHandler(health);
    }

    public delegate void BossHitDelegate();
    public static BossHitDelegate bossHitHandler;

    public static void OnBossHit()
    {
        if (bossHitHandler != null)
            bossHitHandler();
    }

    public delegate void BossCleanupDelegate();
    public static BossCleanupDelegate bossCleanupHandler;

    public static void OnBossCleanup()
    {
        if (bossCleanupHandler != null)
            bossCleanupHandler();
    }
    #endregion

    public bool simulateEvent = false;

    public enum SimulatedEvent
    {
        BOSSDEAD,
        BOSSCLEANUP,
        BOSSAPPROACHES
    }

    public SimulatedEvent eventTosimulate;

    public void Update()
    {
        if (simulateEvent)
        {
            simulateEvent = false;
            switch (eventTosimulate)
            {
                case SimulatedEvent.BOSSCLEANUP:
                    OnBossCleanup();
                    break;
                case SimulatedEvent.BOSSDEAD:
                    OnBossDead();
                    break;
                case SimulatedEvent.BOSSAPPROACHES:
                    OnBossApproaches();
                    break;
            }
        }
    }

    public static void ResetHandlers()
    {
        gameTitleExitedHandler = null;
        gameLoadedHandler = null;
        gameInitiatedHandler = null;
        gameOverHandler = null;
        gameResetHandler = null;
        scoreChangeHandler = null;
        grumpTouchedHandler = null;
        neutralTouchedHandler = null;
        bonusTouchedHandler = null;
        shotHandler = null;
        shotBarHandler = null;
        grumpShotHandler = null;
        bossApproachesHandler = null;
        bossDeadHandler = null;
        warningAnimationHandler = null;
        bossReadyHandler = null;
        bossDamageHandler = null;
        bossCleanupHandler = null;
        bossHitHandler = null;
        mouseUpHandler = null;
    }
}
