using System.Collections;
using UnityEngine;

public class Pelaajan_hyökkäykset : MonoBehaviour {
    Animator m_reaper_animaatiot;
    Animator m_scythe_animaatio;
    Music_handler soundhandler;

    [SerializeField]
    int m_Damage = 3;

    GameObject m_scythe;

    // Start is called before the first frame update
    void Start() {
        soundhandler = GetComponent<Music_handler>();
        m_reaper_animaatiot = GetComponent<Animator>();
        m_scythe = GameObject.FindGameObjectWithTag("player_scythe");
        m_scythe_animaatio = m_scythe.GetComponent<Animator>();
    }

    // Update is called once per frame
    void Update() {
        m_reaper_animaatiot.SetBool("attacking", false);
        m_reaper_animaatiot.SetBool("defending", false);
        m_scythe_animaatio.SetBool("scythe_attack", false);
        // very bad style but we need to disable the animator in order for manual rotating to work
        m_scythe_animaatio.enabled = true;

        // Scythe attack
        if (Input.GetButtonDown("Fire1")) {
            m_reaper_animaatiot.SetBool("attacking", true);
            m_scythe_animaatio.SetBool("scythe_attack", true);
            soundhandler.scytheääni();
        }

        // Scythe defence
        if (Input.GetButton("Fire2")) {
            m_reaper_animaatiot.SetBool("defending", true);
            m_scythe_animaatio.enabled = false;
            m_scythe.transform.Rotate(0, -200, 0);
            soundhandler.scytheääni();
        }
        
        // Return to defaul stance according characters rotation
        // Very difficult to understand, I come up with this by accident
        if (Input.GetButtonUp("Fire2")) {
            m_scythe.transform.localRotation = new Quaternion(90,transform.rotation.y,0, 90);
        }
    }

    public int do_damage() {
        soundhandler.osumaääni();
        return m_Damage;
    }
}
