using System;
using System.Collections;
using System.Collections.Generic;
using Cute;
using LitJson;
using UnityEngine;
using Wizard;
using Wizard.Battle.Recovery;

public class BattleResultUIController : MonoBehaviour
{
	private enum MenuDialogSelect
	{
		None = -1,
		Button1,
		ButtonClose
	}

	public const string BattleResultObjectPass = "Prefab/UI/BattleResult/BattleResultUI";

	public const string RankMatchBattleResultObjectPass = "Prefab/UI/BattleResult/RankMatchBattleResultUI";

	public const string QuestBattleResultObjectPass = "Prefab/UI/BattleResult/QuestSpecialBattleResultUI";

	public const string ColosseumBattleResultObjectPass = "Prefab/UI/BattleResult/ColosseumBattleResultUI";

	public const string PLUS_STRING = "+";

	public static readonly Color PLUS_START_COLOR = new Color32(byte.MaxValue, 192, 0, 0);

	public static readonly Color PLUS_END_COLOR = new Color32(byte.MaxValue, 192, 0, byte.MaxValue);

	public static readonly Color MINUS_START_COLOR = new Color32(128, 192, byte.MaxValue, 0);

	public const float GAUGEUP_DURATION = 0.5f;

	public const float GAUGEUP_DELAY = 0.5f;

	public const float GAUGEUP_LABEL_DURATION = 0.3f;

	public const float GAUGEUP_LABEL_MOVE_DISTANCE = 10f;

	public const float GAUGEUP_LABEL_DISAPPEAR_DURATION = 0.5f;

	public const float GAUGEUP_LABEL_DISAPPEAR_DELAY = 0.5f;

	[SerializeField]
	public RankMatchBattleResult RankMatchBattleResultObject;

	[SerializeField]
	public QuestSpecialBattleResult QuestBattleResultObject;

	[SerializeField]
	private GameObject _battlePassResultPanel;

	[SerializeField]
	private Transform _acncorNoneRoot;

	[SerializeField]
	private UISprite _backGroundWithRank;

	[SerializeField]
	private UISprite _backGroundNotNeedRank;

	[Header("共通")]
	[SerializeField]
	public UIPanel MainPanel;

	[SerializeField]
	public NguiObjs ClassCharObj;

	[SerializeField]
	public UITexture Bg;

	[SerializeField]
	public UISprite ArcaneIn;

	[SerializeField]
	public UISprite ArcaneOut;

	[SerializeField]
	public UISprite ResultTitle;

	[Header("クラス情報")]
	[SerializeField]
	public GameObject ClassInfo;

	[SerializeField]
	private ClassInfoParts _classInfoParts;

	[SerializeField]
	private UITexture ClassLvImg;

	[SerializeField]
	private UILabel ClassLvLabel;

	[SerializeField]
	private UIGauge ClassGaugeBar;

	[SerializeField]
	private ParticleSystem ClassGaugeEfc;

	[SerializeField]
	public UILabel ClassExpAddLabel;

	[SerializeField]
	private UILabel ClassExpNextTitle;

	[SerializeField]
	private UILabel ClassExpNextLabel;

	[Header("下部ボタン")]
	[SerializeField]
	public UIAnchor AnchorBottom;

	[SerializeField]
	public UIGrid ButtonGrid;

	[SerializeField]
	public NguiObjs MissionBtnObj;

	[SerializeField]
	public NguiObjs HomeBtnObj;

	[SerializeField]
	public NguiObjs RetryBtnObj;

	[SerializeField]
	public NguiObjs ReportBtnObj;

	[Header("タイトル画像")]
	[SerializeField]
	private GameObject _titleRoot;

	[SerializeField]
	public UISprite TitleWin;

	[SerializeField]
	public UISprite TitleLose;

	[SerializeField]
	public UISprite TitleDraw;

	[SerializeField]
	public UISprite TitleMatch;

	[Header("通知表示")]
	[SerializeField]
	public NguiObjs ResultInfo;

	[SerializeField]
	private GameObject _notificationAnimationParent;

	[SerializeField]
	private NotificatonAnimation _notificationAnimationPrefab;

	[SerializeField]
	private UISprite _battlePassBG;

	private string _resultTypeMsg = "";

	[SerializeField]
	private GameObject m_MissionBase;

	public IDictionary<string, Vector3> DefaultPosDict = new Dictionary<string, Vector3>();

	private int _classLv;

	private int _classLvPrev;

	private int _classLvMax;

	private int _classExp;

	private int _nowClassExp;

	private int _nextClassExp;

	private IList<NguiObjs> _missionLogList = new List<NguiObjs>();

	private int _beforeClassExp;

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

	private bool _isResultTutorial;

	private bool _isUsingSpecialDeck;

	private int _usingSpecialDeckClassId;

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

	private INextSceneSelector _nextSceneSelector;

	[NonSerialized]
	public IBattleResultReporter resultReporter;

	private IResultAnimationHandler resultAnimationHandler;

	public const int MISSION_SPRITE_WIDTH = 800;

	private const int MISSION_MARGIN = 24;

	private const string MAINTENANCE_TIME_KEY = "maintenance_time";

	private int _selectedClassId;

	private NotificatonAnimation _notificationAnimation;

	[SerializeField]
	private GameObject _missionSelect;

	[SerializeField]
	private GameObject _retrySelect;

	[SerializeField]
	private GameObject _homeSelect;

	private const int MISSION_SELECT = 0;

	private const int RETRY_SELECT = 1;

	private const int HOME_SELECT = 2;

	public DialogBase _missionDialog;

	private MenuDialogSelect _menuDialogSelect = MenuDialogSelect.None;

	[NonSerialized]
	public bool IsRewardWait;

	public bool ResultMsgWindowFlag { get; private set; }

	public bool ResultMsgReportBtnFlag { get; private set; }

	public bool IsWin { get; set; }

	public int AddClassExp { get; private set; }

	public bool IsDraw { get; private set; }

	public bool IsResultOn { get; private set; }

	public bool AlreadyResultRecovery { get; set; }

	public bool GreySpriteBGVisible
	{
		set
		{
			_battlePassBG.gameObject.SetActive(value);
		}
	}

	public IBattleResultReporter ResultReporter => resultReporter;

	public event Action OnResultFinish;

	private void OnDestroy()
	{
		VideoHostingUtil.SetHUDScene(VideoHostingUtil.HUDScene.Home);
		GameMgr.GetIns().GetEffectMgr().Stop(EffectMgr.EffectType.CMN_RESULT_BACK_1);
		GameMgr.GetIns().GetEffectMgr().Stop(EffectMgr.EffectType.CMN_RESULT_BACK_2);
		GameMgr.GetIns().GetEffectMgr().Stop(EffectMgr.EffectType.CMN_RESULT_BACK_3);
		if (resultAnimationHandler != null)
		{
			resultAnimationHandler.Destroy();
		}
		if (GameMgr.GetIns()._rankWinnerReward != null)
		{
			GameMgr.GetIns()._rankWinnerReward.RemoveObject();
			GameMgr.GetIns()._rankWinnerReward = null;
		}
	}

	private void Start()
	{
		_titleRoot.SetActive(value: true);
		IsResultOn = false;
		DefaultPosDict["ClassCharObj"] = ClassCharObj.transform.localPosition;
		DefaultPosDict["ResultTitle"] = ResultTitle.transform.localPosition;
		DefaultPosDict["ClassInfo"] = ClassInfo.transform.localPosition;
		DefaultPosDict["ButtonGrid"] = ButtonGrid.transform.localPosition;
		MainPanel.alpha = 0f;
		TitleMatch.alpha = 0f;
		Toolbox.AudioManager.AddCueSheet("bgm_btl_jingle", "bgm_btl_jingle.acb", "b/", "bgm_btl_jingle.awb");
		ButtonGrid.gameObject.SetActive(value: false);
		IsDraw = false;
		base.gameObject.SetActive(value: false);
		if (RankMatchBattleResultObject != null)
		{
			RankMatchBattleResultObject.Init();
		}
		if (QuestBattleResultObject != null)
		{
			QuestBattleResultObject.Init();
		}
	}

	public void StartUI(bool win, BattleCamera battleCamera)
	{
		base.gameObject.SetActive(value: true);
		if (IsResultOn)
		{
			return;
		}
		IsResultOn = true;
		Toolbox.AudioManager.AddCueSheet("bgm_btl_jingle", "bgm_btl_jingle.acb", "b/", "bgm_btl_jingle.awb");
		VideoHostingUtil.SetHUDScene(VideoHostingUtil.HUDScene.BattleResult);
		DataMgr dataMgr = GameMgr.GetIns().GetDataMgr();
		int skinId = dataMgr.GetPlayerSkinId();
		bool isEvolve = BattleManagerBase.GetIns().BattlePlayer.IsSkinEvolved;
		if (!BattleManagerBase.IsTutorial)
		{
			if (win)
			{
				_resultAssetList.Add(Toolbox.ResourcesManager.GetAssetTypePath(skinId.ToString("00"), isEvolve ? ResourcesManager.AssetLoadPathType.ClassCharaEvolveWin : ResourcesManager.AssetLoadPathType.ClassCharaBaseWin));
				string text = dataMgr.GetPlayerEmotionData()[ClassCharaPrm.EmotionType.WIN].GetVoiceId(isEvolve);
				if (BattleManagerBase.GetIns().IsPuzzleMgr)
				{
					string clearVoiceId = (BattleManagerBase.GetIns() as PuzzleBattleManager).PuzzleQuestData.ClearVoiceId;
					if (!string.IsNullOrEmpty(clearVoiceId))
					{
						text = clearVoiceId;
					}
				}
				_ = isEvolve;
				_resultAssetList.Add("v/vo_" + text + ".acb");
			}
			else
			{
				_resultAssetList.Add(Toolbox.ResourcesManager.GetAssetTypePath(skinId.ToString("00"), isEvolve ? ResourcesManager.AssetLoadPathType.ClassCharaEvolveLose : ResourcesManager.AssetLoadPathType.ClassCharaBaseLose));
				_resultAssetList.Add("v/vo_" + dataMgr.GetPlayerEmotionData()[ClassCharaPrm.EmotionType.LOSE].GetVoiceId(isEvolve) + ".acb");
			}
		}
		if (dataMgr.IsFormatEnableBattleType())
		{
			int num = PlayerStaticData.UserRankCurrentFormat();
			_resultAssetList.Add(Toolbox.ResourcesManager.GetAssetTypePath(num.ToString("00"), ResourcesManager.AssetLoadPathType.RankIcon_L));
		}
		List<GameObject> list = new List<GameObject>();
		list.Add(ClassGaugeEfc.gameObject);
		if (RankMatchBattleResultObject != null)
		{
			list.Add(RankMatchBattleResultObject.RankGaugeEfc.gameObject);
		}
		if (QuestBattleResultObject != null)
		{
			list.Add(QuestBattleResultObject.QuestPointGaugeEffect.gameObject);
		}
		GameMgr.GetIns().GetEffectMgr().SetUIParticleShader(list, delegate
		{
			GameMgr.GetIns().GetEffectMgr().InitCommonEffect("Json/EffectResultData", isBattle: true, isField: false, isBattleEffect: true, delegate
			{
				Toolbox.ResourcesManager.StartCoroutine_LoadAssetGroupAsync(_resultAssetList, delegate
				{
					Toolbox.ResourcesManager.BattleListAssetPathList.AddRange(_resultAssetList);
					IsWin = win;
					DataMgr.BattleType battleType = dataMgr.m_BattleType;
					if (battleType == DataMgr.BattleType.Story && Data.SelectedStoryInfo.IsTutorialCategory)
					{
						_isResultTutorial = true;
						_nextSceneSelector = new TutorialNextSceneSelector(this);
						resultReporter = new TutorialResultReporter();
						resultAnimationHandler = new TutorialResultAnimationHandler(battleCamera);
					}
					else
					{
						ResourcesManager.AssetLoadPathType type = ((!isEvolve) ? (IsWin ? ResourcesManager.AssetLoadPathType.ClassCharaBaseWin : ResourcesManager.AssetLoadPathType.ClassCharaBaseLose) : (IsWin ? ResourcesManager.AssetLoadPathType.ClassCharaEvolveWin : ResourcesManager.AssetLoadPathType.ClassCharaEvolveLose));
						Texture mainTexture = Toolbox.ResourcesManager.LoadObject(Toolbox.ResourcesManager.GetAssetTypePath(skinId.ToString("00"), type, isfetch: true)) as Texture;
						ClassCharObj.textures[0].mainTexture = mainTexture;
						_classInfoParts.InitByCharaPrm(dataMgr.GetPlayerCharaData());
						ClassLvImg.mainTexture = Toolbox.ResourcesManager.LoadObject(Toolbox.ResourcesManager.GetAssetTypePath(dataMgr.GetPlayerClassId().ToString("00"), ResourcesManager.AssetLoadPathType.ClassCharaIconLevel, isfetch: true)) as Texture;
						if (battleType == DataMgr.BattleType.TwoPick)
						{
							_isUsingSpecialDeck = true;
							if (Data.TwoPickInfo.deckInfo != null)
							{
								_usingSpecialDeckClassId = Data.TwoPickInfo.deckInfo.classId;
							}
							else
							{
								_usingSpecialDeckClassId = Data.BattleRecoveryInfo.chara_id;
							}
						}
						SetResultFunc(battleCamera);
					}
					ResultSetupEnd();
				});
			});
		}, isBattle: true);
	}

	private void SetResultFunc(BattleCamera battleCamera)
	{
		if (GameMgr.GetIns().IsReplayBattle)
		{
			_nextSceneSelector = new NullNextSceneSelector(this);
			resultReporter = new RoomMatchResultReporter();
			resultAnimationHandler = new RoomMatchResultAnimationHandler(battleCamera);
			return;
		}
		switch (GameMgr.GetIns().GetDataMgr().m_BattleType)
		{
		case DataMgr.BattleType.FreeBattle:
			_nextSceneSelector = new NetworkMatchNextSceneSelector(this);
			resultReporter = new FreeMatchResultReporter();
			resultAnimationHandler = new FreeMatchResultAnimationHandler(battleCamera);
			break;
		case DataMgr.BattleType.RankBattle:
			_nextSceneSelector = new NetworkMatchNextSceneSelector(this);
			resultReporter = new RankMatchResultReporter();
			resultAnimationHandler = new RankMatchResultAnimationHandler(battleCamera);
			break;
		case DataMgr.BattleType.Practice:
			if (GameMgr.GetIns().IsPuzzleQuest)
			{
				_nextSceneSelector = new PracticePuzzleNextSceneSelector(this);
				resultReporter = new PracticePuzzleResultReporter();
				resultAnimationHandler = new PracticeResultAnimationHandler(battleCamera);
			}
			else
			{
				_nextSceneSelector = new PracticeNextSceneSelector(this);
				resultReporter = new PracticeResultReporter();
				resultAnimationHandler = new PracticeResultAnimationHandler(battleCamera);
			}
			break;
		case DataMgr.BattleType.ColosseumNormal:
		case DataMgr.BattleType.ColosseumTwoPick:
		case DataMgr.BattleType.ColosseumHof:
		case DataMgr.BattleType.ColosseumWindFall:
		case DataMgr.BattleType.ColosseumAvatar:
			_nextSceneSelector = new ArenaNextSceneSelector(this);
			resultReporter = new ColosseumResultReporter();
			resultAnimationHandler = new ColosseumResultAnimationHandler(battleCamera);
			break;
		case DataMgr.BattleType.CompetitionNormal:
		case DataMgr.BattleType.CompetitionTwoPick:
			_nextSceneSelector = new ArenaNextSceneSelector(this);
			resultReporter = new CompetitionResultReporter();
			resultAnimationHandler = new CompetitionResultAnimationHandler(battleCamera);
			break;
		case DataMgr.BattleType.TwoPick:
		case DataMgr.BattleType.Sealed:
			_nextSceneSelector = new ArenaNextSceneSelector(this);
			resultReporter = new ArenaResultReporter();
			resultAnimationHandler = new ArenaResultAnimationHandler(battleCamera);
			break;
		case DataMgr.BattleType.RoomBattle:
		case DataMgr.BattleType.RoomTwoPick:
		case DataMgr.BattleType.TwoPickBackdraft:
			_nextSceneSelector = new NullNextSceneSelector(this);
			resultReporter = new RoomMatchResultReporter();
			resultAnimationHandler = new RoomMatchResultAnimationHandler(battleCamera);
			break;
		case DataMgr.BattleType.Story:
			_nextSceneSelector = new StoryNextSceneSelector(this);
			resultReporter = new StoryResultReporter();
			resultAnimationHandler = new StoryResultAnimationHandler(battleCamera);
			break;
		case DataMgr.BattleType.Quest:
		case DataMgr.BattleType.BossRushQuest:
		case DataMgr.BattleType.SecretBossQuest:
			_nextSceneSelector = new QuestNextSceneSelector(this);
			resultReporter = new QuestResultReporter();
			resultAnimationHandler = new QuestSpecialResultAnimationHandler(battleCamera, GetComponent<QuestSpecialBattleResult>());
			break;
		}
		if (BattleManagerBase.GetIns().IsPuzzleMgr && !IsWin)
		{
			_nextSceneSelector = new NullNextSceneSelector(this);
		}
	}

	private void ResultSetupEnd()
	{
		_nextSceneSelector.Setup(IsWin, base.gameObject);
		ClassCharObj.transform.localPosition = DefaultPosDict["ClassCharObj"] + Vector3.right * 1200f;
		ResultTitle.transform.localPosition = DefaultPosDict["ResultTitle"] + Vector3.up * 500f;
		ClassInfo.transform.localPosition = DefaultPosDict["ClassInfo"] + Vector3.left * 2000f;
		ButtonGrid.transform.localPosition = DefaultPosDict["ButtonGrid"] + Vector3.down * 200f;
		for (int i = 0; i < _missionLogList.Count; i++)
		{
			_missionLogList[i].gameObject.SetActive(value: false);
		}
		ClassCharObj.gameObject.SetActive(value: true);
		ResultTitle.gameObject.SetActive(value: true);
		ClassInfo.gameObject.SetActive(value: true);
		ButtonGrid.gameObject.SetActive(value: true);
		ArcaneIn.transform.localScale = Vector3.one * 0.01f;
		ArcaneOut.transform.localScale = Vector3.one * 0.01f;
		ArcaneIn.alpha = 0f;
		ArcaneOut.alpha = 0f;
		ClassExpAddLabel.alpha = 0f;
		ResultInfo.labels[0].alpha = 0f;
		ResultInfo.sprites[0].alpha = 0f;
		ButtonGrid.repositionNow = true;
		ClassExpNextTitle.text = Data.SystemText.Get("Battle_0205");
		Format format = Data.CurrentFormat;
		if (GameMgr.GetIns().GetDataMgr().IsDipslayHighRankFormat())
		{
			format = PlayerStaticData.HighRankFormat();
		}
		if (format == Format.PreRotation)
		{
			format = Format.Rotation;
		}
		if (GameMgr.GetIns().IsWatchBattle)
		{
			resultReporter.Destroy();
			StartCoroutine(resultAnimationHandler.m_resultAnimationAgent.RunUI(this, _nextSceneSelector, IsWin));
		}
		else
		{
			StartCoroutine(GetServerData());
		}
		if (RankMatchBattleResultObject != null)
		{
			RankMatchBattleResultObject.ResultSetupEnd(format);
		}
		if (QuestBattleResultObject != null)
		{
			QuestBattleResultObject.ResultSetupEnd(format);
		}
	}

	public void SetBattlePassGauge(Action completeAction)
	{
		if (_battlePassResultPanel == null || !PlayerPrefsWrapper.GetBool(PlayerPrefsWrapper.BATTLE_PASS_SHOW_RESULT) || !resultReporter.IsDataExist)
		{
			completeAction();
			return;
		}
		JsonData finishResponseData = resultReporter.GetFinishResponseData();
		if (finishResponseData != null && finishResponseData["data"].Keys.Contains("battle_pass_gauge_info"))
		{
			BattlePassGaugeInfo battlePassGaugeInfo = new BattlePassGaugeInfo(finishResponseData["data"]["battle_pass_gauge_info"]);
			if (battlePassGaugeInfo.IsMaxPoint && battlePassGaugeInfo.IsBeforeMaxPoint)
			{
				completeAction();
				return;
			}
			GreySpriteBGVisible = true;
			BattlePassResultPanel component = UnityEngine.Object.Instantiate(_battlePassResultPanel, _acncorNoneRoot).GetComponent<BattlePassResultPanel>();
			component.Initialize(battlePassGaugeInfo);
			component.SetPointupAnimation(completeAction);
		}
		else
		{
			completeAction();
		}
	}

	public void CreateMissionList()
	{
		SystemText systemText = Data.SystemText;
		DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose();
		dialogBase.SetSize(DialogBase.Size.M);
		dialogBase.SetTitleLabel(systemText.Get("Mission_0003"));
		dialogBase.SetButtonLayout(DialogBase.ButtonLayout.CloseBtn);
		dialogBase.ScrollView.transform.DestroyChildren();
		dialogBase.ScrollView.panel.leftAnchor.absolute = 24;
		dialogBase.ScrollView.panel.rightAnchor.absolute = -24;
		GameObject gameObject = new GameObject("table");
		dialogBase.ScrollView.contentPivot = UIWidget.Pivot.Top;
		dialogBase.AttachToScrollView(gameObject.transform);
		UITable uITable = gameObject.AddComponent<UITable>();
		uITable.columns = 1;
		uITable.keepWithinPanel = true;
		uITable.cellAlignment = UIWidget.Pivot.Center;
		uITable.pivot = UIWidget.Pivot.Center;
		ResourceHandler resourceHandler = base.gameObject.AddMissingComponent<ResourceHandler>();
		int count = Data.MissionInfo.data.user_mission_list.Count;
		for (int i = 0; i < Data.MissionInfo.data.user_mission_list.Count; i++)
		{
			UserMission mission = Data.MissionInfo.data.user_mission_list[i];
			GameObject obj = UnityEngine.Object.Instantiate(m_MissionBase);
			obj.transform.parent = uITable.transform;
			obj.transform.localPosition = Vector3.zero;
			obj.transform.localScale = Vector3.one;
			obj.SetActive(value: true);
			obj.GetComponent<UISprite>().width = 800;
			obj.GetComponent<AchievementWindowBase>().SetMission(mission, resourceHandler, canChangeMissions: false, i != count - 1, displayChange: false);
		}
		_missionDialog = dialogBase;
		StartCoroutine(ResetMissionScrollPos(dialogBase.ScrollView));
		UIManager.GetInstance().closeInSceneCenterLoading();
	}

	private IEnumerator ResetMissionScrollPos(UIScrollView scroll)
	{
		yield return new WaitForSeconds(0.1f);
		scroll.ResetPosition();
	}

	private IEnumerator GetServerData()
	{
		LocalLog.AccumulateLastTraceLog("GetServerData ");
		LocalLog.SendClientInfoTraceLog(delegate
		{
			resultReporter.Report(IsWin);
		});
		while (!resultReporter.IsEnd)
		{
			yield return null;
		}
		LocalLog.AccumulateLastTraceLog("GetServerData ReporterEnd");
		if (!resultReporter.IsDataExist)
		{
			Toolbox.NetworkManager.NetworkUI.OpenGoToTitleErrorPopUp(Data.SystemText.Get("ErrorHeader_3502"), Data.SystemText.Get("Error_3502"), "");
			yield break;
		}
		DataMgr dataMgr = GameMgr.GetIns().GetDataMgr();
		if (RankMatchBattleResultObject != null)
		{
			RankMatchBattleResultObject.GetServerData();
		}
		if (QuestBattleResultObject != null)
		{
			QuestBattleResultObject.GetServerData(resultReporter);
		}
		if (dataMgr.IsColosseumBattleType())
		{
			SetBackGroundNeedBattlePoint(needBattlePoint: false);
		}
		GameMgr.GetIns().GetDataMgr().CacheSingleRecovryData();
		RecoveryRecordManagerBase.DeleteRecoveryFile();
		AddClassExp = resultReporter.ClassExp;
		resultReporter.Destroy();
		if (!_isResultTutorial)
		{
			if (_isUsingSpecialDeck)
			{
				_selectedClassId = ((_usingSpecialDeckClassId != 0) ? _usingSpecialDeckClassId : dataMgr.GetPlayerClassId());
			}
			else
			{
				_selectedClassId = dataMgr.GetPlayerClassId();
			}
			_beforeClassExp = dataMgr.GetClassPrm(_selectedClassId).GetClassCharaExp();
		}
		_classExpList.Clear();
		for (int num = 0; num < Data.Load.data._classCharaExpList.Count; num++)
		{
			_classExpList.Add(Data.Load.data._classCharaExpList[num].necessary_exp);
		}
		_classLvMax = _classExpList.Count;
		SetClassExp(0, isLvUpCheck: false);
		_classLvPrev = _classLv;
		StartCoroutine(resultAnimationHandler.m_resultAnimationAgent.RunUI(this, _nextSceneSelector, IsWin));
	}

	public void PrepareAchievementLog()
	{
		if (GameMgr.GetIns().IsWatchBattle)
		{
			return;
		}
		List<NotificatonAnimation.Param> list = new List<NotificatonAnimation.Param>();
		JsonData finishResponseData = resultReporter.GetFinishResponseData();
		if (finishResponseData != null && finishResponseData["data"].Keys.Contains("maintenance_time"))
		{
			DateTime dateTime = DateTime.Parse(finishResponseData["data"]["maintenance_time"].ToString());
			list.Add(new NotificatonAnimation.Param(NotificatonAnimation.Param.Type.MaintenanceOnResult, Data.SystemText.Get("System_0044", ConvertTime.ToLocal(dateTime))));
		}
		if (finishResponseData != null && finishResponseData["data"].Keys.Contains("gathering_notification"))
		{
			string valueOrDefault = finishResponseData["data"]["gathering_notification"].GetValueOrDefault("matching_established_message", string.Empty);
			if (!string.IsNullOrEmpty(valueOrDefault))
			{
				list.Add(new NotificatonAnimation.Param(NotificatonAnimation.Param.Type.GatheringMatching, valueOrDefault));
			}
		}
		for (int i = 0; i < resultReporter.UserMission.Count; i++)
		{
			list.Add(new NotificatonAnimation.Param(NotificatonAnimation.Param.Type.Result, resultReporter.UserMission[i].achieved_message));
		}
		for (int j = 0; j < resultReporter.UserAchievement.Count; j++)
		{
			list.Add(new NotificatonAnimation.Param(NotificatonAnimation.Param.Type.Result, resultReporter.UserAchievement[j].achieved_message));
		}
		StartCoroutine(ShowAchieveLog(list));
	}

	public void RewardCheck()
	{
		IsRewardWait = false;
	}

	public void FinishResult()
	{
		this.OnResultFinish.Call();
	}

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

	private void StartClassExp()
	{
		ClassGaugeEfc.gameObject.SetActive(value: true);
		ClassGaugeEfc.Play();
	}

	private void UpdateClassExp(int num)
	{
		SetClassExp(num, isLvUpCheck: true);
	}

	public void SetClassExp(int num, bool isLvUpCheck)
	{
		_classExp = _beforeClassExp + num;
		_classLv = GetClassLv(_classExp);
		_nowClassExp = GetClassExpNow(_classExp);
		_nextClassExp = Mathf.Max(0, _classExpList[_classLv - 1] - _nowClassExp);
		ClassLvLabel.text = _classLv.ToString();
		ClassExpNextLabel.text = _nextClassExp.ToString();
		if (AddClassExp >= 0)
		{
			ClassExpAddLabel.text = ((AddClassExp - num >= 0) ? "+" : "") + (AddClassExp - num);
		}
		else
		{
			ClassExpAddLabel.text = (AddClassExp - num).ToString();
		}
		ClassGaugeBar.Value = (((float)_classExpList[_classLv - 1] >= 0f) ? Mathf.Min((float)_nowClassExp / (float)_classExpList[_classLv - 1], 1f) : 1f);
		if (isLvUpCheck && _classLv > _classLvPrev)
		{
			GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_RESULT_LEVELUP);
			GameMgr.GetIns().GetEffectMgr().Start(EffectMgr.EffectType.CMN_RESULT_LVUP_1, ClassLvImg.transform.position);
			GameMgr.GetIns().GetEffectMgr().Start(EffectMgr.EffectType.CMN_RESULT_GAUGE_1, ClassGaugeBar.GetTransformGaugeStartEdge().position);
			_classLvPrev = _classLv;
		}
	}

	private void CompleteClassExp()
	{
		ClassGaugeEfc.Stop();
		TweenAlpha.Begin(ClassExpAddLabel.gameObject, 0.5f, 0f).delay = 0.5f;
		SetClassLvAndExp();
	}

	public void SetClassLvAndExp()
	{
		DataMgr dataMgr = GameMgr.GetIns().GetDataMgr();
		switch (dataMgr.m_BattleType)
		{
		case DataMgr.BattleType.FreeBattle:
			_classLv = Data.FreeMatchFinish.data.class_chara_level;
			_classExp = Data.FreeMatchFinish.data.class_chara_experience;
			break;
		case DataMgr.BattleType.RankBattle:
			_classLv = Data.RankMatchFinish.data.class_chara_level;
			_classExp = Data.RankMatchFinish.data.class_chara_experience;
			break;
		case DataMgr.BattleType.Story:
			_classLv = Data.StoryFinish.data.class_chara_level;
			_classExp = Data.StoryFinish.data.class_chara_experience;
			break;
		case DataMgr.BattleType.Practice:
			_classLv = Data.PracticeFinish.data.class_chara_level;
			_classExp = Data.PracticeFinish.data.class_chara_experience;
			break;
		case DataMgr.BattleType.RoomBattle:
			_classLv = Data.FreeMatchFinish.data.class_chara_level;
			_classExp = Data.FreeMatchFinish.data.class_chara_experience;
			break;
		case DataMgr.BattleType.Quest:
		case DataMgr.BattleType.BossRushQuest:
		case DataMgr.BattleType.SecretBossQuest:
			_classLv = Data.QuestFinish.data.class_chara_level;
			_classExp = Data.QuestFinish.data.class_chara_experience;
			break;
		}
		ClassCharaPrm classPrm = dataMgr.GetClassPrm(_selectedClassId);
		classPrm.SetClassCharaLv(_classLv);
		classPrm.SetClassCharaExp(_classExp);
	}

	private int GetClassLv(int num)
	{
		int num2 = 1;
		int num3 = 0;
		for (int i = 0; i < _classExpList.Count; i++)
		{
			num3 += _classExpList[i];
			if (num < num3)
			{
				break;
			}
			num2++;
		}
		return Mathf.Min(num2, _classLvMax);
	}

	private int GetClassExpNow(int num)
	{
		int num2 = num;
		for (int i = 0; i < _classExpList.Count && num2 >= _classExpList[i]; i++)
		{
			num2 -= _classExpList[i];
		}
		return num2;
	}

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

	public void SetSpecialResultTypeText(string text)
	{
		_resultTypeMsg = text;
		ResultMsgWindowFlag = true;
	}

	public void SetBattleFinishConsistency()
	{
		IsDraw = true;
		ResultMsgReportBtnFlag = true;
	}

	public IEnumerator ShowSpecialResultInfo()
	{
		ResultInfo.labels[0].text = _resultTypeMsg;
		ResultInfo.labels[0].alpha = 0f;
		ResultInfo.sprites[0].alpha = 0f;
		ResultInfo.labels[0].transform.localPosition = Vector3.right * 200f;
		ResultInfo.sprites[0].transform.localScale = new Vector3(0.01f, 0.1f, 1f);
		TweenAlpha.Begin(ResultInfo.sprites[0].gameObject, 0.2f, 1f);
		iTween.ScaleTo(ResultInfo.sprites[0].gameObject, iTween.Hash("scale", new Vector3(1f, 0.1f, 1f), "time", 0.2f, "islocal", true, "easetype", iTween.EaseType.easeInQuad));
		iTween.ScaleTo(ResultInfo.sprites[0].gameObject, iTween.Hash("scale", Vector3.one, "time", 0.5f, "delay", 0.2f, "islocal", true, "easetype", iTween.EaseType.easeOutBack));
		yield return new WaitForSeconds(0.5f);
		TweenAlpha.Begin(ResultInfo.labels[0].gameObject, 0.2f, 1f);
		iTween.MoveTo(ResultInfo.labels[0].gameObject, iTween.Hash("position", Vector3.zero, "time", 0.3f, "islocal", true, "easetype", iTween.EaseType.easeOutExpo));
		yield return new WaitForSeconds(2f);
		TweenAlpha.Begin(ResultInfo.sprites[0].gameObject, 0.1f, 0f).delay = 0.2f;
		TweenAlpha.Begin(ResultInfo.labels[0].gameObject, 0.1f, 0f).delay = 0.2f;
		iTween.ScaleTo(ResultInfo.sprites[0].gameObject, iTween.Hash("scale", new Vector3(1f, 0.1f, 1f), "time", 0.3f, "islocal", true, "easetype", iTween.EaseType.easeInExpo));
		iTween.MoveTo(ResultInfo.labels[0].gameObject, iTween.Hash("position", Vector3.left * 200f, "time", 0.3f, "islocal", true, "easetype", iTween.EaseType.easeInExpo));
	}

	public void Recovery()
	{
		ClassInfo.SetActive(value: false);
		ClassInfo.SetActive(value: true);
	}

	public IEnumerator RunMatch()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_RANK_UP_MACH_BEGIN);
		TweenAlpha.Begin(TitleMatch.gameObject, 0.2f, 1f);
		TitleMatch.transform.localScale = Vector3.one * 10f;
		iTween.ScaleTo(TitleMatch.gameObject, iTween.Hash("scale", Vector3.one * 0.8f, "time", 0.2f, "easetype", iTween.EaseType.easeInQuad));
		yield return new WaitForSeconds(0.2f);
		GameMgr.GetIns().GetEffectMgr().Start(EffectMgr.EffectType.CMN_RESULT_MATCH_1, Vector3.back);
		TitleMatch.transform.localScale = Vector3.one;
		iTween.ScaleTo(TitleMatch.gameObject, iTween.Hash("scale", Vector3.one * 1.1f, "time", 3f, "easetype", iTween.EaseType.linear));
		yield return new WaitForSeconds(2.5f);
		TweenAlpha.Begin(TitleMatch.gameObject, 0.3f, 0f);
		iTween.ScaleTo(TitleMatch.gameObject, iTween.Hash("scale", Vector3.one * 10f, "time", 0.3f, "easetype", iTween.EaseType.easeInExpo));
		yield return new WaitForSeconds(0.3f);
	}

	private void Update()
	{
		if (_missionDialog != null)
		{
			MenuDialogUpdate(_missionDialog);
		}
	}

	private void MenuDialogUpdate(DialogBase dialog)
	{
		InputMgr inputMgr = GameMgr.GetIns().GetInputMgr();
		if (inputMgr.IsKeyboardCancel())
		{
			_missionDialog.CloseWithoutSelect();
			_menuDialogSelect = MenuDialogSelect.None;
		}
		bool flag = false;
		if (inputMgr.IsKeyboardLeftArrow() || inputMgr.IsKeyboardRightArrow())
		{
			_menuDialogSelect = ((_menuDialogSelect == MenuDialogSelect.Button1) ? MenuDialogSelect.ButtonClose : MenuDialogSelect.Button1);
			flag = true;
		}
		if (flag)
		{
			dialog.KeyboardSelectButton(DialogBase.KeyboardDialogSelect.Button1, _menuDialogSelect == MenuDialogSelect.Button1);
			dialog.KeyboardSelectButton(DialogBase.KeyboardDialogSelect.CloseButton, _menuDialogSelect == MenuDialogSelect.ButtonClose);
		}
		if (inputMgr.IsKeyboardEnter() && _menuDialogSelect != MenuDialogSelect.None)
		{
			_missionDialog.CloseWithoutSelect();
			_menuDialogSelect = MenuDialogSelect.None;
		}
	}

	public void SetBackGroundNeedBattlePoint(bool needBattlePoint)
	{
		_backGroundWithRank.gameObject.SetActive(needBattlePoint);
		_backGroundNotNeedRank.gameObject.SetActive(!needBattlePoint);
	}
}
