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

public static class YotogiSkillSelectWaitMotion
{
	public static void Create()
	{
		if (YotogiSkillSelectWaitMotion.data_dic_ != null)
		{
			return;
		}
		YotogiSkillSelectWaitMotion.data_dic_ = new Dictionary<int, List<YotogiSkillSelectWaitMotion.Data>>();
		using (AFileBase afileBase = GameUty.FileSystem.FileOpen("yotogi_skill_select_wait_motion.nei"))
		{
			using (CsvParser csvParser = new CsvParser())
			{
				bool condition = csvParser.Open(afileBase);
				NDebug.Assert(condition, "file open error[yotogi_skill_select_wait_motion.nei]");
				for (int i = 1; i < csvParser.max_cell_y; i++)
				{
					int num = 0;
					string cellAsString = csvParser.GetCellAsString(num++, i);
					Personal.Data data = Personal.GetData(cellAsString);
					if (!YotogiSkillSelectWaitMotion.data_dic_.ContainsKey(data.id))
					{
						YotogiSkillSelectWaitMotion.data_dic_.Add(data.id, new List<YotogiSkillSelectWaitMotion.Data>());
					}
					List<YotogiSkillSelectWaitMotion.Data> list = YotogiSkillSelectWaitMotion.data_dic_[data.id];
					YotogiSkillSelectWaitMotion.Data item = default(YotogiSkillSelectWaitMotion.Data);
					Relation relation = Relation.Contact;
					try
					{
						relation = (Relation)Enum.Parse(typeof(Relation), csvParser.GetCellAsString(num++, i));
					}
					catch (Exception e)
					{
						NDebug.AssertParseError("MaidStatus.Relation", e);
					}
					item.relation = relation;
					item.motion_script_file = csvParser.GetCellAsString(num++, i) + ".ks";
					item.motion_script_label = csvParser.GetCellAsString(num++, i);
					item.face_blend_name = csvParser.GetCellAsString(num++, i);
					item.face_name = csvParser.GetCellAsString(num++, i);
					list.Add(item);
				}
			}
		}
	}

	public static bool ApplyMaidGesture(Maid maid, YotogiStage.Data stage_data)
	{
		if (YotogiSkillSelectWaitMotion.wait_count_ == 0)
		{
			YotogiSkillSelectWaitMotion.Create();
			YotogiSkillSelectWaitMotion.Data data = YotogiSkillSelectWaitMotion.GetData(maid);
			ScriptManager scriptMgr = GameMain.Instance.ScriptMgr;
			scriptMgr.is_motion_blend = false;
			scriptMgr.LoadMotionScript(0, false, data.motion_script_file, data.motion_script_label, string.Empty, string.Empty, false, true);
			scriptMgr.is_motion_blend = true;
			maid.FaceAnime(data.face_name, 0f, 0);
			maid.FaceBlend("無し");
			maid.OpenMouth(false);
		}
		if (YotogiSkillSelectWaitMotion.wait_count_ < 10)
		{
			YotogiSkillSelectWaitMotion.wait_count_++;
			return false;
		}
		maid.body0.SetMaskMode(TBody.MaskMode.None);
		maid.EyeToCamera(Maid.EyeMoveType.目と顔を向ける, 0f);
		YotogiSkillSelectWaitMotion.ApplyEnvSetting(maid, stage_data);
		GameMain.Instance.MainCamera.SetTargetOffset(new Vector3((float)Screen.width / 256f * 154f - (float)Screen.width / 2f, 0f, 0f), false);
		YotogiSkillSelectWaitMotion.wait_count_ = 0;
		return true;
	}

	public static void ApplyEnvSetting(Maid maid, YotogiStage.Data stage_data)
	{
		stage_data.skillSelectcharacterData.Apply();
		stage_data.skillSelectLightData.Apply();
		CameraMain mainCamera = GameMain.Instance.MainCamera;
		Transform bone = maid.body0.GetBone("Bip01 Head");
		mainCamera.SetTargetPos(bone.position - new Vector3(0.00503452f, 0.02758344f, -0.0292511f), true);
		mainCamera.SetDistance(1.1f, true);
		mainCamera.SetAroundAngle(stage_data.skillSelectcharacterData.cameraAngle, true);
	}

	public static YotogiSkillSelectWaitMotion.Data GetData(Maid maid)
	{
		Status status = maid.status;
		NDebug.Assert(YotogiSkillSelectWaitMotion.data_dic_.ContainsKey(status.personal.id), "error.");
		List<YotogiSkillSelectWaitMotion.Data> list = YotogiSkillSelectWaitMotion.data_dic_[status.personal.id];
		YotogiSkillSelectWaitMotion.Data result = default(YotogiSkillSelectWaitMotion.Data);
		for (int i = 0; i < list.Count; i++)
		{
			if (list[i].relation == status.relation)
			{
				result = list[i];
				break;
			}
		}
		NDebug.Assert(!string.IsNullOrEmpty(result.motion_script_file), "error.");
		return result;
	}

	private static Dictionary<int, List<YotogiSkillSelectWaitMotion.Data>> data_dic_;

	private static int wait_count_;

	public struct Data
	{
		public Relation relation;

		public string motion_script_file;

		public string motion_script_label;

		public string face_blend_name;

		public string face_name;
	}
}
