using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

[System.Serializable]
public class HouseImageSet {

    public ImageSet populated;
    public ImageSet abandoned;
}

public class HouseTile : Tile {

    public List<HouseImageSet> houseImageSets = new List<HouseImageSet>();
    HouseImageSet houseImageSet;
    public bool populated = true;
    public bool hasAlarm = false;

    protected override void Awake()
    {
        houseImageSet = houseImageSets [Random.Range(0, houseImageSets.Count)];
        imageSet = houseImageSet.populated;
            
        base.Awake();

        GameController.Instance.peopleNormal += 2;
        GameController.Instance.housesNormal += 1;
    }

    public void Evacuate()
    {
        populated = false;
        imageSet = houseImageSet.abandoned;
        UpdateSprite();

        if (tileState == TileState.NORMAL)
        {
            GameController.Instance.peopleNormal -= 2;
            GameController.Instance.peopleEvacuated += 2;
        }
    }

    public override void OnFlooded()
    {
        base.OnFlooded();

        GameController.Instance.housesNormal--;
        GameController.Instance.housesFlooded++;

        if (populated)
        {
            if (!hasAlarm)
            {
                GameController.Instance.peopleInjured += 2;
            } else
            {
                populated = false;
                imageSet = houseImageSet.abandoned;
                UpdateSprite();

                GameController.Instance.peopleEvacuated += 2;
            }
            
            GameController.Instance.peopleNormal -= 2;
        }
    }

    public override void OnDestroyed()
    {
        base.OnDestroyed();

        GameController.Instance.housesFlooded--;
        GameController.Instance.housesDestroyed++;

        if (populated)
        {
            GameController.Instance.peopleKilled += 2;
            GameController.Instance.peopleInjured -= 2;
        }

    }
}
