void readLevelWave() { MapLevelInfo = new Dictionary <int, MapGameData>(); XmlDocument xmlDoc = new XmlDocument(); TextAsset path = Resources.Load <TextAsset>(GameConfig.DatabasePathPlay); xmlDoc.LoadXml(path.text); XmlNodeList listMap = xmlDoc.GetElementsByTagName("Map"); foreach (XmlNode infoMap in listMap) { MapGameData map = new MapGameData(); map.EnemyTotal = 0; map.Name = infoMap.SelectSingleNode("Name").InnerText.ToString(); map.Heart = int.Parse(infoMap.SelectSingleNode("Heart").InnerText.ToString()); map.Money = int.Parse(infoMap.SelectSingleNode("Money").InnerText.ToString()); map.StarTotal = int.Parse(infoMap.SelectSingleNode("StarTotal").InnerText.ToString()); map.TowerUsed = infoMap.SelectSingleNode("TowerUsed").InnerText.ToString(); XmlNode nodeWaves = infoMap.SelectSingleNode("Waves"); XmlNodeList listWave = nodeWaves.SelectNodes("Wave"); map.WaveLength = listWave.Count; foreach (XmlNode waveInfo in listWave) { SWave wave = new SWave(0); wave.WaveID = int.Parse(waveInfo.Attributes["WaveID"].InnerText.ToString()); wave.TimeWave = float.Parse(waveInfo.SelectSingleNode("TimeWave").InnerText.ToString()); wave.TimeEnemy = float.Parse(waveInfo.SelectSingleNode("TimeEnemy").InnerText.ToString()); wave.hasBoss = bool.Parse(waveInfo.Attributes["hasBoss"].InnerText.ToString()); XmlNodeList listEnemy = waveInfo.SelectNodes("Enemy"); foreach (XmlNode enemyInfo in listEnemy) { string[] arr = enemyInfo.InnerText.ToString().Split('-'); SEnemyWave enemy = new SEnemyWave(); enemy.ID = arr[0].ToString(); enemy.Quantity = int.Parse(arr[1].ToString()); enemy.TimeSpawn = float.Parse(arr[2].ToString()); wave.Enemies.Add(enemy); wave.TotalEnemy += enemy.Quantity; map.EnemyTotal += enemy.Quantity; } // add wave into map map.Waves.Add(wave); } // add map into array map MapLevelInfo.Add(int.Parse(infoMap.Attributes["MapID"].InnerText.ToString()), map); } }
float countTimeWave(SWave wave) { float count = wave.TimeEnemy * wave.Enemies.Count; foreach (SEnemyWave infoEnemy in wave.Enemies) { count += infoEnemy.Quantity * infoEnemy.TimeSpawn; } return(count); }
void readLevelWave() { MapLevelInfo = new Dictionary<int, MapGameData>(); XmlDocument xmlDoc = new XmlDocument(); TextAsset path = Resources.Load<TextAsset>(GameConfig.DatabasePathPlay); xmlDoc.LoadXml(path.text); XmlNodeList listMap = xmlDoc.GetElementsByTagName("Map"); foreach (XmlNode infoMap in listMap) { MapGameData map = new MapGameData(); map.EnemyTotal = 0; map.Name = infoMap.SelectSingleNode("Name").InnerText.ToString(); map.Heart = int.Parse(infoMap.SelectSingleNode("Heart").InnerText.ToString()); map.Money = int.Parse(infoMap.SelectSingleNode("Money").InnerText.ToString()); map.StarTotal = int.Parse(infoMap.SelectSingleNode("StarTotal").InnerText.ToString()); map.TowerUsed = infoMap.SelectSingleNode("TowerUsed").InnerText.ToString(); XmlNode nodeWaves = infoMap.SelectSingleNode("Waves"); XmlNodeList listWave = nodeWaves.SelectNodes("Wave"); map.WaveLength = listWave.Count; foreach (XmlNode waveInfo in listWave) { SWave wave = new SWave(0); wave.WaveID = int.Parse(waveInfo.Attributes["WaveID"].InnerText.ToString()); wave.TimeWave = float.Parse(waveInfo.SelectSingleNode("TimeWave").InnerText.ToString()); wave.TimeEnemy = float.Parse(waveInfo.SelectSingleNode("TimeEnemy").InnerText.ToString()); wave.hasBoss = bool.Parse(waveInfo.Attributes["hasBoss"].InnerText.ToString()); XmlNodeList listEnemy = waveInfo.SelectNodes("Enemy"); foreach (XmlNode enemyInfo in listEnemy) { string[] arr = enemyInfo.InnerText.ToString().Split('-'); SEnemyWave enemy = new SEnemyWave(); enemy.ID = arr[0].ToString(); enemy.Quantity = int.Parse(arr[1].ToString()); enemy.TimeSpawn = float.Parse(arr[2].ToString()); wave.Enemies.Add(enemy); wave.TotalEnemy += enemy.Quantity; map.EnemyTotal += enemy.Quantity; } // add wave into map map.Waves.Add(wave); } // add map into array map MapLevelInfo.Add(int.Parse(infoMap.Attributes["MapID"].InnerText.ToString()), map); } }
IEnumerator initEnemy() { int wave_lenght = infoMap.Waves.Count; for (int k = 0; k < wave_lenght; k++) { WaveCurrent++; SWave wave = (SWave)infoMap.Waves[k]; enemy_of_wave.Add(wave.WaveID, wave.TotalEnemy); // time show of wave if (wave.TimeWave > 0) { yield return(new WaitForSeconds(wave.TimeWave)); } PlayInfo.Instance.Wave++; checkItemBuffAvailable(); countEnemy = 0; if (k + 1 < infoMap.Waves.Count) { StartCoroutine(nextWaveCooldown(countTimeWave(wave), ((SWave)infoMap.Waves[k + 1]).hasBoss)); } GameObject model = Resources.Load <GameObject>("Prefab/Enemy/Enemy"); EnemyController enemyController = model.GetComponent <EnemyController>(); // show enemy foreach (SEnemyWave infoEnemy in wave.Enemies) { //Set attribute EnemyData tempData = ReadDatabase.Instance.EnemyInfo.ContainsKey(infoEnemy.ID)? ReadDatabase.Instance.EnemyInfo[infoEnemy.ID] : null; if (tempData == null) { break; } GameSupportor.transferEnemyData(enemyController, tempData); int routine = Random.Range(0, enemyRoutine.Length); if (SceneState.Instance.State != ESceneState.BLUETOOTH) { checkVisibleEnemy(enemyController); } for (int i = 0; i < infoEnemy.Quantity; i++) { GameObject enemy = Instantiate(model, enemyStartPos[routine].transform.position, Quaternion.identity) as GameObject; enemy.transform.parent = enemyStartPos[routine].transform; enemy.transform.localScale = Vector3.one; enemy.transform.localPosition = Vector3.zero; enemy.GetComponentInChildren <SpriteRenderer>().material.renderQueue = GameConfig.RenderQueueEnemy - countEnemy; EnemyController ec = enemy.GetComponent <EnemyController>(); ec.stateMove.PathGroup = enemyRoutine[routine].transform; ec.waveID = wave.WaveID; //Set depth cho thanh hp, xu ly thanh mau xuat hien sau phai? ve~ sau foreach (Transform health in enemy.transform) { if (health.name == PlayNameHashIDs.Health) { foreach (Transform child in health) { if (child.name == PlayNameHashIDs.Foreground) { child.GetComponent <UISprite>().depth -= countEnemy; } else if (child.name == PlayNameHashIDs.Background) { child.GetComponent <UISprite>().depth -= (countEnemy + 1); } } break; } } countEnemy++; if (countEnemy >= 100) { countEnemy = 0; } yield return(new WaitForSeconds(infoEnemy.TimeSpawn)); } yield return(new WaitForSeconds(wave.TimeEnemy)); } } }