chenxin
2020-11-19 fdfb88a9ee3652e716e603f759d3be5dcc0bd3bd
Assets/Scripts/TowerDefense/UI/EndlessBossSkill/BossSkillBubbleBomb.cs
@@ -1,5 +1,3 @@
using TowerDefense.UI.HUD;
using Core.Utilities;
using System.Collections.Generic;
using UnityEngine;
using TowerDefense.Agents;
@@ -12,9 +10,14 @@
 */
namespace KTGMGemClient
{
    /// <summary>
    /// 泡泡炸弹配置数据
    /// </summary>
    public class BubbleBombConfig
    {
        public BubbleBombAgent Agent { get; set; }
        public GameObject obj { get; set; }
        /// <summary>
        /// 需要被攻击的次数,攻击 * 次炸弹才会被销毁
@@ -71,15 +74,15 @@
        /// </summary>
        public bool IsAttack { get; set; }
        /// <summary>
        /// 延迟产生伤害时间
        /// </summary>
        public float AttackTime { get; set; }
    }
    public class BossSkillBubbleBomb : EndlessBossSkill
    {
        public BossSkillBubbleBomb(boss_skill param) : base(param)
        {
            random = new System.Random();
        }
        public BossSkillBubbleBomb(boss_skill param) : base(param) { }
        /// <summary>
        /// 被攻击的次数
@@ -93,7 +96,14 @@
        /// </summary>
        protected List<BubbleBombConfig> bubbleBombList;
        protected System.Random random;
        /// <summary>
        /// 泡泡炸弹对象池
        /// </summary>
        protected List<GameObject> bubbleBombPool;
        private int getCount;
        private int recycleCount;
        /// <summary>
        /// 释放技能
@@ -102,7 +112,6 @@
        {
            base.ReleaseSkill();
            Debug.Log("--------------------- 泡泡炸弹释放 ---------------------");
            // cx test
            SpawnBubbleBomb();
        }
@@ -120,7 +129,6 @@
                    Debug.Log("--------------------- WTF 不支持哦~ ---------------------");
                    break;
                case EndlessBossSkillUseTarget.Tunel:
                    EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.EndlessBossSkillGlintTitle);
                    SpawnOnTunel();
                    break;
            }
@@ -131,29 +139,30 @@
        /// </summary>
        protected void SpawnOnTunel()
        {
            // 有可能只在某一条赛道生成,也有可能在所有赛道生成
            List<int> tunelIdList = GetTunelList();
            GameObject prefab = Resources.Load<GameObject>(prefabPath);
            for (int i = 0; i < tunelIdList.Count; ++i)
            {
                Poolable poolable = Poolable.TryGetPoolable<Poolable>(prefab);
                BubbleBombAgent bubbleBomb = poolable.GetComponent<BubbleBombAgent>();
                GameObject obj = GetBubbleBomb();
                BubbleBombAgent bubbleBomb = obj.GetComponent<BubbleBombAgent>();
                // 分配唯一id
                bubbleBomb.Id = GameUtils.GetId();
                bubbleBomb.waveLineID = tunelIdList[i] - 1;
                bubbleBomb.AgentType = SpawnAgentType.BubbleBomb;
                bubbleBomb.opponentAgent = false;
                bubbleBomb.Reset();
                bubbleBomb.Initialize();
                // 出生位置
                Vector3 spawnPosition = EndlessLevelManager.instance.GetTunelWorldPosition(tunelIdList[i], (EndlessBossSkillTunelType)SkillData.target[1]);
                bubbleBomb.transform.position = spawnPosition;
                obj.transform.position = spawnPosition;
                bubbleBomb.PlayNormalEffect();
                AgentInsManager.instance.addAgent(bubbleBomb);
                BubbleBombConfig config = new BubbleBombConfig();
                config.Agent = bubbleBomb;
                config.obj = obj;
                config.NeedAttackCount = (int)SkillData.effect[0];
                config.StartPosition = spawnPosition;
                config.TargetPosition = EndlessLevelManager.instance.GetHomeBasePosition(tunelIdList[i]);
@@ -161,33 +170,6 @@
                config.MoveSpeed = SkillData.effect[1];
                bubbleBombList.Add(config);
            }
        }
        /// <summary>
        /// 获取赛道列表
        /// </summary>
        protected List<int> GetTunelList()
        {
            List<int> tunelIdList = new List<int>();
            // cx test 后面改
            int configTunel = SkillData.tunnel[0];
            if (configTunel <= 5)
                // 直接对应具体的一条赛道
                tunelIdList.Add(configTunel);
            else if (configTunel == 6)
            {
                // 所有赛道
                for (int i = 1; i <= 5; ++i)
                {
                    tunelIdList.Add(i);
                }
            }
            else if (configTunel == 7)
                // 随机一条
                tunelIdList.Add(random.Next(1, 6));
            return tunelIdList;
        }
        public override void Reset()
@@ -201,6 +183,7 @@
        {
            base.Clear();
            ClearBubbleBomb();
            ClearBubbleBombPool();
        }
        /// <summary>
@@ -214,10 +197,8 @@
                bubbleBombList[i].Agent.StopNormalEffect();
                bubbleBombList[i].Agent.StopExplodeEffect();
                if (!bubbleBombList[i].Agent.bInDeathState)
                    AgentInsManager.instance.removeAgent(bubbleBombList[i].Agent);
                Poolable.TryPool(bubbleBombList[i].Agent.gameObject);
                AgentInsManager.instance.removeAgent(bubbleBombList[i].Agent);
                RecycleBubbleBomb(bubbleBombList[i].obj);
            }
            bubbleBombList.Clear();
@@ -226,8 +207,58 @@
        public override void Init()
        {
            base.Init();
            Debug.Log("--------------------- 泡泡炸弹技能初始化 ---------------------");
            Debug.Log("---- 泡泡炸弹技能初始化 ----");
            bubbleBombList = new List<BubbleBombConfig>();
            bubbleBombPool = new List<GameObject>();
        }
        /// <summary>
        /// 从对象池中获取一个炸弹
        /// </summary>
        protected GameObject GetBubbleBomb()
        {
            GameObject ret;
            if (bubbleBombPool.Count > 0)
            {
                ret = bubbleBombPool[0];
                bubbleBombPool.Remove(bubbleBombPool[0]);
            }
            else
            {
                GameObject prefab = Resources.Load<GameObject>(prefabPath);
                ret = GameObject.Instantiate(prefab);
            }
            ret.SetActive(true);
            return ret;
        }
        /// <summary>
        /// 回收泡泡炸弹
        /// </summary>
        /// <param name="obj"></param>
        protected void RecycleBubbleBomb(GameObject obj)
        {
            if (obj != null)
            {
                obj.SetActive(false);
                bubbleBombPool.Add(obj);
            }
        }
        /// <summary>
        /// 清空泡泡炸弹对象池
        /// </summary>
        protected void ClearBubbleBombPool()
        {
            while (bubbleBombPool.Count > 0)
            {
                GameObject obj = bubbleBombPool[0];
                bubbleBombPool.Remove(obj);
                GameObject.Destroy(obj);
            }
        }
        protected override void AddEvent()
@@ -256,9 +287,10 @@
                {
                    BubbleBombConfig config = bubbleBombList[i];
                    // 攻击次数够了被打死了 或者 达到基地了
                    if (config.Agent.bInDeathState) return;
                    if (config.IsAttackDeath || config.IsArrived) return;
                    ++config.AttackCount;
                    Debug.Log($"---- BubbleBombAgent Id: {id}, AttackCount: {config.AttackCount} ----");
                    if (config.AttackCount >= config.NeedAttackCount)
                        AgentDead(config);
@@ -280,7 +312,7 @@
                {
                    BubbleBombConfig config = bubbleBombList[i];
                    if (config.Agent.bInDeathState) return;
                    if (config.IsAttackDeath || config.IsArrived) return;
                    AgentDead(config);
                    break;
@@ -301,7 +333,7 @@
                {
                    BubbleBombConfig config = bubbleBombList[i];
                    if (config.Agent.bInDeathState) return;
                    if (config.IsAttackDeath || config.IsArrived) return;
                    config.IsDizzinessed = true;
                    config.Agent.CanMove = false;
@@ -318,11 +350,10 @@
        /// <param name="config"></param>
        private void AgentDead(BubbleBombConfig config)
        {
            config.IsAttackDeath = true;
            AgentInsManager.instance.removeAgent(config.Agent);
            config.Agent.StopNormalEffect();
            config.Agent.PlayExplodeEffect();
            AgentInsManager.instance.removeAgent(config.Agent);
            config.Agent.bInDeathState = true;
            config.IsAttackDeath = true;
        }
        /// <summary>
@@ -332,10 +363,9 @@
        private void AgentArrived(BubbleBombConfig config)
        {
            config.IsArrived = true;
            AgentInsManager.instance.removeAgent(config.Agent);
            config.Agent.StopNormalEffect();
            config.Agent.PlayExplodeEffect();
            AgentInsManager.instance.removeAgent(config.Agent);
            config.Agent.bInDeathState = true;
        }
        public override void Update(float deltaTime)
@@ -344,17 +374,16 @@
            for (int i = 0; i < bubbleBombList.Count; ++i)
            {
                if (bubbleBombList[i] == null) continue;
                BubbleBombConfig config = bubbleBombList[i];
                // 泡泡炸弹已经触发了攻击,延时一会过后掉爱心
                if (config.IsAttack)
                {
                    config.AttackTime -= deltaTime;
                    if (config.AttackTime <= 0)
                    {
                        EndlessGameUI.instance.DestroyTowerGrid(config.Agent.waveLineID);
                        EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.EndlessLoseHeart, 3);
                        config.IsAttack = false;
                    }
                }
@@ -367,7 +396,8 @@
                    if (config.DestroyTime <= 0)
                    {
                        bubbleBombList[i].Agent.Reset();
                        Poolable.TryPool(bubbleBombList[i].Agent.gameObject);
                        RecycleBubbleBomb(bubbleBombList[i].obj);
                        AgentInsManager.instance.removeAgent(bubbleBombList[i].Agent);
                        bubbleBombList.Remove(bubbleBombList[i]);
                        --i;
                    }
@@ -390,11 +420,11 @@
                }
                // 更新移动
                if (!config.Agent.bInDeathState && config.Agent.CanMove)
                if (config.Agent.CanMove)
                {
                    Vector3 pos = config.Agent.transform.position;
                    Vector3 pos = config.obj.transform.position;
                    pos.z -= deltaTime * config.MoveSpeed;
                    config.Agent.transform.position = pos;
                    config.obj.transform.position = pos;
                    if (pos.z <= config.TargetPosition.z)
                    {
@@ -403,6 +433,11 @@
                        config.AttackTime = 0.65f;
                    }
                }
                else
                {
                    // cx test
                    Debug.LogError("---- 泡泡炸弹不能移动??? ----");
                }
            }
        }
    }