using UnityEngine;
using System.Collections;

public class EnemyCollision : MonoBehaviour {

	private bool isHit;
	private EnemyAI enemyStats;
	private PlayerStats playerStats;

	void Start(){
		isHit = false;
		enemyStats = GameObject.Find ("Enemy").GetComponent<EnemyAI> ();
		playerStats = GameObject.Find ("Player").GetComponent<PlayerStats> ();
	}

	/*
	 * All enemy interactions handled here
	 */ 
	void OnTriggerEnter2D(Collider2D col){
		if (isHit == true) { // If hit recently, don't register hits
			return;
		}
		if (isHit == false) {
			if (col.tag == "currentWeapon") { // Enemy hits with slash attack
				isHit = true;
				enemyStats.Damage (playerStats.getDamageOutput());
				// stats.knockback()
				StartCoroutine (ExecuteAfterTime (1));
			}
			if (col.tag == "playerKick") { // Enemy hits with kick attack
				isHit = true;
				enemyStats.Damage (2);
				// stats.shieldBreak()
				// Check if shielding in other script
				StartCoroutine (ExecuteAfterTime (0.2f));
			}
		}

	}
	/*
	 * After parameter time, sets player hitable again
	 */ 
	IEnumerator ExecuteAfterTime(float time){ 
		yield return new WaitForSeconds (time);
		isHit = false;
	}

}