| | |
| | | using TowerDefense.UI.HUD; |
| | | using Core.Utilities; |
| | | using System.Collections.Generic; |
| | | using UnityEngine; |
| | | using TowerDefense.Agents; |
| | | using TowerDefense.Level; |
| | | using DG.Tweening; |
| | | using MoreMountains.NiceVibrations; |
| | | |
| | | /** |
| | | * 泡泡炸弹 |
| | |
| | | */ |
| | | namespace KTGMGemClient |
| | | { |
| | | /// <summary> |
| | | /// 泡泡炸弹配置数据 |
| | | /// </summary> |
| | | public class BubbleBombConfig |
| | | { |
| | | public BubbleBombAgent Agent { get; set; } |
| | | |
| | | public GameObject obj { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 需要被攻击的次数,攻击 * 次炸弹才会被销毁 |
| | |
| | | /// </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> |
| | | /// 被攻击的次数 |
| | |
| | | /// </summary> |
| | | protected List<BubbleBombConfig> bubbleBombList; |
| | | |
| | | protected System.Random random; |
| | | /// <summary> |
| | | /// 泡泡炸弹对象池 |
| | | /// </summary> |
| | | protected List<GameObject> bubbleBombPool; |
| | | |
| | | protected int capacity = 10; |
| | | |
| | | private int getCount; |
| | | |
| | | private int recycleCount; |
| | | |
| | | /// <summary> |
| | | /// 释放技能 |
| | |
| | | { |
| | | base.ReleaseSkill(); |
| | | Debug.Log("--------------------- 泡泡炸弹释放 ---------------------"); |
| | | // cx test |
| | | SpawnBubbleBomb(); |
| | | } |
| | | |
| | |
| | | /// </summary> |
| | | protected void SpawnOnTunel() |
| | | { |
| | | // 有可能只在某一条赛道生成,也有可能在所有赛道生成 |
| | | List<int> tunelIdList = GetTunelList(); |
| | | GameObject prefab = Resources.Load<GameObject>(prefabPath); |
| | | |
| | | for (int i = 0; i < tunelIdList.Count; ++i) |
| | | { |
| | | GameObject obj = Poolable.TryGetPoolable(prefab); |
| | | GameObject obj = GetBubbleBomb(); |
| | | BubbleBombAgent bubbleBomb = obj.GetComponent<BubbleBombAgent>(); |
| | | |
| | | // 分配唯一id |
| | |
| | | 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]); |
| | |
| | | config.MoveSpeed = SkillData.effect[1]; |
| | | bubbleBombList.Add(config); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取赛道列表 |
| | | /// </summary> |
| | | protected List<int> GetTunelList() |
| | | { |
| | | List<int> tunelIdList = new List<int>(); |
| | | int count = 0; |
| | | // 剩余没有用到的赛道 |
| | | List<int> remainList = new List<int>() { 1, 2, 3, 4, 5 }; |
| | | |
| | | for (int i = 0; i < SkillData.tunnel.Count; ++i) |
| | | { |
| | | // 统计6这种类型的数量 |
| | | if (SkillData.tunnel[i] == 6) |
| | | { |
| | | ++count; |
| | | continue; |
| | | } |
| | | |
| | | tunelIdList.Add(SkillData.tunnel[i]); |
| | | remainList.Remove(SkillData.tunnel[i]); |
| | | } |
| | | |
| | | for (int i = 0; i < count; ++i) |
| | | { |
| | | int num = random.Next(remainList.Count); |
| | | tunelIdList.Add(remainList[num]); |
| | | remainList.Remove(remainList[num]); |
| | | } |
| | | |
| | | return tunelIdList; |
| | | } |
| | | |
| | | public override void Reset() |
| | |
| | | { |
| | | base.Clear(); |
| | | ClearBubbleBomb(); |
| | | ClearBubbleBombPool(); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | 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(); |
| | |
| | | base.Init(); |
| | | Debug.Log("--------------------- 泡泡炸弹技能初始化 ---------------------"); |
| | | bubbleBombList = new List<BubbleBombConfig>(); |
| | | bubbleBombPool = new List<GameObject>(); |
| | | |
| | | GameObject prefab = Resources.Load<GameObject>(prefabPath); |
| | | |
| | | for (int i = 0; i < capacity; ++i) |
| | | { |
| | | GameObject obj = GameObject.Instantiate(prefab); |
| | | obj.SetActive(false); |
| | | bubbleBombPool.Add(obj); |
| | | } |
| | | } |
| | | |
| | | /// <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() |
| | |
| | | if (config.Agent.bInDeathState) return; |
| | | |
| | | ++config.AttackCount; |
| | | Debug.Log($"--------------------- BubbleBombAgent Id: {id}, AttackCount:{config.AttackCount} ---------------------"); |
| | | |
| | | if (config.AttackCount >= config.NeedAttackCount) |
| | | AgentDead(config); |
| | |
| | | |
| | | 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) |
| | | { |
| | | EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.EndlessLoseHeart, 3); |
| | | ViewPortAdj.instance.cachedCamera.DOShakePosition(0.25f, 1.5f, 4); |
| | | MMVibrationManager.Haptic(HapticTypes.HeavyImpact); |
| | | config.IsAttack = false; |
| | | } |
| | | } |
| | |
| | | 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; |
| | | } |
| | |
| | | } |
| | | |
| | | // 更新移动 |
| | | if (!config.Agent.bInDeathState && config.Agent.CanMove) |
| | | if (config.Agent != null && !config.Agent.bInDeathState && 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) |
| | | { |