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

public class CharacterAttacker : MonoBehaviour {

    [SerializeField]
    private float attackInterval = 2f;

    [SerializeField]
    private uint attackDamage = 30;

    private float lastAttack = 0;

    protected Character controller;

    public virtual void PrepareAttacker (Character controller) {
        this.controller = controller;
        lastAttack = 0;
    }

    public void Attack () {
        if (Time.time - this.lastAttack > this.attackInterval) {

            this.lastAttack = Time.time;
            this.controller.CharacterAnimator.SetTrigger(Keys.Animator.ATTACK_KEY);

            if (this.controller is Zombie) {
                var ai = this.controller.GetComponent<ZombieAIController>();
                if (ai) {
                    var target = ai.Target.GetComponent<Character>();
                    if (target) {
                        target.Health.DealDamage(this.attackDamage);
                    }
                }
            }
        }
    }
}