using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Cute;
using LitJson;
using UnityEngine;
using Wizard.Battle.Mulligan;
using Wizard.Battle.Operation;
using Wizard.Battle.Phase;
using Wizard.Battle.Touch;
using Wizard.Battle.View;
using Wizard.Battle.View.Vfx;

namespace Wizard.Battle.Recovery;

public class RecoveryDataHandler
{
	protected bool isEmitEnterRoom;

	protected NetworkBattleManagerBase _networkBattleMgr;

	protected StockReceiveMgr stockReceiveMessageMgr = new StockReceiveMgr("seq");

	protected Coroutine _coroutineInBattle;

	protected const string DATA_PARAM_VID = "vid";

	protected const string DATA_PARAM_URI = "uri";

	protected const string DATA_PARAM_TIME = "time";

	private readonly List<NetworkBattleDefine.NetworkBattleURI> RecoveryExceptUriList = new List<NetworkBattleDefine.NetworkBattleURI>
	{
		NetworkBattleDefine.NetworkBattleURI.ChatStamp,
		NetworkBattleDefine.NetworkBattleURI.Touch,
		NetworkBattleDefine.NetworkBattleURI.TurnEndReady,
		NetworkBattleDefine.NetworkBattleURI.SelectSkill,
		NetworkBattleDefine.NetworkBattleURI.SlideObject,
		NetworkBattleDefine.NetworkBattleURI.SelectObject
	};

	private NetworkBattleDefine.NetworkBattleURI _hasSequenceUri;

	private int _hasSequenceResult;

	private bool _isPlayerSend;

	private bool _isOpponentDisconnect;

	private Coroutine _timeOutCoroutine;

	private bool isFirstTimeSet;

	private DateTime _firstTime;

	private DateTime _lastTime;

	private float _pastTime;

	private DateTime _battleStartDate;

	private const int TIMEOUT_TIME = 10;

	private JsonData jsonObject;

	private Action OnFinishRecoveryLogSync;

	private bool isTurnStartWithNoAction;

	private CanNotTouchCardVfx _canNotTouchCardVfx;

	private const float FUSION_WAIT_TIME = 0.3f;

	private const string RECOVERY_KEY = "operations";

	private const string OPERATION_KEY = "operation";

	private const string SEQ_KEY = "seq";

	private const string PLAY_KEY = "play";

	private const string BOOL_KEY = "bool";

	private const string INDEX_KEY = "index";

	private const string SKILL_TARGET_KEY = "skill_target";

	private const string TARGET_KEY = "target";

	private const string ATTACK_KEY = "attack";

	private const string EVOLVE_KEY = "evolve";

	private const string MULLIGAN_KEY = "mulligan";

	private const string MULLIGAN_ABANDON = "abandoned_cards";

	private const string TURN_END_KEY = "turn_end";

	private const string IS_BURIAL_RITE_KEY = "is_burial_rite";

	public const string IS_CHOICE_BRAVE_KEY = "is_choice_brave";

	private const string START_CHOICE_KEY = "start_choice";

	private const string START_SELECT_KEY = "start_select";

	public const string START_FUSION_KEY = "start_fusion";

	private const string SELECT_KEY = "select";

	public const string SELECT_FUSION_KEY = "select_fusion";

	private const string CANCEL_SELECT_KEY = "cancel_select";

	private const string CANCEL_CHOICE_KEY = "cancel_choice";

	public const string CANCEL_FUSION_KEY = "cancel_fusion";

	private const string COMP_CHOICE_KEY = "comp_choice";

	private const string COMP_SELECT_KEY = "comp_select";

	public const string COMP_FUSION = "comp_fusion";

	private List<object> _mulliganList = new List<object>();

	private int playIndex;

	public int receivedMaxSequenceNum { get; protected set; }

	public event Action OnCompleteRecovery;

	public RecoveryDataHandler(NetworkBattleManagerBase networkbattleManager, Action onFinishRecoveringData, Action onFinishRecoveryLogSync, RecoveryOperationInfo aiBattleRecoveryData = null)
	{
		OnFinishRecoveryLogSync = onFinishRecoveryLogSync;
		if (GameMgr.GetIns().IsAINetwork)
		{
			if (aiBattleRecoveryData != null)
			{
				AISetup(networkbattleManager, onFinishRecoveringData, aiBattleRecoveryData);
			}
			else
			{
				RecoveryManagerBase.OpenRecoveryFailedDialog();
			}
			return;
		}
		string text = OperationRecorderBase.RecordDirectoryPath + "recovery_network.json";
		if (File.Exists(text))
		{
			jsonObject = RecoveryOperationInfo.ReadRecoveryFile(text);
			Setup(networkbattleManager, onFinishRecoveringData);
		}
		else
		{
			RecoveryManagerBase.OpenRecoveryFailedDialog();
		}
	}

	private void Setup(NetworkBattleManagerBase networkbattleManager, Action onFinishRecoveringData)
	{
		_networkBattleMgr = networkbattleManager;
		_coroutineInBattle = BattleCoroutine.GetInstance().StartCoroutine(StockDataPlayer(onFinishRecoveringData));
	}

	private void AISetup(NetworkBattleManagerBase networkbattleManager, Action onFinishRecoveringData, RecoveryOperationInfo aiBattleRecoveryData)
	{
		_networkBattleMgr = networkbattleManager;
		_coroutineInBattle = BattleCoroutine.GetInstance().StartCoroutine(AIStockDataPlayer(onFinishRecoveringData, aiBattleRecoveryData));
	}

	public virtual void Stop()
	{
		BattleCoroutine.GetInstance().StopCoroutine(_coroutineInBattle);
	}

	public void OnBattleReceived()
	{
		Dictionary<string, object> play_list = Data.BattleRecoveryInfo.play_list;
		if (play_list != null && play_list.ContainsKey("uri"))
		{
			string text = play_list["uri"].ToString();
			if (text != null && text == "Watch")
			{
				ParseBattleWatchData(play_list);
			}
		}
	}

	private void ParseBattleWatchData(Dictionary<string, object> received)
	{
		if (!received.TryGetValue("playlist", out var value) || !(value is List<object> list))
		{
			return;
		}
		for (int i = 0; i < list.Count; i++)
		{
			Dictionary<string, object> dictionary = list[i] as Dictionary<string, object>;
			int num = int.Parse(dictionary["seq"].ToString());
			if (receivedMaxSequenceNum < num)
			{
				receivedMaxSequenceNum = int.Parse(dictionary["seq"].ToString());
			}
			if (stockReceiveMessageMgr.CheckStockData(dictionary))
			{
				stockReceiveMessageMgr.StockData(dictionary);
			}
		}
	}

	public int GetWatchSequenceNum()
	{
		return stockReceiveMessageMgr.GetMaxSequenceNumber();
	}

	public int GetCurrentSequenceNumber()
	{
		return stockReceiveMessageMgr.SequenceAlreadyNumber;
	}

	protected IEnumerator StockDataPlayer(Action onFinishRecoveringData)
	{
		while (true)
		{
			if ((bool)ToolboxGame.RealTimeNetworkAgent && !ToolboxGame.RealTimeNetworkAgent.IsPlayReceiveDataOk())
			{
				yield return null;
				continue;
			}
			if (stockReceiveMessageMgr.SequenceAlreadyNumber == GetWatchSequenceNum())
			{
				_networkBattleMgr.GetNetworkBattleReceiver().CheckLatestReplayInfoInRecoveryExceptUriList();
				CallRecoveryFinish(onFinishRecoveringData, waitForAck: true);
			}
			Dictionary<string, object> dictionary = stockReceiveMessageMgr.FindData(stockReceiveMessageMgr.SequenceAlreadyNumber + 1);
			if (dictionary != null)
			{
				bool flag = isOwner(dictionary["vid"].ToString());
				string value = dictionary["uri"].ToString();
				if (!Enum.IsDefined(typeof(NetworkBattleDefine.NetworkBattleURI), value))
				{
					NextStockReceive(dictionary);
					continue;
				}
				NetworkBattleDefine.NetworkBattleURI networkBattleURI = (NetworkBattleDefine.NetworkBattleURI)Enum.Parse(typeof(NetworkBattleDefine.NetworkBattleURI), value);
				if (networkBattleURI == NetworkBattleDefine.NetworkBattleURI.PlayActions || networkBattleURI == NetworkBattleDefine.NetworkBattleURI.TurnStart || networkBattleURI == NetworkBattleDefine.NetworkBattleURI.TurnEndActions || networkBattleURI == NetworkBattleDefine.NetworkBattleURI.Echo)
				{
					ToolboxGame.RealTimeNetworkAgent.AddActionSequence();
					LocalLog.AccumulateLastTraceLog("uri:" + networkBattleURI.ToString() + " ActionSeq:" + ToolboxGame.RealTimeNetworkAgent.GetActionSequenceCount() + " Recovery");
				}
				if (networkBattleURI == NetworkBattleDefine.NetworkBattleURI.BattleStart)
				{
					DateTime battleStartDate = ((!dictionary.ContainsKey(NetworkBattleDefine.NetworkParameterNames[NetworkBattleDefine.NetworkParameter.battleStartDate])) ? GetCulculateWaitTime(double.Parse(dictionary["time"].ToString())) : new DateTime(long.Parse(dictionary[NetworkBattleDefine.NetworkParameterNames[NetworkBattleDefine.NetworkParameter.battleStartDate]].ToString())));
					_battleStartDate = battleStartDate;
					ToolboxGame.RealTimeNetworkAgent.SetIsBattleStart(flag: true);
				}
				if (networkBattleURI == NetworkBattleDefine.NetworkBattleURI.JudgeResult)
				{
					_hasSequenceResult = int.Parse(dictionary[NetworkBattleDefine.NetworkParameterNames[NetworkBattleDefine.NetworkParameter.result]].ToString());
				}
				RecordLogTime(dictionary, networkBattleURI);
				CheckNoAction(flag, networkBattleURI);
				if (!flag)
				{
					bool isOpponentDisconnected = ToolboxGame.RealTimeNetworkAgent.IsOpponentDisconnected;
					bool flag2 = networkBattleURI == NetworkBattleDefine.NetworkBattleURI.OppoDisconnect;
					_isOpponentDisconnect = isOpponentDisconnected || flag2;
				}
				if (!RecoveryExceptUriList.Contains(networkBattleURI))
				{
					if (networkBattleURI != NetworkBattleDefine.NetworkBattleURI.OppoDisconnect && networkBattleURI != NetworkBattleDefine.NetworkBattleURI.RecoveryStart && networkBattleURI != NetworkBattleDefine.NetworkBattleURI.RecoveryEnd && (networkBattleURI != NetworkBattleDefine.NetworkBattleURI.JudgeResult || _hasSequenceResult != 0))
					{
						_hasSequenceUri = networkBattleURI;
						_isPlayerSend = flag;
					}
					if (networkBattleURI == NetworkBattleDefine.NetworkBattleURI.TurnStart && flag)
					{
						_networkBattleMgr.BattlePlayer.PlayerEmotion.ResetPlayCount();
					}
					_networkBattleMgr.GetNetworkBattleReceiver().ReceivedMessage(networkBattleURI, isHaveSequence: true, dictionary, flag, null, checkBreakData: false);
					if (_hasSequenceUri == NetworkBattleDefine.NetworkBattleURI.TurnEndFinal || _hasSequenceUri == NetworkBattleDefine.NetworkBattleURI.BattleFinish || _hasSequenceUri == NetworkBattleDefine.NetworkBattleURI.Retire)
					{
						CallRecoveryFinish(onFinishRecoveringData, waitForAck: false);
					}
				}
				else
				{
					_networkBattleMgr.GetNetworkBattleReceiver().RecordReplayInfoInRecoveryExceptUriList(networkBattleURI, isHaveSequence: true, dictionary, flag);
				}
				if (networkBattleURI == NetworkBattleDefine.NetworkBattleURI.ChatStamp && flag)
				{
					_networkBattleMgr.BattlePlayer.PlayerEmotion.AddPlayCount();
				}
				NextStockReceive(dictionary);
			}
			yield return null;
		}
	}

	private void NextStockReceive(Dictionary<string, object> frontData)
	{
		stockReceiveMessageMgr.UpdateSequenceAlreadyNumber(frontData);
		stockReceiveMessageMgr.RemoveSelectData(frontData);
	}

	protected IEnumerator AIStockDataPlayer(Action onFinishRecoveringData, RecoveryOperationInfo aiBattleRecoveryData)
	{
		if (!aiBattleRecoveryData.SetupInfo.HasMulliganInfo)
		{
			yield return null;
			AICallRecoveryFinish(onFinishRecoveringData, waitForAck: true, aiBattleRecoveryData);
		}
		else
		{
			SingleMulliganMgr singleMulliganMgr = new SingleMulliganMgr();
			MulliganInfoControl component = GameMgr.GetIns().GetGameObjMgr().AddUIContainerChildPrefab("Prefab/UI/MulliganInfo")
				.GetComponent<MulliganInfoControl>();
			singleMulliganMgr.InitMulligan(component, _networkBattleMgr.BattlePlayer.PlayerBattleView);
			SkillProcessor skillProcessor = new SkillProcessor();
			singleMulliganMgr.MulliganStartDraw(aiBattleRecoveryData.SetupInfo.DidPlayerGoFirst, skillProcessor);
			foreach (int playerMulliganReplaceCard in aiBattleRecoveryData.SetupInfo.PlayerMulliganReplaceCards)
			{
				int cardIndex = playerMulliganReplaceCard;
				BattleCardBase battleCardBase = _networkBattleMgr.BattlePlayer.HandCardList.SingleOrDefault((BattleCardBase c) => c.Index == cardIndex);
				if (battleCardBase != null)
				{
					singleMulliganMgr.AbandonList.Add(battleCardBase);
				}
			}
			singleMulliganMgr.Submit(BattleManagerBase.GetIns());
			singleMulliganMgr.GetMulliganInfo().SetPlayerReady();
			IEnumerable<IOperationCommand> _commands = aiBattleRecoveryData.ActionCommands;
			EnemyAI ai = BattleManagerBase.GetIns().EnemyAI as EnemyAI;
			while (_commands.Any())
			{
				IOperationCommand operationCommand = _commands.FirstOrDefault();
				if (operationCommand != null)
				{
					bool isSelfTurn = _networkBattleMgr.BattlePlayer.IsSelfTurn;
					operationCommand.Operation(_networkBattleMgr);
					ai.UpdateAICurrentVirtualField();
					if (operationCommand is TurnEndOperationCommand && !_networkBattleMgr.IsBattleEnd)
					{
						if (isSelfTurn)
						{
							_networkBattleMgr.ControlTurnStartOpponent();
						}
						else
						{
							_networkBattleMgr.ControlTurnStartPlayer();
						}
						ai.UpdateAICurrentVirtualField();
					}
				}
				_commands = _commands.Skip(1);
				yield return null;
			}
			if (_networkBattleMgr.BattlePlayer.IsSelfTurn)
			{
				_networkBattleMgr.BattlePlayer.TurnStartEffectEnd();
			}
			AICallRecoveryFinish(onFinishRecoveringData, waitForAck: true, aiBattleRecoveryData);
		}
		yield return null;
	}

	private void CheckNoAction(bool isPlayer, NetworkBattleDefine.NetworkBattleURI uri)
	{
		if (isPlayer)
		{
			switch (uri)
			{
			case NetworkBattleDefine.NetworkBattleURI.TurnStart:
				isTurnStartWithNoAction = true;
				break;
			default:
				isTurnStartWithNoAction = false;
				break;
			case NetworkBattleDefine.NetworkBattleURI.OppoDisconnect:
			case NetworkBattleDefine.NetworkBattleURI.RecoveryStart:
			case NetworkBattleDefine.NetworkBattleURI.RecoveryEnd:
				break;
			}
		}
	}

	private void RecordLogTime(Dictionary<string, object> frontData, NetworkBattleDefine.NetworkBattleURI uri)
	{
		if (!frontData.ContainsKey("time"))
		{
			return;
		}
		if (!_networkBattleMgr._recoveryController.IsMariganFinished)
		{
			if (!isFirstTimeSet)
			{
				isFirstTimeSet = true;
				_firstTime = GetCulculateWaitTime(double.Parse(frontData["time"].ToString()));
			}
		}
		else if (uri == NetworkBattleDefine.NetworkBattleURI.TurnStart || uri == NetworkBattleDefine.NetworkBattleURI.Ready)
		{
			isFirstTimeSet = true;
			_firstTime = GetCulculateWaitTime(double.Parse(frontData["time"].ToString()));
		}
		_lastTime = GetCulculateWaitTime(double.Parse(frontData["time"].ToString()));
	}

	private void CallRecoveryFinish(Action onFinishRecoveringData, bool waitForAck)
	{
		onFinishRecoveringData.Call();
		_networkBattleMgr.SetupFieldAndHandAfterRecovery(delegate
		{
			CompleteRecovery(waitForAck);
		});
	}

	private void AICallRecoveryFinish(Action onFinishRecoveringData, bool waitForAck, RecoveryOperationInfo aiBattleRecoveryData)
	{
		onFinishRecoveringData.Call();
		_networkBattleMgr._recoveryController = null;
		SequentialVfxPlayer sequentialVfxPlayer = SequentialVfxPlayer.Create();
		if (!aiBattleRecoveryData.SetupInfo.HasMulliganInfo)
		{
			if (!aiBattleRecoveryData.SetupInfo.HasMulliganInfo)
			{
				sequentialVfxPlayer = SequentialVfxPlayer.Create(_networkBattleMgr.MulliganMgr.RecoverMulligan(didPlayerSubmitMulligan: false, _networkBattleMgr), InstantVfx.Create(delegate
				{
					if (_networkBattleMgr.GetCurrentPhase() is RecoveryNetworkBeforeSubmitMulliganPhase recoveryNetworkBeforeSubmitMulliganPhase)
					{
						recoveryNetworkBeforeSubmitMulliganPhase.RecoveryEnd();
					}
				}));
			}
		}
		else
		{
			_networkBattleMgr.ReinitializeTurnPanelControl();
			_networkBattleMgr.BattlePlayer.PlayerBattleView.ClearPlayQueue();
			if (_networkBattleMgr.BattlePlayer.IsSelfTurn)
			{
				_networkBattleMgr.BattlePlayer.TurnStartEffectEnd();
			}
			_networkBattleMgr.SetupFieldAndHandAfterRecovery(null, aiBattleRecoveryData);
			ParallelVfxPlayer vfx = ParallelVfxPlayer.Create(InstantVfx.Create(delegate
			{
				GameMgr.GetIns().GetBattleCtrl().StartCoroutine(FontChanger.FontChange(null));
			}), _networkBattleMgr.BattlePlayer.Recovery(), _networkBattleMgr.BattleEnemy.Recovery());
			IBattlePlayerView battlePlayerView = (_networkBattleMgr.BattleEnemy.IsSelfTurn ? _networkBattleMgr.BattleEnemy.BattleView : _networkBattleMgr.BattlePlayer.BattleView);
			sequentialVfxPlayer.Register(vfx);
			sequentialVfxPlayer.Register(HandViewBase.CreateHideCardMeshesVfx(_networkBattleMgr.BattleEnemy.HandCardList));
			sequentialVfxPlayer.Register(InstantVfx.Create(delegate
			{
				_networkBattleMgr.BattlePlayer.UpdateHandCardsPlayability();
			}));
			sequentialVfxPlayer.Register(battlePlayerView.RecoveryTurnStart());
			sequentialVfxPlayer.Register(_networkBattleMgr.GetCurrentPhase().Setup());
		}
		AIOpenRecovery(aiBattleRecoveryData);
		sequentialVfxPlayer.Register(InstantVfx.Create(delegate
		{
			_networkBattleMgr.BattlePlayer.PlayerBattleView.ResetTouchable();
			if (_canNotTouchCardVfx != null)
			{
				_canNotTouchCardVfx.End();
				_canNotTouchCardVfx = null;
			}
			_networkBattleMgr.RecoveryEnd();
			ToolboxGame.RealTimeNetworkAgent.EndRecovery();
			ToolboxGame.UIManager.CloseInSceneLoadingBattle();
		}));
		sequentialVfxPlayer.Register(_networkBattleMgr.JudgeBattleResult());
		_networkBattleMgr.VfxMgr.RegisterSequentialVfx(sequentialVfxPlayer);
	}

	private void CompleteRecovery(bool waitForAck)
	{
		Stop();
		_networkBattleMgr.RecoveryEnd();
		StopTimeOut();
		NetworkBattleReceiver.RESULT_CODE rESULT_CODE = _networkBattleMgr.JudgeCurrentFinishStatus();
		SequentialVfxPlayer sequentialVfxPlayer = SequentialVfxPlayer.Create();
		if (_networkBattleMgr.IsBattleEnd)
		{
			sequentialVfxPlayer.Register(InstantVfx.Create(delegate
			{
				_networkBattleMgr.BattlePlayer.PlayerBattleView.HideTurnEndButton();
			}));
		}
		bool flag = false;
		bool isCheckTimeOutTurnEnd = true;
		switch (rESULT_CODE)
		{
		case NetworkBattleReceiver.RESULT_CODE.DeckoutWin:
			CheckDeckoutResult(sequentialVfxPlayer, isDeckoutWin: true);
			break;
		case NetworkBattleReceiver.RESULT_CODE.DeckoutLose:
			CheckDeckoutResult(sequentialVfxPlayer, isDeckoutWin: false);
			break;
		case NetworkBattleReceiver.RESULT_CODE.NotFinish:
			if (_networkBattleMgr._specialWinVfx != null)
			{
				RegisterSpecialWin(sequentialVfxPlayer);
				break;
			}
			switch (_hasSequenceUri)
			{
			case NetworkBattleDefine.NetworkBattleURI.TurnEndActions:
				if (_isPlayerSend)
				{
					GameMgr.GetIns().GetNetworkUserInfoData().TurnState = 0;
					_networkBattleMgr.SendTurnEnd();
				}
				else
				{
					_networkBattleMgr.networkBattleData.isReceiveTurnEndAction = true;
					_networkBattleMgr.SendEcho(_networkBattleMgr.networkBattleData.GetReceiveData().playCardIndex, _networkBattleMgr.networkBattleData.GetReceiveData().actionType, isNotActiveSeq: true);
				}
				break;
			case NetworkBattleDefine.NetworkBattleURI.TurnEnd:
			{
				GameMgr.GetIns().GetNetworkUserInfoData().TurnState = 0;
				bool flag2 = false;
				if (!_isPlayerSend)
				{
					flag2 = true;
				}
				else if (_networkBattleMgr.BattlePlayer.IsExtraTurn && !_isOpponentDisconnect)
				{
					flag2 = true;
				}
				if (flag2)
				{
					_networkBattleMgr.SendJudge();
					flag = true;
					RealTimeNetworkAgent realTimeNetworkAgent = ToolboxGame.RealTimeNetworkAgent;
					realTimeNetworkAgent.OnAck = (Action<Dictionary<string, object>>)Delegate.Combine(realTimeNetworkAgent.OnAck, new Action<Dictionary<string, object>>(AckTurnStartToRecoveryEnd));
				}
				break;
			}
			case NetworkBattleDefine.NetworkBattleURI.Ready:
				sequentialVfxPlayer.Register(_networkBattleMgr.StartBattle());
				break;
			case NetworkBattleDefine.NetworkBattleURI.TurnStart:
				if (_networkBattleMgr.BattlePlayer.IsShortageDeck)
				{
					sequentialVfxPlayer.Register(SendDeckShortage(_networkBattleMgr.BattlePlayer));
				}
				else if (_networkBattleMgr.BattleEnemy.IsShortageDeck)
				{
					sequentialVfxPlayer.Register(SendDeckShortage(_networkBattleMgr.BattleEnemy));
				}
				else if (!_isPlayerSend && _networkBattleMgr.BattlePlayer.IsExtraTurn)
				{
					_networkBattleMgr.SendEcho(_networkBattleMgr.networkBattleData.GetReceiveData().playCardIndex, _networkBattleMgr.networkBattleData.GetReceiveData().actionType);
				}
				GameMgr.GetIns().GetNetworkUserInfoData().TurnState = ((!_networkBattleMgr.BattlePlayer.IsSelfTurn) ? 1 : 0);
				break;
			case NetworkBattleDefine.NetworkBattleURI.Judge:
				if (_networkBattleMgr.BattlePlayer.IsExtraTurn)
				{
					_networkBattleMgr.VfxMgr.RegisterSequentialVfx(_networkBattleMgr.ControlTurnStartOpponent());
					GameMgr.GetIns().GetNetworkUserInfoData().TurnState = 0;
					isCheckTimeOutTurnEnd = false;
				}
				else if (_networkBattleMgr.IsBeforePlayerTurn)
				{
					sequentialVfxPlayer.Register(_networkBattleMgr.ControlTurnStartPlayer());
					GameMgr.GetIns().GetNetworkUserInfoData().TurnState = 0;
					isCheckTimeOutTurnEnd = false;
				}
				else
				{
					GameMgr.GetIns().GetNetworkUserInfoData().TurnState = 0;
				}
				break;
			default:
				if (_networkBattleMgr._recoveryController.IsMariganFinished)
				{
					GameMgr.GetIns().GetNetworkUserInfoData().TurnState = ((!_networkBattleMgr.BattlePlayer.IsSelfTurn) ? 1 : 0);
				}
				break;
			}
			break;
		default:
			if (_networkBattleMgr.IsBattleEnd)
			{
				BattlePlayer battlePlayer = _networkBattleMgr.BattlePlayer;
				BattleEnemy battleEnemy = _networkBattleMgr.BattleEnemy;
				ParallelVfxPlayer parallelVfxPlayer = ParallelVfxPlayer.Create();
				if (battlePlayer.Class.IsDead)
				{
					parallelVfxPlayer.Register(battlePlayer.Class.DestroyInPlay(new SkillProcessor()));
				}
				if (battleEnemy.Class.IsDead)
				{
					parallelVfxPlayer.Register(battleEnemy.Class.DestroyInPlay(new SkillProcessor()));
				}
				sequentialVfxPlayer.Register(parallelVfxPlayer);
			}
			break;
		}
		_networkBattleMgr.VfxMgr.RegisterSequentialVfx(SequentialVfxPlayer.Create(InstantVfx.Create(delegate
		{
			_networkBattleMgr.BattlePlayer.PlayerBattleView.ResetTouchable();
			ToolboxGame.RealTimeNetworkAgent.EndRecovery();
			_networkBattleMgr._recoveryController = null;
			if (_networkBattleMgr.BattlePlayer.IsSelfTurn || !Data.BattleRecoveryInfo.IsMulliganEnd)
			{
				RecoveryCreateRegisterAction(delegate
				{
					if (!_networkBattleMgr.IsBattleEnd)
					{
						IPlayerView playerBattleView = _networkBattleMgr.BattlePlayer.PlayerBattleView;
						playerBattleView.TurnEndButtonUI._isButtonForcedOff = false;
						_networkBattleMgr.BattlePlayer.TurnStartEffectEnd();
						playerBattleView.ShowTurnEndButton();
					}
					if (!Data.BattleRecoveryInfo.IsReceivedDeal)
					{
						_networkBattleMgr.NetworkSender.SendDeal();
					}
					if (_canNotTouchCardVfx != null)
					{
						_canNotTouchCardVfx.End();
						_canNotTouchCardVfx = null;
					}
					OpenRecovery(isCheckTimeOutTurnEnd);
				});
			}
			else
			{
				OpenRecovery(isCheckTimeOutTurnEnd);
			}
			if (Data.BattleRecoveryInfo.IsMulliganEnd)
			{
				_networkBattleMgr.BattleUIContainer.Battery.SetActive(value: true);
				_networkBattleMgr.BattlePlayer.StatusPanelControl.ShowStatusPanelAlways();
				_networkBattleMgr.BattleEnemy.StatusPanelControl.ShowStatusPanelAlways();
			}
			ToolboxGame.UIManager.CloseInSceneLoadingBattle();
		}), sequentialVfxPlayer));
		ToolboxGame.RealTimeNetworkAgent.IsNotPlayReceivingData = false;
		if (_hasSequenceUri == NetworkBattleDefine.NetworkBattleURI.TurnEndFinal && rESULT_CODE != NetworkBattleReceiver.RESULT_CODE.NotFinish)
		{
			_networkBattleMgr.SendJudge();
		}
		if ((_hasSequenceUri == NetworkBattleDefine.NetworkBattleURI.JudgeResult && _hasSequenceResult != 0) || _hasSequenceUri == NetworkBattleDefine.NetworkBattleURI.BattleFinish)
		{
			if (!_isPlayerSend)
			{
				_networkBattleMgr.VfxMgr.RegisterSequentialVfx(SequentialVfxPlayer.Create(InstantVfx.Create(delegate
				{
					RealTimeNetworkAgent realTimeNetworkAgent5 = ToolboxGame.RealTimeNetworkAgent;
					realTimeNetworkAgent5.OnAck = (Action<Dictionary<string, object>>)Delegate.Combine(realTimeNetworkAgent5.OnAck, new Action<Dictionary<string, object>>(AckBattleFinish));
					StartTimeOut(10, isBattleFinish: true);
					_networkBattleMgr.BattleFinishToTurnEndFinal(isSelfTurn: false);
				})));
			}
			_networkBattleMgr.NetworkSender.SendRecoveryEnd();
			return;
		}
		if (isCheckTimeOutTurnEnd && _networkBattleMgr.BattlePlayer.IsSelfTurn && (float)TimeUtil.GetElapsedTime(_firstTime, _lastTime.AddSeconds(TimeNativePlugin.GetDeviceOperatingTime())) >= 80f)
		{
			if (rESULT_CODE != NetworkBattleReceiver.RESULT_CODE.NotFinish)
			{
				_networkBattleMgr.BattleFinishToTurnEndFinal(_networkBattleMgr.BattlePlayer.IsSelfTurn);
				RealTimeNetworkAgent realTimeNetworkAgent2 = ToolboxGame.RealTimeNetworkAgent;
				realTimeNetworkAgent2.OnAck = (Action<Dictionary<string, object>>)Delegate.Combine(realTimeNetworkAgent2.OnAck, new Action<Dictionary<string, object>>(AckTurnEndFinalToRecoveryEnd));
			}
			else
			{
				RealTimeNetworkAgent realTimeNetworkAgent3 = ToolboxGame.RealTimeNetworkAgent;
				realTimeNetworkAgent3.OnAck = (Action<Dictionary<string, object>>)Delegate.Combine(realTimeNetworkAgent3.OnAck, new Action<Dictionary<string, object>>(AckTurnEndToRecoveryEnd));
			}
		}
		else if (!flag)
		{
			_networkBattleMgr.NetworkSender.SendRecoveryEnd();
		}
		if (waitForAck)
		{
			RealTimeNetworkAgent realTimeNetworkAgent4 = ToolboxGame.RealTimeNetworkAgent;
			realTimeNetworkAgent4.OnAck = (Action<Dictionary<string, object>>)Delegate.Combine(realTimeNetworkAgent4.OnAck, new Action<Dictionary<string, object>>(AckToComplete));
			StartTimeOut(10);
		}
		else
		{
			AckToComplete(null);
		}
	}

	private void AckTurnEndToRecoveryEnd(Dictionary<string, object> objs)
	{
		if (NetworkBattleGenericTool.FindDictionaryURI(objs) == NetworkBattleDefine.NetworkURINames[NetworkBattleDefine.NetworkBattleURI.TurnEnd])
		{
			RealTimeNetworkAgent realTimeNetworkAgent = ToolboxGame.RealTimeNetworkAgent;
			realTimeNetworkAgent.OnAck = (Action<Dictionary<string, object>>)Delegate.Remove(realTimeNetworkAgent.OnAck, new Action<Dictionary<string, object>>(AckTurnEndToRecoveryEnd));
			_networkBattleMgr.NetworkSender.SendRecoveryEnd();
		}
	}

	private void AckTurnEndFinalToRecoveryEnd(Dictionary<string, object> objs)
	{
		if (NetworkBattleGenericTool.FindDictionaryURI(objs) == NetworkBattleDefine.NetworkURINames[NetworkBattleDefine.NetworkBattleURI.TurnEndFinal])
		{
			RealTimeNetworkAgent realTimeNetworkAgent = ToolboxGame.RealTimeNetworkAgent;
			realTimeNetworkAgent.OnAck = (Action<Dictionary<string, object>>)Delegate.Remove(realTimeNetworkAgent.OnAck, new Action<Dictionary<string, object>>(AckTurnEndFinalToRecoveryEnd));
			_networkBattleMgr.NetworkSender.SendJudgeResult(NetworkBattleSender.JUDGE_RESULT_STATUS.RecoveryBattleFinishToJudge);
		}
	}

	private void AckTurnStartToRecoveryEnd(Dictionary<string, object> objs)
	{
		if (_networkBattleMgr.BattleEnemy.IsExtraTurn && !_isOpponentDisconnect && NetworkBattleGenericTool.FindDictionaryURI(objs) == NetworkBattleDefine.NetworkURINames[NetworkBattleDefine.NetworkBattleURI.Judge])
		{
			RealTimeNetworkAgent realTimeNetworkAgent = ToolboxGame.RealTimeNetworkAgent;
			realTimeNetworkAgent.OnAck = (Action<Dictionary<string, object>>)Delegate.Remove(realTimeNetworkAgent.OnAck, new Action<Dictionary<string, object>>(AckTurnStartToRecoveryEnd));
			_networkBattleMgr.NetworkSender.SendRecoveryEnd();
		}
		else if (NetworkBattleGenericTool.FindDictionaryURI(objs) == NetworkBattleDefine.NetworkURINames[NetworkBattleDefine.NetworkBattleURI.TurnStart])
		{
			RealTimeNetworkAgent realTimeNetworkAgent2 = ToolboxGame.RealTimeNetworkAgent;
			realTimeNetworkAgent2.OnAck = (Action<Dictionary<string, object>>)Delegate.Remove(realTimeNetworkAgent2.OnAck, new Action<Dictionary<string, object>>(AckTurnStartToRecoveryEnd));
			_networkBattleMgr.NetworkSender.SendRecoveryEnd();
		}
	}

	private void AckToComplete(Dictionary<string, object> objs)
	{
		RealTimeNetworkAgent realTimeNetworkAgent = ToolboxGame.RealTimeNetworkAgent;
		realTimeNetworkAgent.OnAck = (Action<Dictionary<string, object>>)Delegate.Remove(realTimeNetworkAgent.OnAck, new Action<Dictionary<string, object>>(AckToComplete));
		this.OnCompleteRecovery.Call();
	}

	private void CheckDeckoutResult(SequentialVfxPlayer afterRecoveryResultVfx, bool isDeckoutWin)
	{
		if (_networkBattleMgr._specialWinVfx != null)
		{
			RegisterSpecialWin(afterRecoveryResultVfx);
		}
		else if (_networkBattleMgr != null && _networkBattleMgr.BattleResultControl != null && !_networkBattleMgr.BattleResultControl.IsResultOn)
		{
			if (_networkBattleMgr.GetBattlePlayer(isDeckoutWin).IsShortageDeck && _networkBattleMgr.GetBattlePlayer(isDeckoutWin).Class.SkillApplyInformation.IsShortageDeckWin)
			{
				afterRecoveryResultVfx.Register(SendDeckShortage(_networkBattleMgr.GetBattlePlayer(isDeckoutWin)));
			}
			else
			{
				afterRecoveryResultVfx.Register(SendDeckShortage(_networkBattleMgr.GetBattlePlayer(!isDeckoutWin)));
			}
		}
	}

	private void RegisterSpecialWin(SequentialVfxPlayer afterRecoveryResultVfx)
	{
		afterRecoveryResultVfx.Register(SequentialVfxPlayer.Create(_networkBattleMgr._specialWinVfx, InstantVfx.Create(delegate
		{
			if (!_isPlayerSend)
			{
				_networkBattleMgr.SendEchoRecovery(_networkBattleMgr._lastReceivedData);
			}
		})));
	}

	private void AckBattleFinish(Dictionary<string, object> objs)
	{
		StopTimeOut();
		RealTimeNetworkAgent realTimeNetworkAgent = ToolboxGame.RealTimeNetworkAgent;
		realTimeNetworkAgent.OnAck = (Action<Dictionary<string, object>>)Delegate.Remove(realTimeNetworkAgent.OnAck, new Action<Dictionary<string, object>>(AckBattleFinish));
		this.OnCompleteRecovery.Call();
	}

	private void OpenRecovery(bool isSetTurnTimeoutTimer)
	{
		OnFinishRecoveryLogSync.Call();
		if (isFirstTimeSet)
		{
			_pastTime = TimeUtil.GetElapsedTime(_firstTime, _lastTime.AddSeconds(TimeNativePlugin.GetDeviceOperatingTime()));
		}
		if (isSetTurnTimeoutTimer)
		{
			_networkBattleMgr.RecoveryTimeOutSetting(0f - _pastTime, Data.BattleRecoveryInfo.IsMulliganEnd, -1L);
			_networkBattleMgr.SetTimeDecrementFlag(isTurnStartWithNoAction);
		}
		ToolboxGame.RealTimeNetworkAgent.StartPreparedStartTimer(_battleStartDate);
	}

	private void AIOpenRecovery(RecoveryOperationInfo aiBattleRecoveryData)
	{
		OnFinishRecoveryLogSync.Call();
		DateTimeOffset dateTimeOffset = new DateTimeOffset(DateTime.Now.Ticks, new TimeSpan(0, 0, 0));
		long num = dateTimeOffset.ToUnixTimeSeconds();
		long num2 = (aiBattleRecoveryData.SetupInfo.HasMulliganInfo ? aiBattleRecoveryData.TurnStartTime : aiBattleRecoveryData.MulliganStartTime);
		if (num2 == 0L)
		{
			num2 = aiBattleRecoveryData.OpeningStartTime;
		}
		if (!_networkBattleMgr.IsBattleEnd)
		{
			_networkBattleMgr.RecoveryTimeOutSetting(-(num - num2), aiBattleRecoveryData.SetupInfo.HasMulliganInfo, num2);
			_networkBattleMgr.SetTimeDecrementFlag(isTurnStartWithNoAction);
		}
		ToolboxGame.RealTimeNetworkAgent.StartPreparedStartTimer(DateTime.Now.AddSeconds(-(num - num2)));
	}

	private void RecoveryCreateRegisterAction(Action callback)
	{
		if (jsonObject == null)
		{
			OnFinishRecoveryLogSync.Call();
			return;
		}
		if (!jsonObject.Keys.Contains("operations"))
		{
			RecoveryManagerBase.OpenRecoveryFailedDialog();
			return;
		}
		JsonData jsonData = jsonObject["operations"];
		List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
		for (int i = 0; i < jsonData.Count; i++)
		{
			Dictionary<string, object> dictionary = new Dictionary<string, object>();
			foreach (string key in jsonData[i].Keys)
			{
				if (key == "abandoned_cards")
				{
					JsonData jsonData2 = jsonData[i]["abandoned_cards"];
					for (int j = 0; j < jsonData2.Count; j++)
					{
						_mulliganList.Add(jsonData2[j]);
					}
				}
				dictionary.Add(key, jsonData[i][key]);
			}
			list.Add(dictionary);
		}
		_networkBattleMgr.BattlePlayer.PlayerBattleView.TurnEndButtonUI._isButtonForcedOff = true;
		_networkBattleMgr.BattlePlayer.PlayerBattleView.TurnEndButtonUI.DisableButton();
		if (_canNotTouchCardVfx == null)
		{
			_canNotTouchCardVfx = new CanNotTouchCardVfx();
			_networkBattleMgr.VfxMgr.RegisterImmediateVfx(_canNotTouchCardVfx);
		}
		UIManager.GetInstance().StartCoroutine(StockRecoveryPlayer(list, callback));
	}

	private void AINetworkRecoveryCreateRegisterAction(Action callback)
	{
		_networkBattleMgr.BattlePlayer.PlayerBattleView.TurnEndButtonUI._isButtonForcedOff = true;
		_networkBattleMgr.BattlePlayer.PlayerBattleView.TurnEndButtonUI.DisableButton();
		if (_canNotTouchCardVfx == null)
		{
			_canNotTouchCardVfx = new CanNotTouchCardVfx();
			_networkBattleMgr.VfxMgr.RegisterImmediateVfx(_canNotTouchCardVfx);
		}
		callback.Call();
	}

	protected virtual IEnumerator StockRecoveryPlayer(List<Dictionary<string, object>> recoveryDictList, Action callback)
	{
		bool skipRecoveryData = true;
		if (skipRecoveryData && recoveryDictList.Count > 0 && Convert.ToInt32(recoveryDictList.Last()["seq"].ToString()) <= Data.BattleRecoveryInfo.Pub_seq)
		{
			playIndex = recoveryDictList.Count;
		}
		while (playIndex < recoveryDictList.Count)
		{
			if (skipRecoveryData && (bool)ToolboxGame.RealTimeNetworkAgent && !ToolboxGame.RealTimeNetworkAgent.IsPlayReceiveDataOk())
			{
				yield return null;
				continue;
			}
			try
			{
				Dictionary<string, object> dictionary = recoveryDictList[playIndex];
				new List<BattleCardBase>();
				object obj = null;
				BattleCardBase selectPlayCard = null;
				bool flag = false;
				if (Convert.ToInt32(dictionary["seq"].ToString()) > Data.BattleRecoveryInfo.Pub_seq)
				{
					string text = dictionary["operation"].ToString();
					switch (text)
					{
					case "play":
					{
						BattleCardBase cardBaseByPrefix5 = GetCardBaseByPrefix(dictionary["index"].ToString());
						bool flag3 = int.Parse(dictionary["is_choice_brave"].ToString()) == 1;
						if (dictionary.ContainsKey("skill_target"))
						{
							obj = dictionary["skill_target"];
						}
						bool isTargetSelectSkill = obj != null;
						VfxBase vfxBase = ((!flag3) ? _networkBattleMgr.OperateMgr.InitSetCard(cardBaseByPrefix5, isPlayer: true, isTargetSelectSkill) : NullVfx.GetInstance());
						List<BattleCardBase> list = CreateSkillTargetListFromJsonData(isTargetSelectSkill, obj);
						_networkBattleMgr.VfxMgr.RegisterSequentialVfx(SequentialVfxPlayer.Create(vfxBase, _networkBattleMgr.OperateMgr.PlayCard(cardBaseByPrefix5, isPlayer: true, list, isRecovery: true, null, flag3)));
						break;
					}
					case "attack":
					{
						BattleCardBase cardBaseByPrefix3 = GetCardBaseByPrefix(dictionary["index"].ToString());
						BattleCardBase cardBaseByPrefix4 = GetCardBaseByPrefix(dictionary["target"].ToString());
						RegisterPairToAttackSelectControl(cardBaseByPrefix3, cardBaseByPrefix4);
						_networkBattleMgr.VfxMgr.RegisterSequentialVfx(_networkBattleMgr.OperateMgr.Attack(cardBaseByPrefix3, cardBaseByPrefix4, isPlayer: true));
						break;
					}
					case "evolve":
					{
						BattleCardBase cardBaseByPrefix = GetCardBaseByPrefix(dictionary["index"].ToString());
						if (dictionary.ContainsKey("skill_target"))
						{
							obj = dictionary["skill_target"];
						}
						bool isTargetSelectSkill = obj != null;
						List<BattleCardBase> list = CreateSkillTargetListFromJsonData(isTargetSelectSkill, obj);
						_networkBattleMgr.VfxMgr.RegisterSequentialVfx(_networkBattleMgr.OperateMgr.EvolutionCard(cardBaseByPrefix, isPlayer: true, list));
						break;
					}
					case "mulligan":
						if (!_networkBattleMgr.networkBattleData.isPlayerMulliganEnd)
						{
							for (int num = 0; num < _mulliganList.Count; num++)
							{
								BattleCardBase cardBaseByPrefix2 = GetCardBaseByPrefix(_mulliganList[num].ToString());
								_networkBattleMgr.MulliganMgr.PlayerMlgCtrl.RegisterAbandonCard(cardBaseByPrefix2);
							}
							_networkBattleMgr.VfxMgr.RegisterSequentialVfx(_networkBattleMgr.MulliganMgr.Submit(_networkBattleMgr));
						}
						break;
					case "start_select":
						selectPlayCard = GetCardBaseByPrefix(dictionary["index"].ToString());
						flag = int.Parse(dictionary["bool"].ToString()) == 1;
						EmitHandUtility.SendSelectSkill(NetworkBattleSender.SELECT_SKILL_OPERATION.StartSelect, _networkBattleMgr, selectPlayCard, flag);
						_networkBattleMgr.OperateReceive.GetPlayActionsReflection(flag).RecordSelectStart(selectPlayCard);
						break;
					case "select":
					{
						selectPlayCard = GetCardBaseByPrefix(dictionary["index"].ToString());
						flag = int.Parse(dictionary["bool"].ToString()) == 1;
						bool flag2 = int.Parse(dictionary["is_burial_rite"].ToString()) == 1;
						EmitHandUtility.SendSelectSkill(NetworkBattleSender.SELECT_SKILL_OPERATION.SelectCard, _networkBattleMgr, selectPlayCard, flag, null, null, flag2);
						_networkBattleMgr.OperateReceive.GetPlayActionsReflection(flag).RecordSelectCard(selectPlayCard, flag2);
						break;
					}
					case "comp_select":
					{
						selectPlayCard = GetCardBaseByPrefix(dictionary["index"].ToString());
						flag = int.Parse(dictionary["bool"].ToString()) == 1;
						bool flag2 = int.Parse(dictionary["is_burial_rite"].ToString()) == 1;
						bool flag3 = int.Parse(dictionary["is_choice_brave"].ToString()) == 1;
						EmitHandUtility.SendSelectSkill(NetworkBattleSender.SELECT_SKILL_OPERATION.CompleteSelect, _networkBattleMgr, selectPlayCard, flag, null, null, flag2, flag3);
						_networkBattleMgr.OperateReceive.GetPlayActionsReflection(flag).RecordCompleteSelect(selectPlayCard, flag2, flag3);
						break;
					}
					case "cancel_select":
						flag = int.Parse(dictionary["bool"].ToString()) == 1;
						EmitHandUtility.SendSelectSkill(NetworkBattleSender.SELECT_SKILL_OPERATION.CancelSelect, _networkBattleMgr, null, flag);
						_networkBattleMgr.OperateReceive.GetPlayActionsReflection(flag).RecordCancelSelect();
						break;
					case "start_choice":
						selectPlayCard = GetCardBaseByPrefix(dictionary["index"].ToString());
						flag = int.Parse(dictionary["bool"].ToString()) == 1;
						EmitHandUtility.SendSelectSkill(NetworkBattleSender.SELECT_SKILL_OPERATION.StartChoiceSelect, _networkBattleMgr, selectPlayCard, flag);
						_networkBattleMgr.OperateReceive.GetPlayActionsReflection(flag).RecordStartChoiceSelect(selectPlayCard);
						break;
					case "comp_choice":
					{
						selectPlayCard = GetCardBaseByPrefix(dictionary["index"].ToString());
						flag = int.Parse(dictionary["bool"].ToString()) == 1;
						if (dictionary.ContainsKey("skill_target"))
						{
							obj = dictionary["skill_target"];
						}
						bool isTargetSelectSkill = obj != null;
						List<BattleCardBase> list = CreateSkillTargetListFromJsonData(isTargetSelectSkill, obj);
						EmitHandUtility.SendSelectSkill(NetworkBattleSender.SELECT_SKILL_OPERATION.CompleteChoiceSelect, _networkBattleMgr, selectPlayCard, flag, list);
						_networkBattleMgr.OperateReceive.GetPlayActionsReflection(flag).RecordCompleteChoiceSelect(list.Select((BattleCardBase c) => c.CardId).ToList());
						break;
					}
					case "cancel_choice":
						flag = int.Parse(dictionary["bool"].ToString()) == 1;
						EmitHandUtility.SendSelectSkill(NetworkBattleSender.SELECT_SKILL_OPERATION.CancelChoiceSelect, _networkBattleMgr, null, flag);
						_networkBattleMgr.OperateReceive.GetPlayActionsReflection(flag).RecordCancelChoice();
						break;
					case "start_fusion":
						selectPlayCard = GetCardBaseByPrefix(dictionary["index"].ToString());
						EmitHandUtility.SendSelectSkill(NetworkBattleSender.SELECT_SKILL_OPERATION.StartFusionSelect, _networkBattleMgr, selectPlayCard, isEvolveSelect: false);
						_networkBattleMgr.OperateReceive.GetPlayActionsReflection(flag).RecordStartFusion(selectPlayCard);
						break;
					case "select_fusion":
						selectPlayCard = GetCardBaseByPrefix(dictionary["index"].ToString());
						EmitHandUtility.SendSelectSkill(NetworkBattleSender.SELECT_SKILL_OPERATION.SelectFusionIngredient, _networkBattleMgr, selectPlayCard, flag);
						_networkBattleMgr.OperateReceive.GetPlayActionsReflection(flag).RecordSelectFusion(selectPlayCard);
						break;
					case "cancel_fusion":
						EmitHandUtility.SendSelectSkill(NetworkBattleSender.SELECT_SKILL_OPERATION.CancelSelect, _networkBattleMgr, null, isEvolveSelect: false);
						_networkBattleMgr.OperateReceive.GetPlayActionsReflection(flag).RecordCancelSelect();
						break;
					case "comp_fusion":
					{
						selectPlayCard = GetCardBaseByPrefix(dictionary["index"].ToString());
						if (dictionary.ContainsKey("skill_target"))
						{
							obj = dictionary["skill_target"];
						}
						bool isTargetSelectSkill = obj != null;
						EmitHandUtility.SendSelectSkill(NetworkBattleSender.SELECT_SKILL_OPERATION.CompleteFusionSelect, _networkBattleMgr, selectPlayCard, isEvolveSelect: false);
						List<BattleCardBase> list = CreateSkillTargetListFromJsonData(isTargetSelectSkill, obj);
						SequentialVfxPlayer vfx = SequentialVfxPlayer.Create(InstantVfx.Create(delegate
						{
							selectPlayCard.BattleCardView.HideHandCardInfo();
							selectPlayCard.BattleCardView.GameObject.transform.localEulerAngles = FusionTargetSelectTouchProcessor.INIT_LOCAL_EULAR_ANGLE;
						}), selectPlayCard.SelfBattlePlayer.BattleView.PlayQueueView.AddCardToViewVfx(selectPlayCard.BattleCardView, forceCardIntoPlayQueue: true, isSelectTarget: false, isChoice: false), new SkillSelectHandCardsVfx(list), WaitVfx.Create(0.3f), _networkBattleMgr.OperateMgr.FusionCard(selectPlayCard, isPlayer: true, list));
						_networkBattleMgr.VfxMgr.RegisterSequentialVfx(vfx);
						_networkBattleMgr.OperateReceive.GetPlayActionsReflection(flag).ClearData();
						break;
					}
					case "turn_end":
						_networkBattleMgr.VfxMgr.RegisterSequentialVfx(InstantVfx.Create(delegate
						{
						}));
						break;
					default:
						Debug.LogError("Auto test \"" + text + "\" is not supported.");
						break;
					}
				}
				playIndex++;
			}
			catch
			{
				LocalLog.AccumulateTraceLog("Recovery: Failed to recover actions during disconnection. Force quit recovery. actionName:" + recoveryDictList[playIndex]["operation"].ToString() + ", playIndex:" + playIndex);
				callback.Call();
				yield break;
			}
			yield return null;
		}
		callback.Call();
	}

	private List<BattleCardBase> CreateSkillTargetListFromJsonData(bool isTargetSelectSkill, object jsonDataObject)
	{
		if (!isTargetSelectSkill)
		{
			return null;
		}
		List<BattleCardBase> list = new List<BattleCardBase>();
		if (jsonDataObject is IEnumerable enumerable)
		{
			foreach (object item in enumerable)
			{
				string text = item.ToString();
				BattleCardBase battleCardBase = GetCardBaseByPrefix(text);
				if (battleCardBase == null)
				{
					bool flag = (text.Contains("p") ? true : false);
					int num = Convert.ToInt32(text.Replace(flag ? "p" : "e", ""));
					if (!CardMaster.GetInstanceForBattle().CardExists(num))
					{
						continue;
					}
					battleCardBase = _networkBattleMgr.CreateTransformCardRegisterVfx(null, num, flag);
				}
				if (battleCardBase != null)
				{
					list.Add(battleCardBase);
				}
			}
		}
		return list;
	}

	private void RegisterTarget(Dictionary<string, object> jsonData, BattleCardBase actionCard)
	{
		if (jsonData.ContainsKey("skill_target"))
		{
			string idxString = jsonData["skill_target"].ToString();
			BattleCardBase cardBaseByPrefix = GetCardBaseByPrefix(idxString);
			if (cardBaseByPrefix != null)
			{
				_networkBattleMgr.VfxMgr.RegisterSequentialVfx(_networkBattleMgr.OperateMgr.BattleCardSelect(actionCard, cardBaseByPrefix, isPlayer: true));
			}
		}
	}

	private BattleCardBase GetCardBaseByPrefix(string idxString)
	{
		BattleCardBase result = null;
		if (idxString.Contains("p"))
		{
			int index = Convert.ToInt32(idxString.Replace("p", ""));
			result = NetworkBattleGenericTool.GetIndexToCardBase(_networkBattleMgr, _networkBattleMgr.BattlePlayer, index);
		}
		else if (idxString.Contains("e"))
		{
			int index2 = Convert.ToInt32(idxString.Replace("e", ""));
			result = NetworkBattleGenericTool.GetIndexToCardBase(_networkBattleMgr, _networkBattleMgr.BattleEnemy, index2);
		}
		return result;
	}

	private void RegisterPairToAttackSelectControl(BattleCardBase attackCard, BattleCardBase targetCard)
	{
		AttackSelectControl.AttackPair attackPair = new AttackSelectControl.AttackPair(attackCard.BattleCardView, targetCard.BattleCardView);
		AttackSelectControl attackSelectControl = _networkBattleMgr.BattlePlayer.BattleView.AttackSelectControl;
		attackPair._attackTarget._isReady = !attackSelectControl.IsCardTranslatable(targetCard.BattleCardView);
		attackSelectControl.RegisterAttackPair(attackPair);
	}

	private VfxBase SendDeckShortage(BattlePlayerBase player)
	{
		VfxBase result = player.SendShortageDeck();
		_networkBattleMgr.BattleFinishToTurnEndFinal(_networkBattleMgr.BattlePlayer.IsSelfTurn);
		return result;
	}

	private void StartTimeOut(int timer, bool isBattleFinish = false)
	{
		StopTimeOut();
		_timeOutCoroutine = UIManager.GetInstance().StartCoroutine(StartTimeOutCorutine(timer, isBattleFinish));
	}

	private IEnumerator StartTimeOutCorutine(int timer, bool isBattleFinish = false)
	{
		long oldTimer = TimeUtil.GetAbsoluteTime().Ticks;
		while (timer - NetworkUtility.GetTimeSpanSecond(oldTimer) > 0)
		{
			yield return null;
		}
		StopTimeOut();
		if (isBattleFinish)
		{
			AckBattleFinish(null);
		}
		else
		{
			AckToComplete(null);
		}
	}

	private void StopTimeOut()
	{
		if (_timeOutCoroutine != null)
		{
			UIManager.GetInstance().StopCoroutine(_timeOutCoroutine);
			_timeOutCoroutine = null;
		}
	}

	protected DateTime GetCulculateWaitTime(double time)
	{
		return TimeUtil.MicroTimeToFromUnixTime((long)time);
	}

	public bool isOwner(string idStr)
	{
		if (Convert.ToInt32(idStr) == GameMgr.GetIns().GetNetworkUserInfoData().GetSelfViewerId())
		{
			return true;
		}
		return false;
	}
}
