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

namespace Wizard;

public class Field1008 : BackGroundBase
{
	private readonly string[] MONITOR_OBJECT_PATH_LIST = new string[4] { "md_bf_1008_01_main/monitor/monitor000__combine_freeze_/monitor000_monitor", "md_bf_1008_01_main/monitor/monitor000__combine_freeze_/monitor000_monitor_L", "md_bf_1008_01_main/monitor/monitor000__combine_freeze_/monitor000_monitor_R", "md_bf_1008_01_monitor_2/monitor002" };

	private const string MONITOR_TEXTURE_NAME = "tx_bf_1008_01_monitor_d";

	public override int FieldId => 1008;

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

	protected override List<string> CollectAdditionalAssets()
	{
		return new List<string> { Toolbox.ResourcesManager.GetAssetTypePath("tx_bf_1008_01_monitor_d", ResourcesManager.AssetLoadPathType.Uilang3DField) };
	}

	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_1008_root").gameObject;
			_fieldParticles = _fieldModel.transform.Find("Particles1008").gameObject;
			_fieldParticleSystemDictionary.Add("opening", _fieldParticles.transform.Find("opening").GetComponent<ParticleSystem>());
			_fieldParticleSystemDictionary.Add("base", _fieldParticles.transform.Find("base").GetComponent<ParticleSystem>());
			_fieldParticleSystemDictionary.Add("gimic_1", _fieldParticles.transform.Find("gimic_1").GetComponent<ParticleSystem>());
			_fieldParticleSystemDictionary.Add("shake", _fieldParticles.transform.Find("shake").GetComponent<ParticleSystem>());
			_fieldObjDictionary.Add("monitor_1", _fieldModel.transform.Find("md_bf_1008_01_monitor_1").gameObject);
			_fieldObjDictionary.Add("monitor_2", _fieldModel.transform.Find("md_bf_1008_01_monitor_2").gameObject);
			_fieldObjDictionary.Add("monitor_3", _fieldModel.transform.Find("md_bf_1008_01_monitor_3").gameObject);
			_fieldObjDictionary.Add("monitor_4", _fieldModel.transform.Find("md_bf_1008_01_monitor_4").gameObject);
			_fieldObjDictionary.Add("monitor_5", _fieldModel.transform.Find("md_bf_1008_01_monitor_5").gameObject);
			string assetTypePath = Toolbox.ResourcesManager.GetAssetTypePath("tx_bf_1008_01_monitor_d", ResourcesManager.AssetLoadPathType.Uilang3DField, isfetch: true);
			Texture texture = Toolbox.ResourcesManager.LoadObject(assetTypePath) as Texture;
			if (texture != null)
			{
				for (int i = 0; i < MONITOR_OBJECT_PATH_LIST.Length; i++)
				{
					MeshRenderer component = _fieldModel.transform.Find(MONITOR_OBJECT_PATH_LIST[i]).GetComponent<MeshRenderer>();
					if (component != null)
					{
						component.material.SetTexture("_MainTex", texture);
					}
				}
			}
			List<string> list = new List<string>(_fieldObjDictionary.Keys);
			List<GameObject> list2 = new List<GameObject>();
			for (int j = 0; j < _fieldObjDictionary.Count; j++)
			{
				list2.Add(_fieldObjDictionary[list[j]]);
			}
			GameMgr.GetIns().GetEffectMgr().SetUIParticleShader(list2, delegate
			{
				base.SetShaderGlobalColorBG = base.Field.transform.Find("SetMaterialColorBGManager").GetComponent<SetShaderGlobalColorBG>();
				base.IsLoadDone = true;
			}, isBattle: true, isField: true);
			_fieldParticleSystemDictionary["base"].Play();
			_fieldObjDictionary["monitor_1"].gameObject.SetActive(value: false);
			_fieldObjDictionary["monitor_2"].gameObject.SetActive(value: true);
			_fieldObjDictionary["monitor_3"].gameObject.SetActive(value: false);
			_fieldObjDictionary["monitor_4"].gameObject.SetActive(value: false);
			_fieldObjDictionary["monitor_5"].gameObject.SetActive(value: false);
		}));
	}

	public override void StartFieldSetEffect(Vector3 pos)
	{
		GameMgr.GetIns().GetEffectMgr().Start(EffectMgr.EffectType.CMN_FIELD_SET_1008, 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_1008_1, pos);
		}
	}

	protected override IEnumerator RunFieldOpening()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySeByStr($"se_field_{_str3DFieldNo}_appear_1", "se_field_" + _str3DFieldNo, 0f, 0L);
		_fieldParticleSystemDictionary["opening"].Play();
		_fieldParticleSystemDictionary["base"].Play();
		_fieldObjDictionary["monitor_1"].gameObject.SetActive(value: false);
		_fieldObjDictionary["monitor_2"].gameObject.SetActive(value: true);
		_fieldObjDictionary["monitor_3"].gameObject.SetActive(value: false);
		_fieldObjDictionary["monitor_4"].gameObject.SetActive(value: false);
		_fieldObjDictionary["monitor_5"].gameObject.SetActive(value: false);
		_battleCamera.Camera.transform.localPosition = new Vector3(3564f, -1182f, -224f);
		_battleCamera.Camera.transform.localRotation = Quaternion.Euler(new Vector3(-18f, -88f, 94.4f));
		iTween.MoveTo(_battleCamera.Camera.gameObject, iTween.Hash("position", new Vector3(197f, -103f, -224f), "time", 2f, "islocal", true, "easetype", iTween.EaseType.easeInOutQuad));
		iTween.RotateTo(_battleCamera.Camera.gameObject, iTween.Hash("rotation", new Vector3(-18f, -88f, 94.4f), "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));
		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(0, 2);
			GameMgr.GetIns().GetSoundMgr().PlaySeByStr("se_field_1008_gim_1", "se_field_" + _str3DFieldNo, 0f, 0L);
			switch (num)
			{
			case 0:
				_fieldObjDictionary["monitor_2"].gameObject.SetActive(value: false);
				_fieldObjDictionary["monitor_5"].gameObject.SetActive(value: true);
				_fieldParticleSystemDictionary["base"].Clear();
				_fieldParticleSystemDictionary["base"].Stop();
				_fieldParticleSystemDictionary["gimic_1"].Play();
				yield return new WaitForSeconds(0.3f);
				_fieldObjDictionary["monitor_5"].gameObject.SetActive(value: false);
				_fieldObjDictionary["monitor_1"].gameObject.SetActive(value: true);
				yield return new WaitForSeconds(2f);
				_fieldObjDictionary["monitor_1"].gameObject.SetActive(value: false);
				_fieldObjDictionary["monitor_5"].gameObject.SetActive(value: true);
				yield return new WaitForSeconds(0.3f);
				_fieldObjDictionary["monitor_5"].gameObject.SetActive(value: false);
				_fieldObjDictionary["monitor_2"].gameObject.SetActive(value: true);
				_fieldParticleSystemDictionary["base"].Play();
				_gimicCntDictionary[obj.tag]--;
				break;
			case 1:
				_fieldObjDictionary["monitor_2"].gameObject.SetActive(value: false);
				_fieldObjDictionary["monitor_5"].gameObject.SetActive(value: true);
				_fieldParticleSystemDictionary["base"].Clear();
				_fieldParticleSystemDictionary["base"].Stop();
				_fieldParticleSystemDictionary["gimic_1"].Play();
				yield return new WaitForSeconds(0.3f);
				_fieldObjDictionary["monitor_5"].gameObject.SetActive(value: false);
				_fieldObjDictionary["monitor_3"].gameObject.SetActive(value: true);
				yield return new WaitForSeconds(2f);
				_fieldObjDictionary["monitor_3"].gameObject.SetActive(value: false);
				_fieldObjDictionary["monitor_5"].gameObject.SetActive(value: true);
				yield return new WaitForSeconds(0.3f);
				_fieldObjDictionary["monitor_5"].gameObject.SetActive(value: false);
				_fieldObjDictionary["monitor_2"].gameObject.SetActive(value: true);
				_fieldParticleSystemDictionary["base"].Play();
				_gimicCntDictionary[obj.tag]--;
				break;
			}
			_gimicCntDictionary[obj.tag] = 0;
		}
		yield return null;
	}

	protected override IEnumerator RunFieldShake()
	{
		_fieldParticleSystemDictionary["base"].Clear();
		_fieldParticleSystemDictionary["base"].Stop();
		_fieldParticleSystemDictionary["shake"].Play();
		yield return new WaitForSeconds(3f);
		_fieldParticleSystemDictionary["base"].Play();
		yield return null;
	}
}
