chenxin
2020-11-04 80b4237334a773b29bf69f38532a90ca659b3bfe
Assets/Scripts/TowerDefense/Level/EndlessWave.cs
@@ -1,4 +1,5 @@
using System;
using UnityEngine;
using System;
using System.Collections.Generic;
using Core.Utilities;
using KTGMGemClient;
@@ -46,9 +47,9 @@
        public event Action WaveCompleted;
        /// <summary>
        /// 波次发生改变
        /// 有新的敌人生成
        /// </summary>
        public event Action WaveChanged;
        public event Action SpawnNewAgent;
        /// <summary>
        /// 怪出生开始节点
@@ -111,10 +112,6 @@
            isWaveStoped = false;
        }
        /// <summary>
        /// Handles spawning the current agent and sets up the next agent for spawning
        /// 在场景内孵化出来一个Boss,这个核心函数最后被规则性的数据接管
        /// </summary>
        protected virtual void SpawnCurrent()
        {
            if (isWaveStoped) return;
@@ -126,21 +123,41 @@
                SafelyBroadcastWaveCompletedEvent();
            }
            else
            {
                ++spawnedEnemies;
                if (SpawnNewAgent != null)
                    SpawnNewAgent();
                if (spawnedEnemies >= waveData.Config.amount)
                {
                    StopWave();
                    SafelyBroadcastWaveCompletedEvent();
                }
            }
        }
        /// <summary>
        /// 生成agent
        /// </summary>
        /// <returns>Agent</returns>
        protected virtual Agent SpawnAgent()
        protected virtual void SpawnAgent()
        {
            int index = GetIndexByResId(waveData.EnemyData.resource);
            // 木属性小怪需要同时生成两个,先这么写吧(WTF)
            bool isDouble = waveData.EnemyData.resource == 103;
            Poolable agentPoolable = Poolable.TryGetPoolable<Poolable>(AgentConfigurationList[index].agentPrefab.gameObject);
            Agent newAgent = agentPoolable.GetComponent<Agent>();
            newAgent.transform.position = StartingNode.transform.position;
            if (isDouble)
            {
                Vector3 pos = newAgent.transform.position;
                pos.x -= 2f;
                newAgent.transform.position = pos;
            }
            newAgent.transform.rotation = StartingNode.transform.rotation;
            newAgent.SetNode(StartingNode, WaveLineId - 1);
            newAgent.opponentAgent = false;
@@ -157,7 +174,42 @@
            // 加入Manager统一管理.
            AgentInsManager.instance.addAgent(newAgent);
            return newAgent;
            if (isDouble)
            {
                Poolable agentPoolable2 = Poolable.TryGetPoolable<Poolable>(AgentConfigurationList[index].agentPrefab.gameObject);
                Agent doubleAgent = agentPoolable2.GetComponent<Agent>();
                doubleAgent.transform.position = StartingNode.transform.position;
                Vector3 pos = doubleAgent.transform.position;
                pos.x += 2f;
                doubleAgent.transform.position = pos;
                doubleAgent.transform.rotation = StartingNode.transform.rotation;
                doubleAgent.SetNode(StartingNode, WaveLineId - 1);
                doubleAgent.opponentAgent = false;
                doubleAgent.Initialize();
                doubleAgent.SetAgentData(hp, speed, gold);
                doubleAgent.healthBar.SetHealthLevel(1);
                AgentInsManager.instance.addAgent(doubleAgent);
            }
        }
        /// <summary>
      /// 从Tower的AttributeId获取到怪物的数据
      /// </summary>
      /// <param name="id"></param>
      /// <returns></returns>
      protected List<int> GetMonsterDataFromAttributeId(int id)
        {
            geminfo tgem = new geminfo();
            if (JsonDataCenter.gemInfoDic.TryGetValue(id, out tgem))
                return tgem.summon;
            else
            {
                Debug.Log("找不到对应ID的Gem:" + id);
                return null;
            }
        }
        /// <summary>
@@ -174,7 +226,7 @@
        }
        /// <summary>
        /// 暂时先这么处理
        /// 暂时先这么处理 cx test
        /// </summary>
        /// <param name="resId">endless_enemy表的资源id</param>
        /// <returns>所有可选的agent列表的索引</returns>