using ActionGameFramework.Health; using System; using TowerDefense.Agents; using TowerDefense.UI.HUD; using UnityEngine; using TowerDefense.Level; using System.Collections.Generic; using KTGMGemClient; namespace TowerDefense.Towers.Projectiles { [RequireComponent(typeof(Damager))] public class BallisticAttack : MonoBehaviour { /// /// 链式攻击的概率,目前只有一个链式攻击的模式,暂时不需要处理细节,先测试起来 /// public float chainAttackRate = 0; /// /// 当前攻击塔位对应的属性ID /// public int attributeId = 0; /// /// The Damager attached to the object /// protected Damager damager; /// /// 攻击增加. /// public float attackRise { get; set; } public void DealDamage(Targetable enemy) { float finalDamage = damager.finalDamage; bool crit = damager.isCrit; if (crit) finalDamage += finalDamage; // 精英怪和Boss双倍攻击. bool doubleHit = damager.doubleHit && enemy.bElit; if (doubleHit) finalDamage *= 2; // 处理光塔对应的攻击增加: if (attackRise > 0) finalDamage += (finalDamage * attackRise); // 破甲状态 if (enemy.bShieldBreak) finalDamage += (finalDamage * 0.1f); // 处理PVE无尽模式,buff增加的伤害 finalDamage += ProcessEndlessBuffAttack(finalDamage); // 提前处理非当前Enemy的爆炸攻击: if (chainAttackRate > 0) AgentInsManager.instance.StartExplodeAttack((Agent)enemy, finalDamage); int tid = enemy.liveID; Vector3 backPos = enemy.position; // 这里也可以把碰撞点传进来 enemy.TakeDamage(finalDamage, enemy.position, damager.alignmentProvider); // 处理塔位的技能攻击: ProcessTowerAttributeAttack(enemy, finalDamage, attributeId); if (!enemy.opponentAgent) { if (GameUI.instanceExists) GameUI.instance.generateBloodText(backPos, finalDamage, crit, doubleHit); else if (EndlessGameUI.instanceExists) EndlessGameUI.instance.generateBloodText(backPos, finalDamage, crit, doubleHit); } // 播放受击动画: if ((!enemy.isDead) && (enemy.liveID == tid)) (enemy as Agent).PlayOnHit(); } /// /// 处理PVE无尽模式buff增加的伤害 /// /// protected float ProcessEndlessBuffAttack(float finalDamage) { // 非无尽模式 if (!EndlessBuffManager.instanceExists) return 0; List list = EndlessBuffManager.instance.GetBuffListByEffectType(EndlessBuffEffectType.Attack, attributeId); if (list.Count == 0) return 0; float ratio = 0; float add = 0; for (int i = 0; i < list.Count; ++i) { ratio += list[i].Config.buff_effect[1]; add += list[i].Config.buff_effect[2]; } return finalDamage * (1 + ratio / 100f) + add; } /// /// 处理塔位的属性攻击 /// /// /// protected void ProcessTowerAttributeAttack(Targetable enemy, float damage, int attid) { int id = (int)Math.Floor(attid / 10000.0f); switch (id) { case 2: // 减速. enemy.addSpeedSlowRate(0.25f); enemy.SetTargetableMatColor(Color.blue); break; case 3: // 中毒 enemy.poisonAgent(damage, attid); enemy.SetTargetableMatColor(Color.green); break; case 5: // 破甲 enemy.bShieldBreak = true; break; } return; } /// /// Cache the damager component attached to this object /// protected virtual void Awake() { damager = GetComponent(); attackRise = 0.0f; } } }