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

public class TutorialResultAnimationAgent : ResultAnimationAgent
{
	public override IEnumerator RunUI(BattleResultUIController battleResultControl, INextSceneSelector nextSceneSelector, bool isWin)
	{
		m_BattleCamera.m_CutInCamera.gameObject.SetActive(value: false);
		if (battleResultControl.IsDraw)
		{
			battleResultControl.TitleWin.gameObject.SetActive(value: false);
			battleResultControl.TitleLose.gameObject.SetActive(value: false);
			battleResultControl.TitleDraw.gameObject.SetActive(value: true);
			battleResultControl.TitleDraw.transform.localScale = Vector3.one * 10f;
			battleResultControl.TitleDraw.alpha = 0f;
			battleResultControl.Bg.color = new Color32(0, 48, 16, 0);
			battleResultControl.ResultTitle.spriteName = "result_top_lose";
		}
		else if (isWin)
		{
			battleResultControl.TitleWin.transform.localScale = Vector3.one * 10f;
			battleResultControl.TitleWin.gameObject.SetActive(value: true);
			battleResultControl.TitleLose.gameObject.SetActive(value: false);
			battleResultControl.TitleDraw.gameObject.SetActive(value: false);
			battleResultControl.TitleWin.alpha = 0f;
			battleResultControl.Bg.color = new Color32(32, 24, 0, 0);
			battleResultControl.ResultTitle.spriteName = "result_top_win";
		}
		else
		{
			battleResultControl.TitleLose.transform.localScale = Vector3.one * 10f;
			battleResultControl.TitleWin.gameObject.SetActive(value: false);
			battleResultControl.TitleLose.gameObject.SetActive(value: true);
			battleResultControl.TitleDraw.gameObject.SetActive(value: false);
			battleResultControl.TitleLose.alpha = 0f;
			battleResultControl.Bg.color = new Color32(0, 24, 48, 0);
			battleResultControl.ResultTitle.spriteName = "result_top_lose";
		}
		battleResultControl.MainPanel.alpha = 1f;
		yield return new WaitForSeconds(0.1f);
		if (battleResultControl.IsDraw)
		{
			TweenAlpha.Begin(battleResultControl.TitleDraw.gameObject, 0.2f, 1f);
			iTween.ScaleTo(battleResultControl.TitleDraw.gameObject, iTween.Hash("scale", Vector3.one, "time", 0.2f, "islocal", true, "easetype", iTween.EaseType.easeInQuad));
			GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_RESULT_YOULOSE);
			GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_JINGLE_LOSE);
		}
		else if (isWin)
		{
			TweenAlpha.Begin(battleResultControl.TitleWin.gameObject, 0.2f, 1f);
			iTween.ScaleTo(battleResultControl.TitleWin.gameObject, iTween.Hash("scale", Vector3.one, "time", 0.2f, "islocal", true, "easetype", iTween.EaseType.easeInQuad));
			GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_RESULT_YOUWIN);
			GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_JINGLE_WIN);
		}
		else
		{
			TweenAlpha.Begin(battleResultControl.TitleLose.gameObject, 0.2f, 1f);
			iTween.ScaleTo(battleResultControl.TitleLose.gameObject, iTween.Hash("scale", Vector3.one, "time", 0.2f, "islocal", true, "easetype", iTween.EaseType.easeInQuad));
			GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_RESULT_YOULOSE);
			GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_JINGLE_LOSE);
		}
		TweenAlpha.Begin(battleResultControl.Bg.gameObject, 0.5f, 0.75f);
		yield return new WaitForSeconds(0.2f);
		TweenAlpha.Begin(battleResultControl.ArcaneIn.gameObject, 0.5f, 1f);
		TweenAlpha.Begin(battleResultControl.ArcaneOut.gameObject, 0.5f, 1f);
		iTween.ScaleTo(battleResultControl.ArcaneIn.gameObject, iTween.Hash("scale", Vector3.one, "time", 2f, "islocal", true, "easetype", iTween.EaseType.easeOutExpo));
		iTween.ScaleTo(battleResultControl.ArcaneOut.gameObject, iTween.Hash("scale", Vector3.one, "time", 2f, "islocal", true, "easetype", iTween.EaseType.easeOutExpo));
		if (battleResultControl.IsDraw)
		{
			GameMgr.GetIns().GetEffectMgr().Start(EffectMgr.EffectType.CMN_RESULT_TITLE_3, Vector3.zero);
			battleResultControl.TitleDraw.transform.localScale = Vector3.one;
			iTween.ScaleTo(battleResultControl.TitleDraw.gameObject, iTween.Hash("scale", Vector3.one * 1.1f, "time", 2f, "islocal", true, "easetype", iTween.EaseType.linear));
		}
		else if (isWin)
		{
			GameMgr.GetIns().GetEffectMgr().Start(EffectMgr.EffectType.CMN_RESULT_TITLE_1, Vector3.zero);
			battleResultControl.TitleWin.transform.localScale = Vector3.one;
			iTween.ScaleTo(battleResultControl.TitleWin.gameObject, iTween.Hash("scale", Vector3.one * 1.1f, "time", 2f, "islocal", true, "easetype", iTween.EaseType.linear));
		}
		else
		{
			GameMgr.GetIns().GetEffectMgr().Start(EffectMgr.EffectType.CMN_RESULT_TITLE_2, Vector3.zero);
			battleResultControl.TitleLose.transform.localScale = Vector3.one;
			iTween.ScaleTo(battleResultControl.TitleLose.gameObject, iTween.Hash("scale", Vector3.one * 1.1f, "time", 2f, "islocal", true, "easetype", iTween.EaseType.linear));
		}
		yield return new WaitForSeconds(2f);
		if (BattleManagerBase.IsTutorial)
		{
			Invoke("returnTutorial", 2f);
		}
		else if (Data.SelectedStoryInfo.IsTutorialReplay)
		{
			BattleEndTutorialReplay(isWin);
		}
		GameMgr.GetIns().GetDataMgr().SetPlayerEmotionId(string.Empty);
		GameMgr.GetIns().GetDataMgr().SetEnemyEmotionId(string.Empty);
		battleResultControl.FinishResult();
	}

	private void returnTutorial()
	{
		int tutorial_step = Data.Load.data._userTutorial.tutorial_step;
		if (tutorial_step <= 11)
		{
			if (tutorial_step != 1 && tutorial_step != 11)
			{
				return;
			}
		}
		else
		{
			switch (tutorial_step)
			{
			default:
				_ = 100;
				return;
			case 21:
				break;
			case 31:
				return;
			}
		}
		GameMgr.GetIns().GetBattleCtrl().BattleEnd(UIManager.ViewScene.AreaSelect);
	}

	private void BattleEndTutorialReplay(bool isWin)
	{
		switch (Data.Load.data._userTutorial.tutorial_replay_step)
		{
		case 1:
		case 11:
			GameMgr.GetIns().GetBattleCtrl().BattleEnd(UIManager.ViewScene.AreaSelect);
			break;
		case 21:
		case 100:
			if (isWin)
			{
				UIManager.GetInstance().createInSceneLoading();
				UIManager.GetInstance().CreatFadeClose(delegate
				{
					UIManager.GetInstance().StartCoroutine(GameMgr.GetIns().GetBattleCtrl().BattleEnd(delegate
					{
						UIManager.GetInstance().ChangeViewScene(UIManager.ViewScene.Scenario2);
					}));
				});
			}
			else
			{
				GameMgr.GetIns().GetBattleCtrl().BattleEnd(UIManager.ViewScene.AreaSelect);
			}
			break;
		}
	}

	private void OnRequestTutorialFinish(NetworkTask.ResultCode successcode)
	{
		ToolboxGame.SetUp.BuildFirstScene();
		UIManager.GetInstance().createInSceneLoading();
		UIManager.GetInstance().CreatFadeClose(delegate
		{
			UIManager.GetInstance().StartCoroutine(GameMgr.GetIns().GetBattleCtrl().BattleEnd(delegate
			{
				UIManager.GetInstance().DestroyView(UIManager.ViewScene.AreaSelect);
				UIManager.GetInstance().ChangeViewScene(UIManager.ViewScene.Scenario2);
			}));
		});
	}
}
