From 09bc892c7283df8757a07b646d5af21ddaa263d1 Mon Sep 17 00:00:00 2001
From: lcy <1459594991@qq.com>
Date: 星期四, 06 十一月 2025 18:22:34 +0800
Subject: [PATCH] 164 天子的考验-客户端

---
 Main/System/Battle/BattleHUDWin.cs |  157 +++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 117 insertions(+), 40 deletions(-)

diff --git a/Main/System/Battle/BattleHUDWin.cs b/Main/System/Battle/BattleHUDWin.cs
index ef233a2..df219fd 100644
--- a/Main/System/Battle/BattleHUDWin.cs
+++ b/Main/System/Battle/BattleHUDWin.cs
@@ -7,36 +7,23 @@
 using System;
 using LitJson;
 
-
 //  杩欎釜鐣岄潰鏄� persistent鐨勭晫闈�
 public class BattleHUDWin : UIBase
 {
-    // 缁勪欢寮曠敤
-    // private List<HUDContent> damageList = new List<HUDContent>();
-
-    // private List<BuffContent> buffList = new List<BuffContent>();
-
     private GameObjectPoolManager.GameObjectPool damagePrefabPool;
-
     private GameObjectPoolManager.GameObjectPool buffIconPrefabPool;
-
     private GameObjectPoolManager.GameObjectPool buffLabelPrefabPool;
 
     public Transform damageNode;
-
     public Transform buffIconNode;
-
     public Transform buffLabelNode;
 
     private BattleField battleField;
-
     private List<DamageContent> damageContentList = new List<DamageContent>();
 
-    // 鐢熷懡鍛ㄦ湡
     protected override void InitComponent()
     {
         base.InitComponent();
-        // 鍒濆鍖栫粍浠跺紩鐢� 缁戝畾鎸夐挳绛塙I缁勪欢浜嬩欢
     }
 
     protected override void OnPreOpen()
@@ -45,8 +32,6 @@
         EventBroadcast.Instance.AddListener<BattleDmgInfo>(EventName.BATTLE_DAMAGE_TAKEN, OnDamageTaken);
         EventBroadcast.Instance.AddListener<string, JsonData>(EventName.BATTLE_END, OnBattleEnd);
         damagePrefabPool = GameObjectPoolManager.Instance.RequestPool(UILoader.LoadPrefab("DamageContent"));
-        // buffIconPrefabPool = GameObjectPoolManager.Instance.RequestPool();
-        // buffLabelPrefabPool = GameObjectPoolManager.Instance.RequestPool(ResManager.Instance.LoadAsset<GameObject>("UIComp", "BuffContent"));
     }
 
     private void OnBattleEnd(string guid, JsonData data)
@@ -83,8 +68,13 @@
     protected override void OnClose()
     {
         base.OnClose();
-        battleField.OnBattlePause -= OnBattlePause;
-        battleField = null;
+        if (battleField != null)
+        {
+            battleField.OnBattlePause -= OnBattlePause;
+            battleField.OnBattleRun -= OnBattleRun;
+            battleField.OnSpeedRatioChange -= OnSpeedRatioChange;
+            battleField = null;
+        }
     }
 
     protected override void NextFrameAfterOpen()
@@ -105,32 +95,98 @@
 
     private void OnDamageTaken(BattleDmgInfo damageInfo)
     {
-        GameObject damageContent = damagePrefabPool.Request();
-        DamageContent content = damageContent.GetComponent<DamageContent>();
-        damageContent.transform.SetParent(damageNode, false);
-        damageContent.transform.localPosition = new Vector3(damageContent.transform.localPosition.x, damageContent.transform.localPosition.y, 0);
-        content.SetDamage(damageInfo, () => RemoveDamageContent(content));
-        damageContentList.Add(content);
+        SetTargetDamage(damageInfo);
+        SetSelfDamage(damageInfo);
+    }
 
-        var heroRect = damageInfo.hurtObj.heroRectTrans;
-        if (heroRect == null)
-            return;
+    private void SetSelfDamage(BattleDmgInfo damageInfo)
+    {
+        if (damageInfo.casterDamageList.Count > 0)
+        {
+            GameObject damageContent = damagePrefabPool.Request();
+            DamageContent content = damageContent.GetComponent<DamageContent>();
+            damageContent.transform.SetParent(damageNode, false);
+            
+            var heroRect = damageInfo.casterObj.heroRectTrans;
+            if (heroRect == null)
+            {
+                damagePrefabPool.Release(damageContent);
+                return;
+            }
 
-        var contentRect = content.GetComponent<RectTransform>();
-        var contentParentRect = contentRect.parent as RectTransform;
+            var contentRect = content.GetComponent<RectTransform>();
+            var contentParentRect = contentRect.parent as RectTransform;
 
-        // 鑾峰彇 heroRect 鐨勪笘鐣屽潗鏍囷紙閿氱偣涓轰腑蹇冿級
-        Vector3 worldTargetPos = heroRect.transform.TransformPoint(heroRect.rect.center);
+            // 鑾峰彇 heroRect 鐨勪笘鐣屽潗鏍囷紙閿氱偣涓轰腑蹇冿級
+            Vector3 worldTargetPos = heroRect.transform.TransformPoint(heroRect.rect.center);
 
-        // 杞崲鍒� content 鐖惰妭鐐逛笅鐨� anchoredPosition
-        Vector2 anchoredPos;
-        RectTransformUtility.ScreenPointToLocalPointInRectangle(
-            contentParentRect,
-            RectTransformUtility.WorldToScreenPoint(null, worldTargetPos),
-            null,
-            out anchoredPos);
+            // 杞崲鍒� content 鐖惰妭鐐逛笅鐨� anchoredPosition
+            Vector2 anchoredPos;
+            RectTransformUtility.ScreenPointToLocalPointInRectangle(
+                contentParentRect,
+                RectTransformUtility.WorldToScreenPoint(null, worldTargetPos),
+                null,
+                out anchoredPos);
 
-        contentRect.anchoredPosition = anchoredPos;
+            // 璁剧疆鍔ㄦ�佷綅缃紙浼氳鐩栭厤缃腑鐨勪綅缃級
+            Vector2 beginPos = anchoredPos;
+            Vector2 endPos = anchoredPos + new Vector2(0, 150);
+            content.SetPosition(beginPos, endPos);
+
+            // 璁剧疆閫熷害姣斾緥
+            if (battleField != null)
+            {
+                content.SetRatio(battleField.speedRatio, 1f);
+            }
+            
+            content.SetDamage(damageInfo, damageInfo.casterDamageList, () => RemoveDamageContent(content));
+            damageContentList.Add(content);
+        }
+    }
+
+    private void SetTargetDamage(BattleDmgInfo damageInfo)
+    {
+        if (damageInfo.targetDamageList.Count > 0)
+        {
+            GameObject damageContent = damagePrefabPool.Request();
+            DamageContent content = damageContent.GetComponent<DamageContent>();
+            damageContent.transform.SetParent(damageNode, false);
+            
+            var heroRect = damageInfo.hurtObj.heroRectTrans;
+            if (heroRect == null)
+            {
+                damagePrefabPool.Release(damageContent);
+                return;
+            }
+
+            var contentRect = content.GetComponent<RectTransform>();
+            var contentParentRect = contentRect.parent as RectTransform;
+
+            // 鑾峰彇 heroRect 鐨勪笘鐣屽潗鏍囷紙閿氱偣涓轰腑蹇冿級
+            Vector3 worldTargetPos = heroRect.transform.TransformPoint(heroRect.rect.center);
+
+            // 杞崲鍒� content 鐖惰妭鐐逛笅鐨� anchoredPosition
+            Vector2 anchoredPos;
+            RectTransformUtility.ScreenPointToLocalPointInRectangle(
+                contentParentRect,
+                RectTransformUtility.WorldToScreenPoint(null, worldTargetPos),
+                null,
+                out anchoredPos);
+
+            // 璁剧疆鍔ㄦ�佷綅缃紙浼氳鐩栭厤缃腑鐨勪綅缃級
+            Vector2 beginPos = anchoredPos;
+            Vector2 endPos = anchoredPos + new Vector2(0, 150);
+            content.SetPosition(beginPos, endPos);
+
+            // 璁剧疆閫熷害姣斾緥
+            if (battleField != null)
+            {
+                content.SetRatio(battleField.speedRatio, 1f);
+            }
+            
+            content.SetDamage(damageInfo, damageInfo.targetDamageList, () => RemoveDamageContent(content));
+            damageContentList.Add(content);
+        }
     }
 
     public void SetBattleField(BattleField _battleField)
@@ -138,15 +194,26 @@
         if (battleField != null)
         {
             battleField.OnBattlePause -= OnBattlePause;
+            battleField.OnBattleRun -= OnBattleRun;
+            battleField.OnSpeedRatioChange -= OnSpeedRatioChange;
         }
         ClearContent(string.Empty, true);
         battleField = _battleField;
         battleField.OnBattlePause += OnBattlePause;
+        battleField.OnBattleRun += OnBattleRun;
+        battleField.OnSpeedRatioChange += OnSpeedRatioChange;
+    }
+
+    private void OnSpeedRatioChange(float newSpeedRatio)
+    {
+        foreach (var content in damageContentList)
+        {
+            content.SetRatio(newSpeedRatio, 1f);
+        }
     }
 
     private void OnBattlePause(bool isPause)
     {
-        //  娓告垙鏆傚仠
         if (isPause)
         {
             foreach (var content in damageContentList)
@@ -154,7 +221,6 @@
                 content.Stop();
             }
         }
-        //  娓告垙鎭㈠
         else
         {
             foreach (var content in damageContentList)
@@ -163,4 +229,15 @@
             }
         }
     }
+
+    private void OnBattleRun()
+    {
+        for (int i = damageContentList.Count - 1; i >= 0; i--)
+        {
+            if (i < damageContentList.Count)
+            {
+                damageContentList[i].Run();
+            }
+        }
+    }
 }

--
Gitblit v1.8.0