using UnityEngine;
using System.Collections;

public class WorkerSpriteHandler : MonoBehaviour {

    private int randomGender = 0;
    private Renderer genderRenderer;
    public Animator myAnim, effectAnim;
    // Use this for initialization
    void Start() {
        genderRenderer = GetComponent<Renderer>();
        myAnim = GetComponent<Animator>();
	
        //GenderRandomizer();
    }
    void OnEnable()
    {
        EventManager.StartListening(Constants.CombinationFailed, ComboFailed);
        EventManager.StartListening(Constants.CombinationSuccessful, ComboSuccess);
		EventManager.StartListening(Constants.GenerateCombo, GenderRandomizer);
    }
    void OnDisable()
    {
        EventManager.StopListening(Constants.CombinationFailed, ComboFailed);
        EventManager.StopListening(Constants.CombinationSuccessful, ComboSuccess);
		EventManager.StopListening(Constants.GenerateCombo, GenderRandomizer);
    }
    // Update is called once per frame
    void GenderRandomizer()
    {
        randomGender = Random.Range(0, 3);
        if (randomGender == 1 || randomGender == 3)
        {
            //character is male
            myAnim.Play("Male_Idle");
			effectAnim.Play("Male_IdleEffect");
        }
        if (randomGender == 2 || randomGender == 0)
        {
            //character is female
            myAnim.Play("Female_Idle");
			effectAnim.Play("Female_IdleEffect");
        } 
	}
    void ComboFailed()
    {
        if (randomGender == 1 || randomGender == 3)
        {
            myAnim.Play("Male_Failure");
			effectAnim.Play("Male_FailEffect");
        }
        else
        {
            myAnim.Play("Female_Failure");
			effectAnim.Play("Female_FailEffect");
        }
    }
    void ComboSuccess()
    {
        if (randomGender == 1 || randomGender == 3)
        {
            myAnim.Play("Male_Success");

			effectAnim.Play("Male_SuccessEffect");
        }
        else
        {
            myAnim.Play("Female_Success");
			effectAnim.Play("Female_SuccessEffect");
        }
    }
}
