From 6b3cb63ae5d3f3c4b196a236b08fc3a4e8dfd5c6 Mon Sep 17 00:00:00 2001
From: River Jiang <546213258@qq.com>
Date: Thu, 22 Oct 2020 20:09:26 +0800
Subject: [PATCH] 火塔加入充能条

---
 Assets/Scripts/TowerDefense/Affectors/AttackAffector.cs |   73 +++++++++++++++++++++++++++++++-----
 1 files changed, 62 insertions(+), 11 deletions(-)

diff --git a/Assets/Scripts/TowerDefense/Affectors/AttackAffector.cs b/Assets/Scripts/TowerDefense/Affectors/AttackAffector.cs
index 48634b4..5ed2192 100644
--- a/Assets/Scripts/TowerDefense/Affectors/AttackAffector.cs
+++ b/Assets/Scripts/TowerDefense/Affectors/AttackAffector.cs
@@ -101,11 +101,17 @@
 		/// </summary>
 		protected Targetable m_TrackingEnemy;
 
-
 		/// <summary>
 		/// 处理装弹时间.
 		/// </summary>
 		protected float fillBulletTime = 0.0f;
+
+        /// <summary>
+        /// 充能时间
+        /// </summary>
+        protected float energyCalTime = 0;
+		protected float fInEnergy = 0;
+		protected float fBackupTimer = 0.0f;
 
 		/// <summary>
 		/// Gets the search rate from the targetter
@@ -224,15 +230,13 @@
 			m_Launcher = GetComponent<ILauncher>();
 		}
 
-		/// <summary>
-		/// Update the timers
-		/// </summary>
-		protected virtual void Update()
-		{
+
+		protected void updateTowerSkillData()
+        {
 			// 
 			// 预留出来装填子弹的时间.
-			if( fillBulletTime > 0 )
-            {
+			if (fillBulletTime > 0)
+			{
 				fillBulletTime -= Time.deltaTime;
 				if (fillBulletTime <= 0.3f)
 				{
@@ -241,10 +245,54 @@
 				}
 
 				if (fillBulletTime <= 0)
-                {
+				{
 					fillBulletTime = 0;
-				}			
+				}
 			}
+
+			// 
+			// 充能时间的处理
+			if( towerPtr && towerPtr.energyCtl)
+            {
+				if( this.fInEnergy <= 0)
+                {
+					this.energyCalTime += Time.deltaTime;
+					float process = energyCalTime % 11.0f;
+					int proint = (int)Math.Floor(process);
+					towerPtr.energyCtl.SetEnergyProgress(proint);
+					if (proint == 10)
+					{
+						fInEnergy = 5.0f;
+
+						// 设置多倍攻击速度
+						fBackupTimer = m_FireTimer;
+						m_FireTimer = m_FireTimer / 3.0f;
+					}
+                }
+                else
+                {
+					fInEnergy -= Time.deltaTime;
+					if( fInEnergy <= 0)
+                    {
+						fInEnergy = 0.0f;
+						this.energyCalTime = 0.0f;	
+						towerPtr.energyCtl.SetEnergyProgress(0);
+
+						// 恢复正常攻击速度 
+						m_FireTimer = fBackupTimer;
+					}
+				}
+
+			}
+		}
+
+		/// <summary>
+		/// Update the timers
+		/// </summary>
+		protected virtual void Update()
+		{
+			// 处理当前Affector所在Tower对应的技能
+			updateTowerSkillData();
 
 			m_FireTimer -= Time.deltaTime;
 			if( trackingEnemy == null )
@@ -253,6 +301,10 @@
 			{
 				OnFireTimer();
 				m_FireTimer = 1 / fireRate;
+
+				// 多倍攻速:
+				if (fInEnergy > 0.0f)
+					m_FireTimer = m_FireTimer / 3.0f;
 			}
 		}
 
@@ -277,7 +329,6 @@
 		/// </summary>
 		protected virtual void FireProjectile()
 		{
-			// WORK START: 确保获取
 			// 不再处理多子弹攻击,确保只有一个弹道
 			isMultiAttack = false; 
 			m_TrackingEnemy = targetter.GetTarget( waveLineID, bWoodAffector );

--
Gitblit v1.9.1