using UnityEngine;
using System.Collections;

public class Puzzle1 : MonoBehaviour {

    public string chest;
    private GameObject chesto;
    public bool enabled = false;
    public int numListeners;
    public bool[] listeners;

	// Use this for initialization
	void Start () {
        this.chesto = GameObject.Find(chest).gameObject;
        this.chesto.SetActive(enabled);
        this.listeners = new bool[numListeners];
        for (int i = 0; i < numListeners; i++) this.listeners[i] = false;
	}

    void enable()
    {
        this.isEnabled();
        if (enabled)
        {
            this.chesto.SetActive(enabled);    
        }
    }

    public void activeListener(int key) {
        this.listeners[key] = true;
        this.enable();
    }

    private void isEnabled()
    {
        foreach (bool l in listeners)
        {
            if (!l)
            {
                this.enabled = false;
                return;
            }
        }

        this.enabled = true;
    }
}
