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

namespace Wizard;

public class Field51 : BackGroundBase
{
	public override int FieldId => 51;

	public Field51(string bgmId = "NONE")
		: base(bgmId)
	{
	}

	protected override void BattleFieldBuild()
	{
		BattleCoroutine.GetInstance().StartCoroutine(BackGroundBase.ObjectChecker(0.5f, _str3DFieldPath, delegate
		{
			base.Field = GameObject.Find(_str3DFieldPath);
			base.Field.transform.parent = GameMgr.GetIns().m_GameManagerObj.transform;
			GimicAudioList = base.Field.GetComponent<AudioList>().GimicAudioList;
			_fieldModel = base.Field.transform.Find("md_bf_0051_root").gameObject;
			_fieldParticles = _fieldModel.transform.Find("Particles51").gameObject;
			_fieldParticleSystemDictionary.Add("light", _fieldModel.transform.Find("md_bf_0051_01_movebranchlight_r/position/root/joint1/joint2/joint3/light").GetComponent<ParticleSystem>());
			_fieldParticleSystemDictionary.Add("light_gimic", _fieldModel.transform.Find("md_bf_0051_01_movebranchlight_r/position/root/joint1/joint2/joint3/light_gimic").GetComponent<ParticleSystem>());
			_fieldParticleSystemDictionary.Add("light_shake", _fieldModel.transform.Find("md_bf_0051_01_movebranchlight_r/position/root/joint1/joint2/joint3/light_shake").GetComponent<ParticleSystem>());
			_fieldParticleSystemDictionary.Add("light_l", _fieldModel.transform.Find("md_bf_0051_01_movebranchlight_l/position/root/joint1/joint2/joint3/light_l").GetComponent<ParticleSystem>());
			_fieldParticleSystemDictionary.Add("light_shake_l", _fieldModel.transform.Find("md_bf_0051_01_movebranchlight_l/position/root/joint1/joint2/joint3/light_shake_l").GetComponent<ParticleSystem>());
			_fieldObjDictionary.Add("movebranch_a", _fieldModel.transform.Find("md_bf_0051_01_movebranch_a").gameObject);
			_fieldObjDictionary.Add("movebranch_b", _fieldModel.transform.Find("md_bf_0051_01_movebranch_b").gameObject);
			_fieldObjDictionary.Add("movebranch_c", _fieldModel.transform.Find("md_bf_0051_01_movebranch_c").gameObject);
			_fieldObjDictionary.Add("movebranch_d", _fieldModel.transform.Find("md_bf_0051_01_movebranch_d").gameObject);
			_fieldObjDictionary.Add("movebranch_e", _fieldModel.transform.Find("md_bf_0051_01_movebranch_e").gameObject);
			_fieldObjDictionary.Add("movebranch_f", _fieldModel.transform.Find("md_bf_0051_01_movebranch_f").gameObject);
			_fieldObjDictionary.Add("movebranchlight_l", _fieldModel.transform.Find("md_bf_0051_01_movebranchlight_l").gameObject);
			_fieldObjDictionary.Add("movebranchlight_r", _fieldModel.transform.Find("md_bf_0051_01_movebranchlight_r").gameObject);
			m_FieldAnimatorDictionary.Add("movebranch_a", _fieldObjDictionary["movebranch_a"].GetComponent<Animator>());
			m_FieldAnimatorDictionary.Add("movebranch_b", _fieldObjDictionary["movebranch_b"].GetComponent<Animator>());
			m_FieldAnimatorDictionary.Add("movebranch_c", _fieldObjDictionary["movebranch_c"].GetComponent<Animator>());
			m_FieldAnimatorDictionary.Add("movebranch_d", _fieldObjDictionary["movebranch_d"].GetComponent<Animator>());
			m_FieldAnimatorDictionary.Add("movebranch_e", _fieldObjDictionary["movebranch_e"].GetComponent<Animator>());
			m_FieldAnimatorDictionary.Add("movebranch_f", _fieldObjDictionary["movebranch_f"].GetComponent<Animator>());
			m_FieldAnimatorDictionary.Add("movebranchlight_l", _fieldObjDictionary["movebranchlight_l"].GetComponent<Animator>());
			m_FieldAnimatorDictionary.Add("movebranchlight_r", _fieldObjDictionary["movebranchlight_r"].GetComponent<Animator>());
			_fieldParticleSystemDictionary.Add("shake", _fieldParticles.transform.Find("shake").GetComponent<ParticleSystem>());
			List<string> list = new List<string>(_fieldObjDictionary.Keys);
			List<GameObject> list2 = new List<GameObject>();
			for (int i = 0; i < _fieldObjDictionary.Count; i++)
			{
				list2.Add(_fieldObjDictionary[list[i]]);
			}
			GameMgr.GetIns().GetEffectMgr().SetUIParticleShader(list2, delegate
			{
				base.SetShaderGlobalColorBG = base.Field.transform.Find("SetMaterialColorBGManager").GetComponent<SetShaderGlobalColorBG>();
				base.IsLoadDone = true;
			}, isBattle: true, isField: true);
		}));
	}

	public override void StartFieldSetEffect(Vector3 pos)
	{
		GameMgr.GetIns().GetEffectMgr().Start(EffectMgr.EffectType.CMN_FIELD_SET_51, pos);
	}

	public override void StartFieldTapEffect(int areaId, Vector3 pos)
	{
		base.StartFieldTapEffect(areaId, pos);
		GameMgr.GetIns().GetEffectMgr().Start(EffectMgr.EffectType.CMN_FIELD_TAP_51_1, pos);
	}

	protected override IEnumerator RunFieldOpening()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySeByStr($"se_field_{_str3DFieldNo}_appear_1", "se_field_" + _str3DFieldNo, 0f, 0L);
		_fieldParticleSystemDictionary["light"].Play();
		_fieldParticleSystemDictionary["light_l"].Play();
		_battleCamera.Camera.transform.localPosition = new Vector3(3322f, -1847f, 36f);
		_battleCamera.Camera.transform.localRotation = Quaternion.Euler(new Vector3(-84f, -90f, 90f));
		Vector3[] bezierQuad = MotionUtils.GetBezierQuad(new Vector3(3322f, -1847f, 36f), new Vector3(2800f, 40f, 36f), new Vector3(1036f, -27.7f, 0f), 10);
		iTween.MoveTo(_battleCamera.Camera.gameObject, iTween.Hash("path", bezierQuad, "movetopath", false, "time", 1.5f, "islocal", true, "easetype", iTween.EaseType.easeInSine));
		iTween.RotateTo(_battleCamera.Camera.gameObject, iTween.Hash("rotation", new Vector3(-8f, -90f, 90f), "time", 1.5f, "islocal", true, "easetype", iTween.EaseType.easeInSine));
		yield return new WaitForSeconds(1.5f);
		_battleCamera.Camera.transform.localPosition = new Vector3(1036f, -27.7f, 0f);
		_battleCamera.Camera.transform.localRotation = Quaternion.Euler(new Vector3(-8f, -90f, 90f));
		iTween.MoveTo(_battleCamera.Camera.gameObject, iTween.Hash("position", new Vector3(-323f, -19f, -18f), "time", 0.5f, "islocal", true, "easetype", iTween.EaseType.easeOutQuad));
		iTween.RotateTo(_battleCamera.Camera.gameObject, iTween.Hash("rotation", new Vector3(-1f, -90f, 90f), "time", 0.5f, "islocal", true, "easetype", iTween.EaseType.easeOutQuad));
		yield return new WaitForSeconds(0.5f);
		iTween.MoveTo(_battleCamera.Camera.gameObject, iTween.Hash("position", _battleCamera.BattleCameraPos, "time", 2f, "islocal", true, "easetype", iTween.EaseType.easeInOutExpo));
		iTween.RotateTo(_battleCamera.Camera.gameObject, iTween.Hash("rotation", _battleCamera.BattleCameraRot, "time", 2f, "islocal", true, "easetype", iTween.EaseType.easeInOutExpo));
		yield return new WaitForSeconds(0f);
	}

	protected override IEnumerator RunFieldGimic(GameObject obj)
	{
		string tag = obj.tag;
		if (tag != null && tag == "FieldGimic1" && _gimicCntDictionary[obj.tag] == 0)
		{
			GameMgr.GetIns().GetSoundMgr().PlaySeByStr($"se_field_{_str3DFieldNo}_gim_1", "se_field_" + _str3DFieldNo, 0f, 0L);
			_gimicCntDictionary[obj.tag]++;
			m_FieldAnimatorDictionary["movebranchlight_r"].SetTrigger("tap");
			_fieldParticleSystemDictionary["light"].Stop();
			_fieldParticleSystemDictionary["light_gimic"].Play();
			yield return new WaitForSeconds(2f);
			_fieldParticleSystemDictionary["light"].Play();
			_gimicCntDictionary[obj.tag] = 0;
		}
		yield return new WaitForSeconds(0f);
	}

	protected override IEnumerator RunFieldShake()
	{
		m_FieldAnimatorDictionary["movebranch_a"].SetTrigger("shake");
		m_FieldAnimatorDictionary["movebranch_b"].SetTrigger("shake");
		m_FieldAnimatorDictionary["movebranch_c"].SetTrigger("shake");
		m_FieldAnimatorDictionary["movebranch_d"].SetTrigger("shake");
		m_FieldAnimatorDictionary["movebranch_e"].SetTrigger("shake");
		m_FieldAnimatorDictionary["movebranch_f"].SetTrigger("shake");
		m_FieldAnimatorDictionary["movebranchlight_l"].SetTrigger("shake");
		m_FieldAnimatorDictionary["movebranchlight_r"].SetTrigger("shake");
		_fieldParticleSystemDictionary["shake"].Play();
		_fieldParticleSystemDictionary["light_shake"].Play();
		_fieldParticleSystemDictionary["light_shake_l"].Play();
		yield return new WaitForSeconds(3f);
	}
}
