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

public class StageField : BackGroundBase
{
	private static Dictionary<int, Color32> specialSkinIdAndColor = new Dictionary<int, Color32>
	{
		{
			2001,
			new Color32(125, 229, 72, byte.MaxValue)
		},
		{
			2002,
			new Color32(248, 116, 171, byte.MaxValue)
		},
		{
			2003,
			new Color32(96, 110, 178, byte.MaxValue)
		},
		{
			2004,
			new Color32(238, 185, 39, byte.MaxValue)
		},
		{
			2005,
			new Color32(171, 202, 233, byte.MaxValue)
		},
		{
			2006,
			new Color32(218, 25, 132, byte.MaxValue)
		},
		{
			2007,
			new Color32(239, 75, 129, byte.MaxValue)
		},
		{
			2008,
			new Color32(byte.MaxValue, 209, 0, byte.MaxValue)
		},
		{
			2018,
			new Color32(64, 234, byte.MaxValue, byte.MaxValue)
		},
		{
			3101,
			new Color32(156, 219, 217, byte.MaxValue)
		},
		{
			3102,
			new Color32(246, 117, 153, byte.MaxValue)
		},
		{
			3103,
			new Color32(225, 6, 0, byte.MaxValue)
		},
		{
			3104,
			new Color32(byte.MaxValue, 184, 28, byte.MaxValue)
		},
		{
			3105,
			new Color32(200, 0, 161, byte.MaxValue)
		},
		{
			3106,
			new Color32(166, 10, 61, byte.MaxValue)
		},
		{
			3107,
			new Color32(229, 155, 220, byte.MaxValue)
		},
		{
			3108,
			new Color32(126, 147, 167, byte.MaxValue)
		},
		{
			3111,
			new Color32(0, 156, 222, byte.MaxValue)
		}
	};

	public override int FieldId => 1004;

	public override int FieldEffectId => 1004;

	public StageField(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_1004_root").gameObject;
			_fieldObjDictionary.Add("clock", _fieldModel.transform.Find("md_bf_1004_01_clock").gameObject);
			_fieldObjDictionary.Add("screen_01", _fieldModel.transform.Find("md_bf_1004_01_screen_01").gameObject);
			_fieldObjDictionary.Add("screen_02", _fieldModel.transform.Find("md_bf_1004_01_screen_02").gameObject);
			_fieldObjDictionary.Add("screen_03", _fieldModel.transform.Find("md_bf_1004_01_screen_03").gameObject);
			_fieldObjDictionary.Add("screen_04", _fieldModel.transform.Find("md_bf_1004_01_screen_04").gameObject);
			_fieldObjDictionary.Add("symbol", _fieldModel.transform.Find("md_bf_1004_01_symbol").gameObject);
			m_FieldAnimatorDictionary.Add("clock", _fieldObjDictionary["clock"].GetComponent<Animator>());
			m_FieldAnimatorDictionary.Add("symbol", _fieldObjDictionary["symbol"].GetComponent<Animator>());
			_fieldParticles = _fieldModel.transform.Find("Particles1004").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("gimic_2", _fieldParticles.transform.Find("gimic_2").GetComponent<ParticleSystem>());
			_fieldParticleSystemDictionary.Add("gimic_3", _fieldParticles.transform.Find("gimic_3").GetComponent<ParticleSystem>());
			_fieldParticleSystemDictionary.Add("shake", _fieldParticles.transform.Find("shake").GetComponent<ParticleSystem>());
			Color color = Global.EFFECT_COLOR_ELF;
			if (specialSkinIdAndColor.ContainsKey(GameMgr.GetIns().GetDataMgr().GetPlayerSkinId()))
			{
				color = specialSkinIdAndColor[GameMgr.GetIns().GetDataMgr().GetPlayerSkinId()];
			}
			else
			{
				switch (GameMgr.GetIns().GetDataMgr().GetPlayerClassId())
				{
				case 1:
					color = Global.EFFECT_COLOR_ELF;
					break;
				case 2:
					color = Global.EFFECT_COLOR_ROYAL;
					break;
				case 3:
					color = Global.EFFECT_COLOR_WITCH_2;
					break;
				case 4:
					color = Global.EFFECT_COLOR_DRAGON;
					break;
				case 5:
					color = Global.EFFECT_COLOR_NECROMANCER;
					break;
				case 6:
					color = Global.EFFECT_COLOR_VANPIRE;
					break;
				case 7:
					color = Global.EFFECT_COLOR_BISHOP;
					break;
				case 8:
					color = Global.EFFECT_COLOR_NEMESIS;
					break;
				}
			}
			for (int i = 0; i < _fieldParticleSystemDictionary["base"].gameObject.transform.childCount; i++)
			{
				_fieldParticleSystemDictionary["base"].gameObject.transform.GetChild(i).GetComponent<Renderer>().material.color = color;
			}
			_fieldParticleSystemDictionary["base"].Play();
			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>();
				_fieldObjDictionary["screen_01"].gameObject.SetActive(value: true);
				_fieldObjDictionary["screen_02"].gameObject.SetActive(value: false);
				_fieldObjDictionary["screen_03"].gameObject.SetActive(value: false);
				_fieldObjDictionary["screen_04"].gameObject.SetActive(value: false);
				base.IsLoadDone = true;
			}, isBattle: true, isField: true);
		}));
	}

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

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

	protected override IEnumerator RunFieldOpening()
	{
		_fieldObjDictionary["screen_01"].gameObject.SetActive(value: true);
		_fieldObjDictionary["screen_02"].gameObject.SetActive(value: false);
		_fieldObjDictionary["screen_03"].gameObject.SetActive(value: false);
		_fieldObjDictionary["screen_04"].gameObject.SetActive(value: false);
		GameMgr.GetIns().GetSoundMgr().PlaySeByStr($"se_field_{_str3DFieldNo}_appear_1", "se_field_" + _str3DFieldNo, 0f, 0L);
		_fieldParticleSystemDictionary["opening"].Play();
		m_FieldAnimatorDictionary["clock"].SetTrigger("opening");
		_battleCamera.Camera.transform.localPosition = new Vector3(-403f, -21f, -570f);
		_battleCamera.Camera.transform.localRotation = Quaternion.Euler(new Vector3(-18f, -90f, 95f));
		Vector3[] bezierQuad = MotionUtils.GetBezierQuad(new Vector3(-403f, -21f, -570f), new Vector3(245f, -195f, -175f), new Vector3(758f, -334f, -101f), 10);
		iTween.MoveTo(_battleCamera.Camera.gameObject, iTween.Hash("path", bezierQuad, "movetopath", false, "time", 1.8f, "delay", 0.2f, "islocal", true, "easetype", iTween.EaseType.easeInOutQuart));
		iTween.RotateTo(_battleCamera.Camera.gameObject, iTween.Hash("rotation", new Vector3(-18f, -90f, 95.5f), "time", 1.8f, "delay", 0.2f, "islocal", true, "easetype", iTween.EaseType.easeInOutQuart));
		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));
		_fieldParticleSystemDictionary["opening"].Clear();
		_fieldParticleSystemDictionary["opening"].Stop();
		_fieldObjDictionary["screen_01"].gameObject.SetActive(value: true);
		_fieldObjDictionary["screen_02"].gameObject.SetActive(value: false);
		_fieldObjDictionary["screen_03"].gameObject.SetActive(value: false);
		_fieldObjDictionary["screen_04"].gameObject.SetActive(value: false);
		yield return new WaitForSeconds(0f);
	}

	protected override IEnumerator RunFieldShake()
	{
		m_FieldAnimatorDictionary["symbol"].SetTrigger("tap");
		_fieldParticleSystemDictionary["base"].Clear();
		_fieldParticleSystemDictionary["base"].Stop();
		_fieldParticleSystemDictionary["shake"].Play();
		yield return new WaitForSeconds(3f);
		_fieldParticleSystemDictionary["base"].Play();
		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, 3);
			GameMgr.GetIns().GetSoundMgr().PlaySeByStr("se_field_1004_gim_1", "se_field_" + _str3DFieldNo, 0f, 0L);
			switch (num)
			{
			case 0:
				m_FieldAnimatorDictionary["symbol"].SetTrigger("tap");
				_fieldObjDictionary["screen_01"].gameObject.SetActive(value: false);
				_fieldObjDictionary["screen_04"].gameObject.SetActive(value: true);
				_fieldParticleSystemDictionary["base"].Clear();
				_fieldParticleSystemDictionary["base"].Stop();
				_fieldParticleSystemDictionary["gimic_1"].Play();
				yield return new WaitForSeconds(3f);
				_fieldObjDictionary["screen_04"].gameObject.SetActive(value: false);
				_fieldObjDictionary["screen_01"].gameObject.SetActive(value: true);
				_fieldParticleSystemDictionary["base"].Play();
				yield return new WaitForSeconds(0f);
				_gimicCntDictionary[obj.tag]--;
				break;
			case 1:
				m_FieldAnimatorDictionary["symbol"].SetTrigger("tap");
				_fieldObjDictionary["screen_01"].gameObject.SetActive(value: false);
				_fieldObjDictionary["screen_03"].gameObject.SetActive(value: true);
				_fieldParticleSystemDictionary["base"].Clear();
				_fieldParticleSystemDictionary["base"].Stop();
				_fieldParticleSystemDictionary["gimic_2"].Play();
				yield return new WaitForSeconds(3f);
				_fieldObjDictionary["screen_03"].gameObject.SetActive(value: false);
				_fieldObjDictionary["screen_01"].gameObject.SetActive(value: true);
				_fieldParticleSystemDictionary["base"].Play();
				yield return new WaitForSeconds(0f);
				_gimicCntDictionary[obj.tag]--;
				break;
			case 2:
				m_FieldAnimatorDictionary["symbol"].SetTrigger("tap");
				_fieldObjDictionary["screen_01"].gameObject.SetActive(value: false);
				_fieldObjDictionary["screen_02"].gameObject.SetActive(value: true);
				_fieldParticleSystemDictionary["base"].Clear();
				_fieldParticleSystemDictionary["base"].Stop();
				_fieldParticleSystemDictionary["gimic_3"].Play();
				yield return new WaitForSeconds(3f);
				_fieldObjDictionary["screen_02"].gameObject.SetActive(value: false);
				_fieldObjDictionary["screen_01"].gameObject.SetActive(value: true);
				_fieldParticleSystemDictionary["base"].Play();
				yield return new WaitForSeconds(0f);
				_gimicCntDictionary[obj.tag]--;
				break;
			}
		}
		yield return null;
	}
}
