using Cute;

namespace Wizard;

public static class PracticeDeckSelectConfirmDialog
{
	private const int DECK_SELECT_DIALOG_PANEL_DEPTH = 15;

	private const string DECK_DECISION_PATH = "UI/DeckList/DeckDecision";

	public static void Create(DialogBase dialogDeckList, DeckData deck, bool isBattleAgain)
	{
		if (!deck.IsUsable())
		{
			InCompleteDeckDecideDialog.Create(dialogDeckList, deck);
			return;
		}
		CompleteDeckDecideDialog.CreateForSingleDeck(dialogDeckList, deck, showSimpleStageOption: true, delegate
		{
			DecideDeck(deck, isBattleAgain);
		});
	}

	public static void DecideDeck(DeckData deck, bool isBattleAgain)
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		DataMgr dataMgr = GameMgr.GetIns().GetDataMgr();
		dataMgr.Load();
		DeckListUtility.DataMgrSaveLastSelectDeckData(deck);
		dataMgr.SetEnemySubClassID(10);
		dataMgr.SetEnemyMyRotationInfo("");
		dataMgr.SetEnemySleeveId(3000011L);
		Data.CurrentFormat = deck.Format;
		CardMaster.SetBattleCardMasterId(FormatBehaviorManager.GetDefaultBehaviour(deck.Format).CardMasterId);
		DataMgr dataMgr2 = GameMgr.GetIns().GetDataMgr();
		if (isBattleAgain)
		{
			dataMgr2.Load();
			int enemyCharaOld = dataMgr2.GetEnemyCharaId();
			dataMgr2.SetSoroPlay3DFieldID(dataMgr2.Practice3DfieldId);
			GameMgr.GetIns().GetSoundMgr().StopAllBGM(0.5f);
			UIManager.GetInstance().CreatFadeClose(delegate
			{
				StartBattleAgain(enemyCharaOld);
			});
		}
		else
		{
			UIManager.GetInstance().ChangeViewScene(UIManager.ViewScene.ClassSelectionPage, null, ClassSelectionPageParam.CreatePracticeSelect());
		}
	}

	private static void StartBattleAgain(int enemyCharaOld)
	{
		UIManager.GetInstance().StartCoroutine(BattleManagerBase.GetIns().GetBattleControl().BattleEnd(delegate
		{
			UIManager.GetInstance().CreatFadeOpen();
			DataMgr dataMgr = GameMgr.GetIns().GetDataMgr();
			dataMgr.SetEnemyCharaId(enemyCharaOld);
			dataMgr.SetCurrentEnemyDeckDataFromAIDeck(dataMgr.GetEnemyClassId(), dataMgr.m_EnemyAIDifficulty, dataMgr.m_EnemyAILogicLevel, dataMgr.m_EnemyAIMaxLife, dataMgr.m_EnemyAIDeckId, dataMgr.m_EnemyAIStyleId, dataMgr.m_EnemyAIEmoteId, dataMgr.m_EnemyAIUseInnerEmote);
			dataMgr.LoadEnemyClassData();
			PracticeStartTask task = new PracticeStartTask();
			UIManager.GetInstance().StartCoroutine(Toolbox.NetworkManager.Connect(task, delegate
			{
				UIManager.ChangeViewSceneParam param = new UIManager.ChangeViewSceneParam
				{
					IsShow_CardIntroduction = true
				};
				UIManager.GetInstance().ChangeViewScene(UIManager.ViewScene.Battle, param);
			}));
		}));
	}
}
