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;
|
|
/**
|
* 泡泡炸弹
|
* @Author: chenxin
|
* @Date: 2020-11-02 17:09:03
|
*/
|
namespace KTGMGemClient
|
{
|
public class BubbleBombConfig
|
{
|
public BubbleBombAgent Agent { 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; }
|
|
public float AttackTime { get; set; }
|
}
|
|
public class BossSkillBubbleBomb : EndlessBossSkill
|
{
|
public BossSkillBubbleBomb(boss_skill param) : base(param)
|
{
|
random = new System.Random();
|
}
|
|
/// <summary>
|
/// 被攻击的次数
|
/// </summary>
|
protected int beAttackedCount;
|
|
protected string prefabPath = "Prefabs/Endless/BubbleBomb";
|
|
/// <summary>
|
/// 所有存在于场景中的泡泡炸弹
|
/// </summary>
|
protected List<BubbleBombConfig> bubbleBombList;
|
|
protected System.Random random;
|
|
/// <summary>
|
/// 释放技能
|
/// </summary>
|
public override void ReleaseSkill()
|
{
|
base.ReleaseSkill();
|
Debug.Log("--------------------- 泡泡炸弹释放 ---------------------");
|
// cx test
|
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();
|
GameObject prefab = Resources.Load<GameObject>(prefabPath);
|
|
for (int i = 0; i < tunelIdList.Count; ++i)
|
{
|
GameObject obj = Poolable.TryGetPoolable(prefab);
|
BubbleBombAgent bubbleBomb = obj.GetComponent<BubbleBombAgent>();
|
|
// 分配唯一id
|
bubbleBomb.Id = GameUtils.GetId();
|
bubbleBomb.waveLineID = tunelIdList[i] - 1;
|
bubbleBomb.AgentType = SpawnAgentType.BubbleBomb;
|
bubbleBomb.opponentAgent = false;
|
bubbleBomb.Reset();
|
|
// 出生位置
|
Vector3 spawnPosition = EndlessLevelManager.instance.GetTunelWorldPosition(tunelIdList[i], (EndlessBossSkillTunelType)SkillData.target[1]);
|
bubbleBomb.transform.position = spawnPosition;
|
bubbleBomb.PlayNormalEffect();
|
AgentInsManager.instance.addAgent(bubbleBomb);
|
|
BubbleBombConfig config = new BubbleBombConfig();
|
config.Agent = bubbleBomb;
|
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);
|
}
|
}
|
|
/// <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.Reset();
|
beAttackedCount = 0;
|
ClearBubbleBomb();
|
}
|
|
public override void Clear()
|
{
|
base.Clear();
|
ClearBubbleBomb();
|
}
|
|
/// <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();
|
|
if (!bubbleBombList[i].Agent.bInDeathState)
|
AgentInsManager.instance.removeAgent(bubbleBombList[i].Agent);
|
|
Poolable.TryPool(bubbleBombList[i].Agent.gameObject);
|
}
|
|
bubbleBombList.Clear();
|
}
|
|
public override void Init()
|
{
|
base.Init();
|
Debug.Log("--------------------- 泡泡炸弹技能初始化 ---------------------");
|
bubbleBombList = new List<BubbleBombConfig>();
|
}
|
|
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;
|
|
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)
|
{
|
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.IsAttackDeath || config.IsArrived)
|
{
|
config.DestroyTime -= deltaTime;
|
|
if (config.DestroyTime <= 0)
|
{
|
bubbleBombList[i].Agent.Reset();
|
Poolable.TryPool(bubbleBombList[i].Agent.gameObject);
|
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.bInDeathState && config.Agent.CanMove)
|
{
|
Vector3 pos = config.Agent.transform.position;
|
pos.z -= deltaTime * config.MoveSpeed;
|
config.Agent.transform.position = pos;
|
|
if (pos.z <= config.TargetPosition.z)
|
{
|
AgentArrived(config);
|
config.IsAttack = true;
|
config.AttackTime = 0.65f;
|
}
|
}
|
}
|
}
|
}
|
}
|