static void Postfix(SGContractsWidget __instance, Contract contract) { SimGameState Sim = (SimGameState)ReflectionHelper.GetPrivateProperty(__instance, "Sim"); int MinSalvage = Sim.Constants.Finances.ContractFloorSalvageBonus; int MaxSalvage = Sim.Constants.Salvage.DefaultSalvagePotential; if (contract.Override.salvagePotential > -1) { MaxSalvage = contract.Override.salvagePotential; } else if (contract.SalvagePotential > -1) { MaxSalvage = contract.SalvagePotential; } if (MaxSalvage > 0) { MaxSalvage = MaxSalvage + MinSalvage; } TextMeshProUGUI NegSalvageMin = (TextMeshProUGUI)ReflectionHelper.GetPrivateField(__instance, "NegSalvageMin"); TextMeshProUGUI NegSalvageMax = (TextMeshProUGUI)ReflectionHelper.GetPrivateField(__instance, "NegSalvageMax"); NegSalvageMin.text = string.Format("{0} / {1}", Math.Floor(MinSalvage / 4f), MinSalvage); NegSalvageMax.text = string.Format("{0} / {1}", Math.Floor(MaxSalvage / 4f), MaxSalvage); }
static void Postfix(MechLabMechInfoWidget __instance) { MechLabHardpointElement[] hardpoints = (MechLabHardpointElement[])ReflectionHelper.GetPrivateField(__instance, "hardpoints"); MechLabPanel mechLab = (MechLabPanel)ReflectionHelper.GetPrivateField(__instance, "mechLab"); var all_locations = new List <MechLabLocationWidget> { mechLab.headWidget, mechLab.centerTorsoWidget, mechLab.leftTorsoWidget, mechLab.rightTorsoWidget, mechLab.leftArmWidget, mechLab.rightArmWidget, mechLab.leftLegWidget, mechLab.rightLegWidget }; int totalBallisticHardpoints = 0; int totalEnergyHardpoints = 0; int totalMissileHardpoints = 0; int totalSmallHardpoints = 0; int currentBallisticCount = 0; int currentEnergyCount = 0; int currentMissileCount = 0; int currentSmallCount = 0; foreach (var location in all_locations) { totalBallisticHardpoints += location.totalBallisticHardpoints; totalEnergyHardpoints += location.totalEnergyHardpoints; totalMissileHardpoints += location.totalMissileHardpoints; totalSmallHardpoints += location.totalSmallHardpoints; currentBallisticCount += (int)ReflectionHelper.GetPrivateField(location, "currentBallisticCount"); currentEnergyCount += (int)ReflectionHelper.GetPrivateField(location, "currentEnergyCount"); currentMissileCount += (int)ReflectionHelper.GetPrivateField(location, "currentMissileCount"); currentSmallCount += (int)ReflectionHelper.GetPrivateField(location, "currentSmallCount"); } ; hardpoints[0].SetData(WeaponCategory.Ballistic, string.Format("{0}/{1}", currentBallisticCount, totalBallisticHardpoints)); hardpoints[1].SetData(WeaponCategory.Energy, string.Format("{0}/{1}", currentEnergyCount, totalEnergyHardpoints)); hardpoints[2].SetData(WeaponCategory.Missile, string.Format("{0}/{1}", currentMissileCount, totalMissileHardpoints)); hardpoints[3].SetData(WeaponCategory.AntiPersonnel, string.Format("{0}/{1}", currentSmallCount, totalSmallHardpoints)); }
static void Postfix(MechBayMechInfoWidget __instance) { ModBase.Sim = __instance.sim; ModBase.mechBay = (MechBayPanel)ReflectionHelper.GetPrivateField(__instance, "mechBay"); ModBase.currentMech = (MechDef)ReflectionHelper.GetPrivateField(__instance, "selectedMech"); }
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); } }