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

public class RoyalPalaceField : BackGroundBase
{
	public override int FieldId => 4;

	public RoyalPalaceField(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_plce_root").gameObject;
			_fieldParticles = _fieldModel.transform.Find("Particles04").gameObject;
			_fieldObjDictionary.Add(_fieldParticles.name, _fieldParticles);
			_fieldObjDictionary.Add("chandelier", _fieldModel.transform.Find("md_bf_plce_01_chandelier").gameObject);
			_fieldObjDictionary.Add("armor", _fieldModel.transform.Find("md_bf_plce_01_armor").gameObject);
			_fieldObjDictionary.Add("tapestry_a", _fieldModel.transform.Find("md_bf_plce_01_tapestry_a").gameObject);
			_fieldObjDictionary.Add("tapestry_b", _fieldModel.transform.Find("md_bf_plce_01_tapestry_b").gameObject);
			m_FieldAnimatorDictionary.Add("armor", _fieldObjDictionary["armor"].GetComponent<Animator>());
			m_FieldAnimatorDictionary.Add("chandelier", _fieldObjDictionary["chandelier"].GetComponent<Animator>());
			m_FieldAnimatorDictionary.Add("tapestry_a", _fieldObjDictionary["tapestry_a"].GetComponent<Animator>());
			m_FieldAnimatorDictionary.Add("tapestry_b", _fieldObjDictionary["tapestry_b"].GetComponent<Animator>());
			_fieldParticleSystemDictionary.Add("armor_threat", _fieldParticles.transform.Find("armor_threat").GetComponent<ParticleSystem>());
			_fieldParticleSystemDictionary.Add("armor_demo", _fieldParticles.transform.Find("armor_demo").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_4, pos);
	}

	public override void StartFieldTapEffect(int areaId, Vector3 pos)
	{
		base.StartFieldTapEffect(areaId, pos);
		switch (areaId)
		{
		case 1:
			GameMgr.GetIns().GetEffectMgr().Start(EffectMgr.EffectType.CMN_FIELD_TAP_4_1, pos);
			break;
		case 2:
			GameMgr.GetIns().GetEffectMgr().Start(EffectMgr.EffectType.CMN_FIELD_TAP_4_2, pos);
			break;
		}
	}

	protected override IEnumerator RunFieldOpening()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySeByStr($"se_field_{_str3DFieldNo}_appear_1", "se_field_" + _str3DFieldNo, 0f, 0L);
		m_FieldAnimatorDictionary["tapestry_a"].speed = 0.4f + Random.value * 0.2f;
		m_FieldAnimatorDictionary["tapestry_b"].speed = 0.4f + Random.value * 0.2f;
		m_RandomActionTime = 20f;
		_battleCamera.Camera.transform.localPosition = new Vector3(-460f, 85f, -100f);
		_battleCamera.Camera.transform.localRotation = Quaternion.Euler(new Vector3(-25f, -97f, 93f));
		iTween.MoveTo(_battleCamera.Camera.gameObject, iTween.Hash("position", new Vector3(880f, -545f, -50f), "time", 2f, "islocal", true, "easetype", iTween.EaseType.easeInOutQuad));
		iTween.RotateTo(_battleCamera.Camera.gameObject, iTween.Hash("rotation", new Vector3(-25f, -97f, 93f), "time", 2f, "islocal", true, "easetype", iTween.EaseType.easeInOutQuad));
		yield return new WaitForSeconds(0.5f);
		m_FieldAnimatorDictionary["armor"].SetTrigger("Threat");
		_fieldParticleSystemDictionary["armor_threat"].Play();
		yield return new WaitForSeconds(1.5f);
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_CAMERA_ZOOM_OUT);
		iTween.MoveTo(_battleCamera.Camera.gameObject, iTween.Hash("position", new Vector3(240f, -250f, -400f), "time", 1f, "islocal", true, "easetype", iTween.EaseType.easeInExpo));
		iTween.RotateTo(_battleCamera.Camera.gameObject, iTween.Hash("rotation", new Vector3(-5f, -5f, 40f), "time", 1f, "islocal", true, "easetype", iTween.EaseType.easeInExpo));
		iTween.MoveTo(_battleCamera.Camera.gameObject, iTween.Hash("position", _battleCamera.BattleCameraPos, "time", 1f, "delay", 1f, "islocal", true, "easetype", iTween.EaseType.easeOutExpo));
		iTween.RotateTo(_battleCamera.Camera.gameObject, iTween.Hash("rotation", _battleCamera.BattleCameraRot, "time", 1f, "delay", 1f, "islocal", true, "easetype", iTween.EaseType.easeOutExpo));
		yield return new WaitForSeconds(1f);
		_fieldObjDictionary["chandelier"].SetActive(value: false);
		yield return new WaitForSeconds(0.2f);
		_fieldObjDictionary["chandelier"].SetActive(value: true);
		yield return new WaitForSeconds(0f);
	}

	protected override IEnumerator RunFieldGimic(GameObject obj)
	{
		string tag = obj.tag;
		if (tag != null && tag == "FieldGimic1" && _gimicCntDictionary[obj.tag] == 0)
		{
			_gimicCntDictionary[obj.tag]++;
			int num = Random.Range(1, 3);
			GameMgr.GetIns().GetSoundMgr().PlaySeByStr($"se_field_{_str3DFieldNo}_gim_{num}", "se_field_" + _str3DFieldNo, 0f, 0L);
			switch (num)
			{
			case 1:
				m_FieldAnimatorDictionary["armor"].SetTrigger("Threat");
				_fieldParticleSystemDictionary["armor_threat"].Play();
				yield return new WaitForSeconds(1f);
				break;
			case 2:
				m_FieldAnimatorDictionary["armor"].SetTrigger("Demo");
				_fieldParticleSystemDictionary["armor_demo"].Play();
				yield return new WaitForSeconds(7.1f);
				break;
			}
			_gimicCntDictionary[obj.tag] = 0;
		}
		yield return new WaitForSeconds(0f);
	}

	protected override IEnumerator RunFieldShake()
	{
		m_FieldAnimatorDictionary["armor"].SetTrigger("Shake");
		m_FieldAnimatorDictionary["chandelier"].SetTrigger("Shake");
		m_FieldAnimatorDictionary["tapestry_a"].speed = 0.8f + Random.value * 0.4f;
		m_FieldAnimatorDictionary["tapestry_b"].speed = 0.8f + Random.value * 0.4f;
		m_FieldAnimatorDictionary["tapestry_a"].SetTrigger("Shake");
		m_FieldAnimatorDictionary["tapestry_b"].SetTrigger("Shake");
		yield return new WaitForSeconds(3f);
		m_FieldAnimatorDictionary["tapestry_a"].speed = 0.4f + Random.value * 0.2f;
		m_FieldAnimatorDictionary["tapestry_b"].speed = 0.4f + Random.value * 0.2f;
		yield return new WaitForSeconds(0f);
	}

	public override void UpdateFieldRandom()
	{
		if (IsFieldRandom)
		{
			m_RandomActionTime -= Time.deltaTime;
			if (m_RandomActionTime <= 0f)
			{
				m_FieldAnimatorDictionary["tapestry_a"].SetTrigger("LoopRandom");
				m_FieldAnimatorDictionary["tapestry_b"].SetTrigger("LoopRandom");
				m_RandomActionTime = Random.value * 20f + 20f;
			}
		}
	}
}
