From b75bf9422e886b9bda37d5e3e2acf975b304ffc4 Mon Sep 17 00:00:00 2001
From: yyl <yyl>
Date: 星期三, 05 十一月 2025 16:47:25 +0800
Subject: [PATCH] 125 战斗血量问题修复
---
Main/System/Battle/BattleUtility.cs | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 114 insertions(+), 4 deletions(-)
diff --git a/Main/System/Battle/BattleUtility.cs b/Main/System/Battle/BattleUtility.cs
index a315880..201d318 100644
--- a/Main/System/Battle/BattleUtility.cs
+++ b/Main/System/Battle/BattleUtility.cs
@@ -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);
@@ -283,19 +283,129 @@
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>
/// 淇濊瘉鎵�鏈夊垎閰嶉」鍔犺捣鏉ョ瓑浜巘otalDamage锛岄伩鍏嶅洜鏁撮櫎瀵艰嚧鐨勮宸�
--
Gitblit v1.8.0