From a5666fce59f464fb9e0813adb4fc85260dd24bc3 Mon Sep 17 00:00:00 2001
From: wangguan <wangguan@kt007.com>
Date: Tue, 15 Dec 2020 21:15:43 +0800
Subject: [PATCH] SDK对接

---
 Assets/Scripts/TowerDefense/UI/EndlessBossSkill/BossSkillBubbleBomb.cs |   61 ++++++++++++++++--------------
 1 files changed, 33 insertions(+), 28 deletions(-)

diff --git a/Assets/Scripts/TowerDefense/UI/EndlessBossSkill/BossSkillBubbleBomb.cs b/Assets/Scripts/TowerDefense/UI/EndlessBossSkill/BossSkillBubbleBomb.cs
index 5eb9475..66d576c 100644
--- a/Assets/Scripts/TowerDefense/UI/EndlessBossSkill/BossSkillBubbleBomb.cs
+++ b/Assets/Scripts/TowerDefense/UI/EndlessBossSkill/BossSkillBubbleBomb.cs
@@ -2,6 +2,7 @@
 using UnityEngine;
 using TowerDefense.Agents;
 using TowerDefense.Level;
+using TMPro;
 
 /**
  * 泡泡炸弹
@@ -101,8 +102,6 @@
         /// </summary>
         protected List<GameObject> bubbleBombPool;
 
-        protected int capacity = 10;
-
         private int getCount;
 
         private int recycleCount;
@@ -171,6 +170,10 @@
                 config.DestroyTime = bubbleBomb.GetExplodeTime();
                 config.MoveSpeed = SkillData.effect[1];
                 bubbleBombList.Add(config);
+
+                bubbleBomb.Blood.SetPos();
+                bubbleBomb.Blood.SetRemainHitCount(config.NeedAttackCount);
+                bubbleBomb.Blood.ShowBlood();
             }
         }
 
@@ -209,18 +212,9 @@
         public override void Init()
         {
             base.Init();
-            Debug.Log("--------------------- 泡泡炸弹技能初始化 ---------------------");
+            Debug.Log("---- 泡泡炸弹技能初始化 ----");
             bubbleBombList = new List<BubbleBombConfig>();
             bubbleBombPool = new List<GameObject>();
-
-            GameObject prefab = Resources.Load<GameObject>(prefabPath);
-
-            for (int i = 0; i < capacity; ++i)
-            {
-                GameObject obj = GameObject.Instantiate(prefab);
-                obj.SetActive(false);
-                bubbleBombPool.Add(obj);
-            }
         }
 
         /// <summary>
@@ -239,6 +233,15 @@
             {
                 GameObject prefab = Resources.Load<GameObject>(prefabPath);
                 ret = GameObject.Instantiate(prefab);
+                BubbleBombAgent agent = ret.GetComponent<BubbleBombAgent>();
+
+                prefab = Resources.Load<GameObject>($"Prefabs/BubbleBombBlood");
+                GameObject bubbleBombBlood = GameObject.Instantiate(prefab);
+                GameObject bloodUI = GameObject.Find("MainUI/BloodUI");
+                bubbleBombBlood.transform.SetParent(bloodUI.transform, false);
+
+                agent.Blood = bubbleBombBlood.GetComponent<BubbleBombBlood>();
+                agent.Blood.Target = agent;
             }
 
             ret.SetActive(true);
@@ -254,6 +257,8 @@
         {
             if (obj != null)
             {
+                BubbleBombAgent agent = obj.GetComponent<BubbleBombAgent>();
+                agent.Blood.HideBlood();
                 obj.SetActive(false);
                 bubbleBombPool.Add(obj);
             }
@@ -268,6 +273,8 @@
             {
                 GameObject obj = bubbleBombPool[0];
                 bubbleBombPool.Remove(obj);
+                BubbleBombAgent agent = obj.GetComponent<BubbleBombAgent>();
+                GameObject.Destroy(agent.Blood.gameObject);
                 GameObject.Destroy(obj);
             }
         }
@@ -298,10 +305,10 @@
                 {
                     BubbleBombConfig config = bubbleBombList[i];
                     // 攻击次数够了被打死了 或者 达到基地了
-                    if (config.Agent.bInDeathState) return;
+                    if (config.IsAttackDeath || config.IsArrived) return;
 
                     ++config.AttackCount;
-                    Debug.Log($"--------------------- BubbleBombAgent Id: {id}, AttackCount:{config.AttackCount} ---------------------");
+                    config.Agent.Blood.SetRemainHitCount(config.NeedAttackCount - config.AttackCount);
 
                     if (config.AttackCount >= config.NeedAttackCount)
                         AgentDead(config);
@@ -323,8 +330,9 @@
                 {
                     BubbleBombConfig config = bubbleBombList[i];
 
-                    if (config.Agent.bInDeathState) return;
+                    if (config.IsAttackDeath || config.IsArrived) return;
 
+                    config.Agent.Blood.HideBlood();
                     AgentDead(config);
                     break;
                 }
@@ -344,7 +352,7 @@
                 {
                     BubbleBombConfig config = bubbleBombList[i];
 
-                    if (config.Agent.bInDeathState) return;
+                    if (config.IsAttackDeath || config.IsArrived) return;
 
                     config.IsDizzinessed = true;
                     config.Agent.CanMove = false;
@@ -361,11 +369,11 @@
         /// <param name="config"></param>
         private void AgentDead(BubbleBombConfig config)
         {
+            config.Agent.Blood.HideBlood();
+            config.IsAttackDeath = true;
+            AgentInsManager.instance.removeAgent(config.Agent);
             config.Agent.StopNormalEffect();
             config.Agent.PlayExplodeEffect();
-            AgentInsManager.instance.removeAgent(config.Agent);
-            config.Agent.bInDeathState = true;
-            config.IsAttackDeath = true;
         }
 
         /// <summary>
@@ -374,11 +382,11 @@
         /// <param name="config"></param>
         private void AgentArrived(BubbleBombConfig config)
         {
+            config.Agent.Blood.HideBlood();
             config.IsArrived = true;
+            AgentInsManager.instance.removeAgent(config.Agent);
             config.Agent.StopNormalEffect();
             config.Agent.PlayExplodeEffect();
-            AgentInsManager.instance.removeAgent(config.Agent);
-            config.Agent.bInDeathState = true;
         }
 
         public override void Update(float deltaTime)
@@ -389,6 +397,8 @@
             {
                 BubbleBombConfig config = bubbleBombList[i];
 
+                if (config.Agent == null || config.obj == null) continue;
+
                 // 泡泡炸弹已经触发了攻击,延时一会过后掉爱心
                 if (config.IsAttack)
                 {
@@ -396,7 +406,7 @@
 
                     if (config.AttackTime <= 0)
                     {
-                        EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.EndlessLoseHeart, 3);
+                        EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.EndlessLoseHeart, 2);
                         config.IsAttack = false;
                     }
                 }
@@ -433,7 +443,7 @@
                 }
 
                 // 更新移动
-                if (config.Agent != null && !config.Agent.bInDeathState && config.Agent.CanMove)
+                if (config.Agent != null && config.Agent.CanMove)
                 {
                     Vector3 pos = config.obj.transform.position;
                     pos.z -= deltaTime * config.MoveSpeed;
@@ -445,11 +455,6 @@
                         config.IsAttack = true;
                         config.AttackTime = 0.65f;
                     }
-                }
-                else
-                {
-                    // cx test
-                    Debug.Log("--------------------- 泡泡炸弹不能移动 ---------------------");
                 }
             }
         }

--
Gitblit v1.9.1