static void Postfix(MechDef def, BattleTech.StatTooltipData __instance) { HeatConstantsDef heatConstants = ModBase.combatConstants.Heat; float total_heat_sinking = heatConstants.InternalHeatSinkCount * heatConstants.DefaultHeatSinkDissipationCapacity; float extra_engine_heat_sinking = BTMechDef.GetExtraEngineSinking(def); total_heat_sinking += extra_engine_heat_sinking; float heat_sinking_ratio = 1; float total_weapon_heat = 0; float weapon_heat_ratio = 1; float jump_distance = BTMechDef.GetJumpJetsMaxDistance(def); int max_heat = heatConstants.MaxHeat; foreach (MechComponentRef mechComponentRef in def.Inventory) { if (mechComponentRef.Def == null) { mechComponentRef.RefreshComponentDef(); } // Weapon total heat if (mechComponentRef.Def is WeaponDef weapon) { total_weapon_heat += (float)weapon.HeatGenerated; } // Heat sink total dissipation else if (mechComponentRef.Def is HeatSinkDef heat_sink) { total_heat_sinking += heat_sink.DissipationCapacity; } // Bank/Exchanger effects if (mechComponentRef.Def.statusEffects != null) { foreach (EffectData effect in mechComponentRef.Def.statusEffects) { StatisticEffectData statisticData = effect.statisticData; if (statisticData.statName == "MaxHeat") { BTStatistics.ApplyEffectStatistic(statisticData, ref max_heat); } else if (statisticData.statName == "HeatGenerated" && (statisticData.targetCollection == StatisticEffectData.TargetCollection.Weapon || BTStatistics.IsWildcardStatistic(statisticData))) { BTStatistics.ApplyEffectStatistic(statisticData, ref weapon_heat_ratio); } else if (statisticData.statName == "JumpDistanceMultiplier") { BTStatistics.ApplyEffectStatistic(statisticData, ref jump_distance); } } } } total_weapon_heat *= weapon_heat_ratio; total_heat_sinking *= heat_sinking_ratio; if (extra_engine_heat_sinking > 0f) { __instance.dataList.Add("Heat dissipation", string.Format("{0}\n(DHS)", (int)total_heat_sinking)); } else { __instance.dataList.Add("Heat dissipation", string.Format("{0}", (int)total_heat_sinking)); } if (total_weapon_heat > 0) { __instance.dataList.Add("Alpha strike heat", string.Format("{0}", (int)total_weapon_heat)); __instance.dataList.Add("Alpha strike heat delta", string.Format("{0}", (int)(total_weapon_heat - total_heat_sinking))); } __instance.dataList.Add("Max heat capacity", string.Format("{0}", (int)max_heat)); if (jump_distance > 0) { float max_jump_heat = ((jump_distance / heatConstants.JumpHeatUnitSize) + 1) * heatConstants.JumpHeatPerUnit; max_jump_heat *= heatConstants.GlobalHeatIncreaseMultiplier; max_jump_heat = Mathf.Max(heatConstants.JumpHeatMin, max_jump_heat); __instance.dataList.Add("Max jump heat", string.Format("{0}", (int)max_jump_heat)); } }
static void Postfix(object data, ref bool __result, BattleTech.UI.Tooltips.TooltipPrefab_Generic __instance) { if (!__result || ModBase.currentMech == null) { return; } if ((ModBase.Sim == null || ModBase.Sim.CurRoomState != DropshipLocation.MECH_BAY) && !ModBase.inMechLab) { return; } if (ModBase.combatConstants == null) { ModBase.combatConstants = CombatGameConstants.CreateFromSaved(UnityGameInstance.BattleTechGame); } MechDef currentMech = ModBase.currentMech; ChassisDef currentChassis = currentMech.Chassis; BaseDescriptionDef baseDescriptionDef = (BaseDescriptionDef)data; string extra_stats = string.Empty; switch (baseDescriptionDef.Id) { case "TooltipMechPerformanceFirepower": float alpha_damage = 0; float alpha_instability = 0; float alpha_heat = 0; // Calculate alpha strike total damage, heat damage and instability. foreach (MechComponentRef mechComponentRef in currentMech.Inventory) { if (mechComponentRef.Def is WeaponDef weapon) { alpha_damage += weapon.Damage * weapon.ShotsWhenFired; alpha_instability += weapon.Instability * weapon.ShotsWhenFired; alpha_heat += weapon.HeatDamage * weapon.ShotsWhenFired; } } if (alpha_damage > 0) { if (alpha_heat > 0) { extra_stats += string.Format("Alpha strike damage: <b>{0}</b> ( <b>{1} H</b> )\n", alpha_damage, alpha_heat); } else { extra_stats += string.Format("Alpha strike damage: <b>{0}</b>\n", alpha_damage); } } if (alpha_instability > 0) { extra_stats += string.Format("Alpha strike stability damage: <b>{0}</b>\n", alpha_instability); } break; case "TooltipMechPerformanceHeat": HeatConstantsDef heatConstants = ModBase.combatConstants.Heat; float total_heat_sinking = heatConstants.InternalHeatSinkCount * heatConstants.DefaultHeatSinkDissipationCapacity; float extra_engine_heat_sinking = BTMechDef.GetExtraEngineSinking(currentMech); total_heat_sinking += extra_engine_heat_sinking; float heat_sinking_ratio = 1; float total_weapon_heat = 0; float weapon_heat_ratio = 1; float jump_distance = BTMechDef.GetJumpJetsMaxDistance(currentMech); int max_heat = heatConstants.MaxHeat; foreach (MechComponentRef mechComponentRef in currentMech.Inventory) { if (mechComponentRef.Def == null) { mechComponentRef.RefreshComponentDef(); } // Weapon total heat if (mechComponentRef.Def is WeaponDef weapon) { total_weapon_heat += (float)weapon.HeatGenerated; } // Heat sink total dissipation else if (mechComponentRef.Def is HeatSinkDef heat_sink) { total_heat_sinking += heat_sink.DissipationCapacity; } // Bank/Exchanger effects if (mechComponentRef.Def.statusEffects != null) { foreach (EffectData effect in mechComponentRef.Def.statusEffects) { StatisticEffectData statisticData = effect.statisticData; if (statisticData.statName == "MaxHeat") { BTStatistics.ApplyEffectStatistic(statisticData, ref max_heat); } else if (statisticData.statName == "HeatGenerated" && statisticData.targetCollection == StatisticEffectData.TargetCollection.Weapon) { BTStatistics.ApplyEffectStatistic(statisticData, ref weapon_heat_ratio); } else if (statisticData.statName == "JumpDistanceMultiplier") { BTStatistics.ApplyEffectStatistic(statisticData, ref jump_distance); } } } } total_weapon_heat *= weapon_heat_ratio; total_heat_sinking *= heat_sinking_ratio; extra_stats += string.Format("Heat dissipation: <b>{0}</b>\n", (int)total_heat_sinking); if (extra_engine_heat_sinking > 0f) { extra_stats += "Engine heat sinks: <b>double</b>\n"; } if (total_weapon_heat > 0) { extra_stats += string.Format("Alpha strike heat: <b>{0}</b>\n", (int)total_weapon_heat); extra_stats += string.Format("Alpha strike heat delta: <b>{0}</b>\n", (int)(total_weapon_heat - total_heat_sinking)); } extra_stats += string.Format("Max heat capacity: <b>{0}</b>\n", (int)max_heat); if (jump_distance > 0) { float max_jump_heat = ((jump_distance / heatConstants.JumpHeatUnitSize) + 1) * heatConstants.JumpHeatPerUnit; max_jump_heat *= heatConstants.GlobalHeatIncreaseMultiplier; max_jump_heat = Mathf.Max(heatConstants.JumpHeatMin, max_jump_heat); extra_stats += string.Format("Max jump heat: <b>{0}</b>\n", (int)max_jump_heat); } break; case "TooltipMechPerformanceSpeed": float max_walk_distance = currentChassis.MovementCapDef.MaxWalkDistance; float max_sprint_distance = currentChassis.MovementCapDef.MaxSprintDistance; float max_jump_distance = BTMechDef.GetJumpJetsMaxDistance(currentMech); foreach (MechComponentRef mechComponentRef in currentMech.Inventory) { if (mechComponentRef.Def == null) { mechComponentRef.RefreshComponentDef(); } // Various movement effects if (mechComponentRef.Def.statusEffects != null) { foreach (EffectData effect in mechComponentRef.Def.statusEffects) { StatisticEffectData statisticData = effect.statisticData; if (statisticData.statName == "WalkSpeed") { BTStatistics.ApplyEffectStatistic(statisticData, ref max_walk_distance); } else if (statisticData.statName == "RunSpeed") { BTStatistics.ApplyEffectStatistic(statisticData, ref max_sprint_distance); } else if (statisticData.statName == "JumpDistanceMultiplier") { BTStatistics.ApplyEffectStatistic(statisticData, ref max_jump_distance); } } } } extra_stats += string.Format("Walk distance: <b>{0}m</b>\n", (int)max_walk_distance); extra_stats += string.Format("Sprint distance: <b>{0}m</b>\n", (int)max_sprint_distance); if (max_jump_distance > 0) { extra_stats += string.Format("Jump distance: <b>{0}m</b>\n", (int)max_jump_distance); } break; case "TooltipMechPerformanceMelee": float melee_damage = currentChassis.MeleeDamage; float melee_instability = currentChassis.MeleeInstability; float dfa_damage = currentChassis.DFADamage * 2; float dfa_instability = currentChassis.DFAInstability; float dfa_self_damage = currentChassis.DFASelfDamage; float support_damage = 0; float support_heat = 0; foreach (MechComponentRef mechComponentRef in currentMech.Inventory) { if (mechComponentRef.Def == null) { mechComponentRef.RefreshComponentDef(); } // Take Melee/DFA upgrades into account if (mechComponentRef.Def.statusEffects != null) { foreach (EffectData effect in mechComponentRef.Def.statusEffects) { if (effect.effectType != EffectType.StatisticEffect) { continue; } if (effect.statisticData.targetWeaponSubType == WeaponSubType.Melee) { if (effect.statisticData.statName == "DamagePerShot") { BTStatistics.ApplyEffectStatistic(effect.statisticData, ref melee_damage); } else if (effect.statisticData.statName == "Instability") { BTStatistics.ApplyEffectStatistic(effect.statisticData, ref melee_instability); } } else if (effect.statisticData.targetWeaponSubType == WeaponSubType.DFA) { if (effect.statisticData.statName == "DamagePerShot") { BTStatistics.ApplyEffectStatistic(effect.statisticData, ref dfa_damage); } else if (effect.statisticData.statName == "Instability") { BTStatistics.ApplyEffectStatistic(effect.statisticData, ref dfa_instability); } else if (effect.statisticData.statName == "DFASelfDamage") { BTStatistics.ApplyEffectStatistic(effect.statisticData, ref dfa_self_damage); } } } } // Calculate support weapon damage if (mechComponentRef.Def is WeaponDef weapon && weapon.Category == WeaponCategory.AntiPersonnel) { support_damage += weapon.Damage * weapon.ShotsWhenFired; support_heat += weapon.HeatDamage * weapon.ShotsWhenFired; } } extra_stats += string.Format("Melee damage: <b>{0}</b> ( Stability: <b>{1}</b> )\n", (int)melee_damage, (int)melee_instability); if (BTMechDef.GetJumpJetsAmount(currentMech) > 0) { extra_stats += string.Format("DFA damage: <b>{0}</b> ( Stability: <b>{1}</b> )\n", (int)dfa_damage, (int)dfa_instability); extra_stats += string.Format("DFA self-damage: <b>{0}</b> ( per leg )\n", (int)dfa_self_damage); } if (support_damage > 0) { if (support_heat > 0) { extra_stats += string.Format("Support weapons damage: <b>{0}</b> ( <b>{1} H</b> )\n", support_damage, support_heat); } else { extra_stats += string.Format("Support weapons damage: <b>{0}</b>\n", support_damage); } } break; // No idea what to put on those two. Feel free to contribute. case "TooltipMechPerformanceRange": break; case "TooltipMechPerformanceDurability": break; } if (extra_stats.Length != 0) { TextMeshProUGUI body = (TextMeshProUGUI)ReflectionHelper.GetPrivateField(__instance, "body"); body.text = string.Format("{0}\n{1}", extra_stats, body.text); } }