Assets/Scripts/TowerDefense/Agents/Agent.cs
@@ -13,6 +13,7 @@
using TowerDefense.Economy;
using TowerDefense.Level;
using TowerDefense.Nodes;
using TowerDefense.UI.HUD;
using UnityEngine;
using UnityEngine.AI;
@@ -290,6 +291,38 @@
        private string paramName = "AgentActionState";
        /// <summary>
        /// 外部赋值,唯一标识一个代理
        /// </summary>
        public int Id { get; set; }
        private Tween repelTween;
        /// <summary>
        /// 击退距离
        /// </summary>
        protected float repelDistance { get; set; } = 7f;
        /// <summary>
        /// 击退时间间隔
        /// </summary>
        protected float repelTime { get; set; } = 0.5f;
        /// <summary>
        /// 是否受到木属性强化子弹攻击
        /// </summary>
        public bool IsEnhancedBulletAttack { get; set; }
        /// <summary>
        /// 木属性精灵瞄准小怪特效
        /// </summary>
        public ParticleSystem WoodAimEffect;
        /// <summary>
        /// 有几个木属性精灵瞄准了Agent
        /// </summary>
        public int WoodAimCount { get; set; }
        /// <summary>
        /// 更新怪物的移动速度。
        /// </summary>
        /// <param name="fscale"></param>
@@ -449,15 +482,45 @@
            return true;
        }
        /// <summary>
        /// Agent被击退
        /// </summary>
        public void AgentBeRepelled()
        {
            CanMove = false;
            if (repelTween != null)
                repelTween.Kill();
            Node StartingNodeList = EndlessLevelManager.instance.StartingNodeList[waveLineID];
            repelTween = transform.DOMoveZ(Mathf.Min(StartingNodeList.transform.position.z, transform.position.z + repelDistance), repelTime);
            repelTween.onComplete = RepelCompleted;
        }
        private void RepelCompleted()
        {
            CanMove = true;
            repelTween = null;
        }
        /// <summary>
        /// Stops the navMeshAgent and attempts to return to pool
        /// </summary>
        public override void Remove()
        {
            GameObject prefab = Resources.Load<GameObject>("Prefabs/Endless/AgentDeathEffect");
            if (prefab != null)
            {
                GameObject obj = Poolable.TryGetPoolable(prefab);
                obj.transform.position = transform.position;
                ParticleSystem ps = obj.transform.GetChild(0).GetComponent<ParticleSystem>();
                ps?.Play();
            }
            // 统一管理器内删除当前的Agent:
            AgentInsManager.instance.removeAgent(this);
            EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.EndlessAgentDead, this);
            if (EnemyData != null)
                EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.EndlessAgentDead, EnemyData.point);
            base.Remove();
            if (m_LevelManager) m_LevelManager.DecrementNumberOfEnemies();
@@ -479,18 +542,29 @@
            poisonAttid = 0;
            poisonTimes = 0;
            timeToPoisonHurt = 0;
            isFrost = false;
            bShieldBreak = false;
            bInDeathAct = false;
            ChangeState(AgentActionState.Move);
            configuration.ClearShieldWall();
            StopFrostParticle();
            if (WoodAimCount > 0)
                WoodAimCount = 0;
            WoodAimEffect.Stop();
            WoodAimEffect.Clear();
            //this.SetTargetableMatColor(Color.white);
            // 删除当前停止特效和状态.
            if (MoveStopTime > 0)
                MoveStopTime = 0.0f;
            if (repelTween != null)
            {
                repelTween.Kill();
                repelTween = null;
            }
            // 停止DoTween动画.
            this.transform.DOKill();
@@ -500,13 +574,8 @@
        private void StopFrostParticle()
        {
            if (isFrost)
            {
                isFrost = false;
                if (FrostParticle != null)
                    FrostParticle.Stop();
            }
            if (FrostParticle != null)
                FrostParticle.Stop();
        }
        /// <summary>   
@@ -514,6 +583,7 @@
        /// </summary>
        public virtual void Initialize()
        {
            Id = GameUtils.GetId();
            ResetPositionData();
            LazyLoad();
            configuration.SetHealth(configuration.maxHealth);
@@ -828,14 +898,14 @@
            return;
        }
        float atime = 0;
        /// <summary>
        /// 更新动作信息.
        /// </summary>
        /// <returns></returns>
        protected void UpdateAction()
        {
            if (ActionAnimator == null) return;
            AnimatorStateInfo stateInfo = ActionAnimator.GetCurrentAnimatorStateInfo(0);
            switch (ActionState)
@@ -868,27 +938,8 @@
            if (state == ActionState) return;
            ActionState = state;
            ActionAnimator.SetInteger(paramName, (int)state);
        }
        /// <summary>
        /// 检查自身血量
        /// </summary>
        private void CheckHealth()
        {
            if (this.healthVal <= 0.1)
            {
                Die();
                //Debug.Log("删除多余的攻击Agent.");
            }
        }
        private void Die()
        {
            // 统一管理器内删除当前的Agent:
            AgentInsManager.instance.removeAgent(this);
            this.Remove();
            if (ActionAnimator != null)
                ActionAnimator.SetInteger(paramName, (int)state);
        }
        /// <summary>
@@ -1051,32 +1102,25 @@
        }
        /// <summary>
        /// 播放受击动画,直接从头开始播放
        /// </summary>
        public void PlayOnHitImmediately()
        {
            ChangeState(AgentActionState.GetHit);
            if (ActionAnimator)
            {
                ActionAnimator.Play("GetHit", 0, 0);
                ActionAnimator.Update(0);
            }
        }
        /// <summary>
        /// 播放火技能打击动画
        /// </summary>
        public void PlayFireSkillHit()
        {
            if (FireSkillParticle != null)
                FireSkillParticle.Play();
        }
        public void PlayGetHitParticle(int attributeId)
        {
            //这里的id是BallisticAttack上面设置的
            if (attributeId == 10101)
            {
                //10101 火
            }
            else if (attributeId == 20101)
            {
                //20101 水
            }
            else if (attributeId == 30101)
            {
                //30101 木
            }
        }
        public void PlayAttack()
@@ -1087,6 +1131,8 @@
        public override void PlayDeath()
        {
            if (bInDeathAct) return;
            if (isPoison)
            {
                isPoison = false;
@@ -1111,10 +1157,15 @@
                }
            }
            ChangeState(AgentActionState.Death);
            // 统一管理器内删除当前的Agent:
            AgentInsManager.instance.removeAgent(this);
            bInDeathAct = true;
            if (EnemyData != null && EndlessGameUI.instance.state != EndlessGameUI.State.GameOver)
            {
                // Debug.Log("小怪被杀死了,增加能量" + EnemyData.energy);
                EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.EnergyUp, EnemyData.energy);
            }
            Remove();
        }
        /// <summary>