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

public class RunMashManager : MonoBehaviour
{

    [Header("Players")]
    [SerializeField] private SimpleCharacter player1;
    [SerializeField]
    private SimpleCharacter
        player2,
        player3;
    private float timerCurrent = 0;
    [SerializeField] private float maxTime = 30f;
    [SerializeField] private int scorePerSec = 25;

    [SerializeField] private GameObject gameDone;


    private void Update()
    {
        timerCurrent += Time.deltaTime;
    }

    public void SetPlayerVisuals(CharacterRandomizer.Character character1, CharacterRandomizer.Character character2, CharacterRandomizer.Character character3)
    {

        player1.SetHeadSprites(character1);

        player2.SetHeadSprites(character2);

        player3.SetHeadSprites(character3);

    }

    public void Finish()
    {
        if(timerCurrent < maxTime)
        {
            Score.Instance.UpdateScore((int)(scorePerSec * maxTime - timerCurrent));
        }
        WinMinigame();
    }

    public void WinMinigame()
    {
        StartCoroutine(WinEffect());
    }


    private IEnumerator WinEffect()
    {
        gameDone.gameObject.SetActive(true);
        yield return new WaitForSeconds(3f);
        CrowdMinigameManager.Instance.SetState(CrowdMinigameManager.State.Bridge);
    }

}
