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

public class RankMatchBattleResult : MonoBehaviour
{
	protected enum RankMatchResultState
	{
		NONE,
		RANK_UP_END,
		RANK_DOWN_END,
		TIER_UP_END
	}

	[SerializeField]
	private BattleResultUIController _battleResultNewControl;

	[SerializeField]
	public UIButton BgBtn;

	[SerializeField]
	public UISprite TitleFailed;

	[SerializeField]
	public NguiObjs WinsObj;

	[Header("ランク情報")]
	[SerializeField]
	public GameObject RankInfo;

	[SerializeField]
	protected UITexture RankIcon;

	[SerializeField]
	protected GameObject RankGaugeParent;

	[SerializeField]
	protected UIGauge RankGaugeBar;

	[SerializeField]
	public ParticleSystem RankGaugeEfc;

	[SerializeField]
	protected UILabel RankExpTitle;

	[SerializeField]
	protected UILabel RankExpLabel;

	[SerializeField]
	public UILabel RankExpAddLabel;

	[SerializeField]
	protected UILabel RankExpNextTitle;

	[SerializeField]
	protected UILabel RankExpNextLabel;

	[SerializeField]
	public UILabel RankExpBonusTitle;

	[SerializeField]
	public UILabel RankExpBonusLabel;

	[SerializeField]
	public UILabel RankExpBonusInfo;

	[SerializeField]
	protected UILabel _formatLabel;

	[Header("ランク昇格降格")]
	[SerializeField]
	protected UITexture DivRankIcon;

	[SerializeField]
	protected UITexture TierRankIcon;

	[SerializeField]
	protected UISprite TierUpFrontImg;

	[SerializeField]
	public UISprite BlackBg;

	[SerializeField]
	public GameObject DivPanel;

	[SerializeField]
	protected UISprite DivPanelBg;

	[SerializeField]
	protected UISprite RankUpImg;

	[SerializeField]
	protected UISprite RankDownImg;

	[SerializeField]
	public UISprite PromoTitle;

	[SerializeField]
	public UITexture PromoRankIcon;

	[SerializeField]
	public GameObject PromoPanel;

	[SerializeField]
	protected UIGrid PromoOrbGrid;

	[SerializeField]
	protected NguiObjs[] PromoOrbList;

	[SerializeField]
	protected UISprite PromoOrbLine;

	protected RankMatchResultState resultState;

	private int _rankLv;

	private int _rankLvPrev;

	private int _rankLvMax;

	private int _rankExp;

	private int _nowRankExp;

	private int _nextRankExp;

	private int _beforeRankExp;

	private IList<int> _rankExpList = new List<int>();

	private List<RankInfo> _rankInfoList = new List<RankInfo>();

	private int _cumulativeBattlePointToMaster;

	private bool _isRankFix;

	private SystemText _wizardText;

	private const float WIN_LABEL_POSITION_Y = -11f;

	[NonSerialized]
	public bool IsRunUIStop;

	public bool IsPromoNow { get; private set; }

	public bool IsPromoPrev { get; private set; }

	public int BeforeRankLv { get; private set; }

	public int WinCount { get; private set; }

	public int BasicExp_and_SuperiorBonus => Data.RankMatchFinish.data.BasicExp_and_SuperiorBonus;

	public int RankExpBonus { get; private set; }

	public void Init()
	{
		TitleFailed.alpha = 0f;
		_wizardText = Data.SystemText;
		_battleResultNewControl.DefaultPosDict["RankInfo"] = RankInfo.transform.localPosition;
		_battleResultNewControl.DefaultPosDict["TierUpFrontImg"] = TierUpFrontImg.transform.localPosition;
		_battleResultNewControl.DefaultPosDict["PromoTitle"] = PromoTitle.transform.localPosition;
		_battleResultNewControl.DefaultPosDict["PromoRankIcon"] = PromoRankIcon.transform.localPosition;
		_battleResultNewControl.DefaultPosDict["PromoPanel"] = PromoPanel.transform.localPosition;
		_formatLabel.text = UIUtil.GetFormatName(Data.CurrentFormat);
		if (Data.CurrentFormat == Format.Rotation)
		{
			_formatLabel.text = Data.SystemText.Get("Common_0187");
		}
		DivRankIcon.alpha = 0f;
		TierRankIcon.alpha = 0f;
		TierUpFrontImg.alpha = 0f;
		BlackBg.alpha = 0f;
		BgBtn.onClick.Clear();
		BgBtn.onClick.Add(new EventDelegate(delegate
		{
			OnClickBgBtn();
		}));
		BgBtn.gameObject.SetActive(value: false);
	}

	public void ResultSetupEnd(Format format)
	{
		PromoTitle.transform.localPosition = _battleResultNewControl.DefaultPosDict["PromoTitle"] + Vector3.up * 500f;
		PromoPanel.transform.localPosition = _battleResultNewControl.DefaultPosDict["PromoPanel"] + Vector3.down * 600f;
		RankInfo.transform.localPosition = _battleResultNewControl.DefaultPosDict["RankInfo"] + Vector3.left * 2000f;
		RankInfo.gameObject.SetActive(value: true);
		BgBtn.gameObject.SetActive(value: true);
		DivPanel.SetActive(value: false);
		RankExpAddLabel.alpha = 0f;
		RankExpBonusTitle.alpha = 0f;
		RankExpBonusLabel.alpha = 0f;
		RankExpBonusInfo.alpha = 0f;
		WinsObj.labels[0].alpha = 0f;
		WinsObj.labels[1].alpha = 0f;
		BlackBg.alpha = 0f;
		PromoRankIcon.alpha = 0f;
		bool flag = !PlayerStaticData.IsMaxRank(format);
		if (!UserRank.IsGrandMasterAvailability)
		{
			flag = !PlayerStaticData.IsMasterRank(format);
		}
		RankExpNextTitle.text = Data.SystemText.Get("Battle_0206");
		RankExpBonusTitle.text = Data.SystemText.Get("Battle_0208");
		WinsObj.labels[1].text = Data.SystemText.Get("Battle_0466");
		RankExpBonusInfo.text = Data.SystemText.Get("Battle_0465");
		RankExpTitle.text = Data.SystemText.Get(PlayerStaticData.IsMasterRank(format) ? "Common_0048" : "Common_0047");
		RankGaugeParent.SetActive(flag && !PlayerStaticData.IsGrandMasterRank(format));
		RankExpNextTitle.gameObject.SetActive(flag);
		RankExpNextLabel.gameObject.SetActive(flag);
	}

	public void GetServerData()
	{
		DataMgr dataMgr = GameMgr.GetIns().GetDataMgr();
		RankMatchFinishDetail data = Data.RankMatchFinish.data;
		BeforeRankLv = (_rankLvPrev = PlayerStaticData.UserRankCurrentFormat());
		IsPromoPrev = Data.Load.data._userRank[(int)Data.CurrentFormat].user_promotion_match.match_count > 0;
		Data.Load.data._userRank[(int)Data.CurrentFormat].rank = data.UserRank;
		PlayerStaticData.UserPromotionFlag = Data.Load.data._userRank[(int)Data.CurrentFormat].user_promotion_match.is_promotion;
		IsPromoNow = PlayerStaticData.UserPromotionFlag;
		if (!IsPromoPrev && IsPromoNow)
		{
			_isRankFix = true;
		}
		else if (IsPromoPrev && IsPromoNow)
		{
			_isRankFix = true;
		}
		else if (IsPromoPrev && !IsPromoNow)
		{
			if (_battleResultNewControl.IsWin)
			{
				_isRankFix = false;
			}
			else
			{
				_isRankFix = true;
			}
		}
		else
		{
			_isRankFix = false;
		}
		if (BeforeRankLv != PlayerStaticData.UserRankCurrentFormat())
		{
			PlayerStaticData.LoadUserRankTexture(Data.CurrentFormat);
		}
		WinCount = data.SuccessiveWinNumber;
		WinsObj.labels[0].text = WinCount.ToString();
		WinsObj.GetComponent<UITable>().Reposition();
		RankExpBonus = data.SuccessiveWinBonus;
		Vector3 localPosition = WinsObj.labels[1].transform.localPosition;
		localPosition.y = -11f;
		WinsObj.labels[1].transform.localPosition = localPosition;
		Format format = Data.CurrentFormat;
		if (dataMgr.IsDipslayHighRankFormat())
		{
			format = PlayerStaticData.HighRankFormat();
		}
		if (format == Format.PreRotation)
		{
			format = Format.Rotation;
		}
		_beforeRankExp = (PlayerStaticData.IsMasterRank(format) ? PlayerStaticData.UserMasterPoint(format) : PlayerStaticData.UserBattlePoint(format));
		if (dataMgr.IsFormatEnableBattleType() && UserRank.IsGrandMasterAvailability && PlayerStaticData.IsMasterRank(format) && !PlayerStaticData.IsMaxRank(format))
		{
			int num = PlayerStaticData.UserBattlePointEachRankCurrentFormat();
			int num2 = data.AfterMasterPoint - PlayerStaticData.UserMasterPointCurrentFormat();
			_beforeRankExp = num - num2;
		}
		_rankExpList.Clear();
		_rankInfoList = Data.Load.data.RankInfoList;
		bool flag = true;
		if (Data.CurrentFormat == Format.Crossover)
		{
			_rankInfoList = Data.Crossover.GetRankInfoRawList();
			flag = false;
		}
		if (dataMgr.IsFormatEnableBattleType())
		{
			for (int i = 0; i < _rankInfoList.Count; i++)
			{
				if (flag && i >= 24)
				{
					_rankExpList.Add(_rankInfoList[i]._necessaryMasterPoint);
				}
				else
				{
					_rankExpList.Add(_rankInfoList[i].necessary_point);
				}
			}
		}
		_rankLvMax = _rankInfoList[_rankInfoList.Count - 1].RankId;
		if (dataMgr.IsFormatEnableBattleType() && PlayerStaticData.IsMasterRankCurrentFormat())
		{
			_cumulativeBattlePointToMaster = 0;
			_cumulativeBattlePointToMaster = 0;
			for (int j = 0; j < _rankInfoList.Count; j++)
			{
				_cumulativeBattlePointToMaster += _rankInfoList[j].necessary_point;
			}
			_rankExp += _cumulativeBattlePointToMaster;
		}
		SetRankExp(0, isLvUpCheck: false);
		if (dataMgr.m_BattleType != DataMgr.BattleType.RankBattle)
		{
			return;
		}
		if (PlayerStaticData.IsMasterRankCurrentFormat())
		{
			Data.Load.data._userRank[(int)Data.CurrentFormat].master_point = Data.RankMatchFinish.data.AfterMasterPoint;
			if (Data.CurrentFormat == Format.Crossover)
			{
				Data.Load.data._userRank[(int)Data.CurrentFormat].grandMasterData.currentMasterPoint = Data.RankMatchFinish.data.AfterMasterPoint;
			}
		}
		else
		{
			Data.Load.data._userRank[(int)Data.CurrentFormat].battle_point = Data.RankMatchFinish.data.AfterBattlePoint;
		}
		RankIcon.mainTexture = Toolbox.ResourcesManager.LoadObject<Texture>(Toolbox.ResourcesManager.GetAssetTypePath(BeforeRankLv.ToString("00"), ResourcesManager.AssetLoadPathType.RankIcon_L, isfetch: true));
	}

	public IEnumerator RunTierUp()
	{
		RankIcon.mainTexture = Toolbox.ResourcesManager.LoadObject<Texture>(Toolbox.ResourcesManager.GetAssetTypePath(PlayerStaticData.UserRankCurrentFormat().ToString("00"), ResourcesManager.AssetLoadPathType.RankIcon_L, isfetch: true));
		TierRankIcon.mainTexture = Toolbox.ResourcesManager.LoadObject<Texture>(Toolbox.ResourcesManager.GetAssetTypePath(BeforeRankLv.ToString("00"), ResourcesManager.AssetLoadPathType.RankIcon_L, isfetch: true));
		if (BeforeRankLv == 25)
		{
			RankGaugeParent.SetActive(value: false);
		}
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_RANK_UP_MACH_SUCCES_2);
		TweenAlpha.Begin(TierRankIcon.gameObject, 0.5f, 1f);
		TierRankIcon.transform.localScale = Vector3.one * 0.05f;
		iTween.ScaleTo(TierRankIcon.gameObject, iTween.Hash("scale", Vector3.one, "time", 1f, "easetype", iTween.EaseType.easeInExpo));
		iTween.RotateBy(TierRankIcon.gameObject, iTween.Hash("y", 360f, "time", 1f, "easetype", iTween.EaseType.linear));
		yield return new WaitForSeconds(1f);
		GameMgr.GetIns().GetEffectMgr().Start(EffectMgr.EffectType.CMN_RESULT_TIERUP_1, Vector3.back);
		TierRankIcon.mainTexture = Toolbox.ResourcesManager.LoadObject<Texture>(Toolbox.ResourcesManager.GetAssetTypePath((BeforeRankLv + 1).ToString("00"), ResourcesManager.AssetLoadPathType.RankIcon_L, isfetch: true));
		TweenAlpha.Begin(TierUpFrontImg.gameObject, 0.5f, 1f);
		TierUpFrontImg.transform.localPosition = _battleResultNewControl.DefaultPosDict["TierUpFrontImg"] + Vector3.down * 60f;
		iTween.MoveTo(TierUpFrontImg.gameObject, iTween.Hash("position", _battleResultNewControl.DefaultPosDict["TierUpFrontImg"], "time", 0.5f, "islocal", true, "easetype", iTween.EaseType.easeOutQuad));
		yield return new WaitForSeconds(1f);
		resultState = RankMatchResultState.TIER_UP_END;
	}

	public IEnumerator RunMatchUI()
	{
		PromoRankIcon.mainTexture = Toolbox.ResourcesManager.LoadObject<Texture>(Toolbox.ResourcesManager.GetAssetTypePath((BeforeRankLv + 1).ToString("00"), ResourcesManager.AssetLoadPathType.RankIcon_L, isfetch: true));
		int match_count = Data.Load.data.GetRankInfo(Data.CurrentFormat, BeforeRankLv).match_count;
		for (int i = 0; i < PromoOrbList.Length; i++)
		{
			if (i < match_count)
			{
				PromoOrbList[i].gameObject.SetActive(value: true);
				if (i < PlayerStaticData.UserPromotionMatchCount - 1)
				{
					if (PlayerStaticData.UserPromotionIsWin(i))
					{
						PromoOrbList[i].sprites[0].spriteName = "orb_win";
						PromoOrbList[i].labels[1].gameObject.SetActive(value: true);
						PromoOrbList[i].labels[2].gameObject.SetActive(value: false);
					}
					else
					{
						PromoOrbList[i].sprites[0].spriteName = "orb_lose";
						PromoOrbList[i].labels[1].gameObject.SetActive(value: false);
						PromoOrbList[i].labels[2].gameObject.SetActive(value: true);
					}
				}
				else
				{
					if (i != PlayerStaticData.UserPromotionMatchCount - 1)
					{
						PromoOrbList[i].sprites[0].width = 38;
					}
					PromoOrbList[i].sprites[0].spriteName = "orb_empty";
					PromoOrbList[i].labels[1].gameObject.SetActive(value: false);
					PromoOrbList[i].labels[2].gameObject.SetActive(value: false);
				}
				PromoOrbList[i].labels[0].text = _wizardText.Get("Battle_0209", (i + 1).ToString());
			}
			else
			{
				PromoOrbList[i].gameObject.SetActive(value: false);
			}
			PromoOrbGrid.cellWidth = 500f / (float)match_count;
			PromoOrbGrid.Reposition();
		}
		PromoOrbLine.rightAnchor.target = PromoOrbList[match_count - 1].transform;
		PromoOrbLine.ResetAnchors();
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_RANK_UP_MACH_WINDOW_MOVE);
		TweenAlpha.Begin(BlackBg.gameObject, 0.5f, 0.5f);
		iTween.MoveTo(PromoTitle.gameObject, iTween.Hash("position", _battleResultNewControl.DefaultPosDict["PromoTitle"], "time", 0.5f, "islocal", true, "easetype", iTween.EaseType.easeOutExpo));
		TweenAlpha.Begin(PromoRankIcon.gameObject, 0.5f, 1f);
		PromoRankIcon.transform.localPosition = _battleResultNewControl.DefaultPosDict["PromoRankIcon"] + Vector3.down * 40f;
		iTween.MoveTo(PromoRankIcon.gameObject, iTween.Hash("position", _battleResultNewControl.DefaultPosDict["PromoRankIcon"], "time", 0.5f, "islocal", true, "easetype", iTween.EaseType.easeOutQuad));
		iTween.MoveTo(PromoPanel, iTween.Hash("position", _battleResultNewControl.DefaultPosDict["PromoPanel"], "time", 0.5f, "islocal", true, "easetype", iTween.EaseType.easeOutExpo));
		yield return new WaitForSeconds(1f);
		if (_battleResultNewControl.IsWin)
		{
			GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_RANK_UP_MACH_WIN);
			GameMgr.GetIns().GetEffectMgr().Start(EffectMgr.EffectType.CMN_RESULT_ORB_1, PromoOrbList[PlayerStaticData.UserPromotionMatchCount - 1].sprites[0].transform.position);
		}
		else
		{
			GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_RANK_UP_MACH_LOSE);
			GameMgr.GetIns().GetEffectMgr().Start(EffectMgr.EffectType.CMN_RESULT_ORB_2, PromoOrbList[PlayerStaticData.UserPromotionMatchCount - 1].sprites[0].transform.position);
		}
		yield return new WaitForSeconds(0.5f);
		if (_battleResultNewControl.IsWin)
		{
			PromoOrbList[PlayerStaticData.UserPromotionMatchCount - 1].sprites[0].spriteName = "orb_win";
			PromoOrbList[PlayerStaticData.UserPromotionMatchCount - 1].labels[1].gameObject.SetActive(value: true);
			PromoOrbList[PlayerStaticData.UserPromotionMatchCount - 1].labels[1].alpha = 0f;
			iTween.MoveFrom(PromoOrbList[PlayerStaticData.UserPromotionMatchCount - 1].labels[1].gameObject, iTween.Hash("y", PromoOrbList[PlayerStaticData.UserPromotionMatchCount - 1].labels[1].transform.localPosition.y - 10f, "time", 0.5f, "islocal", true, "easetype", iTween.EaseType.easeOutQuad));
			TweenAlpha.Begin(PromoOrbList[PlayerStaticData.UserPromotionMatchCount - 1].labels[1].gameObject, 0.5f, 1f);
		}
		else
		{
			PromoOrbList[PlayerStaticData.UserPromotionMatchCount - 1].sprites[0].spriteName = "orb_lose";
			PromoOrbList[PlayerStaticData.UserPromotionMatchCount - 1].labels[2].gameObject.SetActive(value: true);
			iTween.MoveFrom(PromoOrbList[PlayerStaticData.UserPromotionMatchCount - 1].labels[2].gameObject, iTween.Hash("y", PromoOrbList[PlayerStaticData.UserPromotionMatchCount - 1].labels[2].transform.localPosition.y + 10f, "time", 0.5f, "islocal", true, "easetype", iTween.EaseType.easeOutQuad));
			TweenAlpha.Begin(PromoOrbList[PlayerStaticData.UserPromotionMatchCount - 1].labels[2].gameObject, 0.5f, 1f);
		}
		yield return new WaitForSeconds(1.5f);
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_RANK_UP_MACH_WINDOW_MOVE);
		TweenAlpha.Begin(BlackBg.gameObject, 0.5f, 0f);
		TweenAlpha.Begin(PromoRankIcon.gameObject, 0.5f, 0f);
		iTween.MoveTo(PromoTitle.gameObject, iTween.Hash("position", _battleResultNewControl.DefaultPosDict["PromoTitle"] + Vector3.up * 500f, "time", 0.5f, "islocal", true, "easetype", iTween.EaseType.easeInExpo));
		iTween.MoveTo(PromoPanel, iTween.Hash("position", _battleResultNewControl.DefaultPosDict["PromoPanel"] + Vector3.down * 600f, "time", 0.5f, "islocal", true, "easetype", iTween.EaseType.easeInExpo));
		yield return new WaitForSeconds(1f);
	}

	public IEnumerator RunRankUp()
	{
		DivRankIcon.mainTexture = Toolbox.ResourcesManager.LoadObject<Texture>(Toolbox.ResourcesManager.GetAssetTypePath(BeforeRankLv.ToString("00"), ResourcesManager.AssetLoadPathType.RankIcon_L, isfetch: true));
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_RANK_UP_MACH_WINDOW_MOVE);
		DivPanel.SetActive(value: true);
		RankUpImg.alpha = 0f;
		RankDownImg.alpha = 0f;
		TweenAlpha.Begin(BlackBg.gameObject, 0.5f, 0.5f);
		DivPanelBg.transform.localScale = new Vector3(1f, 0.01f, 1f);
		iTween.ScaleTo(DivPanelBg.gameObject, iTween.Hash("y", 1f, "time", 0.5f, "easetype", iTween.EaseType.easeInOutExpo));
		yield return new WaitForSeconds(0.2f);
		TweenAlpha.Begin(DivRankIcon.gameObject, 0.5f, 1f);
		DivRankIcon.transform.localPosition = new Vector3(0f, 60f, -200f);
		iTween.MoveTo(DivRankIcon.gameObject, iTween.Hash("y", 80f, "time", 0.5f, "islocal", true, "easetype", iTween.EaseType.easeOutQuad));
		yield return new WaitForSeconds(0.5f);
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_RANK_UP_MACH_SUCCESS);
		GameMgr.GetIns().GetEffectMgr().Start(EffectMgr.EffectType.CMN_RESULT_RANKUP_1, DivRankIcon.transform.position);
		yield return new WaitForSeconds(0.5f);
		DivRankIcon.mainTexture = Toolbox.ResourcesManager.LoadObject<Texture>(Toolbox.ResourcesManager.GetAssetTypePath((BeforeRankLv + 1).ToString("00"), ResourcesManager.AssetLoadPathType.RankIcon_L, isfetch: true));
		TweenAlpha.Begin(RankUpImg.gameObject, 0.5f, 1f);
		RankUpImg.transform.localPosition = new Vector3(0f, -140f, 0f);
		iTween.MoveTo(RankUpImg.gameObject, iTween.Hash("y", -120f, "time", 0.5f, "islocal", true, "easetype", iTween.EaseType.easeOutQuad));
		yield return new WaitForSeconds(0.5f);
		resultState = RankMatchResultState.RANK_UP_END;
	}

	private IEnumerator EndRankUp()
	{
		resultState = RankMatchResultState.NONE;
		GameMgr.GetIns().GetEffectMgr().FadeStop(EffectMgr.EffectType.CMN_RESULT_RANKUP_1);
		TweenAlpha.Begin(DivRankIcon.gameObject, 0.5f, 0f);
		TweenAlpha.Begin(RankUpImg.gameObject, 0.5f, 0f);
		yield return new WaitForSeconds(0.2f);
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_RANK_UP_MACH_WINDOW_MOVE);
		TweenAlpha.Begin(BlackBg.gameObject, 0.5f, 0f);
		iTween.ScaleTo(DivPanelBg.gameObject, iTween.Hash("y", 0.01f, "time", 0.5f, "easetype", iTween.EaseType.easeInOutExpo));
		yield return new WaitForSeconds(0.5f);
		RankIcon.mainTexture = Toolbox.ResourcesManager.LoadObject<Texture>(Toolbox.ResourcesManager.GetAssetTypePath((BeforeRankLv + 1).ToString("00"), ResourcesManager.AssetLoadPathType.RankIcon_L, isfetch: true));
		RankIcon.transform.localScale = Vector3.one * 0.5f;
		iTween.ScaleTo(RankIcon.gameObject, iTween.Hash("scale", Vector3.one, "time", 0.5f, "easetype", iTween.EaseType.easeOutBack));
		DivPanel.SetActive(value: false);
		IsRunUIStop = false;
	}

	public IEnumerator RunRankDown()
	{
		DivRankIcon.mainTexture = Toolbox.ResourcesManager.LoadObject<Texture>(Toolbox.ResourcesManager.GetAssetTypePath(BeforeRankLv.ToString("00"), ResourcesManager.AssetLoadPathType.RankIcon_L, isfetch: true));
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_RANK_UP_MACH_WINDOW_MOVE);
		DivPanel.SetActive(value: true);
		RankUpImg.alpha = 0f;
		RankDownImg.alpha = 0f;
		TweenAlpha.Begin(BlackBg.gameObject, 0.5f, 0.5f);
		DivPanelBg.transform.localScale = new Vector3(1f, 0.01f, 1f);
		iTween.ScaleTo(DivPanelBg.gameObject, iTween.Hash("y", 1f, "time", 0.5f, "easetype", iTween.EaseType.easeInOutExpo));
		yield return new WaitForSeconds(0.2f);
		TweenAlpha.Begin(DivRankIcon.gameObject, 0.5f, 1f);
		DivRankIcon.transform.localPosition = new Vector3(0f, 60f, -200f);
		iTween.MoveTo(DivRankIcon.gameObject, iTween.Hash("y", 80f, "time", 0.5f, "islocal", true, "easetype", iTween.EaseType.easeOutQuad));
		yield return new WaitForSeconds(0.5f);
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_RANK_UP_MACH_RANK_DOWN);
		GameMgr.GetIns().GetEffectMgr().Start(EffectMgr.EffectType.CMN_RESULT_RANKDOWN_1, DivRankIcon.transform.position);
		yield return new WaitForSeconds(0.5f);
		DivRankIcon.mainTexture = Toolbox.ResourcesManager.LoadObject<Texture>(Toolbox.ResourcesManager.GetAssetTypePath((BeforeRankLv - 1).ToString("00"), ResourcesManager.AssetLoadPathType.RankIcon_L, isfetch: true));
		TweenAlpha.Begin(RankDownImg.gameObject, 0.5f, 1f);
		RankDownImg.transform.localPosition = new Vector3(0f, -100f, 0f);
		iTween.MoveTo(RankDownImg.gameObject, iTween.Hash("y", -120f, "time", 0.5f, "islocal", true, "easetype", iTween.EaseType.easeOutQuad));
		yield return new WaitForSeconds(0.5f);
		resultState = RankMatchResultState.RANK_DOWN_END;
	}

	private IEnumerator EndRankDown()
	{
		resultState = RankMatchResultState.NONE;
		GameMgr.GetIns().GetEffectMgr().FadeStop(EffectMgr.EffectType.CMN_RESULT_RANKDOWN_1);
		TweenAlpha.Begin(DivRankIcon.gameObject, 0.5f, 0f);
		TweenAlpha.Begin(RankDownImg.gameObject, 0.5f, 0f);
		yield return new WaitForSeconds(0.2f);
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_RANK_UP_MACH_WINDOW_MOVE);
		TweenAlpha.Begin(BlackBg.gameObject, 0.5f, 0f);
		iTween.ScaleTo(DivPanelBg.gameObject, iTween.Hash("y", 0.01f, "time", 0.5f, "easetype", iTween.EaseType.easeInOutExpo));
		yield return new WaitForSeconds(0.5f);
		RankIcon.mainTexture = Toolbox.ResourcesManager.LoadObject<Texture>(Toolbox.ResourcesManager.GetAssetTypePath((BeforeRankLv - 1).ToString("00"), ResourcesManager.AssetLoadPathType.RankIcon_L, isfetch: true));
		RankIcon.transform.localScale = Vector3.one * 0.5f;
		iTween.ScaleTo(RankIcon.gameObject, iTween.Hash("scale", Vector3.one, "time", 0.5f, "easetype", iTween.EaseType.easeOutBack));
		DivPanel.SetActive(value: false);
		IsRunUIStop = false;
	}

	private IEnumerator EndTierUp()
	{
		resultState = RankMatchResultState.NONE;
		GameMgr.GetIns().GetEffectMgr().FadeStop(EffectMgr.EffectType.CMN_RESULT_TIERUP_1);
		TweenAlpha.Begin(TierRankIcon.gameObject, 0.5f, 0f);
		TweenAlpha.Begin(TierUpFrontImg.gameObject, 0.5f, 0f);
		yield return new WaitForSeconds(0.5f);
		IsRunUIStop = false;
	}

	public IEnumerator RunFailed()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_RANK_UP_MACH_FAILED);
		TweenAlpha.Begin(TitleFailed.gameObject, 0.5f, 1f);
		TitleFailed.transform.localPosition = new Vector3(0f, 50f, 0f);
		iTween.MoveTo(TitleFailed.gameObject, iTween.Hash("y", 0f, "time", 3f, "islocal", true, "easetype", iTween.EaseType.easeOutExpo));
		GameMgr.GetIns().GetEffectMgr().Start(EffectMgr.EffectType.CMN_RESULT_FAILED_1, Vector3.back);
		yield return new WaitForSeconds(2.5f);
		TweenAlpha.Begin(TitleFailed.gameObject, 0.5f, 0f);
		yield return new WaitForSeconds(0.5f);
	}

	public void SetRankExp(int num, bool isLvUpCheck)
	{
		if (GameMgr.GetIns().GetDataMgr().IsFormatEnableBattleType())
		{
			_rankExp = _beforeRankExp + num;
			if (UserRank.IsGrandMasterAvailability && PlayerStaticData.IsMasterRankCurrentFormat())
			{
				_rankExp += _cumulativeBattlePointToMaster;
			}
			_rankLv = GetRankLv(_rankExp);
			int rankIndexFromRankID = GetRankIndexFromRankID(_rankLv);
			_nowRankExp = GetRankExpNow(_rankExp);
			CorrectGrandMasterRankLvAndExpNow();
			_nextRankExp = Mathf.Max(0, _rankExpList[rankIndexFromRankID] - _nowRankExp);
			if (PlayerStaticData.IsMasterRankCurrentFormat())
			{
				RankExpLabel.text = (_beforeRankExp + num).ToString();
			}
			else
			{
				RankExpLabel.text = _rankExp.ToString();
			}
			RankExpNextLabel.text = (IsMaxRank(_rankLv) ? "-" : _nextRankExp.ToString());
			if (BasicExp_and_SuperiorBonus >= 0)
			{
				RankExpAddLabel.text = ((BasicExp_and_SuperiorBonus - num >= 0) ? "+" : "") + (BasicExp_and_SuperiorBonus - num);
			}
			else
			{
				RankExpAddLabel.text = (BasicExp_and_SuperiorBonus - num).ToString();
			}
			RankGaugeBar.Value = Mathf.Min((float)_nowRankExp / (float)_rankExpList[rankIndexFromRankID], 1f);
			if (isLvUpCheck && _rankLv > _rankLvPrev)
			{
				PlayRankUpGaugeEffect();
				_rankLvPrev = _rankLv;
			}
		}
	}

	private bool IsMaxRank(int rank)
	{
		if (Data.CurrentFormat == Format.Crossover)
		{
			return Data.Crossover.IsMaxRank(rank);
		}
		return rank >= Data.Load.data.RankInfoList.Count;
	}

	private void SetRankExpBonus(int num)
	{
		_rankExp = Mathf.Min(_beforeRankExp + BasicExp_and_SuperiorBonus + num, Data.RankMatchFinish.data.AfterExp);
		RankExpLabel.text = _rankExp.ToString();
		if (UserRank.IsGrandMasterAvailability && PlayerStaticData.IsMasterRankCurrentFormat())
		{
			_rankExp += _cumulativeBattlePointToMaster;
		}
		_rankLv = GetRankLv(_rankExp);
		_nowRankExp = GetRankExpNow(_rankExp);
		int rankIndexFromRankID = GetRankIndexFromRankID(_rankLv);
		CorrectGrandMasterRankLvAndExpNow();
		_nextRankExp = Mathf.Max(0, _rankExpList[rankIndexFromRankID] - _nowRankExp);
		RankExpNextLabel.text = (PlayerStaticData.IsMaxRank(Data.CurrentFormat) ? "-" : _nextRankExp.ToString());
		RankExpBonusLabel.text = ((RankExpBonus - num >= 0) ? "+" : "") + (RankExpBonus - num);
		RankGaugeBar.Value = Mathf.Min((float)_nowRankExp / (float)_rankExpList[rankIndexFromRankID], 1f);
		if (_rankLv > _rankLvPrev)
		{
			PlayRankUpGaugeEffect();
			_rankLvPrev = _rankLv;
		}
	}

	private void CorrectGrandMasterRankLvAndExpNow()
	{
		if (UserRank.IsGrandMasterAvailability && PlayerStaticData.IsGrandMasterRankCurrentFormat() && _rankLv < _rankLvPrev)
		{
			for (int num = _rankLvPrev; num > _rankLv; num--)
			{
				_nowRankExp -= _rankExpList[num - 1];
			}
			_rankLv = _rankLvPrev;
		}
	}

	private void PlayRankUpGaugeEffect()
	{
		if (!PlayerStaticData.IsGrandMasterRankCurrentFormat())
		{
			GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_RESULT_LEVELUP);
			GameMgr.GetIns().GetEffectMgr().Start(EffectMgr.EffectType.CMN_RESULT_GAUGE_2, RankGaugeBar.GetTransformGaugeStartEdge().position);
		}
	}

	public void SettingAddRankExpTextAnimation()
	{
		iTween.ValueTo(base.gameObject, iTween.Hash("from", 0, "to", BasicExp_and_SuperiorBonus, "time", 0.5f, "delay", 0.5f, "onstart", "StartRankExp", "onupdate", "UpdateRankExp", "oncomplete", "CompleteRankExp", "easetype", iTween.EaseType.easeOutQuad));
		bool flag = BasicExp_and_SuperiorBonus >= 0;
		RankExpAddLabel.text = (flag ? "+" : string.Empty) + BasicExp_and_SuperiorBonus;
		RankExpAddLabel.color = (flag ? BattleResultUIController.PLUS_START_COLOR : BattleResultUIController.MINUS_START_COLOR);
		TweenAlpha.Begin(RankExpAddLabel.gameObject, 0.3f, 1f);
		iTween.MoveFrom(RankExpAddLabel.gameObject, iTween.Hash("y", RankExpAddLabel.transform.localPosition.y - 10f, "time", 0.3f, "islocal", true, "easetype", iTween.EaseType.easeOutExpo));
	}

	public void AddRankExpBonus()
	{
		iTween.ValueTo(base.gameObject, iTween.Hash("from", 0, "to", RankExpBonus, "time", 0.5f, "delay", 0.5f, "onstart", "StartRankExpBonus", "onupdate", "UpdateRankExpBonus", "oncomplete", "CompleteRankExpBonus", "easetype", iTween.EaseType.easeOutQuad));
		RankExpBonusTitle.alpha = 1f;
		RankExpBonusLabel.text = ((RankExpBonus >= 0) ? "+" : "") + RankExpBonus;
		RankExpBonusLabel.color = BattleResultUIController.PLUS_END_COLOR;
		iTween.MoveFrom(RankExpBonusTitle.gameObject, iTween.Hash("x", RankExpBonusTitle.transform.localPosition.x - 50f, "time", 0.5f, "islocal", true, "easetype", iTween.EaseType.easeOutExpo));
		TweenAlpha.Begin(RankExpBonusInfo.gameObject, 0.3f, 1f).delay = 0.1f;
		iTween.MoveFrom(RankExpBonusInfo.gameObject, iTween.Hash("x", RankExpBonusInfo.transform.localPosition.x - 50f, "time", 0.5f, "delay", 0.1f, "islocal", true, "easetype", iTween.EaseType.easeOutExpo));
	}

	private void StartRankExp()
	{
		RankGaugeEfc.gameObject.SetActive(value: true);
		RankGaugeEfc.Play();
	}

	private void StartRankExpBonus()
	{
		RankGaugeEfc.gameObject.SetActive(value: true);
		RankGaugeEfc.Play();
	}

	private void UpdateRankExp(int num)
	{
		SetRankExp(num, isLvUpCheck: true);
	}

	private void UpdateRankExpBonus(int num)
	{
		SetRankExpBonus(num);
	}

	private void CompleteRankExp()
	{
		RankGaugeEfc.Stop();
		TweenAlpha.Begin(RankExpAddLabel.gameObject, 0.5f, 0f).delay = 0.5f;
	}

	private void CompleteRankExpBonus()
	{
		RankGaugeEfc.Stop();
		TweenAlpha.Begin(RankExpBonusTitle.gameObject, 0.5f, 0f).delay = 0.5f;
		TweenAlpha.Begin(RankExpBonusLabel.gameObject, 0.5f, 0f).delay = 0.5f;
	}

	private int GetRankIndexFromRankID(int rankID)
	{
		for (int i = 0; i < _rankInfoList.Count; i++)
		{
			if (_rankInfoList[i].RankId == rankID)
			{
				return i;
			}
		}
		Debug.LogError("未知のランクID:" + rankID);
		return 0;
	}

	private int GetRankLv(int currentExp)
	{
		int num = 1;
		int num2 = 0;
		if (_isRankFix)
		{
			num = _rankLvPrev;
		}
		else
		{
			num = _rankInfoList[0].RankId;
			for (int i = 0; i < _rankExpList.Count; i++)
			{
				num2 += _rankExpList[i];
				if (currentExp < num2)
				{
					break;
				}
				num = _rankInfoList[i].RankId + 1;
			}
		}
		return Mathf.Min(num, _rankLvMax);
	}

	private int GetRankExpNow(int currentExp)
	{
		int num2;
		if (_isRankFix)
		{
			int num = _rankLv - 1;
			if (Data.CurrentFormat == Format.Crossover)
			{
				num = _rankLv - Data.Crossover.GetRankInfoRawList()[0].RankId;
			}
			num2 = currentExp;
			for (int i = 0; i < num; i++)
			{
				num2 -= _rankExpList[i];
			}
			num2 = Mathf.Min(num2, _rankExpList[num]);
		}
		else
		{
			num2 = currentExp;
			for (int j = 0; j < _rankExpList.Count && num2 >= _rankExpList[j]; j++)
			{
				num2 -= _rankExpList[j];
			}
		}
		return num2;
	}

	private void OnClickBgBtn()
	{
		switch (resultState)
		{
		case RankMatchResultState.RANK_UP_END:
			StartCoroutine(EndRankUp());
			break;
		case RankMatchResultState.RANK_DOWN_END:
			StartCoroutine(EndRankDown());
			break;
		case RankMatchResultState.TIER_UP_END:
			StartCoroutine(EndTierUp());
			break;
		}
	}
}
