using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Cute;
using UnityEngine;
using Wizard;

public class GachaUI : UIBase
{
	public enum CardPackType
	{
		NONE,
		CRYSTAL,
		CRYSTAL_MULTI,
		DAILY,
		TICKET,
		TICKET_MULTI,
		RUPY,
		RUPY_MULTI,
		CRYSTAL_SPECIAL,
		CRYSTAL_SELECT_SKIN,
		FREE_PACKS,
		FREE_PACK_WITH_SKIN,
		ROTATION_STARTER_PACK,
		CRYSTAL_ACQUIRE_SKIN_CARD_PACK
	}

	private static GachaUI _gachaUiInstance;

	private const int DEPTH_REWARD_DIALOG_PANEL = 600;

	private const int DEPTH_REWARD_DIALOG_INNER = 610;

	private const int DEPTH_SELECT_BUY_NUM_DIALOG = 610;

	private const int DEPTH_TUTORIAL_BUY_CONFIRM = 1000;

	private const int DEPTH_TUTORIAL_LEGEND_PACK_DETAIL_MESSAGE_DIALOG = 1000;

	private const int SORTING_ORDER_TUTORIAL_LEGEND_PACK_DETAIL_MESSAGE_DIALOG = 37;

	private const int ORDER_REWARD_DIALOG = 2;

	public const int BASIC_PACK_ID_START = 10000;

	private const int BASIC_PACK_ID_END = 14999;

	public const int ADDITIONAL_PACK_ID_START = 15000;

	private const int ADDITIONAL_PACK_ID_END = 15999;

	private const int TS_SKIN_PICKUP_PACK_ID_START = 16000;

	private const int TS_SKIN_PICKUP_PACK_ID_END = 16999;

	private const int TS_ROTATION_TICKET_PACK_ID_START = 80000;

	private const int TS_ROTATION_TICKET_ID = 80001;

	private const int TS_ROTATION_TICKET_PACK_ID_END = 89001;

	public const int LEGEND_PACK_GACHA_ID = 90001;

	private const int TS_STEPUP_GACHA_FIRST_ID_START = 97000;

	private const int TS_STEPUP_GACHA_FIRST_ID_END = 97999;

	private const int TS_STEPUP_GACHA_SECOND_ID_START = 98000;

	private const int TS_STEPUP_GACHA_SECOND_ID_END = 98999;

	private const int TS_LEGEND_PACK_GACHA_ID = 99000;

	private const int DEFAULT_DRUMROLL_INDEX = 0;

	private const int MAX_CARD_PACK_NAM = 10;

	private const int DAILY_BUY_PACK_NAM = 1;

	public const int SPECIAL_CARD_PACK_NUM = 10;

	public const int ROTATION_STARTER_PACK_NUM = 10;

	private const string FORMAT_BTN_ROTATION_ON = "btn_gacha_timesliprotation_on";

	private const string FORMAT_BTN_ROTATION_OFF = "btn_gacha_timesliprotation_off";

	private const string FORMAT_BTN_UNLIMITED_ON = "btn_gacha_unlimited_on";

	private const string FORMAT_BTN_UNLIMITED_OFF = "btn_gacha_unlimited_off";

	public const string APPEAL_IMAGE = "card_pack_{0}_poster_sub";

	[SerializeField]
	private UIToggle _skipToggleBtn;

	[SerializeField]
	private CardPackManager _cardPackManager;

	[SerializeField]
	private GameObject _cardPackTopPanel;

	[SerializeField]
	private GameObject _backGroundObj;

	[SerializeField]
	private UIAnchor _particleAnchor;

	[SerializeField]
	private CardDetailUI _cardDetailPrefab;

	private CardDetailUI _cardDetailDialog;

	[SerializeField]
	private GameObject _cardPackOpenUiPanel;

	[SerializeField]
	private PurchaseConfirm _prefabDialogPurchaseConfirm;

	[SerializeField]
	private GachaSelectBuyNumPopup _prefabDialogSelectBuyNumber;

	[SerializeField]
	private GachaResultBuyCardPackDialog _gachaResultDialog;

	[SerializeField]
	private GameObject _prefabRewardDialog;

	private bool _isSkipOpen;

	private GameObject _cardPackTopBar;

	private TopBar _topBar;

	private List<string> _loadList = new List<string>();

	private PackOpenDetail _packOpenData;

	[SerializeField]
	private ShopDrumrollScrollManager _drumrollManager;

	[SerializeField]
	private GameObject _scrollStopCollider;

	private int _openedPackId;

	private bool _isCheckGachaPointConfirmDialog;

	private bool _isPackOpen;

	private bool _isRotationStarterCardPackOpen;

	private bool _isBuyConnect;

	[SerializeField]
	private UIButton _rotationBtn;

	[SerializeField]
	private UIButton _unlimitedBtn;

	[SerializeField]
	private GameObject _rotationBadge;

	[SerializeField]
	private GameObject _unlimitedBadge;

	[SerializeField]
	private GachaPointExchangeDialog _gachaPointExchangeDialog;

	private bool _isTutorial;

	private bool _isRotation = true;

	private TimerMgr _timerManager;

	[SerializeField]
	private GachaPackAreaLayout _packAreaLayout;

	[SerializeField]
	private NotificatonAnimation _notificationAnimationPrefab;

	[SerializeField]
	private GameObject _achieveLog;

	[SerializeField]
	public GameObject StarterClassSelectDialog;

	private NotificatonAnimation _notificationAnimation;

	private int _localSelectedClassId = 10;

	public bool IsDuringPackOpen { get; private set; }

	public static GachaUI GetInstance()
	{
		return _gachaUiInstance;
	}

	public override void onFirstStart()
	{
		_gachaUiInstance = this;
		base.IsShowFooterMenu = true;
		_timerManager = new TimerMgr();
		_backGroundObj.layer = LayerMask.NameToLayer("FrontUI");
		SystemText systemText = Data.SystemText;
		UIManager.ChangeViewSceneParam changeViewSceneParam = new UIManager.ChangeViewSceneParam();
		changeViewSceneParam.MyPageMenuIndex = 5;
		changeViewSceneParam.IsCutCardMotion = true;
		changeViewSceneParam.OnFinishChangeView = delegate
		{
			MyPageMenu.Instance.GoToShopCard();
		};
		_topBar = UIManager.GetInstance().CreateTopBar(base.gameObject, systemText.Get("Shop_0001"), UIManager.ViewScene.MyPage, MoneyDraw: true, changeViewSceneParam);
		_cardPackTopBar = _topBar.gameObject;
		_cardPackTopBar.SetActive(value: true);
		if (_cardDetailDialog == null)
		{
			int num = LayerMask.NameToLayer("Detail");
			UIManager.GetInstance().SetLayerRecursive(_cardPackOpenUiPanel.transform, num);
			_cardDetailDialog = UnityEngine.Object.Instantiate(_cardDetailPrefab);
			_cardDetailDialog.transform.parent = base.transform;
			_cardDetailDialog.transform.localPosition = Vector3.zero;
			_cardDetailDialog.transform.localScale = Vector3.one;
			_cardDetailDialog.gameObject.SetActive(value: false);
			_cardDetailDialog.Initialize(num, CardMaster.CardMasterId.Default);
			_cardDetailDialog.IsShowFlavorTextButton = true;
			_cardDetailDialog.IsShowVoiceButton = true;
			_cardDetailDialog.IsShowEvolutionButton = true;
		}
		if (!PlayerPrefsWrapper.GetValue(PlayerPrefsWrapper.CARDPACK_CARD_AUTO_OPEN))
		{
			_isSkipOpen = false;
			_skipToggleBtn.value = false;
		}
		else
		{
			_isSkipOpen = true;
			_skipToggleBtn.value = true;
		}
		EventDelegate.Add(_skipToggleBtn.onChange, OnChangeSkipBtn);
		_particleAnchor.uiCamera = UIManager.GetInstance().getCamera();
		_particleAnchor.enabled = true;
		_rotationBtn.onClick.Add(new EventDelegate(delegate
		{
			if (!_isRotation)
			{
				SetFormat(Format.Rotation);
				GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_COMMON_BUTTON);
				TweenAlpha.Begin(_drumrollManager.gameObject, 0f, 0f);
				CreateCardPackTop(0, fade: false);
			}
		}));
		_unlimitedBtn.onClick.Add(new EventDelegate(delegate
		{
			if (_isRotation)
			{
				SetFormat(Format.Unlimited);
				GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_COMMON_BUTTON);
				TweenAlpha.Begin(_drumrollManager.gameObject, 0f, 0f);
				CreateCardPackTop(0, fade: false);
			}
		}));
		_isTutorial = Data.Load.data._userTutorial.TutorialStep == 41;
		if (_isTutorial)
		{
			ShowTutorialBuyCardPackDialog();
		}
		ShowFirstTips();
		_packAreaLayout.SetCardDetailDialog(_cardDetailDialog);
		_packAreaLayout.SetTimer(_timerManager);
		_packAreaLayout.SetOnClickExchangePackPoint(OnPushExchangeGachaPoint);
		_packAreaLayout.SetOnClickPurchaseButton(OnClickPurchaseButton);
		base.onFirstStart();
	}

	private void ShowFirstTips()
	{
		if (!_isTutorial)
		{
			UIManager.GetInstance().CheckFirstTips(FirstTips.TipsType.GachaPointExchange, delegate
			{
			});
		}
	}

	public override void onMove()
	{
		_timerManager.Update();
		base.onMove();
	}

	private void ShowTutorialBuyCardPackDialog()
	{
		DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose();
		dialogBase.SetText(Data.SystemText.Get("Tutorial_0013"));
		dialogBase.SetButtonLayout(DialogBase.ButtonLayout.OkBtn);
		dialogBase.gameObject.SetLayer(base.gameObject.layer, isSetChildren: true);
		dialogBase.SetBackViewLayer(base.gameObject.layer);
		dialogBase.SetPanelDepth(1000);
		dialogBase.SetPanelSortingOrder(37);
		MyPageMenu.Instance.SetGuideToOkOnlyDialog(dialogBase);
		dialogBase.OnClose = delegate
		{
			_packAreaLayout.SetTutorialTicketPurchasebutton();
		};
	}

	protected override void onOpen()
	{
		base.onOpen();
		UIManager.GetInstance().UpDateRupyNum();
		UIManager.GetInstance().UpDateCrystalNum();
		if (_cardPackTopBar != null)
		{
			_cardPackTopBar.SetActive(value: true);
		}
		UIManager.GetInstance().ShowFooterMenu(isShow: true);
		if (_isTutorial && Data.Load.data._userTutorial.TutorialStep == 100)
		{
			SetTutorialMode(isTutorial: false);
			UIManager.GetInstance()._Footer.UpdateArenaBadgeIcon();
			UIManager.GetInstance()._Footer.UpdateSoloPlayBadgeIcon();
		}
		GetPackInfoTask();
	}

	protected override void onClose()
	{
		base.onClose();
		PlayerPrefsWrapper.SetValue(PlayerPrefsWrapper.CARDPACK_CARD_AUTO_OPEN, _isSkipOpen);
		if (_isPackOpen)
		{
			List<UIBase_CardManager.CardObjData> cardList2DObjs = UIManager.GetInstance().getCardList2DObjs();
			if (cardList2DObjs.Count > 0)
			{
				cardList2DObjs.ForEach(delegate(UIBase_CardManager.CardObjData g)
				{
					UnityEngine.Object.Destroy(g.CardObj);
				});
			}
			if (Toolbox.ResourcesManager.CardListAssetPathList.Count > 0)
			{
				_loadList.AddRange(Toolbox.ResourcesManager.CardListAssetPathList);
				Toolbox.ResourcesManager.CardListAssetPathList.Clear();
			}
			MyPageMenu.SetEnableReloadCard();
		}
		_timerManager.Dispose();
		UnloadAssets();
		UIManager.GetInstance().DestroyView(UIManager.ViewScene.Gacha);
	}

	private void UnloadAssets()
	{
		Toolbox.ResourcesManager.RemoveAssetGroup(_loadList);
		_loadList.Clear();
		_packAreaLayout.ClearPackBannerResources();
	}

	private void GetPackInfoTask()
	{
		bool flag = Data.Load.data._userTutorial.TutorialStep != 100;
		PackInfoTask task = new PackInfoTask(flag ? ApiType.Type.PackInfoTutorial : ApiType.Type.PackInfo);
		task.SetParameter();
		StartCoroutine(Toolbox.NetworkManager.Connect(task, delegate
		{
			StartLoadCardPack(task.PackFirstTransitionData);
			UIManager.GetInstance()._Footer.SetShopBadgeIconVisible(task.NeedsFooterBadgeIcon);
		}));
	}

	private void BackToMyPage()
	{
		UIManager.ChangeViewSceneParam changeViewSceneParam = new UIManager.ChangeViewSceneParam();
		changeViewSceneParam.NotWait();
		UIManager.GetInstance().ChangeViewScene(UIManager.ViewScene.MyPage, changeViewSceneParam);
	}

	private void StartLoadCardPack(PackInfoTask.PackFirstTransition packFirstTransition)
	{
		bool isTurorialEnd = _isTutorial && Data.Load.data._userTutorial.TutorialStep == 100;
		StartCoroutine(LoadCardPack_Coroutine(delegate
		{
			int index = SetFormatAndGetIndex(isTurorialEnd, packFirstTransition);
			CreateCardPackTop(index);
		}));
	}

	private int SetFormatAndGetIndex(bool isTutorialEnd, PackInfoTask.PackFirstTransition packFirstTransition)
	{
		int viewPackId = GetViewPackId(isTutorialEnd, packFirstTransition);
		SetFormat(GetFormatByViewPackId(viewPackId));
		List<PackConfig> currentFormatPackList = GetCurrentFormatPackList();
		int num = currentFormatPackList.FindIndex((PackConfig data) => data.PackId == viewPackId);
		if (num < 0)
		{
			num = 0;
			viewPackId = currentFormatPackList[num].PackId;
		}
		if (packFirstTransition != null && packFirstTransition.PackId == viewPackId)
		{
			packFirstTransition.SaveViewed();
		}
		return num;
	}

	private int GetViewPackId(bool isTutorialEnd, PackInfoTask.PackFirstTransition packFirstTransition)
	{
		if (Data.Load.data._userTutorial.TutorialStep == 41)
		{
			return GetCurrentLegendPackId();
		}
		if (isTutorialEnd)
		{
			int currentTsRotationTicketPackId = GetCurrentTsRotationTicketPackId();
			PlayerPrefsWrapper.SetValue(PlayerPrefsWrapper.LAST_PURCHASE_PACK_ID, currentTsRotationTicketPackId);
			packFirstTransition?.SaveViewed();
			return currentTsRotationTicketPackId;
		}
		if (_isPackOpen)
		{
			int num = PlayerPrefsWrapper.GetValue(PlayerPrefsWrapper.LAST_PURCHASE_PACK_ID);
			if (IsTsStepupFirstPackId(num))
			{
				PackConfig packConfig = Data.PackInfo.dataList.Find((PackConfig p) => IsTsStepupSecondPackId(p.PackId));
				if (packConfig != null)
				{
					num = packConfig.PackId;
				}
			}
			return num;
		}
		GachaUIParam currentSceneParam = UIManager.GetInstance().GetCurrentSceneParam<GachaUIParam>();
		if (currentSceneParam.EnableOverRideDefaultPackId)
		{
			int overrideDefaultPackId = currentSceneParam.OverrideDefaultPackId;
			switch (overrideDefaultPackId)
			{
			case 90001:
				return GetCurrentLegendPackId();
			case 80001:
				return GetCurrentTsRotationTicketPackId();
			default:
			{
				PackConfig additionalPackByBasePackId = GetAdditionalPackByBasePackId(overrideDefaultPackId);
				if (additionalPackByBasePackId != null)
				{
					if (packFirstTransition != null && packFirstTransition.IsUpdate() && additionalPackByBasePackId.PackId == packFirstTransition.PackId)
					{
						PlayerPrefsWrapper.SetValue(PlayerPrefsWrapper.LAST_PURCHASE_PACK_ID, packFirstTransition.PackId);
						PlayerPrefsWrapper.SetValue(PlayerPrefsWrapper.LAST_PURCHASE_PACK_ID_IN_EXIST_ADDITIONALPACK, packFirstTransition.PackId);
						return packFirstTransition.PackId;
					}
					if (additionalPackByBasePackId.PackId == PlayerPrefsWrapper.GetValue(PlayerPrefsWrapper.LAST_PURCHASE_PACK_ID_IN_EXIST_ADDITIONALPACK))
					{
						return additionalPackByBasePackId.PackId;
					}
				}
				return GetTsSkinPickupPackByBasePackId(overrideDefaultPackId)?.PackId ?? overrideDefaultPackId;
			}
			}
		}
		if (packFirstTransition != null && packFirstTransition.IsUpdate())
		{
			PlayerPrefsWrapper.SetValue(PlayerPrefsWrapper.LAST_PURCHASE_PACK_ID, packFirstTransition.PackId);
			if (IsAdditionalPackId(packFirstTransition.PackId))
			{
				PlayerPrefsWrapper.SetValue(PlayerPrefsWrapper.LAST_PURCHASE_PACK_ID_IN_EXIST_ADDITIONALPACK, packFirstTransition.PackId);
			}
			return packFirstTransition.PackId;
		}
		return PlayerPrefsWrapper.GetValue(PlayerPrefsWrapper.LAST_PURCHASE_PACK_ID);
	}

	private Format GetFormatByViewPackId(int viewPackId)
	{
		if (viewPackId != -1 && IsUnlimitedCardPackId(viewPackId))
		{
			return Format.Unlimited;
		}
		return Format.Rotation;
	}

	private IEnumerator LoadCardPack_Coroutine(Action callback)
	{
		ResourcesManager resMgr = Toolbox.ResourcesManager;
		bool needTutorialTips = _isTutorial;
		bool isSkipped = _cardPackManager.IsSkipped;
		if (isSkipped && _packOpenData != null)
		{
			needTutorialTips = false;
			_gachaResultDialog.Create(_packOpenData, _cardDetailDialog);
			_gachaResultDialog.AddOnClose(delegate
			{
				CreateRewardFromMisshonDialog(needTutorialTips);
				ShowTutorialFinishTips();
			});
			while (_gachaResultDialog.IsLoading)
			{
				yield return null;
			}
			UIManager.GetInstance().closeInSceneCenterLoading();
		}
		if (_packOpenData != null)
		{
			if (_packOpenData.reward_list.Count > 0)
			{
				_gachaResultDialog.IsFlickEnable = false;
				CreateRewardDialog(needTutorialTips, isSkipped);
			}
			else if (!isSkipped)
			{
				CreateRewardFromMisshonDialog(needTutorialTips);
			}
		}
		_packOpenData = null;
		List<PackConfig> dataList = Data.PackInfo.dataList;
		for (int num = 0; num < dataList.Count; num++)
		{
			PackConfig packConfig = dataList[num];
			_loadList.Add(packConfig.GetPackPosterTexturePath(isFetch: false));
			_loadList.Add(packConfig.GetPackTitleLogoTexturePath(isFetch: false));
			_loadList.Add(packConfig.GetPackIconTexturePath(isFetch: false));
			_loadList.Add(packConfig.GetPackDrumrollLogoTexturePath(isFetch: false));
			if (packConfig.IsPrerelease && !packConfig.PrereleasePurchaseInfo.IsCountLimitedPrerelease)
			{
				_loadList.Add(packConfig.GetPackBounsPosterTexturePath(isFetch: false));
			}
			if (packConfig.IsShowAppealImage)
			{
				string assetTypePath = Toolbox.ResourcesManager.GetAssetTypePath($"card_pack_{packConfig.PackId}_poster_sub", ResourcesManager.AssetLoadPathType.ShopCardPack);
				_loadList.Add(assetTypePath);
			}
		}
		_loadList.Add(resMgr.GetAssetTypePath("cmn_shop_icon_1", ResourcesManager.AssetLoadPathType.Effect2D));
		resMgr.StartCoroutine_LoadAssetGroupAsync(_loadList, delegate
		{
			callback.Call();
		});
	}

	private void CreateRewardFromMisshonDialog(bool needTutorialTips)
	{
		if (Data.PackOpen.data.AchievedInfo != null && Data.PackOpen.data.AchievedInfo._rewards.Count > 0)
		{
			DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose();
			dialogBase.SetSize(DialogBase.Size.M);
			dialogBase.SetTitleLabel(Data.SystemText.Get("Story_0029"));
			dialogBase.SetButtonLayout(DialogBase.ButtonLayout.OkBtn);
			dialogBase.gameObject.layer = LayerMask.NameToLayer("MyPage");
			dialogBase.SetBackViewLayer(LayerMask.NameToLayer("MyPage"));
			dialogBase.SetPanelSortingOrder(2);
			dialogBase.gameObject.transform.localPosition = Vector3.back;
			dialogBase.SetBackViewPosition(Vector3.back);
			dialogBase.SetPanelDepth(600);
			dialogBase.OnClose = delegate
			{
				DialogCreator.ShowCpAppliedDialog(Data.PackOpen.data.AchievedInfo._lotteryData, delegate
				{
					if (needTutorialTips)
					{
						ShowTutorialFinishTips();
					}
					ShowGachaPointExchangeable(delegate
					{
						UIManager.GetInstance().StartCoroutine(ShowAchieveLog(Data.PackOpen.data.NotificatonAnimationParams));
					});
				});
			};
			RewardBase component = NGUITools.AddChild(dialogBase.gameObject, _prefabRewardDialog.gameObject).GetComponent<RewardBase>();
			component.GetComponent<UIPanel>().depth = 610;
			component.GetComponent<UIPanel>().sortingOrder = 2;
			component.SetCardDetailUI(_cardDetailDialog);
			for (int num = 0; num < Data.PackOpen.data.AchievedInfo._rewards.Count; num++)
			{
				component.AddReward(Data.PackOpen.data.AchievedInfo._rewards[num]);
			}
			component.EndCreate();
			return;
		}
		DialogCreator.ShowCpAppliedDialog(Data.PackOpen.data.AchievedInfo._lotteryData, delegate
		{
			if (needTutorialTips)
			{
				ShowTutorialFinishTips();
			}
			ShowGachaPointExchangeable(delegate
			{
				UIManager.GetInstance().StartCoroutine(ShowAchieveLog(Data.PackOpen.data.NotificatonAnimationParams));
			});
		});
	}

	private void CreateRewardDialog(bool needTutorialTips, bool isSkipped)
	{
		DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose();
		dialogBase.SetSize(DialogBase.Size.M);
		dialogBase.SetTitleLabel(Data.SystemText.Get("Dia_BuyCard_004_Title"));
		dialogBase.SetButtonLayout(DialogBase.ButtonLayout.OkBtn);
		dialogBase.gameObject.layer = LayerMask.NameToLayer("MyPage");
		dialogBase.SetBackViewLayer(LayerMask.NameToLayer("MyPage"));
		dialogBase.SetPanelSortingOrder(2);
		dialogBase.gameObject.transform.localPosition = Vector3.back;
		dialogBase.SetBackViewPosition(Vector3.back);
		dialogBase.SetPanelDepth(600);
		dialogBase.OnClose = delegate
		{
			_gachaResultDialog.IsFlickEnable = true;
			if (!isSkipped)
			{
				CreateRewardFromMisshonDialog(needTutorialTips);
			}
		};
		RewardBase component = NGUITools.AddChild(dialogBase.gameObject, _prefabRewardDialog.gameObject).GetComponent<RewardBase>();
		component.GetComponent<UIPanel>().depth = 610;
		component.GetComponent<UIPanel>().sortingOrder = 2;
		component.SetCardDetailUI(_cardDetailDialog);
		for (int num = 0; num < _packOpenData.reward_list.Count; num++)
		{
			component.AddReward(_packOpenData.reward_list[num]);
		}
		component.EndCreate();
	}

	private void ShowTutorialFinishTips()
	{
		if (_isTutorial)
		{
			_isTutorial = false;
			UIManager.GetInstance().StartFirstTips(FirstTips.TipsType.ShopCardPack, delegate
			{
				GameMgr.GetIns().GetInputMgr().isBackKeyEnable = true;
			});
			FirstTips.SaveFinishFirstTips(FirstTips.TipsType.GachaPointExchange);
		}
	}

	private void CreateCardPackTop(int index, bool fade = true)
	{
		IsDuringPackOpen = false;
		if (!_cardPackTopPanel.activeSelf)
		{
			_cardPackTopPanel.SetActive(value: true);
		}
		UpdateUserItemCount();
		List<PackConfig> packList = GetCurrentFormatPackList();
		List<ShopDrumrollScrollManager.DrumrollItem> list = new List<ShopDrumrollScrollManager.DrumrollItem>();
		foreach (PackConfig item in packList)
		{
			Texture logoImage = Toolbox.ResourcesManager.LoadObject(item.GetPackDrumrollLogoTexturePath(isFetch: true)) as Texture;
			bool flag = false;
			bool isNew = false;
			if (Data.Load.data._userTutorial.TutorialStep != 41)
			{
				flag = item.IsPrerelease;
				isNew = item.IsNew && !flag;
			}
			list.Add(new ShopDrumrollScrollManager.DrumrollItem(logoImage, isNew, flag));
		}
		List<PackConfig> list2 = null;
		List<PackConfig> list3 = null;
		if (_isRotation)
		{
			list2 = packList;
			list3 = GetPackList(rotation: false);
		}
		else
		{
			list2 = GetPackList(rotation: true);
			list3 = packList;
		}
		_rotationBadge.SetActive(value: false);
		for (int i = 0; i < list2.Count; i++)
		{
			if (PlayerStaticData.GetHaveUserGoods(UserGoods.Type.Item, list2[i].GetTicketId()) > 0 && !list2[i].IsPrerelease)
			{
				_rotationBadge.gameObject.SetActive(value: true);
				break;
			}
		}
		_unlimitedBadge.SetActive(value: false);
		for (int j = 0; j < list3.Count; j++)
		{
			if (PlayerStaticData.GetHaveUserGoods(UserGoods.Type.Item, list3[j].GetTicketId()) > 0)
			{
				_unlimitedBadge.gameObject.SetActive(value: true);
				break;
			}
		}
		StartCoroutine(_drumrollManager.CreateDrumrollScroll_Coroutine(list, index, ChangePackTop, delegate
		{
			SetEnableScroll(enable: true);
			for (int k = 0; k < packList.Count; k++)
			{
				PackConfig packConfig = packList[k];
				int haveUserGoods = PlayerStaticData.GetHaveUserGoods(UserGoods.Type.Item, packConfig.GetTicketId());
				ShopDrumrollScrollItem component = _drumrollManager.ItemList[k].GetComponent<ShopDrumrollScrollItem>();
				bool activeBadge = haveUserGoods > 0;
				if (packConfig.IsPrerelease && packConfig.PrereleasePurchaseInfo.TicketRupyCountRemain == 0)
				{
					activeBadge = false;
				}
				component.SetActiveBadge(activeBadge);
				if (Data.Load.data._userTutorial.TutorialStep == 41)
				{
					UIManager.SetObjectToGrey(component.gameObject, !IsLegendPackId(packConfig.PackId));
				}
			}
			ChangePackTop(index);
			if (fade)
			{
				if (_isPackOpen)
				{
					GameMgr.GetIns().GetInputMgr().isBackKeyEnable = true;
				}
				UIManager.GetInstance().OnReadyViewScene(isFadein: true);
			}
			if (Data.Load.data._userTutorial.TutorialStep == 41)
			{
				SetTutorialMode(isTutorial: true);
			}
			StartCoroutine(ShowTimeslipResurgentFirstTips());
		}));
	}

	private IEnumerator ShowTimeslipResurgentFirstTips()
	{
		if (!_isTutorial && !_isRotation)
		{
			while (FirstTips.IsFirstTipsOpen(FirstTips.TipsType.GachaPointExchange) || UIManager.GetInstance().IsActiveFirstTips())
			{
				yield return null;
			}
			UIManager.GetInstance().CheckFirstTips(FirstTips.TipsType.TimeslipResurgentCard);
		}
	}

	private void SetTutorialMode(bool isTutorial)
	{
		UIManager.SetObjectToGrey(_unlimitedBtn.gameObject, isTutorial);
		UIManager.SetObjectToGrey(_topBar.BackButton.gameObject, isTutorial);
		UIManager.SetObjectToGrey(_skipToggleBtn.gameObject, isTutorial);
		_packAreaLayout.SetToGrayRateButton(isTutorial);
		UIManager.SetObjectToGrey(_topBar.BuyCrystalButton.gameObject, b: true);
		_topBar.BuyCrystalButton.isEnabled = false;
		SetEnableScroll(!isTutorial);
		Footer footer = UIManager.GetInstance()._Footer;
		for (int i = 0; i < footer._underButtons.Length; i++)
		{
			footer.SetButtonEnableColorChange(i, !isTutorial);
		}
		footer.SetButtonEnable(5, !isTutorial);
		float alpha = 1f;
		if (!isTutorial)
		{
			MyPageMenu.Instance.FinishTutorialMode();
			if (!_isSkipOpen)
			{
				alpha = 0f;
			}
		}
		else
		{
			alpha = 0f;
		}
		_skipToggleBtn.activeSprite.gameObject.GetComponent<UISprite>().alpha = alpha;
	}

	private void SetEnableScroll(bool enable)
	{
		if (_scrollStopCollider != null)
		{
			_scrollStopCollider.SetActive(!enable);
		}
	}

	public void UpdateUserItemCount()
	{
		_packAreaLayout.UpdateRupyCount(PlayerStaticData.UserRupyCount);
		_packAreaLayout.UpdateCrystalCount(PlayerStaticData.UserCrystalCount);
	}

	private void OnChangeSkipBtn()
	{
		if (_skipToggleBtn.value != _isSkipOpen)
		{
			if (_skipToggleBtn.value)
			{
				_isSkipOpen = true;
				GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_TOGGLE_ON);
			}
			else
			{
				_isSkipOpen = false;
				GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_TOGGLE_OFF);
			}
		}
	}

	private void GhachaPointConfirmDialog(PackConfig openedPackConfig, Action onFinish = null)
	{
		DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose();
		dialogBase.SetTitleLabel(Data.SystemText.Get("Shop_0171"));
		dialogBase.SetButtonLayout(DialogBase.ButtonLayout.BlueBtn_CancelBtn);
		dialogBase.SetText(Data.SystemText.Get("Shop_0172"));
		dialogBase.SetLayer("MyPage");
		dialogBase.SetPanelSortingOrder(2);
		dialogBase.gameObject.transform.localPosition = Vector3.back;
		dialogBase.SetBackViewPosition(Vector3.back);
		dialogBase.SetPanelDepth(600);
		dialogBase.OnClose = delegate
		{
			onFinish.Call();
		};
		dialogBase.SetButtonText(Data.SystemText.Get("Shop_0154"));
		dialogBase.onPushButton1 = delegate
		{
			OnPushExchangeGachaPoint(openedPackConfig);
		};
	}

	private List<PackConfig> GetCurrentFormatPackList()
	{
		return GetPackList(_isRotation);
	}

	private List<PackConfig> GetPackList(bool rotation)
	{
		if (rotation)
		{
			Func<PackConfig, bool> rotationCheck = delegate(PackConfig packInfo)
			{
				if (packInfo.IsHideNotEnoughBuy)
				{
					return packInfo.EnableBuyPack();
				}
				return packInfo.IsRotationStarterCardPack ? (packInfo.OpenCountLimit > packInfo.OpenCount || _isRotationStarterCardPackOpen) : (!IsUnlimitedCardPackId(packInfo.PackId));
			};
			return Data.PackInfo.dataList.FindAll((PackConfig data) => rotationCheck(data));
		}
		return Data.PackInfo.dataList.FindAll((PackConfig data) => IsUnlimitedCardPackId(data.PackId));
	}

	private bool ContainsRotationCardSet(int parentGachaId)
	{
		if (Data.Load.data.RotationCardSetList.Contains(parentGachaId))
		{
			return true;
		}
		if (Prerelease.Status == Prerelease.eStatus.PRE_ROTATION)
		{
			return Prerelease.Instance.RotationCardSetList.Contains(parentGachaId);
		}
		return false;
	}

	private bool IsBasicPackId(int packId)
	{
		if (10000 < packId)
		{
			return packId <= 14999;
		}
		return false;
	}

	public static bool IsAdditionalPackId(int packId)
	{
		if (15000 < packId)
		{
			return packId <= 15999;
		}
		return false;
	}

	public static bool IsTsSkinPickupPackId(int packId)
	{
		if (16000 < packId)
		{
			return packId <= 16999;
		}
		return false;
	}

	public static bool IsTsStepupPackId(int packId)
	{
		if (!IsTsStepupFirstPackId(packId))
		{
			return IsTsStepupSecondPackId(packId);
		}
		return true;
	}

	private static bool IsTsStepupFirstPackId(int packId)
	{
		if (97000 < packId)
		{
			return packId <= 97999;
		}
		return false;
	}

	private static bool IsTsStepupSecondPackId(int packId)
	{
		if (98000 < packId)
		{
			return packId <= 98999;
		}
		return false;
	}

	private bool IsTsRotationTicketPackId(int packId)
	{
		if (80000 < packId)
		{
			return packId <= 89001;
		}
		return false;
	}

	private bool IsLegendPackId(int packId)
	{
		if (packId != 90001)
		{
			return packId >= 99000;
		}
		return true;
	}

	private int GetCurrentTsRotationTicketPackId()
	{
		return Data.PackInfo.dataList.FirstOrDefault((PackConfig p) => IsTsRotationTicketPackId(p.PackId)).PackId;
	}

	private int GetCurrentLegendPackId()
	{
		return Data.PackInfo.dataList.FirstOrDefault((PackConfig p) => IsLegendPackId(p.PackId)).PackId;
	}

	private PackConfig GetAdditionalPackByBasePackId(int basePackId)
	{
		List<PackConfig> list = Data.PackInfo.dataList.FindAll((PackConfig p) => p.BasePackId == basePackId);
		PackConfig result = null;
		if (list != null)
		{
			result = list.FirstOrDefault((PackConfig p) => IsAdditionalPackId(p.PackId));
		}
		return result;
	}

	private PackConfig GetTsSkinPickupPackByBasePackId(int basePackId)
	{
		List<PackConfig> list = Data.PackInfo.dataList.FindAll((PackConfig p) => p.BasePackId == basePackId);
		PackConfig result = null;
		if (list != null)
		{
			result = list.FirstOrDefault((PackConfig p) => IsTsSkinPickupPackId(p.PackId));
		}
		return result;
	}

	private bool IsUnlimitedCardPackId(int packId)
	{
		if (!IsBasicPackId(packId))
		{
			return false;
		}
		if (Data.Load.data.RotationCardSetList.Contains(packId))
		{
			return false;
		}
		if (Prerelease.Status == Prerelease.eStatus.PRE_ROTATION && Prerelease.Instance.RotationCardSetList.Contains(packId))
		{
			return false;
		}
		return true;
	}

	private void SetFormat(Format format)
	{
		_isRotation = format == Format.Rotation;
		if (format == Format.Rotation)
		{
			_rotationBtn.normalSprite = "btn_gacha_timesliprotation_on";
			_unlimitedBtn.normalSprite = "btn_gacha_unlimited_off";
		}
		else
		{
			_rotationBtn.normalSprite = "btn_gacha_timesliprotation_off";
			_unlimitedBtn.normalSprite = "btn_gacha_unlimited_on";
		}
	}

	private void ShowGachaPointExchangeable(Action onFinish = null)
	{
		if (!_isCheckGachaPointConfirmDialog)
		{
			onFinish.Call();
			return;
		}
		_isCheckGachaPointConfirmDialog = false;
		PackConfig openedPackInfo = Data.PackInfo.dataList.FirstOrDefault((PackConfig data) => data.PackId == _openedPackId);
		if (openedPackInfo == null || openedPackInfo.GachaPointData == null)
		{
			onFinish.Call();
			return;
		}
		PackConfig packConfig = ((!openedPackInfo.IsSpecialCardPack) ? openedPackInfo : Data.PackInfo.dataList.FirstOrDefault((PackConfig data) => data.PackId == openedPackInfo.GachaPointData.GachaPointPackId));
		if (packConfig.GachaPointData == null)
		{
			onFinish.Call();
		}
		else if (packConfig.GachaPointData.IsExchangeableGachaPoint)
		{
			GhachaPointConfirmDialog(packConfig, onFinish);
		}
		else
		{
			onFinish.Call();
		}
	}

	private void OnPushExchangeGachaPoint(PackConfig packConfig)
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_COMMON_BUTTON);
		_gachaPointExchangeDialog.CreateGachaPointExchangeDialog(packConfig, GetPackInfoTask);
	}

	private void ChangePackTop(int index)
	{
		PackConfig packConfig = GetCurrentFormatPackList()[index];
		_packAreaLayout.ShowPackLayout(packConfig, _loadList);
	}

	private void OnClickPurchaseButton(PackConfig packConfig, PackChildGachaInfo gachaInfo)
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_COMMON_BUTTON);
		switch (gachaInfo.PackType)
		{
		case CardPackType.CRYSTAL_SPECIAL:
			if (CheckBuyPackWithCrystal(gachaInfo))
			{
				CreatePurchasePackConfirmDialog(packConfig, gachaInfo, 10);
			}
			break;
		case CardPackType.DAILY:
			if (CheckBuyPackWithCrystal(gachaInfo))
			{
				CreatePurchasePackConfirmDialog(packConfig, gachaInfo, 1);
			}
			break;
		case CardPackType.CRYSTAL_SELECT_SKIN:
			if (CheckBuyPackWithCrystal(gachaInfo))
			{
				PurchaseSelectSkinCard(packConfig, gachaInfo);
			}
			break;
		case CardPackType.CRYSTAL_ACQUIRE_SKIN_CARD_PACK:
			if (CheckBuyPackWithCrystal(gachaInfo))
			{
				PurchaseAcquireSkinCard(packConfig, gachaInfo);
			}
			break;
		case CardPackType.CRYSTAL_MULTI:
			if (CheckBuyPackWithCrystal(gachaInfo))
			{
				CreateSelectBuyNumDialog(packConfig, gachaInfo);
			}
			break;
		case CardPackType.ROTATION_STARTER_PACK:
			if (CheckBuyPackWithCrystal(gachaInfo))
			{
				StarterPackClassSelect(packConfig, gachaInfo);
			}
			break;
		case CardPackType.TICKET_MULTI:
			CreateSelectBuyNumDialog(packConfig, gachaInfo);
			break;
		case CardPackType.RUPY_MULTI:
			CreateSelectBuyNumDialog(packConfig, gachaInfo);
			break;
		case CardPackType.FREE_PACKS:
		case CardPackType.FREE_PACK_WITH_SKIN:
			if (packConfig.Category == PackCategory.RotationStarterCardPack)
			{
				StarterPackClassSelect(packConfig, gachaInfo);
			}
			else
			{
				CreatePurchasePackConfirmDialog(packConfig, gachaInfo, gachaInfo.PackCountBuyPer);
			}
			break;
		case CardPackType.TICKET:
		case CardPackType.RUPY:
			break;
		}
	}

	private void StarterPackClassSelect(PackConfig packConfig, PackChildGachaInfo info)
	{
		DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose();
		GameObject gameObject = UnityEngine.Object.Instantiate(StarterClassSelectDialog);
		dialogBase.SetObj(gameObject);
		gameObject.GetComponent<StarterClassSelectDialog>().Init(dialogBase, packConfig, info, _localSelectedClassId, PurchasePack, SetSelectedClassId);
	}

	private void SetSelectedClassId(int classId)
	{
		_localSelectedClassId = classId;
	}

	private bool CheckBuyPackWithCrystal(PackChildGachaInfo gachaInfo)
	{
		if (PlayerStaticData.IsLootBoxRegulation(PlayerStaticData.LootBoxType.GACHA))
		{
			LootBoxDialogUtility.CreateLootBoxRegulationDialog(PlayerStaticData.LootBoxType.GACHA);
			return false;
		}
		int minimumPurchasePackNum = GetMinimumPurchasePackNum(gachaInfo);
		if (PlayerStaticData.UserCrystalCount < gachaInfo.Cost * minimumPurchasePackNum)
		{
			ShopCommonUtility.CreateCrystalShortagePopup();
			return false;
		}
		return true;
	}

	private void CreateSelectBuyNumDialog(PackConfig packConfig, PackChildGachaInfo info)
	{
		DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose();
		dialogBase.SetSize(DialogBase.Size.M);
		dialogBase.SetTitleLabel(Data.SystemText.Get("Dia_BuyCard_002_Title"));
		dialogBase.SetButtonLayout(DialogBase.ButtonLayout.NONE);
		dialogBase.SetReturnMsg(null, "");
		dialogBase.SetPanelDepth(610);
		int ablePackNumByGachaInfo = GetAblePackNumByGachaInfo(packConfig, info);
		GachaSelectBuyNumPopup gachaSelectBuyNumPopup = UnityEngine.Object.Instantiate(_prefabDialogSelectBuyNumber);
		dialogBase.SetObj(gachaSelectBuyNumPopup.gameObject);
		gachaSelectBuyNumPopup.Init(dialogBase, packConfig, info, ablePackNumByGachaInfo, CreatePurchasePackConfirmDialog);
		if (Data.Load.data._userTutorial.TutorialStep == 41)
		{
			dialogBase.gameObject.SetLayer(base.gameObject.layer, isSetChildren: true);
			dialogBase.SetBackViewLayer(base.gameObject.layer);
			dialogBase.SetDialogNoClose();
			gachaSelectBuyNumPopup.SetTutorialGuide();
		}
	}

	private void CreatePurchasePackConfirmDialog(PackConfig packConfig, PackChildGachaInfo gachaInfo, int buyPackNum)
	{
		int ablePackNumByGachaInfo = GetAblePackNumByGachaInfo(packConfig, gachaInfo);
		if (buyPackNum > ablePackNumByGachaInfo || ablePackNumByGachaInfo <= 0)
		{
			return;
		}
		SystemText systemText = Data.SystemText;
		DialogBase dialogBase = ShopCommonUtility.CreateBasePopupPurchaseConfirm(new EventDelegate(delegate
		{
			PurchasePack(packConfig, gachaInfo, buyPackNum);
		}));
		dialogBase.SetTitleLabel(Data.SystemText.Get("Dia_BuyCard_001_Title"));
		dialogBase.ClickSe_Btn1 = Se.TYPE.SYS_BTN_DECIDE_TRANS;
		if (Data.Load.data._userTutorial.TutorialStep == 41)
		{
			dialogBase.SetButtonDisable(isEnableOK: false, isEnableCancel: true);
			dialogBase.SetDialogNoClose();
			dialogBase.gameObject.SetLayer(base.gameObject.layer, isSetChildren: true);
			dialogBase.SetBackViewLayer(base.gameObject.layer);
			dialogBase.SetPanelDepth(1000);
			MyPageMenu.Instance.SetGuideEffect(dialogBase.Btn1GameObject.transform, new Vector3(-110f, 0f, 0f), -90f);
			dialogBase.OnCloseStart = delegate
			{
				MyPageMenu.Instance.ResetFirstGuide();
			};
		}
		PurchaseConfirm purchaseConfirm = UnityEngine.Object.Instantiate(_prefabDialogPurchaseConfirm);
		dialogBase.SetObj(purchaseConfirm.gameObject);
		string purchaseText = systemText.Get("Shop_0043", packConfig.Title, buyPackNum.ToString());
		int num = gachaInfo.Cost * buyPackNum;
		switch (gachaInfo.PackType)
		{
		case CardPackType.CRYSTAL_MULTI:
			purchaseConfirm.SetClystalConfirmDialog(num, purchaseText, PlayerStaticData.UserCrystalCount, packConfig.ExpirtyInfo);
			ChangePurchaceConfirmDialogLayout(purchaseConfirm, packConfig.PackId);
			break;
		case CardPackType.DAILY:
			purchaseConfirm.SetClystalConfirmDialog(num, purchaseText, PlayerStaticData.UserCrystalCount, packConfig.ExpirtyInfo);
			ChangePurchaceConfirmDialogLayout(purchaseConfirm, packConfig.PackId);
			dialogBase.SetTitleLabel(Data.SystemText.Get("Dia_BuyCard_003_Title"));
			break;
		case CardPackType.TICKET_MULTI:
		{
			Texture icon = Toolbox.ResourcesManager.LoadObject(packConfig.GetPackIconTexturePath(isFetch: true)) as Texture;
			purchaseConfirm.SetTicketConfirmDialog(num, purchaseText, gachaInfo.CostGoodsCount, icon);
			break;
		}
		case CardPackType.RUPY_MULTI:
			purchaseConfirm.SetRupyConfirmDialog(num, purchaseText, PlayerStaticData.UserRupyCount);
			break;
		case CardPackType.CRYSTAL_SPECIAL:
		{
			string purchaseText2 = systemText.Get("Shop_0101", packConfig.Title);
			purchaseConfirm.SetClystalConfirmDialog(num, purchaseText2, PlayerStaticData.UserCrystalCount, packConfig.ExpirtyInfo);
			ChangePurchaceConfirmDialogLayout(purchaseConfirm, packConfig.PackId);
			dialogBase.SetTitleLabel(packConfig.Title);
			break;
		}
		case CardPackType.FREE_PACKS:
		case CardPackType.FREE_PACK_WITH_SKIN:
			purchaseConfirm.SetFreePacksConfirmDialog(purchaseText, num, gachaInfo.AvailableCount, gachaInfo.PackCountBuyPer, gachaInfo.CampaignName);
			break;
		}
		if (packConfig.GachaPointData != null)
		{
			GachaPointData gachaPointData = packConfig.GachaPointData;
			int num2 = gachaPointData.IncreaseGachaPoint;
			if (gachaInfo.OverrideIncreaseGachaPoint > 0)
			{
				num2 = gachaInfo.OverrideIncreaseGachaPoint;
			}
			int num3 = (packConfig.IsSpecialCardPack ? num2 : (num2 * buyPackNum));
			if (packConfig.IsPrerelease && (gachaInfo.PackType == CardPackType.CRYSTAL_MULTI || gachaInfo.PackType == CardPackType.CRYSTAL_SPECIAL))
			{
				int preReleasePointCurent = packConfig.PrereleasePurchaseInfo.PreReleasePointCurent;
				int num4 = preReleasePointCurent + num3;
				bool arleadyLimitPreReleasePoint = preReleasePointCurent == packConfig.PrereleasePurchaseInfo.PreReleasePointLimit;
				if (num4 > packConfig.PrereleasePurchaseInfo.PreReleasePointLimit)
				{
					num4 = packConfig.PrereleasePurchaseInfo.PreReleasePointLimit;
				}
				StartCoroutine(purchaseConfirm.SetCardPackPointWithPreRelease(gachaPointData.GachaPoint, gachaPointData.GachaPoint + num3, preReleasePointCurent, num4, arleadyLimitPreReleasePoint));
			}
			else
			{
				StartCoroutine(purchaseConfirm.SetCardPackPoint(gachaPointData.GachaPoint, gachaPointData.GachaPoint + num3));
			}
		}
		if (gachaInfo.PackType == CardPackType.FREE_PACKS || gachaInfo.PackType == CardPackType.FREE_PACK_WITH_SKIN)
		{
			purchaseConfirm.SetFreePacksLayout();
		}
	}

	private void ChangePurchaceConfirmDialogLayout(PurchaseConfirm purchaseConfirm, int packId)
	{
		if (packId == 94001)
		{
			purchaseConfirm.ChangePurchaceConfirmTextWidth();
		}
	}

	private int GetAblePackNumByGachaInfo(PackConfig packConfig, PackChildGachaInfo gachaInfo)
	{
		int num = 0;
		switch (gachaInfo.PackType)
		{
		case CardPackType.RUPY_MULTI:
			num = Mathf.Min(PlayerStaticData.UserRupyCount / gachaInfo.Cost, 10);
			if (packConfig.IsPrerelease)
			{
				num = Mathf.Min(num, packConfig.PrereleasePurchaseInfo.TicketRupyCountRemain);
			}
			break;
		case CardPackType.CRYSTAL_MULTI:
		case CardPackType.DAILY:
		case CardPackType.CRYSTAL_SPECIAL:
		case CardPackType.CRYSTAL_SELECT_SKIN:
		case CardPackType.CRYSTAL_ACQUIRE_SKIN_CARD_PACK:
			num = Mathf.Min(PlayerStaticData.UserCrystalCount / gachaInfo.Cost, 10);
			if (packConfig.IsPrerelease && packConfig.PrereleasePurchaseInfo.IsCountLimitedPrerelease)
			{
				num = Mathf.Min(num, packConfig.PrereleasePurchaseInfo.GetAbleBuyPackNum());
			}
			break;
		case CardPackType.TICKET_MULTI:
			num = Mathf.Min(gachaInfo.CostGoodsCount / gachaInfo.Cost, 10);
			if (packConfig.IsPrerelease)
			{
				num = Mathf.Min(num, packConfig.PrereleasePurchaseInfo.TicketRupyCountRemain);
			}
			break;
		case CardPackType.FREE_PACKS:
		case CardPackType.FREE_PACK_WITH_SKIN:
			num = ((gachaInfo.AvailableCount / gachaInfo.Cost > 0) ? gachaInfo.PackCountBuyPer : 0);
			break;
		}
		return num;
	}

	private int GetMinimumPurchasePackNum(PackChildGachaInfo gachaInfo)
	{
		int result = 0;
		switch (gachaInfo.PackType)
		{
		case CardPackType.CRYSTAL_MULTI:
		case CardPackType.DAILY:
		case CardPackType.TICKET_MULTI:
		case CardPackType.RUPY_MULTI:
			result = 1;
			break;
		case CardPackType.CRYSTAL_SPECIAL:
		case CardPackType.CRYSTAL_SELECT_SKIN:
		case CardPackType.CRYSTAL_ACQUIRE_SKIN_CARD_PACK:
			result = 10;
			break;
		case CardPackType.FREE_PACKS:
		case CardPackType.FREE_PACK_WITH_SKIN:
			result = gachaInfo.PackCountBuyPer;
			break;
		case CardPackType.ROTATION_STARTER_PACK:
			result = 10;
			break;
		}
		return result;
	}

	private void PurchaseSelectSkinCard(PackConfig packConfig, PackChildGachaInfo gachaInfo)
	{
		GetSelectSkinOwnedStatusTask task = new GetSelectSkinOwnedStatusTask();
		task.SetParameter(packConfig.PackId);
		StartCoroutine(Toolbox.NetworkManager.Connect(task, delegate
		{
			bool flag = false;
			for (CardBasePrm.ClanType clanType = CardBasePrm.ClanType.MIN; clanType < CardBasePrm.ClanType.MAX; clanType++)
			{
				List<SelectSkinCardInfo> source = task.SkinCardListInClassDic[clanType];
				flag |= source.Any((SelectSkinCardInfo x) => x.HasSkin);
			}
			if (flag)
			{
				ConfirmExcludeHasSkinCard(packConfig, gachaInfo, task.SkinCardListInClassDic);
			}
			else
			{
				CreateSelectSkinCardDialog(packConfig, gachaInfo, task.SkinCardListInClassDic, isDefaultExclude: false);
			}
		}));
	}

	private void ConfirmExcludeHasSkinCard(PackConfig packConfig, PackChildGachaInfo gachaInfo, Dictionary<CardBasePrm.ClanType, List<SelectSkinCardInfo>> skinCardDict)
	{
		SystemText systemText = Data.SystemText;
		DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose();
		dialogBase.SetSize(DialogBase.Size.S);
		dialogBase.SetTitleLabel(systemText.Get("Shop_0207"));
		dialogBase.SetText(systemText.Get("Shop_0208"));
		GameObject gameObject = UnityEngine.Object.Instantiate(Resources.Load("UI/layoutParts/Dialog/DialogSubText")) as GameObject;
		dialogBase.SetObj(gameObject);
		DialogSubText component = gameObject.GetComponent<DialogSubText>();
		UILabel labelSubText = component.LabelSubText;
		labelSubText.color = LabelDefine.TEXT_COLOR_CREAM;
		labelSubText.fontSize = 18;
		UIUtil.AddPositionY(labelSubText.transform, -16f);
		component.SetSubText(systemText.Get("Shop_0209"));
		dialogBase.SetButtonLayout(DialogBase.ButtonLayout.BlueBtn_GrayBtn);
		dialogBase.SetButtonText(systemText.Get("Shop_0210"), systemText.Get("Shop_0211"));
		dialogBase.SetButtonDelegate(delegate
		{
			CreateSelectSkinCardDialog(packConfig, gachaInfo, skinCardDict, isDefaultExclude: true);
		}, delegate
		{
			CreateSelectSkinCardDialog(packConfig, gachaInfo, skinCardDict, isDefaultExclude: false);
		});
	}

	private void CreateSelectSkinCardDialog(PackConfig packConfig, PackChildGachaInfo gachaInfo, Dictionary<CardBasePrm.ClanType, List<SelectSkinCardInfo>> skinCardDict, bool isDefaultExclude)
	{
		SelectSkinCardDialog.Create(skinCardDict, delegate(Dictionary<int, bool> selectStateDict)
		{
			CreateSelectSkinConfirmDialog(packConfig, gachaInfo, selectStateDict);
		}, isDefaultExclude, isAcquireSkinCardPack: false, null);
	}

	private void CreateSelectSkinConfirmDialog(PackConfig packConfig, PackChildGachaInfo gachaInfo, Dictionary<int, bool> _selectCardStateDict)
	{
		List<int> selectCardIdList = (from x in _selectCardStateDict
			where x.Value
			select x.Key).ToList();
		SelectCardPurchaseConfirmDialog.Create(packConfig, gachaInfo, 10, selectCardIdList, delegate
		{
			int[] excludeCardIds = (from x in _selectCardStateDict
				where !x.Value
				select x.Key).ToArray();
			PurchasePack(packConfig, gachaInfo, 10, excludeCardIds);
		}, isAcquireSkinCardPack: false);
	}

	private void PurchaseAcquireSkinCard(PackConfig packConfig, PackChildGachaInfo gachaInfo)
	{
		GetSelectSkinOwnedStatusTask task = new GetSelectSkinOwnedStatusTask();
		task.SetParameter(packConfig.PackId);
		StartCoroutine(Toolbox.NetworkManager.Connect(task, delegate
		{
			CreateAcquireSkinCardDialog(packConfig, gachaInfo, task.SkinCardListInClassDic);
		}));
	}

	private void CreateAcquireSkinCardDialog(PackConfig packConfig, PackChildGachaInfo gachaInfo, Dictionary<CardBasePrm.ClanType, List<SelectSkinCardInfo>> skinCardDict)
	{
		SelectSkinCardDialog.Create(skinCardDict, null, isDefaultExclude: false, isAcquireSkinCardPack: true, delegate(int targetCardId, bool hasTargetSkin)
		{
			CreateAcquireSkinCardConfirmDialog(packConfig, gachaInfo, targetCardId, hasTargetSkin);
		});
	}

	private void CreateAcquireSkinCardConfirmDialog(PackConfig packConfig, PackChildGachaInfo gachaInfo, int targetCardId, bool hasTargetSkin)
	{
		SelectCardPurchaseConfirmDialog.Create(packConfig, gachaInfo, 10, new List<int> { targetCardId }, delegate
		{
			PurchasePack(packConfig, gachaInfo, 10, null, CardBasePrm.ClanType.NONE, targetCardId);
		}, isAcquireSkinCardPack: true, hasTargetSkin);
	}

	private void PurchasePack(PackConfig packConfig, PackChildGachaInfo gachaInfo, int packNum, int[] excludeCardIds = null, CardBasePrm.ClanType selectedClassId = CardBasePrm.ClanType.NONE, int? targetCardId = null)
	{
		if (_isBuyConnect)
		{
			return;
		}
		_isBuyConnect = true;
		if (excludeCardIds == null)
		{
			excludeCardIds = new int[0];
		}
		GameMgr.GetIns().GetInputMgr().isBackKeyEnable = false;
		UIManager.GetInstance().CreatFadeClose(delegate
		{
			UIManager.GetInstance().createInSceneLoading();
			PackOpenTask task = new PackOpenTask(Data.Load.data._userTutorial.TutorialStep != 100, packConfig);
			if (CardBasePrm.ClanTypeIsUseable(selectedClassId))
			{
				task.SetStarterPackParameter(packConfig.PackId, gachaInfo.GachaId, packConfig.GachaType, packNum, excludeCardIds, (int)selectedClassId);
			}
			else if (targetCardId.HasValue)
			{
				task.SetAcquireSkinCardPackParameter(packConfig.PackId, gachaInfo.GachaId, packConfig.GachaType, packNum, targetCardId.Value);
			}
			else
			{
				task.SetParameter(packConfig.PackId, gachaInfo.GachaId, packConfig.GachaType, packNum, excludeCardIds);
			}
			_openedPackId = packConfig.PackId;
			_isCheckGachaPointConfirmDialog = false;
			if (packConfig.GachaPointData != null)
			{
				int gachaPointPackId = (IsTsSkinPickupPackId(packConfig.PackId) ? packConfig.PackId : packConfig.GachaPointData.GachaPointPackId);
				if (!Data.PackInfo.dataList.FirstOrDefault((PackConfig data) => data.PackId == gachaPointPackId).GachaPointData.IsExchangeableGachaPoint)
				{
					_isCheckGachaPointConfirmDialog = true;
				}
			}
			StartCoroutine(Toolbox.NetworkManager.Connect(task, delegate
			{
				_isBuyConnect = false;
				_packOpenData = Data.PackOpen.data;
				SuccessPurchasePack(packConfig, task.IsSpecialEffect || task.IsExistFreePackLeaderSkin);
			}, null, OnFailedErrorCodePackOpen));
		});
	}

	private void OnFailedErrorCodePackOpen(int errorCode)
	{
		_isBuyConnect = false;
		ToolboxGame.UIManager.closeInSceneLoading();
		UIManager.GetInstance().CreatFadeOpen();
	}

	private void SuccessPurchasePack(PackConfig packConfig, bool isCoutainSpecialCard)
	{
		List<UIBase_CardManager.CardObjData> cardList2DObjs = UIManager.GetInstance().getCardList2DObjs();
		if (cardList2DObjs.Count > 0 && _isPackOpen)
		{
			cardList2DObjs.ForEach(delegate(UIBase_CardManager.CardObjData g)
			{
				UnityEngine.Object.Destroy(g.CardObj);
			});
		}
		PlayerPrefsWrapper.SetValue(PlayerPrefsWrapper.LAST_PURCHASE_PACK_ID, packConfig.PackId);
		if (GetAdditionalPackByBasePackId(packConfig.BasePackId) != null)
		{
			PlayerPrefsWrapper.SetValue(PlayerPrefsWrapper.LAST_PURCHASE_PACK_ID_IN_EXIST_ADDITIONALPACK, packConfig.PackId);
		}
		_isPackOpen = true;
		if (packConfig.IsRotationStarterCardPack)
		{
			_isRotationStarterCardPackOpen = true;
		}
		IsDuringPackOpen = true;
		_cardPackManager.Init(_isSkipOpen, _cardDetailDialog, UIManager.ViewScene.Gacha, isCoutainSpecialCard, delegate
		{
			UnloadAssets();
			_cardPackTopBar.SetActive(value: false);
			_cardPackTopPanel.SetActive(value: false);
			UIManager.GetInstance().ShowFooterMenu(isShow: false);
			_cardPackManager.StartInstantiateCardPack(packConfig);
		});
	}

	private IEnumerator ShowAchieveLog(List<NotificatonAnimation.Param> paramList)
	{
		if (_notificationAnimation != null)
		{
			UnityEngine.Object.Destroy(_notificationAnimation.gameObject);
			_notificationAnimation = null;
		}
		_notificationAnimation = NGUITools.AddChild(_achieveLog, _notificationAnimationPrefab.gameObject).GetComponent<NotificatonAnimation>();
		yield return StartCoroutine(_notificationAnimation.Exec(paramList));
	}
}
