using UnityEngine;
using System.Collections;

// controls enemy starship - use weapons and devices automatic
public class StarShipAI : MonoBehaviour
{
	[SerializeField] StarShip controlledShip = null;
	[SerializeField] float startDelay = 2f; // in seconds

	float startTimer = 0;


	Weapon[] controlledWeapons = null;

	void Start () {
		if (controlledShip == null)
		{
			controlledShip = GetComponentInChildren<StarShip>();
		}
		if (controlledShip != null)
		{
			controlledWeapons = controlledShip.weapons.ToArray();
		}
		startTimer = startDelay;
	}

	void Update ()
	{
		if (startTimer > 0)
		{
			startTimer -= Time.deltaTime;
			return;
		}
		if (controlledWeapons != null && controlledShip != null && controlledShip.hitPoints > 0)
		{
			foreach(var weapon in controlledWeapons)
			{
				if (weapon != null)
				{
					if (weapon.IsReady)
					{
						weapon.Fire();
					}
				}
			}
		}
	}
}
