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

namespace Wizard;

public class Field1011 : BackGroundBase
{
	public override int FieldId => 1011;

	public Field1011(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_1011_01_root").gameObject;
			_fieldParticles = _fieldModel.transform.Find("Particles1011").gameObject;
			_fieldParticleSystemDictionary.Add("gimic_1", _fieldParticles.transform.Find("gimic_1").GetComponent<ParticleSystem>());
			_fieldParticleSystemDictionary.Add("shake", _fieldParticles.transform.Find("shake").GetComponent<ParticleSystem>());
			_fieldParticleSystemDictionary.Add("opening", _fieldParticles.transform.Find("opening").GetComponent<ParticleSystem>());
			_fieldObjDictionary.Add("lotuscenter", _fieldModel.transform.Find("md_bf_1011_01_lotuscenter").gameObject);
			m_FieldAnimatorDictionary.Add("lotuscenter", _fieldObjDictionary["lotuscenter"].GetComponent<Animator>());
			_fieldObjDictionary.Add("lotus_1", _fieldModel.transform.Find("md_bf_1011_01_lotuscenter/root/pibot/md_bf_1011_01_lotus_1").gameObject);
			m_FieldAnimatorDictionary.Add("lotus_1", _fieldObjDictionary["lotus_1"].GetComponent<Animator>());
			_fieldObjDictionary.Add("lotus_2", _fieldModel.transform.Find("md_bf_1011_01_lotuscenter/root/pibot/md_bf_1011_01_lotus_2").gameObject);
			m_FieldAnimatorDictionary.Add("lotus_2", _fieldObjDictionary["lotus_2"].GetComponent<Animator>());
			_fieldObjDictionary.Add("flower", _fieldModel.transform.Find("md_bf_1011_01_flower").gameObject);
			m_FieldAnimatorDictionary.Add("flower", _fieldObjDictionary["flower"].GetComponent<Animator>());
			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_1011, pos);
	}

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

	protected override IEnumerator RunFieldOpening()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySeByStr($"se_field_{_str3DFieldNo}_appear_1", "se_field_" + _str3DFieldNo, 0f, 0L);
		_fieldParticleSystemDictionary["opening"].Play();
		_battleCamera.Camera.transform.localPosition = new Vector3(2078.8f, -637f, 5.5f);
		_battleCamera.Camera.transform.localRotation = Quaternion.Euler(new Vector3(-18.9f, -87.8f, 88.9f));
		iTween.MoveTo(_battleCamera.Camera.gameObject, iTween.Hash("position", new Vector3(55.6f, 28.2f, -121.5f), "time", 2f, "islocal", true, "easetype", iTween.EaseType.easeInOutQuad));
		iTween.RotateTo(_battleCamera.Camera.gameObject, iTween.Hash("rotation", new Vector3(-17.2f, -106.5f, 94.9f), "time", 2f, "islocal", true, "easetype", iTween.EaseType.easeInOutQuad));
		yield return new WaitForSeconds(2f);
		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));
	}

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

	protected override IEnumerator RunFieldShake()
	{
		_fieldParticleSystemDictionary["shake"].Play();
		m_FieldAnimatorDictionary["lotus_1"].SetTrigger("shake");
		m_FieldAnimatorDictionary["lotus_2"].SetTrigger("shake");
		m_FieldAnimatorDictionary["flower"].SetTrigger("shake");
		yield return new WaitForSeconds(0f);
	}
}
