using System.Collections.Generic;
|
using UnityEngine;
|
using TowerDefense.Agents;
|
using TowerDefense.Level;
|
|
/**
|
* 泡泡炸弹
|
* @Author: chenxin
|
* @Date: 2020-11-02 17:09:03
|
*/
|
namespace KTGMGemClient
|
{
|
/// <summary>
|
/// 泡泡炸弹配置数据
|
/// </summary>
|
public class BubbleBombConfig
|
{
|
public BubbleBombAgent Agent { get; set; }
|
|
public GameObject obj { get; set; }
|
|
/// <summary>
|
/// 需要被攻击的次数,攻击 * 次炸弹才会被销毁
|
/// </summary>
|
public int NeedAttackCount { get; set; }
|
|
/// <summary>
|
/// 已经被攻击的次数
|
/// </summary>
|
public int AttackCount { get; set; }
|
|
/// <summary>
|
/// 是否抵达基地,抵达基地后,不能继续被塔攻击
|
/// </summary>
|
public bool IsArrived { get; set; }
|
|
/// <summary>
|
/// 出生点坐标
|
/// </summary>
|
public Vector3 StartPosition { get; set; }
|
|
/// <summary>
|
/// 目的地坐标,也就是基地位置
|
/// </summary>
|
public Vector3 TargetPosition { get; set; }
|
|
/// <summary>
|
/// 是否被攻击打死,被塔打死或者被火技能宝石打死(火技能宝石是直接秒杀炸弹的)
|
/// </summary>
|
public bool IsAttackDeath { get; set; }
|
|
/// <summary>
|
/// 销毁时间,被塔打死或者攻击玩家基地后,时间减为0之后销毁
|
/// </summary>
|
public float DestroyTime { get; set; }
|
|
/// <summary>
|
/// 移动速度
|
/// </summary>
|
public float MoveSpeed { get; set; }
|
|
/// <summary>
|
/// 是否被眩晕
|
/// </summary>
|
public bool IsDizzinessed { get; set; }
|
|
/// <summary>
|
/// 眩晕时间
|
/// </summary>
|
public float DizzinessTime { 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) { }
|
|
/// <summary>
|
/// 被攻击的次数
|
/// </summary>
|
protected int beAttackedCount;
|
|
protected string prefabPath = "Prefabs/Endless/BubbleBomb";
|
|
/// <summary>
|
/// 所有存在于场景中的泡泡炸弹
|
/// </summary>
|
protected List<BubbleBombConfig> bubbleBombList;
|
|
/// <summary>
|
/// 泡泡炸弹对象池
|
/// </summary>
|
protected List<GameObject> bubbleBombPool;
|
|
protected int capacity = 10;
|
|
private int getCount;
|
|
private int recycleCount;
|
|
/// <summary>
|
/// 释放技能
|
/// </summary>
|
public override void ReleaseSkill()
|
{
|
base.ReleaseSkill();
|
Debug.Log("--------------------- 泡泡炸弹释放 ---------------------");
|
SpawnBubbleBomb();
|
}
|
|
/// <summary>
|
/// 在场景中生成泡泡炸弹
|
/// </summary>
|
protected void SpawnBubbleBomb()
|
{
|
switch ((EndlessBossSkillUseTarget)SkillData.target[0])
|
{
|
case EndlessBossSkillUseTarget.Tower:
|
Debug.Log("--------------------- WTF 不支持哦~ ---------------------");
|
break;
|
case EndlessBossSkillUseTarget.Agent:
|
Debug.Log("--------------------- WTF 不支持哦~ ---------------------");
|
break;
|
case EndlessBossSkillUseTarget.Tunel:
|
SpawnOnTunel();
|
break;
|
}
|
}
|
|
/// <summary>
|
/// 在赛道上生成炸弹
|
/// </summary>
|
protected void SpawnOnTunel()
|
{
|
List<int> tunelIdList = GetTunelList();
|
|
for (int i = 0; i < tunelIdList.Count; ++i)
|
{
|
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]);
|
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.DestroyTime = bubbleBomb.GetExplodeTime();
|
config.MoveSpeed = SkillData.effect[1];
|
bubbleBombList.Add(config);
|
}
|
}
|
|
public override void Reset()
|
{
|
base.Reset();
|
beAttackedCount = 0;
|
ClearBubbleBomb();
|
}
|
|
public override void Clear()
|
{
|
base.Clear();
|
ClearBubbleBomb();
|
ClearBubbleBombPool();
|
}
|
|
/// <summary>
|
/// 清理在场景中的所有炸弹
|
/// </summary>
|
private void ClearBubbleBomb()
|
{
|
for (int i = 0; i < bubbleBombList.Count; ++i)
|
{
|
bubbleBombList[i].Agent.Reset();
|
bubbleBombList[i].Agent.StopNormalEffect();
|
bubbleBombList[i].Agent.StopExplodeEffect();
|
|
AgentInsManager.instance.removeAgent(bubbleBombList[i].Agent);
|
RecycleBubbleBomb(bubbleBombList[i].obj);
|
}
|
|
bubbleBombList.Clear();
|
}
|
|
public override void Init()
|
{
|
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()
|
{
|
EventCenter.Ins.Add<int>((int)KTGMGemClient.EventType.EndlessBossSkillBubbleBombGetHit, OnGetHit);
|
EventCenter.Ins.Add<int>((int)KTGMGemClient.EventType.EndlessFireSkillKillBubbleBomb, OnFireSkillKillBubbleBomb);
|
EventCenter.Ins.Add<int, int>((int)KTGMGemClient.EventType.EndlessBubbleBombBeDizzinessed, OnBubbleBombBeDizzinessed);
|
}
|
|
protected override void RemoveEvent()
|
{
|
EventCenter.Ins.Remove<int>((int)KTGMGemClient.EventType.EndlessBossSkillBubbleBombGetHit, OnGetHit);
|
EventCenter.Ins.Remove<int>((int)KTGMGemClient.EventType.EndlessFireSkillKillBubbleBomb, OnFireSkillKillBubbleBomb);
|
EventCenter.Ins.Remove<int, int>((int)KTGMGemClient.EventType.EndlessBubbleBombBeDizzinessed, OnBubbleBombBeDizzinessed);
|
}
|
|
/// <summary>
|
/// 泡泡炸弹受到一次攻击
|
/// </summary>
|
/// <param name="id">炸弹代理的唯一id</param>
|
private void OnGetHit(int id)
|
{
|
for (int i = 0; i < bubbleBombList.Count; ++i)
|
{
|
if (bubbleBombList[i].Agent.Id == id)
|
{
|
BubbleBombConfig config = bubbleBombList[i];
|
// 攻击次数够了被打死了 或者 达到基地了
|
if (config.Agent.bInDeathState) return;
|
|
++config.AttackCount;
|
Debug.Log($"--------------------- BubbleBombAgent Id: {id}, AttackCount:{config.AttackCount} ---------------------");
|
|
if (config.AttackCount >= config.NeedAttackCount)
|
AgentDead(config);
|
|
break;
|
}
|
}
|
}
|
|
/// <summary>
|
/// 泡泡炸弹被火技能烧死
|
/// </summary>
|
/// <param name="id"></param>
|
private void OnFireSkillKillBubbleBomb(int id)
|
{
|
for (int i = 0; i < bubbleBombList.Count; ++i)
|
{
|
if (bubbleBombList[i].Agent.Id == id)
|
{
|
BubbleBombConfig config = bubbleBombList[i];
|
|
if (config.Agent.bInDeathState) return;
|
|
AgentDead(config);
|
break;
|
}
|
}
|
}
|
|
/// <summary>
|
/// 泡泡炸弹被眩晕
|
/// </summary>
|
/// <param name="id"></param>
|
/// <param name="duration">持续时间</param>
|
private void OnBubbleBombBeDizzinessed(int id, int duration)
|
{
|
for (int i = 0; i < bubbleBombList.Count; ++i)
|
{
|
if (bubbleBombList[i].Agent.Id == id)
|
{
|
BubbleBombConfig config = bubbleBombList[i];
|
|
if (config.Agent.bInDeathState) return;
|
|
config.IsDizzinessed = true;
|
config.Agent.CanMove = false;
|
// 直接覆盖持续时间
|
config.DizzinessTime = duration / 1000f;
|
break;
|
}
|
}
|
}
|
|
/// <summary>
|
/// 炸弹突然去世
|
/// </summary>
|
/// <param name="config"></param>
|
private void AgentDead(BubbleBombConfig config)
|
{
|
config.Agent.StopNormalEffect();
|
config.Agent.PlayExplodeEffect();
|
AgentInsManager.instance.removeAgent(config.Agent);
|
config.Agent.bInDeathState = true;
|
config.IsAttackDeath = true;
|
}
|
|
/// <summary>
|
/// 炸弹到达基地
|
/// </summary>
|
/// <param name="config"></param>
|
private void AgentArrived(BubbleBombConfig config)
|
{
|
config.IsArrived = true;
|
config.Agent.StopNormalEffect();
|
config.Agent.PlayExplodeEffect();
|
AgentInsManager.instance.removeAgent(config.Agent);
|
config.Agent.bInDeathState = true;
|
}
|
|
public override void Update(float deltaTime)
|
{
|
base.Update(deltaTime);
|
|
for (int i = 0; i < bubbleBombList.Count; ++i)
|
{
|
BubbleBombConfig config = bubbleBombList[i];
|
|
// 泡泡炸弹已经触发了攻击,延时一会过后掉爱心
|
if (config.IsAttack)
|
{
|
config.AttackTime -= deltaTime;
|
|
if (config.AttackTime <= 0)
|
{
|
EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.EndlessLoseHeart, 3);
|
config.IsAttack = false;
|
}
|
}
|
|
// 被打死了 或 到达基地
|
if (config.IsAttackDeath || config.IsArrived)
|
{
|
config.DestroyTime -= deltaTime;
|
|
if (config.DestroyTime <= 0)
|
{
|
bubbleBombList[i].Agent.Reset();
|
RecycleBubbleBomb(bubbleBombList[i].obj);
|
AgentInsManager.instance.removeAgent(bubbleBombList[i].Agent);
|
bubbleBombList.Remove(bubbleBombList[i]);
|
--i;
|
}
|
|
continue;
|
}
|
|
// 处理被眩晕的
|
if (config.IsDizzinessed)
|
{
|
config.DizzinessTime -= deltaTime;
|
|
if (config.DizzinessTime <= 0)
|
{
|
// 解除眩晕
|
config.IsDizzinessed = false;
|
config.Agent.CanMove = true;
|
}
|
else continue;
|
}
|
|
// 更新移动
|
if (config.Agent != null && !config.Agent.bInDeathState && config.Agent.CanMove)
|
{
|
Vector3 pos = config.obj.transform.position;
|
pos.z -= deltaTime * config.MoveSpeed;
|
config.obj.transform.position = pos;
|
|
if (pos.z <= config.TargetPosition.z)
|
{
|
AgentArrived(config);
|
config.IsAttack = true;
|
config.AttackTime = 0.65f;
|
}
|
}
|
else
|
{
|
// cx test
|
Debug.Log("--------------------- ---------------------");
|
}
|
}
|
}
|
}
|
}
|