using System.Collections.Generic;
using UnityEngine;

public class ArrowControl : MonoBehaviour
{
	[SerializeField]
	private GameObject ArrowHead;

	[SerializeField]
	private GameObject ArrowEfc;

	[SerializeField]
	private int DivideCnt = 10;

	[SerializeField]
	private bool isEvo;

	private IList<GameObject> ArrowEfcList;

	private GameObject FromObj;

	private GameObject ToObj;

	private bool isOn;

	private bool _isTargettingEnemy;

	private float ChangeTime;

	private IList<int> ArrowTarList;

	private void Start()
	{
		ArrowEfcList = new List<GameObject>();
		ArrowEfcList.Add(ArrowEfc);
		for (int i = 1; i < DivideCnt; i++)
		{
			GameObject gameObject = Object.Instantiate(ArrowEfc);
			if (!(null == gameObject))
			{
				gameObject.transform.parent = base.transform;
				ArrowEfcList.Add(gameObject);
			}
		}
		ArrowTarList = new List<int>();
		for (int j = 0; j < DivideCnt; j++)
		{
			ArrowTarList.Add(j);
		}
		HideArrow();
	}

	private void Update()
	{
		if (isOn)
		{
			SetArrowLine();
		}
	}

	public void ShowArrow(GameObject fromObj, GameObject toObj, bool isTargettingEnemy)
	{
		FromObj = fromObj;
		ToObj = toObj;
		_isTargettingEnemy = isTargettingEnemy;
		isOn = true;
		base.gameObject.SetActive(value: true);
	}

	public void HideArrow()
	{
		isOn = false;
		for (int i = 0; i < DivideCnt; i++)
		{
			ArrowEfcList[i].SetActive(value: false);
		}
		base.gameObject.SetActive(value: false);
	}

	private void SetArrowLine()
	{
		if (isEvo)
		{
			ChangeTime -= Time.deltaTime * 5f;
		}
		else
		{
			ChangeTime -= Time.deltaTime;
		}
		if (ChangeTime <= 0f)
		{
			ChangeTime = 1f;
			ArrowTarList.Add(ArrowTarList[0]);
			ArrowTarList.RemoveAt(0);
		}
		ArrowHead.transform.position = ToObj.transform.position;
		Vector3 position = FromObj.transform.position;
		Vector3 position2 = ToObj.transform.position;
		Vector3 p = (_isTargettingEnemy ? position : position2) + Vector3.back * Vector3.Distance(position, position2) + Vector3.down * Vector3.Distance(position, position2) * -0.5f;
		Vector3[] array = new Vector3[DivideCnt];
		array = MotionUtils.GetBezierQuad(position, p, position2, DivideCnt);
		for (int i = 0; i < array.Length; i++)
		{
			float num = 1f - ChangeTime;
			if (ArrowTarList[i] != 0)
			{
				ArrowEfcList[i].SetActive(value: true);
				ArrowEfcList[i].transform.position = (array[ArrowTarList[i]] - array[ArrowTarList[i] - 1]) * num + array[ArrowTarList[i] - 1];
			}
			else
			{
				ArrowEfcList[i].SetActive(value: false);
				ArrowEfcList[i].transform.position = array[0];
			}
		}
	}
}
