


using System;
using System.Collections;
using UnityEngine;

namespace Subworlds.Scripts
{
  class AttackDroidScript : EnemyScript
  {
    private Vector3 dir;
    private bool attacking;

    private void Awake()
    {
      base.Initialize(100, 5, 70, new int[] { 3, 3, 57 }, 60);
    }

    private void Update()
    {
      if (Network.isServer)
      {
        if (!this.attacking)
        {
          this.r.velocity = new Vector3(0f, 0f, 0f);
          if (this.target)
          {
            if (Mathf.Abs(this.target.transform.position.x - this.t.position.x) < 45f)
            {
              this.attacking = true;
              base.StartCoroutine(this.Attack());
            }
            else
            {
              this.target = null;
              this.r.velocity = new Vector3(0f, 0f, 0f);
            }
          }
        }
      }
    }

    private IEnumerator Attack()
    {
      gameObject.transform.GetChild(0).gameObject.GetComponent<Animation>().Play();
      yield return new WaitForSeconds(0.55f);
      this.dir = this.target.transform.position - this.t.position;
      this.dir.Normalize();
      yield return new WaitForSeconds(0.05f);
      this.r.velocity = this.dir * (35f);
      yield return new WaitForSeconds(0.9f);
      this.r.velocity = new Vector3(0f, 0f, 0f);
      this.attacking = false;
      yield break;
    }
  }
}