using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using wf;

public class MotionAction_Mgr : PartsMgrBase
{
	public static bool IsCaptureOK
	{
		get
		{
			return GameMain.Instance.CharacterMgr.status.GetFlag("モーションキャプチャ成功") == 1;
		}
		private set
		{
			GameMain.Instance.CharacterMgr.status.SetFlag("モーションキャプチャ成功", (!value) ? 0 : 1);
		}
	}

	public static MotionAction_Mgr Instance { get; private set; }

	protected override void Start()
	{
		MotionAction_Mgr.Instance = this;
		base.Start();
		int tmpGenericFlag = GameMain.Instance.CMSystem.GetTmpGenericFlag("ダンスOVRカメラタイプ");
		if ((!base.IsActive || !GameMain.Instance.VRMode || tmpGenericFlag == 1) && !this.m_IsMotionCheckOnly)
		{
			base.IsActive = false;
			base.gameObject.SetActive(false);
			return;
		}
		if (!this.m_IsMotionCheckOnly)
		{
			string text = RhythmAction_Mgr.Instance.MusicCSV_Path + "action_data.nei";
			if (!GameUty.FileSystem.IsExistentFile(text))
			{
				NDebug.Assert("表がありません。" + text, false);
			}
			using (AFileBase afileBase = GameUty.FileSystem.FileOpen(text))
			{
				using (CsvParser csvParser = new CsvParser())
				{
					bool condition = csvParser.Open(afileBase);
					NDebug.Assert(condition, text + "\nopen failed.");
					for (int i = 1; i < csvParser.max_cell_y; i++)
					{
						if (csvParser.IsCellToExistData(0, i))
						{
							ActionCase item = new ActionCase();
							for (int j = 1; j < csvParser.max_cell_x; j++)
							{
								this.ReadActionData(csvParser, j, i, ref item);
							}
							this.m_ActionAllCase.Add(item);
						}
					}
				}
			}
			this.Initialize();
		}
	}

	private void Initialize()
	{
		MotionAction_Mgr.GuidUIInfo.CurrentActionCount = 0;
		foreach (MotionAction_Mgr.GuidUIInfo guidUIInfo in this.m_GuidUIList)
		{
			guidUIInfo.GuidUI.fillAmount = 0f;
			guidUIInfo.GuidUI.gameObject.SetActive(false);
			this.m_AllGuidUIInfo.Add(guidUIInfo.Type, guidUIInfo);
		}
		if (!GameMain.Instance.VRMode || GameMain.Instance.OvrMgr.OvrCamera.IsNoHandController || this.m_IsForceMouseCheck)
		{
			this.m_CheckHand = UnityEngine.Object.Instantiate<GameObject>(Resources.Load<GameObject>("SceneDance/Rhythm_Action/Prefab/" + this.m_strHandName));
			this.m_CheckHand.transform.localScale = this.m_HandSize;
			Transform realHeadTransform = GameMain.Instance.MainCamera.GetRealHeadTransform();
			this.m_CheckHand.transform.parent = ((!GameMain.Instance.VRMode) ? realHeadTransform : GameMain.Instance.OvrMgr.OvrCamera.m_goOvrUiScreen.transform);
			this.m_CheckHand.transform.localEulerAngles = this.m_HandAngle;
			this.m_CheckHand.transform.localPosition = this.m_HandRelatePos;
		}
		else
		{
			OvrMgr.OvrObject.Controller left_controller = GameMain.Instance.OvrMgr.ovr_obj.left_controller;
			OvrMgr.OvrObject.Controller right_controller = GameMain.Instance.OvrMgr.ovr_obj.right_controller;
			this.m_ControllerParent = right_controller.hand_trans.parent;
			if (!this.m_MotionCheckDataVR.ContainsKey(left_controller))
			{
				this.m_MotionCheckDataVR.Add(left_controller, new MotionAction_Mgr.NeedCheckData());
			}
			if (!this.m_MotionCheckDataVR.ContainsKey(right_controller))
			{
				this.m_MotionCheckDataVR.Add(right_controller, new MotionAction_Mgr.NeedCheckData());
			}
		}
	}

	private void ReadActionData(CsvParser csv, int cx, int cy, ref ActionCase case_data)
	{
		switch (cx)
		{
		case 1:
		{
			string[] array = csv.GetCellAsString(cx, cy).Split(new char[]
			{
				':'
			});
			case_data.StartTime = float.Parse(array[0]);
			case_data.EndTime = float.Parse(array[1]);
			break;
		}
		case 2:
		{
			string[] array2 = csv.GetCellAsString(cx, cy).Split(new char[]
			{
				'.'
			});
			case_data.Trigger = array2[0];
			foreach (string s in array2[1].Split(new char[]
			{
				':'
			}))
			{
				case_data.TargetMaidNo.Add(int.Parse(s) - 1);
			}
			break;
		}
		case 3:
			foreach (string value in csv.GetCellAsString(cx, cy).Split(new char[]
			{
				':'
			}))
			{
				case_data.Action.Add((ActionCase.ActionType)Enum.Parse(typeof(ActionCase.ActionType), value));
			}
			break;
		case 4:
		{
			string[] array5 = csv.GetCellAsString(cx, cy).Split(new char[]
			{
				':'
			});
			foreach (string text in array5)
			{
				string[] array7 = text.Split(new char[]
				{
					'.'
				});
				ActionCase.ReactionParam reactionParam = new ActionCase.ReactionParam();
				reactionParam.IsFaceBlend = (array7[0].IndexOf("頬") > 0);
				reactionParam.Name = array7[0];
				reactionParam.SetTime = float.Parse(array7[1]);
				case_data.Reaction.Add(reactionParam);
			}
			break;
		}
		case 5:
		{
			string[] array8 = csv.GetCellAsString(cx, cy).Split(new char[]
			{
				':'
			});
			case_data.Effect = Resources.Load<GameObject>("SceneDance/Rhythm_Action/Prefab/" + array8[0]);
			case_data.EffectTime = float.Parse(array8[1]);
			break;
		}
		}
	}

	private void Update()
	{
		int currentActionCount = MotionAction_Mgr.GuidUIInfo.CurrentActionCount;
		int num = 0;
		foreach (MotionAction_Mgr.GuidUIInfo guidUIInfo in this.m_AllGuidUIInfo.Values)
		{
			if (guidUIInfo.NeedGuid)
			{
				float d = 0f;
				if (currentActionCount > 1)
				{
					d = -(float)(currentActionCount - 1) / 2f + (float)num;
				}
				guidUIInfo.GuidUI.transform.localPosition = Vector3.right * d * this.m_SetGuidSpace;
				num++;
				guidUIInfo.GuidUI.transform.GetChild(0).gameObject.SetActive(num != currentActionCount);
			}
		}
	}

	private IEnumerator CheckActionCase()
	{
		float timer = 0f;
		for (;;)
		{
			yield return null;
			if (!RhythmAction_Mgr.Instance.IsPause)
			{
				timer += RhythmAction_Mgr.Instance.DanceDeltaTime;
				List<ActionCase> list = new List<ActionCase>();
				foreach (ActionCase actionCase in this.m_ActionAllCase)
				{
					if (timer >= actionCase.StartTime && timer < actionCase.EndTime)
					{
						if (!TouchAction_Mgr.Instance.IsMaidTouch() && this.IsTriggerOn(actionCase))
						{
							base.StartCoroutine(this.MotionCheck(actionCase, timer));
							list.Add(actionCase);
						}
					}
					else if (timer > actionCase.EndTime)
					{
						list.Add(actionCase);
					}
				}
				if (list.Count > 0)
				{
					foreach (ActionCase item in list)
					{
						this.m_ActionAllCase.Remove(item);
					}
					if (this.m_ActionAllCase.Count <= 0)
					{
						break;
					}
				}
			}
		}
		yield break;
		yield break;
	}

	private bool IsTriggerOn(ActionCase action_case)
	{
		if (action_case.Trigger == "non")
		{
			return true;
		}
		if (action_case.Trigger == "foundP")
		{
			bool flag = false;
			foreach (int nMaidNo in action_case.TargetMaidNo)
			{
				Maid maid = GameMain.Instance.CharacterMgr.GetMaid(nMaidNo);
				if (!maid)
				{
					return false;
				}
				Vector3 position = GameMain.Instance.MainCamera.GetRealHeadTransform().position;
				Transform obj_tr = maid.body0.GetSlot(1).obj_tr;
				Vector3 vector = obj_tr.rotation * Vector3.forward;
				flag = (Vector3.Dot((position - obj_tr.position).normalized, vector.normalized) > Mathf.Cos(0.7853982f));
				if (flag)
				{
					break;
				}
			}
			return flag;
		}
		return false;
	}

	private IEnumerator MotionCheck(ActionCase case_data, float start_time)
	{
		Func<bool> play_voice = delegate()
		{
			for (int i = 0; i < GameMain.Instance.CharacterMgr.GetMaidCount(); i++)
			{
				Maid maid = GameMain.Instance.CharacterMgr.GetMaid(i);
				if (maid && maid.AudioMan && maid.AudioMan.isPlay())
				{
					return true;
				}
			}
			return false;
		};
		while (play_voice())
		{
			yield return null;
		}
		float timer = start_time;
		bool cursole_visible = false;
		CursorLockMode cursole_state = CursorLockMode.None;
		if (this.m_MotionCheckDataVR.Count > 0)
		{
			foreach (KeyValuePair<OvrMgr.OvrObject.Controller, MotionAction_Mgr.NeedCheckData> keyValuePair in this.m_MotionCheckDataVR)
			{
				keyValuePair.Value.FirstPos = keyValuePair.Key.hand_trans.localPosition;
				keyValuePair.Value.Controller = keyValuePair.Key;
				keyValuePair.Value.Init();
				keyValuePair.Value.MotionEffect.transform.parent = keyValuePair.Value.Controller.hand_trans;
			}
		}
		else
		{
			this.m_MotionCheckDataMouse.Init();
			this.m_MotionCheckDataMouse.MotionEffect.transform.parent = this.m_CheckHand.transform;
			if (!GameMain.Instance.VRMode)
			{
				this.m_MotionCheckDataMouse.FirstPos = Input.mousePosition;
				cursole_visible = Cursor.visible;
				cursole_state = Cursor.lockState;
			}
			else
			{
				this.m_MotionCheckDataMouse.FirstPos = GameMain.Instance.OvrMgr.SystemUICamera.GetOvrVirtualMouseCurrentSidePos();
				this.m_MotionCheckDataMouse.CurrentPos = this.m_MotionCheckDataMouse.FirstPos;
			}
		}
		bool isOK;
		for (;;)
		{
			if (!RhythmAction_Mgr.Instance || !RhythmAction_Mgr.Instance.IsPause)
			{
				timer += ((!RhythmAction_Mgr.Instance) ? Time.deltaTime : RhythmAction_Mgr.Instance.DanceDeltaTime);
				isOK = false;
				bool isEnd = false;
				if (!this.m_IsMotionCheckOnly)
				{
					isEnd = TouchAction_Mgr.Instance.IsMaidTouch();
				}
				Vector3 pos = Vector3.zero;
				foreach (ActionCase.ActionType actionType in case_data.Action)
				{
					if (isOK || isEnd)
					{
						break;
					}
					this.m_AllGuidUIInfo[actionType].NeedGuid = true;
					if (this.m_MotionCheckDataVR.Count > 0)
					{
						foreach (MotionAction_Mgr.NeedCheckData needCheckData in this.m_MotionCheckDataVR.Values)
						{
							pos = needCheckData.Controller.hand_trans.localPosition;
							needCheckData.CurrentPos = pos;
							needCheckData.MotionEffect.transform.localPosition = Vector3.forward * this.m_EffectAdjust;
							Vector3 vector = needCheckData.LastPos;
							if (actionType == ActionCase.ActionType.swing || actionType == ActionCase.ActionType.shake)
							{
								pos += needCheckData.Controller.hand_trans.localRotation * Vector3.forward * this.m_ControllerAdjust;
								vector += needCheckData.LastRot * Vector3.forward * this.m_ControllerAdjust;
							}
							if (this.ActionJudge(needCheckData, vector, pos, actionType))
							{
								isOK = true;
								break;
							}
						}
					}
					else
					{
						if (actionType == case_data.Action.First<ActionCase.ActionType>())
						{
							if (!GameMain.Instance.VRMode)
							{
								Cursor.lockState = CursorLockMode.Confined;
								pos = (this.m_MotionCheckDataMouse.CurrentPos = Input.mousePosition);
							}
							else
							{
								this.m_MotionCheckDataMouse.CurrentPos += (Vector3.right * NInput.GetAxis("Mouse X") + Vector3.up * NInput.GetAxis("Mouse Y")) * this.m_HandMoveSpeed;
								this.m_MotionCheckDataMouse.CurrentPos.x = Mathf.Clamp(this.m_MotionCheckDataMouse.CurrentPos.x, 0f, (float)UICamera.ScreenWidth);
								this.m_MotionCheckDataMouse.CurrentPos.y = Mathf.Clamp(this.m_MotionCheckDataMouse.CurrentPos.y, 0f, (float)UICamera.ScreenHeight);
								pos = this.m_MotionCheckDataMouse.CurrentPos;
							}
						}
						Vector3 lastPos = this.m_MotionCheckDataMouse.LastPos;
						isOK = this.ActionJudge(this.m_MotionCheckDataMouse, lastPos, pos, actionType);
						if (actionType == case_data.Action.First<ActionCase.ActionType>())
						{
							Vector3 vector2 = Vector3.zero;
							if (!GameMain.Instance.VRMode)
							{
								Vector3 zero = Vector3.zero;
								zero.x = (float)Screen.width;
								zero.y = (float)Screen.height;
								zero.z = this.m_HandRelatePos.z;
								Vector3 position = GameMain.Instance.MainCamera.camera.ScreenToWorldPoint(zero);
								position = GameMain.Instance.MainCamera.GetRealHeadTransform().InverseTransformPoint(position);
								float min = -position.x + this.m_HandRelatePos.x;
								float max = position.x + this.m_HandRelatePos.x;
								float min2 = -position.y + this.m_HandRelatePos.y;
								float max2 = position.y + this.m_HandRelatePos.y;
								vector2 = this.m_MotionCheckDataMouse.CurrentPos;
								vector2.z = this.m_HandRelatePos.z;
								vector2 = GameMain.Instance.MainCamera.camera.ScreenToWorldPoint(vector2);
								vector2 = GameMain.Instance.MainCamera.GetRealHeadTransform().InverseTransformPoint(vector2);
								vector2.x = Mathf.Clamp(vector2.x, min, max);
								vector2.y = Mathf.Clamp(vector2.y, min2, max2);
								this.m_CheckHand.transform.localPosition = vector2;
							}
							else
							{
								float num = 1f - Mathf.Clamp01(pos.x / (float)UICamera.ScreenWidth);
								float num2 = 1f - Mathf.Clamp01(pos.y / (float)UICamera.ScreenHeight);
								vector2.x = Mathf.Cos(num * 180f * 0.0174532924f) * this.m_HandMoveWidth;
								vector2.y = Mathf.Cos(num2 * 180f * 0.0174532924f) * this.m_HandMoveHeight;
								this.m_CheckHand.transform.localPosition = vector2 + this.m_HandRelatePos;
							}
							this.m_MotionCheckDataMouse.MotionEffect.transform.localPosition = Vector3.forward * this.m_EffectAdjust;
						}
					}
				}
				if (this.m_MotionCheckDataVR.Count > 0)
				{
					foreach (MotionAction_Mgr.NeedCheckData needCheckData2 in this.m_MotionCheckDataVR.Values)
					{
						needCheckData2.LastRot = needCheckData2.Controller.hand_trans.localRotation;
						needCheckData2.LastPos = needCheckData2.Controller.hand_trans.localPosition;
						needCheckData2.LastVec = needCheckData2.NowVec;
						needCheckData2.EmmitAdjust(this.m_HorizontalColor, this.m_VerticalColor);
					}
				}
				else
				{
					this.m_MotionCheckDataMouse.LastPos = this.m_MotionCheckDataMouse.CurrentPos;
					this.m_MotionCheckDataMouse.LastVec = this.m_MotionCheckDataMouse.NowVec;
					this.m_MotionCheckDataMouse.EmmitAdjust(this.m_HorizontalColor, this.m_VerticalColor);
				}
				if (isOK || isEnd || timer >= case_data.EndTime || this.ForceEnd)
				{
					break;
				}
			}
			yield return null;
		}
		foreach (ActionCase.ActionType key in case_data.Action)
		{
			this.m_AllGuidUIInfo[key].NeedGuid = false;
		}
		if (this.m_MotionCheckDataVR.Count > 0)
		{
			foreach (KeyValuePair<OvrMgr.OvrObject.Controller, MotionAction_Mgr.NeedCheckData> keyValuePair2 in this.m_MotionCheckDataVR)
			{
				UnityEngine.Object.Destroy(keyValuePair2.Value.MotionEffect.gameObject);
			}
		}
		else
		{
			UnityEngine.Object.Destroy(this.m_CheckHand);
		}
		if (!this.m_IsMotionCheckOnly)
		{
			if (isOK)
			{
				base.StartCoroutine(this.FaceChange(case_data, timer));
				base.StartCoroutine(this.EffectCheck(case_data, true));
			}
		}
		else
		{
			if (!GameMain.Instance.VRMode)
			{
				Cursor.lockState = cursole_state;
				Cursor.visible = cursole_visible;
			}
			this.m_IsMotionCheckOnly = false;
			MotionAction_Mgr.IsCaptureOK = isOK;
			if (isOK)
			{
				GameMain.Instance.SoundMgr.PlaySe("SE008.ogg", false);
				Utility.CreatePrefab(base.transform.parent.gameObject, "SceneDance/Rhythm_Action/Prefab/" + this.m_EffectName, true);
				yield return new WaitForSeconds(this.m_WaitTime);
			}
			NDebug.Assert(!string.IsNullOrEmpty(this.m_CheckEndLabel), "MotionAction_Mgr.cs:判定終了後に飛ぶラベルが設定されてません");
			if (!this.ForceEnd)
			{
				GameMain.Instance.ScriptMgr.adv_kag.JumpLabel(this.m_CheckEndLabel);
				GameMain.Instance.ScriptMgr.adv_kag.Exec();
			}
		}
		yield break;
		yield break;
	}

	private bool ActionJudge(MotionAction_Mgr.NeedCheckData checkdata, Vector3 last_pos, Vector3 pos, ActionCase.ActionType action)
	{
		bool result = false;
		checkdata.IsExistMovement = ((pos - last_pos).magnitude >= this.m_MovementRange);
		Vector3 vector = Vector3.zero;
		if (this.m_ControllerParent)
		{
			vector = this.m_ControllerParent.InverseTransformPoint(GameMain.Instance.MainCamera.GetRealHeadTransform().position);
		}
		switch (action)
		{
		case ActionCase.ActionType.wave:
			if (this.m_MotionCheckDataVR.Count > 0)
			{
				if (checkdata.FirstPos.x > this.m_WaveLength)
				{
					if (pos.x < 0f)
					{
						checkdata.FirstPos.x = pos.x;
					}
				}
				else
				{
					if (checkdata.IsExistMovement)
					{
						result = (pos.x >= this.m_WaveLength);
					}
					this.m_AllGuidUIInfo[action].GuidUI.fillAmount = 1f - (this.m_WaveLength - pos.x) / (this.m_WaveLength + Mathf.Abs(checkdata.FirstPos.x));
				}
			}
			else if (checkdata.FirstPos.x > (float)UICamera.ScreenWidth * (1f - this.m_MouseWaveRate))
			{
				if (pos.x < (float)UICamera.ScreenWidth * (1f - this.m_MouseWaveRate))
				{
					checkdata.FirstPos.x = pos.x;
				}
			}
			else
			{
				if (checkdata.IsExistMovement)
				{
					result = (pos.x - checkdata.FirstPos.x >= (float)UICamera.ScreenWidth * this.m_MouseWaveRate);
				}
				this.m_AllGuidUIInfo[action].GuidUI.fillAmount = (pos.x - checkdata.FirstPos.x) / ((float)UICamera.ScreenWidth * this.m_MouseWaveRate);
			}
			break;
		case ActionCase.ActionType.up:
			if (this.m_MotionCheckDataVR.Count > 0)
			{
				if (checkdata.FirstPos.y - vector.y >= this.m_UpLength)
				{
					if (pos.y - vector.y < -this.m_UpLength)
					{
						checkdata.FirstPos.y = pos.y;
					}
				}
				else
				{
					if (checkdata.IsExistMovement)
					{
						result = (pos.y - vector.y >= this.m_UpLength);
					}
					float num = vector.y + this.m_UpLength - checkdata.FirstPos.y;
					this.m_AllGuidUIInfo[action].GuidUI.fillAmount = 1f - (vector.y + this.m_UpLength - pos.y) / num;
				}
			}
			else if (checkdata.FirstPos.y > (float)UICamera.ScreenHeight * (1f - this.m_MouseUpRate))
			{
				if (pos.y < (float)UICamera.ScreenHeight * (1f - this.m_MouseUpRate))
				{
					checkdata.FirstPos.y = pos.y;
				}
			}
			else
			{
				if (checkdata.IsExistMovement)
				{
					result = (pos.y - checkdata.FirstPos.y >= (float)UICamera.ScreenHeight * this.m_MouseUpRate);
				}
				this.m_AllGuidUIInfo[action].GuidUI.fillAmount = (pos.y - checkdata.FirstPos.y) / ((float)UICamera.ScreenHeight * this.m_MouseUpRate);
			}
			break;
		case ActionCase.ActionType.swing:
		case ActionCase.ActionType.shake:
		{
			checkdata.NowVec = (pos - last_pos).normalized;
			if (!checkdata.IsExistMovement)
			{
				return false;
			}
			float num2 = Vector3.Dot(checkdata.NowVec, checkdata.LastVec);
			if (num2 < 0f)
			{
				float num3 = Mathf.Cos(this.m_JudgeLine * 0.0174532924f);
				bool flag;
				if (this.m_MotionCheckDataVR.Count > 0)
				{
					Vector3 lhs = checkdata.Controller.hand_trans.localRotation * Vector3.right;
					lhs.Normalize();
					if (action == ActionCase.ActionType.swing)
					{
						flag = (Mathf.Abs(Vector3.Dot(lhs, checkdata.NowVec)) > num3);
					}
					else
					{
						flag = (Mathf.Abs(Vector3.Dot(lhs, checkdata.NowVec)) <= num3);
					}
				}
				else if (action == ActionCase.ActionType.swing)
				{
					flag = (Mathf.Abs(NInput.GetAxis("Mouse X")) > Mathf.Abs(NInput.GetAxis("Mouse Y")));
				}
				else
				{
					flag = (Mathf.Abs(NInput.GetAxis("Mouse X")) <= Mathf.Abs(NInput.GetAxis("Mouse Y")));
				}
				if (flag)
				{
					if (action == ActionCase.ActionType.swing)
					{
						if (checkdata.ShakeCount[action] >= this.m_SwingCount)
						{
							result = true;
						}
					}
					else if (action == ActionCase.ActionType.shake && checkdata.ShakeCount[action] >= this.m_ShakeCount)
					{
						result = true;
					}
					Dictionary<ActionCase.ActionType, int> shakeCount;
					(shakeCount = checkdata.ShakeCount)[action] = shakeCount[action] + 1;
				}
			}
			if (action == ActionCase.ActionType.swing)
			{
				this.m_AllGuidUIInfo[action].GuidUI.fillAmount = 1f - (float)checkdata.ShakeCount[action] / (float)this.m_SwingCount;
			}
			else if (action == ActionCase.ActionType.shake)
			{
				this.m_AllGuidUIInfo[action].GuidUI.fillAmount = 1f - (float)checkdata.ShakeCount[action] / (float)this.m_ShakeCount;
			}
			break;
		}
		}
		return result;
	}

	private IEnumerator FaceChange(ActionCase case_data, float start_time)
	{
		float timer = start_time;
		List<Maid> target_maid = new List<Maid>();
		foreach (int nMaidNo in case_data.TargetMaidNo)
		{
			if (GameMain.Instance.CharacterMgr.GetMaid(nMaidNo))
			{
				target_maid.Add(GameMain.Instance.CharacterMgr.GetMaid(nMaidNo));
			}
		}
		bool isTouch;
		for (;;)
		{
			if (!RhythmAction_Mgr.Instance.IsPause)
			{
				timer += RhythmAction_Mgr.Instance.DanceDeltaTime;
			}
			bool face_allend = true;
			isTouch = TouchAction_Mgr.Instance.IsMaidTouch();
			foreach (ActionCase.ReactionParam reactionParam in case_data.Reaction)
			{
				if (isTouch)
				{
					break;
				}
				if (timer <= reactionParam.SetTime)
				{
					face_allend = false;
					if (reactionParam.IsFaceBlend)
					{
						foreach (Maid maid in target_maid)
						{
							maid.FaceBlend(reactionParam.Name);
							RhythmAction_Mgr.Instance.SetMaidFaceBlendStop(maid, true);
							TouchAction_Mgr.Instance.GetTouchParam(maid).MotionFaceBlendChange = true;
						}
					}
					else
					{
						foreach (Maid maid2 in target_maid)
						{
							maid2.FaceAnime(reactionParam.Name, 1f, 0);
							RhythmAction_Mgr.Instance.SetMaidFaceStop(maid2, true);
							TouchAction_Mgr.Instance.GetTouchParam(maid2).MotionFaceChange = true;
						}
					}
				}
				else if (reactionParam.IsFaceBlend)
				{
					foreach (Maid maid3 in target_maid)
					{
						RhythmAction_Mgr.Instance.SetMaidFaceBlendStop(maid3, false);
						TouchAction_Mgr.Instance.GetTouchParam(maid3).MotionFaceBlendChange = false;
					}
				}
				else
				{
					foreach (Maid maid4 in target_maid)
					{
						RhythmAction_Mgr.Instance.SetMaidFaceStop(maid4, false);
						TouchAction_Mgr.Instance.GetTouchParam(maid4).MotionFaceChange = false;
					}
				}
			}
			if (face_allend || isTouch)
			{
				break;
			}
			yield return null;
		}
		foreach (Maid maid5 in target_maid)
		{
			if (!isTouch)
			{
				RhythmAction_Mgr.Instance.SetMaidFaceBlendStop(maid5, false);
				RhythmAction_Mgr.Instance.SetMaidFaceStop(maid5, false);
			}
			TouchAction_Mgr.Instance.GetTouchParam(maid5).MotionFaceBlendChange = false;
			TouchAction_Mgr.Instance.GetTouchParam(maid5).MotionFaceChange = false;
		}
		yield break;
		yield break;
	}

	private IEnumerator EffectCheck(ActionCase case_data, bool is_specifytime = true)
	{
		float timer = 0f;
		GameObject effect = UnityEngine.Object.Instantiate<GameObject>(case_data.Effect);
		effect.transform.parent = RhythmAction_Mgr.Instance.transform;
		effect.transform.localPosition = Vector3.zero;
		List<ParticleSystem> effect_part = new List<ParticleSystem>();
		IEnumerator enumerator = effect.transform.GetEnumerator();
		try
		{
			while (enumerator.MoveNext())
			{
				object obj = enumerator.Current;
				Transform transform = (Transform)obj;
				if (transform.GetComponent<ParticleSystem>())
				{
					effect_part.Add(transform.GetComponent<ParticleSystem>());
					RhythmAction_Mgr.Instance.AddParticleSystem(effect_part.Last<ParticleSystem>());
				}
			}
		}
		finally
		{
			IDisposable disposable;
			if ((disposable = (enumerator as IDisposable)) != null)
			{
				disposable.Dispose();
			}
		}
		for (;;)
		{
			if (!RhythmAction_Mgr.Instance.IsPause)
			{
				if (is_specifytime)
				{
					timer += RhythmAction_Mgr.Instance.DanceDeltaTime;
				}
				bool flag;
				if (is_specifytime)
				{
					flag = (timer >= case_data.EffectTime);
				}
				else
				{
					flag = effect_part.All((ParticleSystem particle) => !particle.isPlaying);
				}
				bool flag2 = flag;
				if (flag2)
				{
					break;
				}
			}
			yield return null;
		}
		UnityEngine.Object.Destroy(effect);
		foreach (ParticleSystem particle2 in effect_part)
		{
			RhythmAction_Mgr.Instance.RemoveParticleSystem(particle2);
		}
		yield break;
		yield break;
	}

	public override void StartAction()
	{
		base.StartCoroutine(this.CheckActionCase());
	}

	public override void EndAction()
	{
		base.StopAllCoroutines();
	}

	public void ResponceInit(KagTagSupport tag_data)
	{
		if (tag_data.IsValid("label"))
		{
			this.m_CheckEndLabel = tag_data.GetTagProperty("label").AsString();
		}
		if (tag_data.IsValid("forcemouse"))
		{
			this.m_IsForceMouseCheck = tag_data.GetTagProperty("forcemouse").AsBool();
		}
		this.Initialize();
		ActionCase actionCase = new ActionCase();
		this.m_IsMotionCheckOnly = true;
		if (tag_data.IsValid("action"))
		{
			foreach (string value in tag_data.GetTagProperty("action").AsString().Split(new char[]
			{
				':'
			}))
			{
				actionCase.Action.Add((ActionCase.ActionType)Enum.Parse(typeof(ActionCase.ActionType), value));
			}
		}
		if (tag_data.IsValid("time"))
		{
			actionCase.EndTime = tag_data.GetTagProperty("time").AsReal();
		}
		base.StartCoroutine(this.MotionCheck(actionCase, 0f));
	}

	public static void ResponceStart(KagTagSupport tag_data)
	{
		GameObject gameObject = Utility.CreatePrefab(null, "SceneDance/Rhythm_Action/Prefab/MCMotionCapture", false);
		gameObject.GetComponentInChildren<MotionAction_Mgr>().ResponceInit(tag_data);
	}

	public static void CaptureFlagRecet()
	{
		MotionAction_Mgr.IsCaptureOK = false;
	}

	private List<ActionCase> m_ActionAllCase = new List<ActionCase>();

	[SerializeField]
	[Header("これ以上の動きがなかった場合は無視")]
	[Range(0f, 1f)]
	private float m_MovementRange = 0.1f;

	[SerializeField]
	[Header("コントローラーの補正値(高いほどswingやshakeを満たしやすくなる)")]
	[Range(0f, 15f)]
	private float m_ControllerAdjust = 4f;

	[SerializeField]
	[Header("この距離分手を横に動かすとアクション「wave」を満たす")]
	private float m_WaveLength = 10f;

	[SerializeField]
	[Header("この距離分手を上げるとアクション「up」を満たす")]
	private float m_UpLength = 10f;

	[SerializeField]
	[Header("この回数分手を横に振るとアクション「swing」を満たす")]
	private int m_SwingCount = 20;

	[SerializeField]
	[Header("この回数分手を縦に振るとアクション「shake」を満たす")]
	private int m_ShakeCount = 20;

	[SerializeField]
	[Header("縦振りか横振りかの判定基準")]
	[Range(0f, 90f)]
	private float m_JudgeLine = 30f;

	[SerializeField]
	[Header("アクションガイドUIの設置間隔")]
	private float m_SetGuidSpace = 384f;

	private Dictionary<OvrMgr.OvrObject.Controller, MotionAction_Mgr.NeedCheckData> m_MotionCheckDataVR = new Dictionary<OvrMgr.OvrObject.Controller, MotionAction_Mgr.NeedCheckData>();

	private MotionAction_Mgr.NeedCheckData m_MotionCheckDataMouse = new MotionAction_Mgr.NeedCheckData();

	private Transform m_ControllerParent;

	[SerializeField]
	[Header("各アクション毎のガイドUI")]
	private List<MotionAction_Mgr.GuidUIInfo> m_GuidUIList;

	private Dictionary<ActionCase.ActionType, MotionAction_Mgr.GuidUIInfo> m_AllGuidUIInfo = new Dictionary<ActionCase.ActionType, MotionAction_Mgr.GuidUIInfo>();

	[SerializeField]
	private string m_strHandName = "Sticklight";

	[SerializeField]
	[Header("マウスでモーション判定する時の手の相対位置")]
	private Vector3 m_HandRelatePos;

	[SerializeField]
	[Header("手の初期角度")]
	private Vector3 m_HandAngle;

	[SerializeField]
	[Header("手のサイズ")]
	private Vector3 m_HandSize = Vector3.one * 0.5f;

	private GameObject m_CheckHand;

	[SerializeField]
	[Header("手の横移動範囲(VR時)")]
	private float m_HandMoveWidth = 0.25f;

	[SerializeField]
	[Header("手の縦移動範囲(VR時)")]
	private float m_HandMoveHeight = 0.15f;

	[SerializeField]
	[Range(0f, 1f)]
	[Header("解像度のこの割合分マウスを横に動かすとアクション「wave」を満たす")]
	private float m_MouseWaveRate = 0.25f;

	[SerializeField]
	[Range(0f, 1f)]
	[Header("解像度のこの割合分マウスを上げるとアクション「up」を満たす")]
	private float m_MouseUpRate = 0.5f;

	[SerializeField]
	[Header("手の移動速度(VR時)")]
	private float m_HandMoveSpeed = 20f;

	[SerializeField]
	[Header("エフェクト位置の補正値")]
	[Range(0f, 1f)]
	private float m_EffectAdjust = 0.125f;

	[SerializeField]
	private Color m_HorizontalColor = Color.green;

	[SerializeField]
	private Color m_VerticalColor = Color.red;

	[SerializeField]
	private float m_WaitTime = 2.5f;

	private bool m_IsMotionCheckOnly;

	private string m_CheckEndLabel = string.Empty;

	[SerializeField]
	private bool m_IsForceMouseCheck;

	[SerializeField]
	private string m_EffectName = "love";

	[HideInInspector]
	public bool ForceEnd;

	private class NeedCheckData
	{
		public ParticleSystem MotionEffect { get; private set; }

		public void Init()
		{
			this.ShakeCount.Add(ActionCase.ActionType.shake, 0);
			this.ShakeCount.Add(ActionCase.ActionType.swing, 0);
			GameObject gameObject = Resources.Load<GameObject>("SceneDance/Rhythm_Action/Prefab/MotionEffect");
			gameObject = UnityEngine.Object.Instantiate<GameObject>(gameObject);
			this.MotionEffect = gameObject.GetComponent<ParticleSystem>();
			if (!GameMain.Instance.VRMode)
			{
				ParticleSystem.MainModule mainModule;
				this.MotionEffect.main.startSizeMultiplier = mainModule.startSizeMultiplier / 2f;
			}
		}

		public void EmmitAdjust(Color horizontal, Color vertical)
		{
			Vector3 nowVec = this.NowVec;
			if (this.IsExistMovement)
			{
				nowVec.z = 0f;
				nowVec.Normalize();
				nowVec.x = Mathf.Abs(nowVec.x);
				nowVec.y = Mathf.Abs(nowVec.y);
			}
			else
			{
				nowVec.x = (nowVec.y = 0f);
			}
			float num = nowVec.x / (nowVec.x + nowVec.y);
			this.MotionEffect.main.startColor = num * horizontal + (1f - num) * vertical;
		}

		public Vector3 LastVec = Vector3.zero;

		public Vector3 NowVec = Vector3.zero;

		public Vector3 LastPos = Vector3.zero;

		public Dictionary<ActionCase.ActionType, int> ShakeCount = new Dictionary<ActionCase.ActionType, int>();

		public Quaternion LastRot = Quaternion.identity;

		public Vector3 FirstPos = Vector3.zero;

		public Vector3 CurrentPos = Vector3.zero;

		public OvrMgr.OvrObject.Controller Controller;

		public bool IsExistMovement;
	}

	[Serializable]
	private class GuidUIInfo
	{
		public bool NeedGuid
		{
			get
			{
				return this.m_GuidActive;
			}
			set
			{
				if (this.m_GuidActive == value)
				{
					return;
				}
				this.m_GuidActive = value;
				this.GuidUI.gameObject.SetActive(value);
				int a = (!this.m_GuidActive) ? (MotionAction_Mgr.GuidUIInfo.CurrentActionCount - 1) : (MotionAction_Mgr.GuidUIInfo.CurrentActionCount + 1);
				MotionAction_Mgr.GuidUIInfo.CurrentActionCount = Mathf.Max(a, 0);
			}
		}

		public static int CurrentActionCount;

		public ActionCase.ActionType Type;

		public UIBasicSprite GuidUI;

		private bool m_GuidActive;
	}
}
