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

public class ZombieChaseState : BaseZombieAIState {

    private float attackRange = 1;

    private float maxChaseDistance = 20;

    public override void InitState()
    {
        base.InitState();

        this.controller.Zombie.Movement.IsSlowerDown = false;
    }

    public override void UpdateState()
    {
        base.UpdateState();

        if (this.controller.Target) {

            if (!this.controller.Target.Health.IsAlive)
            {
                this.controller.ChangeState(new ZombiePatrolState());
                return;
            }

            if (this.controller.Target is Player) {
                if (!(this.controller.Target as Player).HasAntena) {
                    // TODO: find antena
                    this.controller.ChangeState(new ZombieTransportState());
                    return;
                }
            }

            var dist = Vector3.Distance (this.controller.transform.position, this.controller.Target.transform.position);
            if (dist < this.attackRange ) {
                this.controller.ChangeState(new ZombieAttackState());
            } else if (dist > this.maxChaseDistance) {
                this.controller.ChangeState(new ZombiePatrolState());
            } else {
                this.controller.Zombie.Movement.MoveTo(this.controller.Target.transform.position);
            }
        }
    }

    public override void DeinitState()
    {
        this.controller.Zombie.Movement.IsSlowerDown = true;

        base.DeinitState();
    }
}