using UnityEngine;
using System.Collections.Generic;

public static class RoomTransition
{
    public static string lastRoom = "corridor";
    public static bool caosState = false;
    public static GameObject[] rooms;

    public static void Initialize()
    {
        var list = new List<GameObject>();
        list.Add(GameObject.Find("hall"));
        list.Add(GameObject.Find("living"));
        list.Add(GameObject.Find("dinner"));
        list.Add(GameObject.Find("kitchen"));
        list.Add(GameObject.Find("corridor"));
        list.Add(GameObject.Find("grampa"));
        list.Add(GameObject.Find("parents"));
        list.Add(GameObject.Find("bedroom"));
        rooms = list.ToArray();
    }
    public static void HideAll()
    {
        foreach (GameObject go in rooms)
            go.SetActive(false);
    }
    public static void GoTo(string name)
    {
        if ((name == "bedroom" && Control.inventory.CheckItem("Chave Pequena") < 1))
        {
            Dialog.PlayScene("lockeddoor");
            return;
        }
        if ((name == "parents"|| name == "dinner") && caosState)
        {
            Dialog.PlayScene("cantopendoor");
            return;
        }

        foreach (GameObject go in rooms)
            if (go.name == name)
            {
                go.SetActive(true);
                go.transform.Find("normal").gameObject.SetActive(!caosState);
                go.transform.Find("broken").gameObject.SetActive(caosState);
                if(name!=lastRoom)
                Control.player.transform.SetPositionAndRotation(
                    go.transform.Find("pos " + lastRoom).position,
                    go.transform.Find("pos " + lastRoom).rotation);
            }
            else go.SetActive(false);
        lastRoom = name;
    }
}
