chenxin
2020-12-01 e36f2a3ac098d6e89d3882f3354ec69c07e71e16
Assets/Scripts/TowerDefense/Affectors/AttackAffector.cs
@@ -8,6 +8,8 @@
using TowerDefense.Towers.Projectiles;
using UnityEngine;
using KTGMGemClient;
using TowerDefense.Agents;
using TowerDefense.Level;
namespace TowerDefense.Affectors
{
@@ -143,6 +145,30 @@
        /// </summary>
        /// <value></value>
        protected float fireSpeed { get; set; } = 5f;
        /// <summary>
        /// 木属性精灵蓄力时间
        /// </summary>
        protected float woodChargeTime { get; set; } = 1.5f;
        protected float woodRemainChargeTime { get; set; }
        /// <summary>
        /// 蓄力特效时间
        /// </summary>
        protected float woodChargeEffectTime { get; set; }
        /// <summary>
        /// 木属性精灵蓄力特效
        /// </summary>
        public ParticleSystem WoodChargeEffect;
        public Transform WoodChargeTransform;
        /// <summary>
        /// 木属性正在瞄准的Agent
        /// </summary>
        protected Agent woodAimAgent;
        /// <summary>
        /// 火精灵攻击最终攻击倍速,里面计算了buff增加的倍速
@@ -308,6 +334,22 @@
        // 处理木精灵装填子弹
        private void HandleBullet()
        {
            if (woodRemainChargeTime > 0f)
                woodRemainChargeTime -= Time.deltaTime;
            if (woodChargeEffectTime > 0f)
            {
                woodChargeEffectTime -= Time.deltaTime;
                UpdateWoodAim();
                if (woodChargeEffectTime <= 0)
                {
                    towerPtr.IsWoodCharge = false;
                    CancelWoodAim();
                    WoodChargeEffect.Stop();
                }
            }
            // 预留出来装填子弹的时间.
            if (fillBulletTime > 0)
            {
@@ -323,6 +365,68 @@
                    fillBulletTime = 0;
                }
            }
        }
        /// <summary>
        /// 更新木属性瞄准
        /// </summary>
        private void UpdateWoodAim()
        {
            // 离得最近的 Agent
            Agent agent = AgentInsManager.instance.GetMinDisAgent(waveLineID, false);
            if (agent != null)
            {
                // 还没有瞄准目标,直接分配
                if (woodAimAgent == null)
                {
                    woodAimAgent = agent;
                    towerPtr.WoodAimAgent = agent;
                    if (agent.WoodAimCount == 0)
                        agent.PlayWoodAimEffect();
                    ++agent.WoodAimCount;
                }
                // 有小怪走到之前瞄准目标的前面 或者 之前瞄准的目标死亡,切换瞄准目标
                else if (woodAimAgent.Id != agent.Id)
                {
                    if (woodAimAgent.WoodAimCount > 0)
                    {
                        --woodAimAgent.WoodAimCount;
                        if (woodAimAgent.WoodAimCount == 0)
                            woodAimAgent.StopWoodAimEffect();
                    }
                    woodAimAgent = agent;
                    towerPtr.WoodAimAgent = agent;
                    if (agent.WoodAimCount == 0)
                        agent.PlayWoodAimEffect();
                    ++agent.WoodAimCount;
                }
            }
        }
        /// <summary>
        /// 取消木属性瞄准
        /// </summary>
        private void CancelWoodAim()
        {
            if (woodAimAgent != null)
            {
                if (woodAimAgent.WoodAimCount > 0)
                {
                    --woodAimAgent.WoodAimCount;
                    if (woodAimAgent.WoodAimCount == 0)
                        woodAimAgent.StopWoodAimEffect();
                }
            }
            woodAimAgent = null;
        }
        // 处理火精灵充能
@@ -342,7 +446,6 @@
                    {
                        fireState = true;
                        fInEnergy = finalFireSpeed;
                        myTower.SetFireMatSpeed(true);//设置了火宝石快速攻击
                        // 设置多倍攻击速度
                        fBackupTimer = m_FireTimer;
                        m_FireTimer = m_FireTimer / finalFireSpeed;
@@ -356,8 +459,6 @@
                    fInEnergy -= Time.deltaTime;
                    if (fInEnergy <= 0)
                    {
                        myTower.SetFireMatSpeed(false);//恢复了火宝石攻击速度
                        fireState = false;
                        EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.FireTowerChargeEnd);
                        fInEnergy = 0.0f;
@@ -448,11 +549,13 @@
            {
                if (fireState)
                {
                    myTower.SetFireMatSpeed(true);//设置了火宝石快速攻击
                    towerPtr.PlayEnergyEffect(true);
                }
            }
            // 如果在木属性蓄力期间,让瞄准动画播放
            if (towerPtr && towerPtr.IsWoodCharge && woodAimAgent != null)
                woodAimAgent.PlayWoodAimEffect();
        }
        /// <summary>
@@ -484,7 +587,7 @@
        /// </summary>
        protected virtual void Update()
        {
            if (m_Launcher == null) return;
            if (m_Launcher == null || towerPtr != null && !towerPtr.CanAttack) return;
            // 处理当前Affector所在Tower对应的技能
            updateTowerSkillData();
@@ -504,7 +607,9 @@
                if (towerPtr && towerPtr.bulletCtl != null)
                {
                    int bnum = towerPtr.bulletCtl.GetCtlProgress();
                    if (bnum == 0) return;
                    // 蓄力时间内不攻击
                    if (bnum == 0 || woodRemainChargeTime > 0f) return;
                }
                if (towerPtr && towerPtr.FreezeBreathCtrl != null)
@@ -531,8 +636,10 @@
            if (m_TrackingEnemy == null || fillBulletTime > 0) return;
            go.GetComponent<Damager>().IsEnhancedBullet = false;
            // 处理子弹充能相关的内容
            if (towerPtr && (towerPtr.bulletCtl != null))
            if (towerPtr && towerPtr.bulletCtl != null)
            {
                int bnum = towerPtr.bulletCtl.decBullet();
                // 暴击子弹的数量,如果获得相应buff可能会修改暴击子弹数量
@@ -541,7 +648,8 @@
                if (bnum < critBulletNum)
                {
                    if (bnum == 0)
                        fillBulletTime = 2.0f;
                        // 不需要装填时间
                        fillBulletTime = 0.1f;
                    //这里需要替换特效
                    var poolable = Core.Utilities.Poolable.TryGetPoolable<Core.Utilities.Poolable>(woodProjectile_SP);
@@ -549,12 +657,22 @@
                    Damager tmpDamager = go.GetComponent<Damager>();
                    tmpDamager.damageMulti = 10.0f;
                    tmpDamager.damage = damagerProjectile.damage;
                    tmpDamager.IsEnhancedBullet = true;
                }
            }
            else
            {
                if (towerPtr)
                    towerPtr.setTowerState(true);
                // 下一颗子弹是强化子弹,然后直接蓄力
                if (bnum - 1 >= 0 && bnum - 1 < critBulletNum)
                {
                    woodRemainChargeTime = woodChargeTime;
                    towerPtr.IsWoodCharge = true;
                    DecreaseWoodChargeTime decreaseWoodChargeTime = (DecreaseWoodChargeTime)EndlessBuffManager.instance.GetBuffInstanceByType(EndlessBuffEffectType.DecreaseWoodChargeTime);
                    if (decreaseWoodChargeTime != null)
                        woodRemainChargeTime = decreaseWoodChargeTime.GetWoodChargeTime(woodChargeTime);
                    woodChargeEffectTime = woodRemainChargeTime + 0.5f / towerLevel.ActionAnimator.speed;
                    WoodChargeEffect.Play();
                }
            }
            if (isMultiAttack)
@@ -572,11 +690,11 @@
                        AudioSourceManager.Ins.Play(audioEnum);
                }
            }
            if (randomAudioSource != null)
            {
                if (Targetter.bSearchTarget)
                    randomAudioSource.PlayRandomClip();
            }
            // if (randomAudioSource != null)
            // {
            //     if (Targetter.bSearchTarget)
            //         randomAudioSource.PlayRandomClip();
            // }
        }
        /// <summary>