using System;
using Cute;
using Wizard;

public class AITurnControl
{
	private DateTime _startTime;

	private bool _isStartTimer;

	public AITurnControl()
	{
		_isStartTimer = false;
	}

	public void StartTurnTimer()
	{
		_isStartTimer = true;
		_startTime = TimeUtil.GetAbsoluteTime();
	}

	public void SetAndStartTurnTimer(DateTime time)
	{
		_isStartTimer = true;
		_startTime = time;
	}

	public void Update(IEnemyAI ai)
	{
		if (ToolboxGame.RealTimeNetworkAgent != null && ToolboxGame.RealTimeNetworkAgent.PlayerNetworkStatus.IsAlive && !ai.IsConnectNetwork)
		{
			ai.Reconnect();
		}
		if (!_isStartTimer || !ToolboxGame.RealTimeNetworkAgent.PlayerNetworkStatus.IsAlive)
		{
			if (_isStartTimer && ai.IsConnectNetwork)
			{
				ai.Disconnect();
			}
		}
		else if ((float)NetworkUtility.GetTimeSpanSecond(_startTime.Ticks) >= 90f)
		{
			if (ai.IsStackAction)
			{
				ai.CleanupStackedAction();
			}
			if (!ai.IsStackAction)
			{
				ai.TurnEnd();
			}
		}
	}

	public void StopTurnTimer()
	{
		_isStartTimer = false;
	}
}
