using System;
using System.Collections.Generic;
using MaidStatus;
using MaidStatus.CsvData;
using UnityEngine;
using wf;

public class CompetitiveShowMgr : BasePanelMgr
{
	public static bool compatibilityMode
	{
		get
		{
			return DailyMgr.IsLegacy;
		}
	}

	public static bool IsCompetitiveShowChara()
	{
		return 0 < CompetitiveShowMgr.check_maid_list.Count;
	}

	public override void Init()
	{
		if (CompetitiveShowMgr.check_maid_list.Count <= 0)
		{
			for (int i = 0; i < SceneCharacterSelect.select_maid_list.Count; i++)
			{
				CompetitiveShowMgr.check_maid_list.Add(SceneCharacterSelect.select_maid_list[i]);
			}
			SceneCharacterSelect.select_maid_list.Clear();
			if (1 < CompetitiveShowMgr.check_maid_list.Count)
			{
				GameMain.Instance.MainCamera.FadeOutNoUI(0f, true);
				GameMain.Instance.MainCamera.FadeIn(0f, false, null, true, true, default(Color));
				GameMain.Instance.SysDlg.Show("演出を簡略化しますか?", SystemDialog.TYPE.YES_NO, delegate
				{
					CompetitiveShowMgr.is_effect_ones = true;
					GameMain.Instance.CMSystem.SetTmpGenericFlag("品評会_演出省略", 1);
					GameMain.Instance.SysDlg.Close();
					GameMain.Instance.MainCamera.FadeInNoUI(0f, true);
					GameMain.Instance.MainCamera.FadeOut(0f, false, null, true, default(Color));
					this.Start2();
				}, delegate
				{
					CompetitiveShowMgr.is_effect_ones = false;
					GameMain.Instance.CMSystem.SetTmpGenericFlag("品評会_演出省略", 0);
					GameMain.Instance.SysDlg.Close();
					GameMain.Instance.MainCamera.FadeInNoUI(0f, true);
					GameMain.Instance.MainCamera.FadeOut(0f, false, null, true, default(Color));
					this.Start2();
				});
			}
			else
			{
				CompetitiveShowMgr.is_effect_ones = false;
				GameMain.Instance.CMSystem.SetTmpGenericFlag("品評会_演出省略", 0);
				this.Start2();
			}
		}
		else
		{
			this.Start2();
		}
	}

	protected override void Start()
	{
		NDebug.AssertNull(this.ClassEffect != null);
		this.ClassEffect.SetActive(false);
		this.is_success = false;
		base.Start();
		this.Init();
	}

	private void Start2()
	{
		Dictionary<int, string> dictionary = new Dictionary<int, string>();
		Dictionary<int, string> dictionary2 = new Dictionary<int, string>();
		List<JobClass.Data> allDatas = JobClass.GetAllDatas(true);
		List<YotogiClass.Data> allDatas2 = YotogiClass.GetAllDatas(true);
		bool lockNTRPlay = GameMain.Instance.CharacterMgr.status.lockNTRPlay;
		Maid maid = null;
		int num = 0;
		while (num < CompetitiveShowMgr.check_maid_list.Count && !this.is_success)
		{
			if (!CompetitiveShowMgr.is_effect_ones && 1 <= num)
			{
				break;
			}
			Maid maid2 = CompetitiveShowMgr.check_maid_list[num];
			AbstractClassData.ClassType classType = AbstractClassData.ClassType.Share;
			classType |= ((!CompetitiveShowMgr.compatibilityMode) ? AbstractClassData.ClassType.New : AbstractClassData.ClassType.Old);
			bool flag = maid2.status.jobClass.GetLearnPossibleClassDatas(true, classType).Count != 0;
			if (!flag)
			{
				List<YotogiClass.Data> learnPossibleClassDatas = maid2.status.yotogiClass.GetLearnPossibleClassDatas(true, classType);
				if (lockNTRPlay)
				{
					List<YotogiClass.Data> list = new List<YotogiClass.Data>();
					foreach (YotogiClass.Data data in learnPossibleClassDatas)
					{
						if (YotogiClass.IsNTRClass(data.id, CompetitiveShowMgr.compatibilityMode))
						{
							list.Add(data);
						}
					}
					foreach (YotogiClass.Data item in list)
					{
						learnPossibleClassDatas.Remove(item);
					}
				}
				flag = (learnPossibleClassDatas.Count != 0);
			}
			if (flag)
			{
				this.is_success = true;
				if (maid == null)
				{
					maid = maid2;
					break;
				}
			}
			num++;
		}
		if (maid == null && 0 < CompetitiveShowMgr.check_maid_list.Count)
		{
			maid = CompetitiveShowMgr.check_maid_list[0];
		}
		if (CompetitiveShowMgr.is_effect_ones)
		{
			this.sceneMgr.GetManager<MaidExaminationMgr>().OpenMaidExaminationPanel(maid, CompetitiveShowMgr.check_maid_list, new CompetitiveShowAPI.dgOnSceneStartCallBack(this.OnFadeInEnd));
		}
		else
		{
			this.sceneMgr.GetManager<MaidExaminationMgr>().OpenMaidExaminationPanel(maid, new List<Maid>
			{
				CompetitiveShowMgr.check_maid_list[0]
			}, new CompetitiveShowAPI.dgOnSceneStartCallBack(this.OnFadeInEnd));
		}
	}

	private void OnFadeInEnd()
	{
		GameMain.Instance.SoundMgr.PlaySe("SE005.ogg", false);
		CameraMain mainCamera = GameMain.Instance.MainCamera;
		mainCamera.SetControl(false);
		Maid maid = GameMain.Instance.CharacterMgr.GetMaid(0);
		Transform bone = maid.body0.GetBone("Bip01 Head");
		Vector3 position = bone.position;
		Vector3 vector = new Vector3(0.03583635f, 0.3097733f, -0.4142513f);
		Vector2 vector2 = new Vector2(-18.80226f, 11.24228f);
		mainCamera.SetTargetPos(vector, true);
		mainCamera.SetAroundAngle(vector2, true);
		mainCamera.SetDistance(0.7f, true);
		Vector3 f_vCenter = new Vector3(position.x - 0.0343059041f, position.y - 0.3253325f, position.z - 0.48361522f);
		Vector2 f_vRotate = new Vector2(-182.2753f, 11.24231f);
		float f_fRadius = 2.8f;
		float num = 5.5f;
		mainCamera.StartAnimationTo(true, vector, 0.7f, vector2, f_vCenter, f_fRadius, f_vRotate, num, "easeOutCubic", false, 0.5f);
		this.wait_time = Time.time + num + 1f;
		this.phase_status_ = CompetitiveShowMgr.PhaseStatus.CameraAction;
	}

	protected virtual void Update()
	{
		if (this.phase_status_ == CompetitiveShowMgr.PhaseStatus.CameraAction && this.wait_time < Time.time)
		{
			Maid maid = GameMain.Instance.CharacterMgr.GetMaid(0);
			if (this.is_success)
			{
				if (UnityEngine.Random.Range(0, 1) == 0)
				{
					maid.FaceAnime("にっこり", 0f, 0);
				}
				else
				{
					maid.FaceAnime("笑顔", 0f, 0);
				}
				maid.FaceBlend("頬１涙０");
				GameMain.Instance.SoundMgr.PlaySe("SE007.ogg", false);
				GameMain.Instance.SoundMgr.PlaySe("SE008.ogg", false);
				if (CompetitiveShowMgr.compatibilityMode)
				{
					GameMain.Instance.SoundMgr.PlayBGMLegacy("BGM021.ogg", 0f, true);
				}
				else
				{
					GameMain.Instance.SoundMgr.PlayBGM("BGM007.ogg", 0f, true);
				}
				GameObject bgObject = GameMain.Instance.BgMgr.BgObject;
				if (bgObject != null)
				{
					GameObject gameObject = Utility.CreatePrefab(bgObject, "Prefab/Particle/PKamihubuki", true);
					Vector3 localPosition = new Vector3(-1.08f, 4.06f, 0.2f);
					gameObject.transform.localPosition = localPosition;
					ParticleSystem[] componentsInChildren = gameObject.GetComponentsInChildren<ParticleSystem>();
					foreach (ParticleSystem particleSystem in componentsInChildren)
					{
						particleSystem.shape.angle = 25f;
					}
				}
				KeyValuePair<string, string> competitiveMotionFileVictory = maid.status.personal.competitiveMotionFileVictory;
				this.ClassEffect.SetActive(true);
				GameMain.Instance.ScriptMgr.LoadMotionScript(0, false, competitiveMotionFileVictory.Key, competitiveMotionFileVictory.Value, string.Empty, string.Empty, false, true);
			}
			else
			{
				if (UnityEngine.Random.Range(0, 1) == 0)
				{
					maid.FaceAnime("泣き", 0f, 0);
				}
				else
				{
					maid.FaceAnime("困った", 0f, 0);
				}
				KeyValuePair<string, string> competitiveMotionFileDefeat = maid.status.personal.competitiveMotionFileDefeat;
				GameMain.Instance.SoundMgr.PlaySe("SE021.ogg", false);
				GameMain.Instance.ScriptMgr.LoadMotionScript(0, false, competitiveMotionFileDefeat.Key, competitiveMotionFileDefeat.Value, string.Empty, string.Empty, false, true);
			}
			this.wait_time = Time.time + 3f;
			this.phase_status_ = CompetitiveShowMgr.PhaseStatus.MotionPlay;
		}
		else if (this.phase_status_ == CompetitiveShowMgr.PhaseStatus.MotionPlay && this.wait_time < Time.time)
		{
			this.sceneMgr.GetManager<MaidExaminationMgr>().BaseOpenPanel();
			this.phase_status_ = CompetitiveShowMgr.PhaseStatus.ResultDraw;
		}
	}

	public GameObject ClassEffect;

	public static List<Maid> check_maid_list = new List<Maid>();

	public static bool is_effect_ones = true;

	private bool is_success;

	private CompetitiveShowMgr.PhaseStatus phase_status_;

	private float wait_time;

	private enum PhaseStatus
	{
		Null,
		CameraAction,
		MotionPlay,
		ResultDraw
	}
}
