using UnityEngine;
using System.Collections.Generic;

public class PianoScript : ScenarioObject {

    // TODO: Change collision boxes on object zo colission get detected properly
    // Create state where if the piano falls over the scenario is failed

    private float maxTime = 30f;
    private int hitsNeeded = 3;
    public int pianoHits = 0;

    private string[] pianoClips;

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

        pianoClips = new string[] {
            "PianoHit_1",
            "PianoHit_2",
            "PianoHit_3",
            "PianoHit_4",
            "PianoHit_5"
        };
    }

    protected override void Update()
    {
 	    base.Update();

        if (!finishedScenario) {
            if (pianoHits >= hitsNeeded) {
                Reset();
                OnScenarioWin();
            }

            float angle = Vector3.Dot(transform.forward, Vector3.up);

            if (Mathf.Abs(angle) > 0.9f) {
                Reset();
                OnScenarioFail();
            }
        }
    }

    private void Reset() {
        pianoHits = 0;
    }

    private void OnTriggerEnter(Collider other) {
        if (other.collider.name == "M_Head" || other.collider.name == "R_Hand") {
            AudioManager.Instance.Play(pianoClips[Random.Range(0, pianoClips.Length - 1)], 1f, false);
            pianoHits++;
        }
    }
}
