From ed98029a88cd89702980ac7c40b711afddc5aeb2 Mon Sep 17 00:00:00 2001
From: hch <305670599@qq.com>
Date: 星期四, 20 十一月 2025 14:44:59 +0800
Subject: [PATCH] Merge branch 'master' of http://mobile.secondworld.net.cn:10010/r/Project_SG_scripts

---
 Main/System/Battle/BattleUtility.cs |  189 ++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 178 insertions(+), 11 deletions(-)

diff --git a/Main/System/Battle/BattleUtility.cs b/Main/System/Battle/BattleUtility.cs
index 3a5e7ee..ca43d82 100644
--- a/Main/System/Battle/BattleUtility.cs
+++ b/Main/System/Battle/BattleUtility.cs
@@ -114,8 +114,8 @@
 
         string result = string.Empty;
 
-        //  濡傛灉鏄棯閬� 鍒欏彧鏄剧ず闂伩涓や釜瀛�
-        if (damage.IsType(DamageType.Dodge))
+        //  濡傛灉鏄棯閬挎垨鍏嶇柅 鍒欏彧鏄剧ず瀵瑰簲鏂囧瓧锛屼笉鏄剧ず鏁板瓧
+        if (damage.IsType(DamageType.Dodge) || damage.IsType(DamageType.Immune))
         {
             result += (char)config.prefix;
         }
@@ -127,7 +127,7 @@
         return result;
     }
 
-    static string ConvertToArtFont(DamageNumConfig config, float _num)
+    public static string ConvertToArtFont(DamageNumConfig config, float _num)
     {
         var stringBuild = new System.Text.StringBuilder();
 
@@ -150,7 +150,7 @@
         return stringBuild.ToString();
     }
 
-    public static int GetMainTargetPositionNum(BattleObject caster, List<HB427_tagSCUseSkill.tagSCUseSkillHurt> targetList, SkillConfig skillConfig)
+    public static int GetMainTargetPositionNum(SkillBase skillBase, BattleObject caster, List<HB427_tagSCUseSkill.tagSCUseSkillHurt> targetList, SkillConfig skillConfig)
     {
         int returnIndex = 0;
         //  鏍规嵁鏁屾柟琛�閲忛樀钀� 瀛樻椿浜烘暟鏉ラ�夋嫨
@@ -185,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);
@@ -272,6 +272,11 @@
             case 5:
                 returnIndex = caster.teamHero.positionNum;
                 break;
+            case 6:
+                //  璺熼殢涓绘妧鑳界殑鐩爣
+                var fromSkill = skillBase.fromSkill;
+                returnIndex = GetMainTargetPositionNum(fromSkill, fromSkill.caster, fromSkill.tagUseSkillAttack.HurtList.ToList(), fromSkill.skillConfig);
+                break;
             default:
                 Debug.LogError("鏆傛椂涓嶆敮鎸佸叾浠栫殑鏂瑰紡閫夋嫨涓荤洰鏍� 鏈夐渶姹傝鑱旂郴绛栧垝 鎶�鑳絠d:" + skillConfig.SkillID + " TagAim " + skillConfig.TagAim);
                 returnIndex = 0;
@@ -283,18 +288,143 @@
 
     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];
+    }
+
+    public static bool IsHealing(HB427_tagSCUseSkill.tagSCUseSkillHurt hurt)
+    {
+        return ((hurt.AttackTypes & (int)ServerDamageType.Recovery) != 0 || 
+                          (hurt.AttackTypes & (int)ServerDamageType.DamageReverse) != 0) &&
+                         (hurt.AttackTypes & (int)ServerDamageType.Damage) == 0 &&
+                         (hurt.AttackTypes & (int)ServerDamageType.Realdamage) == 0 &&
+                         (hurt.AttackTypes & (int)ServerDamageType.SuckHpReverse) == 0 &&
+                         (hurt.AttackTypes & (int)ServerDamageType.SelfHarm) == 0;
+    }
+    
+    /// <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 (totalDamage <= 0)
+        {
+            return new List<long>{};
+        }
+
+        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>
@@ -302,16 +432,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