| | |
| | | using ActionGameFramework.Audio; |
| | | using ActionGameFramework.Health; |
| | | using Core.Health; |
| | | using TowerDefense.Agents; |
| | | using TowerDefense.Targetting; |
| | | using TowerDefense.Towers; |
| | | using TowerDefense.Towers.Projectiles; |
| | | using UnityEngine; |
| | | using KTGMGemClient; |
| | | using TowerDefense.Towers.TowerLaunchers; |
| | | using TowerDefense.Agents; |
| | | using TowerDefense.Level; |
| | | |
| | | namespace TowerDefense.Affectors |
| | |
| | | /// </summary> |
| | | public int maxAttackNum = 1; |
| | | |
| | | |
| | | /// <summary> |
| | | /// The fire rate in fires-per-second |
| | | /// </summary> |
| | | public float fireRate; |
| | | [SerializeField] |
| | | private float projectileFireRate = 1; |
| | | |
| | | public float FireRate |
| | | { |
| | | get { return 1 / GetFireDuration(); } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 是否木属性数据 |
| | |
| | | /// </summary> |
| | | protected float freezeBreathCallTime = 0; |
| | | |
| | | protected float inFreezeBreath = 0; |
| | | protected float inFreezeBreath; |
| | | |
| | | protected float freezeBreathBackTimer = 0; |
| | | |
| | | private int towerAttributeId; |
| | | |
| | | /// <summary> |
| | | /// 火精灵技能固定攻击倍速 |
| | | /// </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 GameObject WoodChargeEffect; |
| | | |
| | | private GameObject woodChargeEffect; |
| | | |
| | | public Transform WoodChargeTransform; |
| | | |
| | | /// <summary> |
| | | /// 木属性正在瞄准的Agent |
| | | /// </summary> |
| | | protected Agent woodAimAgent; |
| | | |
| | | /// <summary> |
| | | /// 火精灵攻击最终攻击倍速,里面计算了buff增加的倍速 |
| | | /// </summary> |
| | | /// <value></value> |
| | | public float finalFireSpeed |
| | | { |
| | | get |
| | | { |
| | | FireRateAdd fireRateAdd = (FireRateAdd)EndlessBuffManager.instance.GetBuffInstanceByType(EndlessBuffEffectType.FireRateAdd); |
| | | float rateAdd = 0; |
| | | |
| | | if (fireRateAdd != null) |
| | | rateAdd = fireRateAdd.GetFireSpeedAdd(towerPtr.attributeId); |
| | | return rateAdd > 1 ? rateAdd : fireSpeed; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// Gets the search rate from the targetter |
| | |
| | | // 处理木精灵装填子弹 |
| | | private void HandleBullet() |
| | | { |
| | | if (woodRemainChargeTime > 0f) |
| | | woodRemainChargeTime -= Time.deltaTime; |
| | | |
| | | if (woodChargeEffectTime > 0f) |
| | | { |
| | | woodChargeEffectTime -= Time.deltaTime; |
| | | UpdateWoodAim(); |
| | | |
| | | if (woodChargeEffectTime <= 0 && woodChargeEffect != null) |
| | | { |
| | | CancelWoodAim(); |
| | | Destroy(woodChargeEffect); |
| | | woodChargeEffect = null; |
| | | } |
| | | } |
| | | |
| | | // 预留出来装填子弹的时间. |
| | | if (fillBulletTime > 0) |
| | | { |
| | |
| | | if (fillBulletTime <= 0.3f) |
| | | { |
| | | if (towerPtr && towerPtr.bulletCtl) |
| | | towerPtr.bulletCtl.resetToMaxBullet(); |
| | | towerPtr.bulletCtl.ResetToMaxBullet(); |
| | | } |
| | | |
| | | if (fillBulletTime <= 0) |
| | |
| | | fillBulletTime = 0; |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 更新木属性瞄准 |
| | | /// </summary> |
| | | private void UpdateWoodAim() |
| | | { |
| | | // 离得最近的 Agent |
| | | Agent agent = GetMinDistanceAgent(); |
| | | |
| | | if (agent != null) |
| | | { |
| | | // 还没有瞄准目标,直接分配 |
| | | if (woodAimAgent == null) |
| | | { |
| | | woodAimAgent = agent; |
| | | |
| | | if (agent.WoodAimCount == 0) |
| | | agent.WoodAimEffect.Play(); |
| | | |
| | | ++agent.WoodAimCount; |
| | | } |
| | | // 有小怪走到之前瞄准目标的前面 或者 之前瞄准的目标死亡,切换瞄准目标 |
| | | else if (woodAimAgent.Id != agent.Id) |
| | | { |
| | | if (woodAimAgent.WoodAimCount > 0) |
| | | { |
| | | --woodAimAgent.WoodAimCount; |
| | | |
| | | if (woodAimAgent.WoodAimCount == 0) |
| | | { |
| | | woodAimAgent.WoodAimEffect.Stop(); |
| | | woodAimAgent.WoodAimEffect.Clear(); |
| | | } |
| | | } |
| | | |
| | | if (agent.WoodAimCount == 0) |
| | | agent.WoodAimEffect.Play(); |
| | | |
| | | ++agent.WoodAimCount; |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取距离终点最近的Agent |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | private Agent GetMinDistanceAgent() |
| | | { |
| | | Agent ret = null; |
| | | float minDistance = -1f; |
| | | |
| | | WaveLineAgentInsMgr[] waveLineAgentIns = AgentInsManager.instance.GetWaveLineList(); |
| | | WaveLineAgentInsMgr waveLineAgentInsMgr = waveLineAgentIns[waveLineID]; |
| | | List<Agent> agents = waveLineAgentInsMgr.listAgent; |
| | | Vector3 endPos = EndlessLevelManager.instance.GetHomeBasePosition(waveLineID + 1); |
| | | |
| | | for (int i = 0; i < agents.Count; ++i) |
| | | { |
| | | float distance = Mathf.Abs(agents[i].transform.position.z - endPos.z); |
| | | |
| | | if (minDistance < 0 || distance < minDistance) |
| | | { |
| | | minDistance = distance; |
| | | ret = agents[i]; |
| | | } |
| | | } |
| | | |
| | | return ret; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 取消木属性瞄准 |
| | | /// </summary> |
| | | private void CancelWoodAim() |
| | | { |
| | | if (woodAimAgent != null && woodAimAgent.WoodAimCount > 0) |
| | | { |
| | | --woodAimAgent.WoodAimCount; |
| | | |
| | | if (woodAimAgent.WoodAimCount == 0) |
| | | { |
| | | woodAimAgent.WoodAimEffect.Stop(); |
| | | woodAimAgent.WoodAimEffect.Clear(); |
| | | } |
| | | } |
| | | |
| | | woodAimAgent = null; |
| | | } |
| | | |
| | | // 处理火精灵充能 |
| | |
| | | if (proint == 10) |
| | | { |
| | | fireState = true; |
| | | fInEnergy = 5.0f; |
| | | fInEnergy = finalFireSpeed; |
| | | myTower.SetFireMatSpeed(true);//设置了火宝石快速攻击 |
| | | // 设置多倍攻击速度 |
| | | fBackupTimer = m_FireTimer; |
| | | m_FireTimer = m_FireTimer / 5.0f; |
| | | m_FireTimer = m_FireTimer / finalFireSpeed; |
| | | |
| | | towerPtr.uiProOffset = 0; |
| | | towerPtr.PlayEnergyEffect(true); |
| | |
| | | Damager damager = projectile.gameObject.GetComponent<Damager>(); |
| | | float finalDamage = damager.damage; |
| | | |
| | | List<EndlessBuffConfig> list = EndlessBuffManager.instance.GetBuffListByEffectType(EndlessBuffEffectType.Attack, towerPtr.attributeId); |
| | | List<EndlessBuffConfig> list = EndlessBuffManager.instance.GetBuffListByEffectType(EndlessBuffEffectType.AttackAdd, towerPtr.attributeId); |
| | | float ratio = 0; |
| | | float add = 0; |
| | | |
| | |
| | | |
| | | if (processInt == (int)Mathf.Floor(FreezeBreath.ChargeTime)) |
| | | { |
| | | inFreezeBreath = FreezeBreath.EffectTime; |
| | | inFreezeBreath = towerPtr.FreezeBreathCtrl.SkillTime; |
| | | towerPtr.FreezeBreathProgressOffset = 0; |
| | | towerPtr.PlayFreezeBreathEffect(true); |
| | | towerPtr.FreezeBreathCtrl.ReleaseCount = 1; |
| | | towerPtr.FreezeBreathCtrl.PlayFreezeEffect(waveLineID); |
| | | towerPtr.FreezeBreathCtrl.ReleaseFreeze(waveLineID, finalDamage, damager.alignmentProvider); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | inFreezeBreath -= Time.deltaTime; |
| | | int time = Mathf.FloorToInt(towerPtr.FreezeBreathCtrl.EffectTime / (towerPtr.FreezeBreathCtrl.DamageCount - 1) * 10); |
| | | int interval = Mathf.FloorToInt(inFreezeBreath * 10); |
| | | int offset = Mathf.FloorToInt(towerPtr.FreezeBreathCtrl.SkillTime * 10) - Mathf.FloorToInt(towerPtr.FreezeBreathCtrl.EffectTime * 10); |
| | | |
| | | if (inFreezeBreath <= FreezeBreath.EffectTime / 2 && towerPtr.FreezeBreathCtrl.ReleaseCount != 2) |
| | | if (interval == time * (towerPtr.FreezeBreathCtrl.DamageCount - towerPtr.FreezeBreathCtrl.ReleaseCount - 1) + offset && towerPtr.FreezeBreathCtrl.ReleaseCount < towerPtr.FreezeBreathCtrl.DamageCount) |
| | | { |
| | | towerPtr.FreezeBreathCtrl.ReleaseCount = 2; |
| | | ++towerPtr.FreezeBreathCtrl.ReleaseCount; |
| | | towerPtr.FreezeBreathCtrl.ReleaseFreeze(waveLineID, finalDamage, damager.alignmentProvider); |
| | | return; |
| | | } |
| | | |
| | | if (inFreezeBreath <= 0) |
| | |
| | | freezeBreathCallTime = 0; |
| | | towerPtr.FreezeBreathCtrl.SetProgress(0); |
| | | towerPtr.PlayFreezeBreathEffect(false); |
| | | towerPtr.FreezeBreathCtrl.ReleaseCount = 3; |
| | | towerPtr.FreezeBreathCtrl.ReleaseFreeze(waveLineID, finalDamage, damager.alignmentProvider); |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取子弹发射时间间隔 |
| | | /// </summary> |
| | | public float GetFireDuration() |
| | | { |
| | | DecreaseTowerAttackCD endlessBuff = (DecreaseTowerAttackCD)EndlessBuffManager.instance.GetBuffInstanceByType(EndlessBuffEffectType.DecreaseTowerAttackCD); |
| | | |
| | | return endlessBuff != null ? endlessBuff.GetDecreaseCD(towerPtr.attributeId, 1 / projectileFireRate) : 1 / projectileFireRate; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// Update the timers |
| | | /// </summary> |
| | | protected virtual void Update() |
| | |
| | | |
| | | if (m_TrackingEnemy != null && m_FireTimer < 0) |
| | | { |
| | | m_FireTimer = 1 / fireRate; |
| | | m_FireTimer = GetFireDuration(); |
| | | |
| | | if (fInEnergy > 0) |
| | | m_FireTimer /= 5; |
| | | m_FireTimer /= finalFireSpeed; |
| | | |
| | | towerLevel.FireSpeed = fInEnergy > 0 ? 5f : 1f; |
| | | towerLevel.FireSpeed = fInEnergy > 0 ? finalFireSpeed : 1f; |
| | | |
| | | 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) |
| | |
| | | |
| | | 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可能会修改暴击子弹数量 |
| | | int critBulletNum = towerPtr.bulletCtl.CritBulletNum; |
| | | |
| | | if (bnum == 0) |
| | | if (bnum < critBulletNum) |
| | | { |
| | | //damagerProjectile.damageMulti = 10.0f; |
| | | fillBulletTime = 2.0f; |
| | | if (bnum == 0) |
| | | // 不需要装填时间 |
| | | fillBulletTime = 0.1f; |
| | | |
| | | //这里需要替换特效 |
| | | var poolable = Core.Utilities.Poolable.TryGetPoolable<Core.Utilities.Poolable>(woodProjectile_SP); |
| | |
| | | Damager tmpDamager = go.GetComponent<Damager>(); |
| | | tmpDamager.damageMulti = 10.0f; |
| | | tmpDamager.damage = damagerProjectile.damage; |
| | | tmpDamager.IsEnhancedBullet = true; |
| | | } |
| | | |
| | | // 下一颗子弹是强化子弹,然后直接蓄力 |
| | | if (bnum - 1 >= 0 && bnum - 1 < critBulletNum) |
| | | { |
| | | woodRemainChargeTime = woodChargeTime; |
| | | DecreaseWoodChargeTime decreaseWoodChargeTime = (DecreaseWoodChargeTime)EndlessBuffManager.instance.GetBuffInstanceByType(EndlessBuffEffectType.DecreaseWoodChargeTime); |
| | | |
| | | if (decreaseWoodChargeTime != null) |
| | | woodRemainChargeTime = decreaseWoodChargeTime.GetWoodChargeTime(woodChargeTime); |
| | | |
| | | woodChargeEffectTime = woodRemainChargeTime + 0.5f / towerLevel.ActionAnimator.speed; |
| | | woodChargeEffect = Instantiate(WoodChargeEffect); |
| | | woodChargeEffect.transform.SetPositionAndRotation(WoodChargeTransform.position, WoodChargeTransform.rotation); |
| | | ParticleSystem ps = woodChargeEffect.transform.GetChild(0).GetComponent<ParticleSystem>(); |
| | | ps.Play(); |
| | | } |
| | | } |
| | | else |
| | | { |