﻿using UnityEngine;
using System.Collections;

[RequireComponent (typeof(Attacker))]
public class SnowGoon : MonoBehaviour {

	private Attacker attacker;
	private Animator anim;
	public bool hasPole = false;


	// Use this for initialization
	void Start () {
		anim = GetComponent<Animator> ();
		attacker = GetComponent<Attacker> ();
	}
	
	// Update is called once per frame
	void Update () {
		//Check health from time to time, if the snow goon has a pole to jump check
		// if health has decreased too low, lose the pole and the ability to jump.
	}

	void OnTriggerEnter2D (Collider2D collider) {
		GameObject obj = collider.gameObject;

		//Scripts for collision matrix

		//This is not the defender you're looking for
		if (!obj.GetComponent<Defender> ()) {
			return;
		}

		//For the jumping snow goons and obstacles
		if (obj.tag == "Obstacle" && hasPole) {
			anim.SetBool ("obstacleInPath", true);
			// in animation, add event "Jump Complete" to avoid repeating animation
		} else {
			//everyhting else gets clawed to death
			anim.SetBool("isAttacking", true);
			attacker.Attack(obj);
		}

	}

	void JumpComplete () {
		anim.SetBool("obstacleInPath", false);
	}
}
