using Cute;

namespace Wizard;

public static class QuestDeckSelectConfirmDialog
{
	public static void Create(DialogBase dialogDeckList, DeckData deck, bool isBattleAgain)
	{
		if (!deck.IsUsable())
		{
			InCompleteDeckDecideDialog.Create(dialogDeckList, deck);
			return;
		}
		CompleteDeckDecideDialog completeDeckDecideDialog = CompleteDeckDecideDialog.CreateForSingleDeck(dialogDeckList, deck, showSimpleStageOption: false, delegate
		{
			DecideDeck(deck, isBattleAgain);
		});
		if (GameMgr.GetIns().GetDataMgr().QuestBattleData.IsMockBattle)
		{
			completeDeckDecideDialog.DecisionUI.SetText(string.Empty, string.Empty);
			completeDeckDecideDialog.Dialog.SetText(Data.SystemText.Get("Quest_0026", deck.GetDeckName()));
		}
	}

	public static void DecideDeck(DeckData deck, bool isBattleAgain)
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE_TRANS);
		DataMgr dataMgr = GameMgr.GetIns().GetDataMgr();
		dataMgr.Load();
		DeckListUtility.DataMgrSaveLastSelectDeckData(deck);
		dataMgr.SetEnemySleeveId(3000011L);
		Data.CurrentFormat = deck.Format;
		new QuestLastUsedDeckSaveDataManager().SaveDeck(dataMgr.QuestBattleData.QuestStageId, deck);
		dataMgr.Load();
		CardMaster.SetBattleCardMasterId(FormatBehaviorManager.GetDefaultBehaviour(deck.Format).CardMasterId);
		if (isBattleAgain)
		{
			GameMgr.GetIns().GetSoundMgr().StopAllBGM(0.5f);
			UIManager.GetInstance().CreatFadeClose(delegate
			{
				UIManager.GetInstance().StartCoroutine(BattleManagerBase.GetIns().GetBattleControl().BattleEnd(delegate
				{
					UIManager.GetInstance().CreatFadeOpen();
					int enemyAiID = ((dataMgr.QuestBattleData != null) ? dataMgr.QuestBattleData.EnemyAiId : (-1));
					dataMgr.SetEnemyCharaId(dataMgr.GetEnemyCharaId());
					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, enemyAiID);
					dataMgr.LoadEnemyClassData();
					ChangeQuestBattleScene();
				}));
			});
			return;
		}
		QuestBattleData battleData = dataMgr.QuestBattleData;
		dataMgr.SetEnemyCharaId(battleData.CharaId);
		dataMgr.SetStoryBgmID(battleData.BgmId);
		dataMgr.SetSoroPlay3DFieldID(battleData.Battle3dFieldID);
		StoryAISettingData settingData = Data.Master.QuestAISettingList.GetSettingData(battleData.EnemyAiId);
		UIManager.GetInstance().createInSceneCenterLoading();
		Data.Master.LoadAICsv(new AICsvLoadingInfo(settingData.DeckId, settingData.StyleId, settingData.EmoteId), delegate
		{
			UIManager.GetInstance().closeInSceneCenterLoading();
			dataMgr.SetQuestAILogicAndDeckData(battleData.EnemyClass, settingData.EnemyAiId);
			dataMgr.LoadEnemyClassData();
			ChangeQuestBattleScene();
		});
	}

	private static void ChangeQuestBattleScene()
	{
		DataMgr dataMgr = GameMgr.GetIns().GetDataMgr();
		QuestStartTask questStartTask = new QuestStartTask();
		questStartTask.SetParameter(dataMgr.QuestBattleData.QuestStageId, dataMgr.QuestBattleData.ExtraDeckScheduleId);
		UIManager.GetInstance().StartCoroutine(Toolbox.NetworkManager.Connect(questStartTask, delegate
		{
			UIManager.ChangeViewSceneParam param = new UIManager.ChangeViewSceneParam
			{
				IsShow_CardIntroduction = true
			};
			UIManager.GetInstance().ChangeViewScene(UIManager.ViewScene.Battle, param);
		}));
	}
}
