From 3b2a6bb9047cfce9f501593b3669a9c1af6c5df4 Mon Sep 17 00:00:00 2001
From: lcy <1459594991@qq.com>
Date: 星期三, 05 十一月 2025 17:40:23 +0800
Subject: [PATCH] 130 战斗修改回合样式

---
 Main/System/Battle/BattleUtility.cs |  205 +++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 197 insertions(+), 8 deletions(-)

diff --git a/Main/System/Battle/BattleUtility.cs b/Main/System/Battle/BattleUtility.cs
index 03d2cda..201d318 100644
--- a/Main/System/Battle/BattleUtility.cs
+++ b/Main/System/Battle/BattleUtility.cs
@@ -102,10 +102,52 @@
             var numChar = (char)GetDamageNumKey(config, basePowerStr[i]);
             if (numChar > 0)
             {
-                result += numChar; 
+                result += numChar;
             }
         }
         return result;
+    }
+
+    public static string DisplayDamageNum(BattleDmg damage)
+    {
+        var config = DamageNumConfig.Get(damage.attackType);
+
+        string result = string.Empty;
+
+        //  濡傛灉鏄棯閬� 鍒欏彧鏄剧ず闂伩涓や釜瀛�
+        if (damage.IsType(DamageType.Dodge))
+        {
+            result += (char)config.prefix;
+        }
+        else
+        {
+            result = ConvertToArtFont(config, damage.damage);
+        }
+
+        return result;
+    }
+
+    public static string ConvertToArtFont(DamageNumConfig config, float _num)
+    {
+        var stringBuild = new System.Text.StringBuilder();
+
+        if (0 != config.plus)
+            stringBuild.Append((char)config.plus);
+        if (0 != config.prefix)
+            stringBuild.Append((char)config.prefix);
+
+        var chars = UIHelper.ReplaceLargeArtNum(_num);
+        for (var i = 0; i < chars.Length; i++)
+        {
+            int numChar = GetDamageNumKey(config, (int)chars[i]);
+
+            if (numChar > 0)
+            {
+                stringBuild.Append((char)numChar);
+            }
+        }
+
+        return stringBuild.ToString();
     }
 
     public static int GetMainTargetPositionNum(BattleObject caster, List<HB427_tagSCUseSkill.tagSCUseSkillHurt> targetList, SkillConfig skillConfig)
@@ -143,7 +185,7 @@
                 break;
             case 1:
                 // 1    瀵逛綅锛�
-                // 榛樿鍙��1涓紝瀵逛綅瑙勫垯涓篈1浼樺厛鎵揃1锛孉2浼樺厛鎵揃2锛孉3浼樺厛鎵揃3锛屽浣嶇洰鏍囨浜℃椂锛屼紭鍏堝墠鎺掞紝姣斿B2宸茬粡姝讳骸锛岄偅涔圓2灏嗕紭鍏堟墦B1锛屽墠鎺�1銆�2銆�3鍙蜂綅缃叏閮ㄦ浜′箣鍚庢墠寮�濮嬮�夋嫨鍚庢帓4銆�5銆�6鍙蜂綅缃紝瀵逛綅鍙彲閫�1涓洰鏍囷紝鍗充富鐩爣
+                // 榛樿鍙��1涓紝瀵逛綅瑙勫垯涓篈1浼樺厛鎵揃1锛孉2浼樺厛鎵揃2锛孉3浼樺厛鎵揃3锛屽浣嶇洰鏍囨浜℃椂锛屼紭鍏堝墠鎺掞紝姣斿B2宸茬粡姝讳骸锛岄偅涔圓2灏嗕紭鍏堟墦B
                 if (targetList.Count > 0)
                 {
                     BattleObject battleObject = caster.battleField.battleObjMgr.GetBattleObject((int)targetList[0].ObjID);
@@ -241,18 +283,128 @@
 
     public static int GetDamageNumKey(DamageNumConfig config, int _num)
     {
-        if (_num == 46)      return config.nums[10]; // '.'
+        if (_num == 46) return config.nums[10]; // '.'
         else if (_num == 107) return config.nums[11]; // 'k'
         else if (_num == 109) return config.nums[12]; // 'm'
-        else if (_num == 98)  return config.nums[13]; // 'b'
+        else if (_num == 98) return config.nums[13]; // 'b'
         else if (_num == 116) return config.nums[14]; // 't'
         int targetNum = _num - 48;
         if (targetNum >= config.nums.Length || targetNum < 0)
         {
-            Debug.LogError("damage config " + config.TypeID + " _num is " +  _num + " out of range");
+            Debug.LogError("damage config " + config.TypeID + " _num is " + _num + " out of range");
             return _num;
         }
         return config.nums[_num - 48];
+    }
+    
+    /// <summary>
+    /// 灏嗘暣涓妧鑳界殑鎬讳激瀹虫寜鍛戒腑娆℃暟鍜屽垎娈甸厤缃垎閰�
+    /// </summary>
+    /// <param name="damageDivideList">鏁翠釜鎶�鑳界殑鎵�鏈夊懡涓垎娈甸厤缃�</param>
+    /// <param name="hitIndex">褰撳墠鏄鍑犲嚮(浠�0寮�濮�)</param>
+    /// <param name="totalDamage">鏁翠釜鎶�鑳界殑鎬讳激瀹�</param>
+    /// <returns>杩欎竴鍑诲唴姣忎竴娈电殑浼ゅ鍊煎垪琛�</returns>
+    public static List<long> DivideDamageToList(int[][] damageDivideList, int hitIndex, long totalDamage)
+    {
+        if (damageDivideList == null || damageDivideList.Length == 0)
+        {
+            Debug.LogError("damageDivideList 涓虹┖鎴栭暱搴︿负0");
+            return new List<long> { totalDamage };
+        }
+
+        if (hitIndex < 0 || hitIndex >= damageDivideList.Length)
+        {
+            Debug.LogError($"hitIndex={hitIndex} 瓒呭嚭鑼冨洿, damageDivideList.Length={damageDivideList.Length}");
+            return new List<long> { totalDamage };
+        }
+
+        int[] currentHitDivide = damageDivideList[hitIndex];
+        if (currentHitDivide == null || currentHitDivide.Length == 0)
+        {
+            Debug.LogError($"damageDivide[{hitIndex}] 涓虹┖鎴栭暱搴︿负0");
+            return new List<long> { totalDamage };
+        }
+
+        // ============ 绗竴姝�: 璁$畻姣忎竴鍑诲簲璇ラ�犳垚鐨勪激瀹� ============
+        // 鍏堣绠楁墍鏈夊嚮鐨勬�绘潈閲�
+        int totalWeight = 0;
+        for (int i = 0; i < damageDivideList.Length; i++)
+        {
+            if (damageDivideList[i] != null && damageDivideList[i].Length > 0)
+            {
+                // 姣忎竴鍑荤殑鏉冮噸鏄叾鎵�鏈夊垎娈典箣鍜�
+                for (int j = 0; j < damageDivideList[i].Length; j++)
+                {
+                    totalWeight += damageDivideList[i][j];
+                }
+            }
+        }
+
+        if (totalWeight == 0)
+        {
+            Debug.LogError("totalWeight 涓� 0");
+            return new List<long> { totalDamage };
+        }
+
+        // 璁$畻褰撳墠杩欎竴鍑荤殑鏉冮噸
+        int currentHitWeight = 0;
+        for (int i = 0; i < currentHitDivide.Length; i++)
+        {
+            currentHitWeight += currentHitDivide[i];
+        }
+
+        // 璁$畻褰撳墠杩欎竴鍑诲簲璇ラ�犳垚鐨勬�讳激瀹�
+        long currentHitTotalDamage;
+        bool isLastHit = hitIndex >= damageDivideList.Length - 1;
+        
+        if (isLastHit)
+        {
+            // 鏈�鍚庝竴鍑�: 璁$畻鍓嶉潰鎵�鏈夊嚮宸茬粡閫犳垚鐨勪激瀹�,鍓╀綑鐨勫叏閮ㄧ粰鏈�鍚庝竴鍑�
+            long previousHitsDamage = 0;
+            for (int i = 0; i < hitIndex; i++)
+            {
+                if (damageDivideList[i] != null)
+                {
+                    int hitWeight = 0;
+                    for (int j = 0; j < damageDivideList[i].Length; j++)
+                    {
+                        hitWeight += damageDivideList[i][j];
+                    }
+                    previousHitsDamage += (long)((float)totalDamage * (float)hitWeight / (float)totalWeight);
+                }
+            }
+            currentHitTotalDamage = totalDamage - previousHitsDamage;
+        }
+        else
+        {
+            // 闈炴渶鍚庝竴鍑�: 鎸夋潈閲嶈绠�
+            currentHitTotalDamage = (long)((float)totalDamage * (float)currentHitWeight / (float)totalWeight);
+        }
+
+        // ============ 绗簩姝�: 灏嗗綋鍓嶈繖涓�鍑荤殑浼ゅ鍒嗛厤鍒板悇鍒嗘 ============
+        List<long> fixedDamageList = new List<long>();
+        long accumulatedDamage = 0;
+
+        for (int i = 0; i < currentHitDivide.Length; i++)
+        {
+            long damage;
+            
+            // 褰撳墠鍑荤殑鏈�鍚庝竴娈佃繘琛岃宸ˉ鍋�
+            if (i == currentHitDivide.Length - 1)
+            {
+                damage = currentHitTotalDamage - accumulatedDamage;
+            }
+            else
+            {
+                // 鎸夊綋鍓嶅嚮鐨勬潈閲嶅垎閰�
+                damage = (long)((float)currentHitTotalDamage * (float)currentHitDivide[i] / (float)currentHitWeight);
+                accumulatedDamage += damage;
+            }
+            
+            fixedDamageList.Add(damage);
+        }
+
+        return fixedDamageList;
     }
 
     /// <summary>
@@ -260,16 +412,53 @@
     /// </summary>
     public static List<long> DivideDamageToList(int[] damageDivide, long totalDamage)
     {
+        if (damageDivide == null || damageDivide.Length == 0)
+        {
+            Debug.LogError("damageDivide 涓虹┖鎴栭暱搴︿负0");
+            return new List<long> { totalDamage };
+        }
+
         List<long> fixedDamageList = new List<long>();
+        long accumulatedDamage = 0; // 绱宸插垎閰嶇殑浼ゅ
 
         for (int i = 0; i < damageDivide.Length; i++)
         {
-            float fixedDamage = (float)totalDamage * (float)damageDivide[i] / 10000f;
-            fixedDamageList.Add((int)fixedDamage);
+            long damage;
+            
+            // 鏈�鍚庝竴娆″垎閰嶏細鐢ㄦ�讳激瀹冲噺鍘诲凡鍒嗛厤鐨勪激瀹筹紝纭繚鎬诲拰绮剧‘
+            if (i == damageDivide.Length - 1)
+            {
+                damage = totalDamage - accumulatedDamage;
+            }
+            else
+            {
+                // 璁$畻褰撳墠鍒嗘浼ゅ锛堝悜涓嬪彇鏁达級
+                damage = (long)((float)totalDamage * (float)damageDivide[i] / 10000f);
+                accumulatedDamage += damage;
+            }
+            
+            fixedDamageList.Add(damage);
         }
-        
+
         return fixedDamageList;
     }
+    
+    public static HB419_tagSCObjHPRefresh FindObjHPRefreshPack(List<GameNetPackBasic> packList)
+    {
+        for (int i = 0; i < packList.Count; i++)
+        {
+            var pack = packList[i];
+            if (pack is HB419_tagSCObjHPRefresh hpRefreshPack)
+            {
+                return hpRefreshPack;
+            }
+            else if (pack is CustomHB426CombinePack)
+            {
+                break;
+            }
+        }
+        return null;
+    }
 
     public static List<HB422_tagMCTurnFightObjDead> FindDeadPack(List<GameNetPackBasic> packList)
     {

--
Gitblit v1.8.0