| | |
| | | public static Dictionary<string, ulong> largestPackUID = new Dictionary<string, ulong>(); |
| | | public static Dictionary<string, Dictionary<long, long>> largestPackUIDAllObjectsToHp = new Dictionary<string, Dictionary<long, long>>(); |
| | | public static Dictionary<string, Dictionary<long, long>> largestPackUIDAllObjectsMaxHp = new Dictionary<string, Dictionary<long, long>>(); |
| | | public static Dictionary<string, Dictionary<long, ulong>> objectLargestPackUID = new Dictionary<string, Dictionary<long, ulong>>(); |
| | | |
| | | protected void OnDisable() |
| | | { |
| | |
| | | long objID = battleObject.ObjID; |
| | | ulong currentPackUID = dmgInfo.battleHurtParam.packUID; |
| | | |
| | | // 检查是否是最新的 PackUID,如果不是则忽略 |
| | | if (!largestPackUID.ContainsKey(guid) || currentPackUID < largestPackUID[guid]) |
| | | // 获取该战场的对象PackUID字典(用于按角色+角色身份粒度判断) |
| | | Dictionary<long, ulong> objPackUIDDict = null; |
| | | if (objectLargestPackUID.ContainsKey(guid)) |
| | | { |
| | | // Debug.LogWarning($"[ExecuteDamageUpdate] 忽略旧包 - ObjID:{objID}, 当前PackUID:{currentPackUID} < 最大PackUID:{largestPackUID[guid]}"); |
| | | return; |
| | | objPackUIDDict = objectLargestPackUID[guid]; |
| | | } |
| | | |
| | | long maxHp, fromHp, toHp, fromShield, toShield; |
| | |
| | | BattleHurtObj hurter = dmgInfo.battleHurtParam.hurter; |
| | | if (hurter?.hurtObj != null && hurter.hurtObj.ObjID == objID) |
| | | { |
| | | // 按对象+受击者身份检查PackUID,避免不同身份(hurter/caster)的包互相阻拦 |
| | | long hurterKey = objID * 2; // hurter用偶数key |
| | | if (objPackUIDDict != null |
| | | && objPackUIDDict.ContainsKey(hurterKey) |
| | | && currentPackUID < objPackUIDDict[hurterKey]) |
| | | { |
| | | // Debug.LogWarning($"[ExecuteDamageUpdate] 忽略旧包(受击者) - ObjID:{objID}, 当前PackUID:{currentPackUID} < 对象受击最大PackUID:{objPackUIDDict[hurterKey]}"); |
| | | return; |
| | | } |
| | | |
| | | // 当前InfoBar是受击者(包括给自己治疗、给自己造成伤害的情况) |
| | | if (hurter.hurtObj.IsTianziBoss()) |
| | | { |
| | |
| | | fromShield = hurter.fromShieldValue; |
| | | toShield = hurter.toShieldValue; |
| | | |
| | | // 更新该对象作为受击者的最大PackUID |
| | | if (objPackUIDDict != null) |
| | | { |
| | | objPackUIDDict[hurterKey] = currentPackUID; |
| | | } |
| | | |
| | | // Debug.LogError($"[ExecuteDamageUpdate] 受击者 - ObjID:{objID}, fromHp:{fromHp}, toHp:{toHp}, maxHp:{maxHp} (PackUID:{currentPackUID})"); |
| | | } |
| | | // 其次判断是否为施法者(施法消耗生命等情况) |
| | |
| | | if (caster?.casterObj == null || caster.casterObj.ObjID != objID) |
| | | { |
| | | // Debug.LogWarning($"[ExecuteDamageUpdate] 当前对象 {objID} 既不是施法者也不是受击者"); |
| | | return; |
| | | } |
| | | |
| | | // 按对象+施法者身份检查PackUID |
| | | long casterKey = objID * 2 + 1; // caster用奇数key |
| | | if (objPackUIDDict != null |
| | | && objPackUIDDict.ContainsKey(casterKey) |
| | | && currentPackUID < objPackUIDDict[casterKey]) |
| | | { |
| | | // Debug.LogWarning($"[ExecuteDamageUpdate] 忽略旧包(施法者) - ObjID:{objID}, 当前PackUID:{currentPackUID} < 对象施法最大PackUID:{objPackUIDDict[casterKey]}"); |
| | | return; |
| | | } |
| | | |
| | |
| | | toHp = caster.toHp; |
| | | fromShield = caster.fromShieldValue; |
| | | toShield = caster.toShieldValue; |
| | | |
| | | // 更新该对象作为施法者的最大PackUID |
| | | if (objPackUIDDict != null) |
| | | { |
| | | objPackUIDDict[casterKey] = currentPackUID; |
| | | } |
| | | |
| | | // Debug.LogError($"[ExecuteDamageUpdate] 施法者 - ObjID:{objID}, fromHp:{fromHp}, toHp:{toHp}, maxHp:{maxHp} (PackUID:{currentPackUID})"); |
| | | } |
| | |
| | | { |
| | | largestPackUIDAllObjectsMaxHp[guid] = new Dictionary<long, long>(); |
| | | } |
| | | if (!objectLargestPackUID.ContainsKey(guid)) |
| | | { |
| | | objectLargestPackUID[guid] = new Dictionary<long, ulong>(); |
| | | } |
| | | |
| | | ulong currentLargestPackUID = largestPackUID[guid]; |
| | | Dictionary<long, long> hpDict = largestPackUIDAllObjectsToHp[guid]; |
| | | Dictionary<long, long> maxHpDict = largestPackUIDAllObjectsMaxHp[guid]; |
| | | Dictionary<long, ulong> objPackUIDDict = objectLargestPackUID[guid]; |
| | | |
| | | // 如果遇到更大的packUID,更新标记(不清空数据,保留所有证据) |
| | | if (currentPackUID > currentLargestPackUID) |
| | |
| | | long maxHp = battleCastObj.maxHp; |
| | | long hpChange = newHp - oldHp; |
| | | |
| | | // 只有当前packUID等于最大packUID时才更新记录 |
| | | if (currentPackUID == currentLargestPackUID) |
| | | // 只有当前packUID不小于该对象的最大packUID时才更新记录 |
| | | ulong casterLastPackUID = objPackUIDDict.ContainsKey(casterID) ? objPackUIDDict[casterID] : 0ul; |
| | | if (currentPackUID >= casterLastPackUID) |
| | | { |
| | | hpDict[casterID] = newHp; |
| | | maxHpDict[casterID] = maxHp; |
| | | objPackUIDDict[casterID] = currentPackUID; |
| | | |
| | | // 打印血量变化日志(施法者通常是恢复生命) |
| | | // string casterName = caster.casterObj.teamHero?.heroConfig.Name ?? "未知武将"; |
| | |
| | | } |
| | | else |
| | | { |
| | | // Debug.LogWarning($"[血量记录] 忽略旧包数据 - 施法者{casterID}, 当前PackUID:{currentPackUID} < 最大PackUID:{currentLargestPackUID}"); |
| | | // Debug.LogWarning($"[血量记录] 忽略旧包数据 - 施法者{casterID}, 当前PackUID:{currentPackUID} < 对象最大PackUID:{casterLastPackUID}"); |
| | | } |
| | | } |
| | | |
| | |
| | | long maxHp = battleHurtObj.maxHp; |
| | | long damage = oldHp - newHp; |
| | | |
| | | // 只有当前packUID等于最大packUID时才更新记录 |
| | | if (currentPackUID == currentLargestPackUID) |
| | | // 只有当前packUID不小于该对象的最大packUID时才更新记录 |
| | | ulong hurterLastPackUID = objPackUIDDict.ContainsKey(hurterID) ? objPackUIDDict[hurterID] : 0ul; |
| | | if (currentPackUID >= hurterLastPackUID) |
| | | { |
| | | hpDict[hurterID] = newHp; |
| | | maxHpDict[hurterID] = maxHp; |
| | | objPackUIDDict[hurterID] = currentPackUID; |
| | | |
| | | // 打印血量变化日志 |
| | | // string hurterName = hurter.hurtObj.teamHero?.heroConfig.Name ?? "未知武将"; |
| | |
| | | } |
| | | else |
| | | { |
| | | // Debug.LogWarning($"[血量记录] 忽略旧包数据 - 受击者{hurterID}, 当前PackUID:{currentPackUID} < 最大PackUID:{currentLargestPackUID}"); |
| | | // Debug.LogWarning($"[血量记录] 忽略旧包数据 - 受击者{hurterID}, 当前PackUID:{currentPackUID} < 对象最大PackUID:{hurterLastPackUID}"); |
| | | } |
| | | } |
| | | } |
| | |
| | | // TODO: 显示buff描述/当前身上所有buff |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 清理指定战场的静态PackUID和血量记录 |
| | | /// </summary> |
| | | public static void ClearStaticBattleData(string guid) |
| | | { |
| | | largestPackUID.Remove(guid); |
| | | largestPackUIDAllObjectsToHp.Remove(guid); |
| | | largestPackUIDAllObjectsMaxHp.Remove(guid); |
| | | objectLargestPackUID.Remove(guid); |
| | | } |
| | | |
| | | public void HaveRest() |
| | | { |
| | | CleanupTips(); |