public static void Postfix(SGBarracksRosterSlot __instance) { if (__instance.Pilot == null) { return; } HBSTooltip tooltip = __instance.gameObject.GetComponent <HBSTooltip>() ?? __instance.gameObject.AddComponent <HBSTooltip>(); Pilot pilot = __instance.Pilot; string Desc = tooltip.GetText(); if (String.IsNullOrEmpty(Desc)) { Desc = ""; } foreach (PilotTooltipTag pqTag in Main.settings.pqTooltipTags) { if (pilot.pilotDef.PilotTags.Contains(pqTag.tag)) { Desc += $"{pqTag.tooltipText}\n\n"; } } Desc += PilotQuirkManager.Instance.getPilotToolTip(pilot); Desc += "<b>Pilot Affinities:</b>\n\n"; Desc += PilotAffinityManager.Instance.getPilotToolTip(pilot); var descriptionDef = new BaseDescriptionDef("Tags", pilot.Callsign, Desc, null); tooltip.SetDefaultStateData(TooltipUtilities.GetStateDataFromObject(descriptionDef)); }
public static SimGameEventDef ModifyContractExpirationEventForPilot(Pilot pilot, CrewDetails details) { SimGameEventDef rawEventDef = ModState.SimGameState.DataManager.SimGameEventDefs.Get(ModConsts.Event_ContractExpired); // Change the description fields BaseDescriptionDef rawBaseDescDef = rawEventDef.Description; StringBuilder detailsSB = new StringBuilder(rawBaseDescDef.Details); detailsSB.Append("\n"); detailsSB.Append("<margin=5em>\n"); // TODO: Localize detailsSB.Append($" Hiring Bonus: {SimGameState.GetCBillString(details.AdjustedBonus)}\n\n"); detailsSB.Append($" Monthly Salary: {SimGameState.GetCBillString(details.AdjustedSalary)}\n\n"); detailsSB.Append("</margin>\n"); BaseDescriptionDef newBaseDescDef = new BaseDescriptionDef(rawBaseDescDef.Id, rawBaseDescDef.Name, detailsSB.ToString(), rawBaseDescDef.Icon); // Change the options to have the correct pay values SimGameEventOption[] newOptions = rawEventDef.Options; foreach (SimGameEventOption sgeOption in newOptions) { if (ModConsts.Event_Option_ContractExpired_Hire_Bonus.Equals(sgeOption.Description.Id)) { (Pilot Pilot, CrewDetails Details)expired = ModState.ExpiredContracts.Peek(); UpdateFundsStat(pilot, expired.Details.AdjustedBonus, sgeOption); } } SimGameEventDef expiredEventDef = new SimGameEventDef( rawEventDef.PublishState, rawEventDef.EventType, rawEventDef.Scope, newBaseDescDef, rawEventDef.Requirements, rawEventDef.AdditionalRequirements, rawEventDef.AdditionalObjects, newOptions, rawEventDef.Weight, rawEventDef.OneTimeEvent, rawEventDef.Tags); return(expiredEventDef); }
static void Postfix(MoraleTooltipData __instance, SimGameState sim, int moraleLevel) { try { SimGameState simGameState = sim ?? UnityGameInstance.BattleTechGame.Simulation; if (simGameState == null) { return; } // Get //BaseDescriptionDef levelDescription = (BaseDescriptionDef)AccessTools.Property(typeof(MoraleTooltipData), "levelDescription").GetValue(__instance, null); string levelDescriptionName = "Morale: " + simGameState.GetDescriptorForMoraleLevel(moraleLevel); string levelDescriptionDetails = "At this level of morale, you will gain " + __instance.resolvePerTurn + " Resolve points per round of battle."; //Logger.Debug("[MoraleTooltipData_Constructor_POSTFIX] levelDescriptionName: " + levelDescriptionName); //Logger.Debug("[MoraleTooltipData_Constructor_POSTFIX] levelDescriptionDetails: " + levelDescriptionDetails); BaseDescriptionDef customLevelDescription = new BaseDescriptionDef("TooltipMoraleCustom", levelDescriptionName, levelDescriptionDetails, ""); // Set //BaseDescriptionDef levelDescription = AccessTools.Property(typeof(MoraleTooltipData), "levelDescription").SetValue(__instance, customLevelDescription, null); new Traverse(__instance).Property("levelDescription").SetValue(customLevelDescription); } catch (Exception e) { Logger.Error(e); } }
static void Postfix(SimGameOptionsMenu __instance, HBSDOTweenButton ___saveGame, HBSTooltipHBSButton ___saveTooltip, HBSDOTweenButton ___restartMission, HBSTooltipHBSButton ___restartTooltip) { CombatGameState combatGameState = SharedState.Combat; if (combatGameState != null && !combatGameState.TurnDirector.IsMissionOver && combatGameState.TurnDirector.GameHasBegun) { Mod.Log.Trace?.Write("SGOM:CS - in combat."); if (Mod.Config.Fixes.DisableCombatRestarts) { Mod.Log.Debug?.Write("Disabling combat restarts."); ___restartMission.SetState(ButtonState.Disabled); string title = new Text(Mod.LocalizedText.Tooltips[ModText.TT_CombatRestartMission_Title]).ToString(); string details = new Text(Mod.LocalizedText.Tooltips[ModText.TT_CombatRestartMission_Details]).ToString(); BaseDescriptionDef def = new BaseDescriptionDef("SGMTipData", title, details, null); ___restartTooltip.SetStateDataForButtonState(ButtonState.Disabled, TooltipUtilities.GetStateDataFromObject(def)); } if (Mod.Config.Fixes.DisableCombatSaves && ___saveGame.State != ButtonState.Disabled) { Mod.Log.Debug?.Write("Disabling combat saves."); ___saveGame.SetState(ButtonState.Disabled); string title = new Text(Mod.LocalizedText.Tooltips[ModText.TT_CombatSave_Title]).ToString(); string details = new Text(Mod.LocalizedText.Tooltips[ModText.TT_CombatSave_Details]).ToString(); BaseDescriptionDef def = new BaseDescriptionDef("SGMTipData", title, details, null); ___saveTooltip.SetStateDataForButtonState(ButtonState.Disabled, TooltipUtilities.GetStateDataFromObject(def)); } } }
public static void Postfix(SGBarracksDossierPanel __instance, Pilot p, Image ___portrait) { if (p == null) { return; } var tooltip = ___portrait.gameObject.GetComponent <HBSTooltip>() ?? ___portrait.gameObject.AddComponent <HBSTooltip>(); var desc = tooltip.GetText(); if (String.IsNullOrEmpty(desc)) { desc = ""; } var specDesc = Descriptions.GetPilotSpecializationsOrProgress(p); desc += specDesc; var descDef = new BaseDescriptionDef("PilotSpecs", p.Callsign, desc, null); tooltip.SetDefaultStateData(TooltipUtilities.GetStateDataFromObject(descDef)); }
public static void Prefix(ref object data) { switch (data) { case DescriptionDef descriptionDef: { data = new BaseDescriptionDef(descriptionDef); break; } case StarSystemDef starSystemDef: { var simGame = UnityGameInstance.BattleTechGame.Simulation; if (simGame == null) { return; } if (simGame.StarSystemDictionary.ContainsKey(starSystemDef.CoreSystemID)) { data = simGame.StarSystemDictionary[starSystemDef.CoreSystemID]; } break; } } }
public static void Postfix(MechBayMechInfoWidget __instance, MechDef ___selectedMech, GameObject ___initiativeObj, TextMeshProUGUI ___initiativeText, HBSTooltip ___initiativeTooltip) { if (___initiativeObj == null || ___initiativeText == null) { return; } //SkillBasedInit.Logger.Log($"MechBayMechInfoWidget::SetInitiative::post - disabling text"); if (___selectedMech == null) { ___initiativeObj.SetActive(true); ___initiativeText.SetText("-"); } else { List <string> details = new List <string>(); // Static initiative from tonnage float tonnage = ___selectedMech.Chassis.Tonnage; int tonnageMod = UnitHelper.GetTonnageModifier(tonnage); details.Add($"Tonnage Base: {tonnageMod}"); // Any modifiers that come from the chassis/mech/vehicle defs int componentsMod = UnitHelper.GetNormalizedComponentModifier(___selectedMech); if (componentsMod > 0) { details.Add($"<space=2em><color=#00FF00>{componentsMod:+0} components</color>"); } else if (componentsMod < 0) { details.Add($"<space=2em><color=#FF0000>{componentsMod:0} components </color>"); } // Modifier from the engine int engineMod = UnitHelper.GetEngineModifier(___selectedMech); if (engineMod > 0) { details.Add($"<space=2em><color=#00FF00>{engineMod:+0} engine</color>"); } else if (engineMod < 0) { details.Add($"<space=2em><color=#FF0000>{engineMod:0} engine</color>"); } // --- Badge --- ___initiativeObj.SetActive(true); ___initiativeText.SetText($"{tonnageMod + componentsMod + engineMod}"); // --- Tooltip --- int maxInit = Math.Max(tonnageMod + componentsMod + engineMod, Mod.MinPhase); details.Add($"Expected Phase: <b>{maxInit}</b> "); string tooltipTitle = $"{___selectedMech.Name}"; string tooltipText = String.Join("\n", details.ToArray()); BaseDescriptionDef initiativeData = new BaseDescriptionDef("MB_MIW_MECH_TT", tooltipTitle, tooltipText, null); ___initiativeTooltip.enabled = true; ___initiativeTooltip.SetDefaultStateData(TooltipUtilities.GetStateDataFromObject(initiativeData)); } }
internal void SetData(BaseDescriptionDef description, string text, UIColor color) { Description = description; Text = text; Color = color; Refresh(); }
public static void SetTooltip(this GameObject go, List <Text> errors, string caption) { var tooltip = go.GetComponent <HBSTooltip>(); if (tooltip != null) { string text = errors.Join(i => i.ToString(), "\n"); var desc = new BaseDescriptionDef("tooltip", caption, text, null); tooltip.SetDefaultStateData(TooltipUtilities.GetStateDataFromObject(desc)); } }
public static SimGameEventDef CreateHeadHuntingEvent(Pilot pilot, CrewDetails details, float retentionCost, float buyoutPayment) { SimGameEventDef rawEventDef = ModState.SimGameState.DataManager.SimGameEventDefs.Get(ModConsts.Event_HeadHunting); int counterOffer = SalaryHelper.CalcCounterOffer(details) * -1; int buyout = details.AdjustedBonus; Mod.Log.Info?.Write($"For headhunting event, counterOffer: {counterOffer} buyout: {buyout}"); // Change the description fields BaseDescriptionDef rawBaseDescDef = rawEventDef.Description; StringBuilder detailsSB = new StringBuilder(rawBaseDescDef.Details); detailsSB.Append("\n\n"); detailsSB.Append("<margin=5em>\n"); detailsSB.Append( new Text(Mod.LocalizedText.Events[ModText.ET_HeadHunted_Retention], new object[] { SimGameState.GetCBillString(counterOffer) }).ToString() ); detailsSB.Append( new Text(Mod.LocalizedText.Events[ModText.ET_HeadHunted_Buyout], new object[] { SimGameState.GetCBillString(buyout) }).ToString() ); detailsSB.Append("</margin>\n"); BaseDescriptionDef newBaseDescDef = new BaseDescriptionDef(rawBaseDescDef.Id, rawBaseDescDef.Name, detailsSB.ToString(), rawBaseDescDef.Icon); // Change the options to have the correct pay values SimGameEventOption[] newOptions = rawEventDef.Options; foreach (SimGameEventOption sgeOption in newOptions) { if (ModConsts.Event_Option_HeadHunting_Leaves.Equals(sgeOption.Description.Id)) { // Mechwarrior leaves, company gets a payoff UpdateFundsStat(pilot, buyout, sgeOption); } else if (ModConsts.Event_Option_HeadHunting_Retained.Equals(sgeOption.Description.Id)) { // Mechwarrior statys, company pays them retention UpdateFundsStat(pilot, counterOffer, sgeOption); } } SimGameEventDef eventDef = new SimGameEventDef( rawEventDef.PublishState, rawEventDef.EventType, rawEventDef.Scope, newBaseDescDef, rawEventDef.Requirements, rawEventDef.AdditionalRequirements, rawEventDef.AdditionalObjects, newOptions, rawEventDef.Weight, rawEventDef.OneTimeEvent, rawEventDef.Tags); return(eventDef); }
protected virtual void SetTooltip(string caption, string text) { if (Tooltip == null) { return; } var loctext = new Text(text); var captest = new Text(caption); var desc = new BaseDescriptionDef("hardpoint", captest.ToString(), loctext.ToString(), HPInfo == null ? "" : HPInfo.WeaponCategory.Icon); Tooltip.SetDefaultStateData(TooltipUtilities.GetStateDataFromObject(desc)); }
// pass in a bunch of ___ variables so we can get access to private members of MechBayMechInfoObject. // And we'll return false so that the original function doesn't get called. public static bool Prefix(MechBayMechInfoWidget __instance, MechDef ___selectedMech, GameObject ___initiativeObj, TextMeshProUGUI ___initiativeText, HBSTooltip ___initiativeTooltip) { if (___initiativeObj == null || ___initiativeText == null) { return(false); } if (___selectedMech == null) { ___initiativeObj.SetActive(false); return(false); } ___initiativeObj.SetActive(true); int num = 1; // default to assault phase float f_walkSpeed = ___selectedMech.Chassis.MovementCapDef.MaxWalkDistance; if (f_walkSpeed >= TheEngineInitiative.Settings.MechPhaseSpecialMinSpeed) { num = 5; //special phase } else if (f_walkSpeed >= TheEngineInitiative.Settings.MechPhaseLightMinSpeed) { num = 4; //light phase } else if (f_walkSpeed >= TheEngineInitiative.Settings.MechPhaseMediumMinSpeed) { num = 3; //medium phase } else if (f_walkSpeed >= TheEngineInitiative.Settings.MechPhaseHeavyMinSpeed) { num = 2; //heavy phase } ___initiativeText.SetText($"{num}"); if (___initiativeTooltip != null) { // build the tooltip. Going to use the mech's name and tell where its speed puts it, initiative-wise. string tooltipTitle = $"{___selectedMech.Name}"; string tooltipText = "A max walking speed of " + $"{f_walkSpeed}" + "m per turn means this mech moves in initiative phase " + $"{num}" + "."; BaseDescriptionDef initiativeData = new BaseDescriptionDef("MB_MIW_MECH_TT", tooltipTitle, tooltipText, null); ___initiativeTooltip.enabled = true; ___initiativeTooltip.SetDefaultStateData(TooltipUtilities.GetStateDataFromObject(initiativeData)); } return(false); }
public static void Postfix(SGBarracksSkillPip __instance, SGBarracksSkillPip.PurchaseState purchaseState, bool canClick, bool showXP, bool needXP, bool isLocked, int ___idx, string ___type, HBSTooltip ___AbilityTooltip) { if (purchaseState == SGBarracksSkillPip.PurchaseState.Unselected) { var sim = UnityGameInstance.BattleTechGame.Simulation; var abilityDictionaries = sim.AbilityTree.Select(x => x.Value).ToList(); var abilityDefs = new List <AbilityDef>(); foreach (var abilityDictionary in abilityDictionaries) { abilityDefs.AddRange(abilityDictionary[___idx].Where(x => x.ReqSkill.ToString() == ___type)); } var title = $"{___type}: Level {___idx+1} Ability Options"; var desc = ""; foreach (var ability in abilityDefs) { var abilityFilter = modSettings.abilityReqs.Values.SelectMany(x => x).ToList(); List <AbilityDef> abilitiesWithReqs = abilityDefs.Where(x => abilityFilter.Any(y => y.Equals(x.Id))).ToList(); if (abilitiesWithReqs.Contains(ability)) { var reqAbilityName = modSettings.abilityReqs.FirstOrDefault(x => x.Value.Contains(ability.Description.Id)).Key; var allAbilities = new List <AbilityDef>(); allAbilities = sim.AbilityTree[___type].SelectMany(x => x.Value).ToList(); var reqAbility = allAbilities.Find(x => x.Id == reqAbilityName); // desc += "<b><u>" + ability.Description.Name + "</b></u> - Requires: " + reqAbility.Description.Name + "\n\n" + ability.Description.Details + "\n\n\n"; } else { desc += "<b><u>" + ability.Description.Name + "</b></u>\n\n" + ability.Description.Details + "\n\n\n"; } } var descDef = new BaseDescriptionDef("PilotSpecs", title, desc, null); ___AbilityTooltip.SetDefaultStateData(TooltipUtilities.GetStateDataFromObject(descDef)); } }
public static void SimGameOptionsMenu_SetSaveTooltip_Postfix(SimGameOptionsMenu __instance, HBSTooltipHBSButton ___saveTooltip, SaveReason ___reason, HBSDOTweenButton ___saveGame) { if (___saveTooltip == null) { return; } GameInstance battleTechGame = UnityGameInstance.BattleTechGame; CombatGameState combat = battleTechGame.Combat; if (combat != null && !combat.TurnDirector.IsMissionOver && combat.TurnDirector.GameHasBegun) { string details = "Saving during combat missions disabled to prevent errors and bugs."; BaseDescriptionDef def = new BaseDescriptionDef("SGMTipData", "Unable to Save", details, null); ___saveTooltip.SetStateDataForButtonState(ButtonState.Disabled, TooltipUtilities.GetStateDataFromObject(def)); } }
public static void Postfix(SGBarracksRosterSlot __instance) { if (__instance.Pilot == null) { return; } var tooltip = __instance.gameObject.GetComponent <HBSTooltip>() ?? __instance.gameObject.AddComponent <HBSTooltip>(); var p = __instance.Pilot; string TagDesc = ""; if (p.pilotDef.PilotTags.Contains("pilot_fatigued")) { TagDesc += "<b>***PILOT FATIGUED***</b>\nPilot will suffer from Low Spirits if used in combat. The lance will also experience reduced Resolve per turn during combat.\n\n"; } else if (p.pilotDef.PilotTags.Contains("pilot_lightinjury")) { TagDesc += "<b>***PILOT LIGHT INJURY***</b>\nPilot cannot drop into combat. This pilot requires rest after dropping too frequently while fatigued.\n\n"; } foreach (var tag in p.pilotDef.PilotTags) { if (Pre_Control.settings.TagIDToDescription.Keys.Contains(tag)) { TagDesc += "<b>" + Pre_Control.settings.TagIDToNames[tag] + ": </b>" + Pre_Control.settings.TagIDToDescription[tag] + "\n\n"; } else if (tag == "PQ_Mech_Mastery") { TagDesc = MechMasterTagDescription(__instance.pilot, TagDesc); } } var descriptionDef = new BaseDescriptionDef("Tags", p.Callsign, TagDesc, null); tooltip.SetDefaultStateData(TooltipUtilities.GetStateDataFromObject(descriptionDef)); }
public static void Postfix(HBSTooltip RoninTooltip, Pilot pilot) { if (RoninTooltip != null) { string text; if (pilot.pilotDef.IsVanguard || pilot.pilotDef.IsRonin) { text = "UnitMechWarriorSpecial"; } else { if (pilot != UnityGameInstance.BattleTechGame.Simulation.Commander) { return; } text = "UnitMechWarriorCommander"; } if (!string.IsNullOrEmpty(text) && UnityGameInstance.BattleTechGame.DataManager.BaseDescriptionDefs.Exists(text)) { BaseDescriptionDef def = UnityGameInstance.BattleTechGame.DataManager.BaseDescriptionDefs.Get(text); RoninTooltip.SetDefaultStateData(TooltipUtilities.GetStateDataFromObject(def)); } } }
public static void Postfix(LanceLoadoutSlot __instance, GameObject ___initiativeObj, TextMeshProUGUI ___initiativeText, UIColorRefTracker ___initiativeColor, HBSTooltip ___initiativeTooltip, LanceConfiguratorPanel ___LC) { if (___initiativeObj == null || ___initiativeText == null || ___initiativeColor == null || ___initiativeTooltip == null) { return; } //SkillBasedInit.Logger.Log($"LanceLoadoutSlot::RefreshInitiativeData::post - disabling text"); bool bothSelected = __instance.SelectedMech != null && __instance.SelectedPilot != null; if (!bothSelected) { ___initiativeText.SetText("-"); ___initiativeColor.SetUIColor(UIColor.MedGray); } else { int initValue = 0; // --- MECH --- MechDef selectedMechDef = __instance.SelectedMech.MechDef; List <string> details = new List <string>(); // Static initiative from tonnage float tonnage = __instance.SelectedMech.MechDef.Chassis.Tonnage; int tonnageMod = UnitHelper.GetTonnageModifier(tonnage); initValue += tonnageMod; details.Add($"Tonnage Base: {tonnageMod}"); // Any special modifiers by type - NA, Mech is the only type // Any modifiers that come from the chassis/mech/vehicle defs int componentsMod = UnitHelper.GetNormalizedComponentModifier(selectedMechDef); initValue += componentsMod; if (componentsMod > 0) { details.Add($"<space=2em><color=#00FF00>{componentsMod:+0} components</color>"); } else if (componentsMod < 0) { details.Add($"<space=2em><color=#FF0000>{componentsMod:0} components</color>"); } // Modifier from the engine int engineMod = UnitHelper.GetEngineModifier(selectedMechDef); initValue += engineMod; if (engineMod > 0) { details.Add($"<space=2em><color=#00FF00>{engineMod:+0} engine</color>"); } else if (engineMod < 0) { details.Add($"<space=2em><color=#FF0000>{engineMod:0} engine</color>"); } // --- PILOT --- Pilot selectedPilot = __instance.SelectedPilot.Pilot; int tacticsMod = PilotHelper.GetTacticsModifier(selectedPilot); details.Add($"<space=2em>{tacticsMod:+0} tactics"); initValue += tacticsMod; int pilotTagsMod = PilotHelper.GetTagsModifier(selectedPilot); details.AddRange(PilotHelper.GetTagsModifierDetails(selectedPilot)); initValue += pilotTagsMod; int[] randomnessBounds = PilotHelper.GetRandomnessBounds(selectedPilot); // --- LANCE --- if (___LC != null) { initValue += ___LC.lanceInitiativeModifier; if (___LC.lanceInitiativeModifier > 0) { details.Add($"<space=2em><color=#00FF00>{___LC.lanceInitiativeModifier:+0} lance</color>"); } else if (___LC.lanceInitiativeModifier < 0) { details.Add($"<space=2em><color=#FF0000>{___LC.lanceInitiativeModifier:0} lance</color>"); } } // --- Badge --- ___initiativeText.SetText($"{initValue}"); ___initiativeText.color = Color.black; ___initiativeColor.SetUIColor(UIColor.White); // --- Tooltip --- int maxInit = Math.Max(initValue - randomnessBounds[0], Mod.MinPhase); int minInit = Math.Max(initValue - randomnessBounds[1], Mod.MinPhase); details.Add($"Total:{initValue}"); details.Add($"<space=2em><color=#FF0000>-{randomnessBounds[0]} to -{randomnessBounds[1]} randomness</color> (piloting)"); details.Add($"<b>Expected Phase<b>: {maxInit} to {minInit}"); string tooltipTitle = $"{selectedMechDef.Name}: {selectedPilot.Name}"; string tooltipText = String.Join("\n", details.ToArray()); BaseDescriptionDef initiativeData = new BaseDescriptionDef("LLS_MECH_TT", tooltipTitle, tooltipText, null); ___initiativeTooltip.enabled = true; ___initiativeTooltip.SetDefaultStateData(TooltipUtilities.GetStateDataFromObject(initiativeData)); } }
public static void Postfix(MechBayMechInfoWidget __instance, MechDef ___selectedMech, GameObject ___initiativeObj, TextMeshProUGUI ___initiativeText, HBSTooltip ___initiativeTooltip) { Mod.Log.Trace?.Write("MBMIW:SI:post - entered."); if (___initiativeObj == null || ___initiativeText == null) { return; } if (___selectedMech == null) { ___initiativeObj.SetActive(true); ___initiativeText.SetText("-"); } else { List <string> details = new List <string>(); // Static initiative from tonnage int initPhase = PhaseHelper.TonnageToPhase((int)Math.Ceiling(___selectedMech.Chassis.Tonnage)); int initLabelVal = (Mod.MaxPhase + 1) - initPhase; details.Add(new Text(Mod.Config.LocalizedText[ModConfig.LT_TT_BASE], new object[] { initLabelVal }).ToString()); // Any bonuses from equipment int componentBonus = UnitHelper.GetNormalizedComponentModifier(___selectedMech); string componentColor = "FFFFFF"; if (componentBonus > 0) { componentColor = "00FF00"; } if (componentBonus < 0) { componentColor = "FF0000"; } details.Add(new Text(Mod.Config.LocalizedText[ModConfig.LT_TT_COMPONENT], new object[] { componentColor, componentBonus }).ToString()); Mod.Log.Debug?.Write($"Component bonus is: {componentBonus}"); // No Lance bonus // No Pilot bonus // --- Badge --- int summaryInitLabel = initLabelVal + componentBonus; if (summaryInitLabel > Mod.MaxPhase) { summaryInitLabel = Mod.MaxPhase; } else if (summaryInitLabel < Mod.MinPhase) { summaryInitLabel = Mod.MinPhase; } ___initiativeObj.SetActive(true); ___initiativeText.SetText($"{summaryInitLabel}"); // --- Tooltip --- string tooltipTitle = $"{___selectedMech.Name}"; string detailsS = String.Join("\n", details.ToArray()); string tooltipText = new Text(Mod.Config.LocalizedText[ModConfig.LT_MB_TT_SUMMARY], new object[] { detailsS, summaryInitLabel }).ToString(); BaseDescriptionDef initiativeData = new BaseDescriptionDef("MB_MIW_MECH_TT", tooltipTitle, tooltipText, null); ___initiativeTooltip.enabled = true; ___initiativeTooltip.SetDefaultStateData(TooltipUtilities.GetStateDataFromObject(initiativeData)); } }
public static void Postfix(LanceLoadoutSlot __instance, GameObject ___initiativeObj, TextMeshProUGUI ___initiativeText, UIColorRefTracker ___initiativeColor, HBSTooltip ___initiativeTooltip, LanceConfiguratorPanel ___LC) { Mod.Log.Trace?.Write("LLS:RID:post - entered."); if (___initiativeObj == null || ___initiativeText == null || ___initiativeColor == null || ___initiativeTooltip == null) { return; } bool bothSelected = __instance.SelectedMech != null && __instance.SelectedPilot != null; if (!bothSelected) { ___initiativeText.SetText("-"); ___initiativeColor.SetUIColor(UIColor.MedGray); } else { // --- MECH --- MechDef selectedMechDef = __instance.SelectedMech.MechDef; List <string> details = new List <string>(); // Static initiative from tonnage int initPhase = PhaseHelper.TonnageToPhase((int)Math.Ceiling(__instance.SelectedMech.MechDef.Chassis.Tonnage)); int initLabelVal = (Mod.MaxPhase + 1) - initPhase; details.Add(new Text(Mod.Config.LocalizedText[ModConfig.LT_TT_BASE], new object[] { initLabelVal }).ToString()); // Any bonuses from equipment int componentBonus = UnitHelper.GetNormalizedComponentModifier(__instance.SelectedMech.MechDef); string componentColor = "FFFFFF"; if (componentBonus > 0) { componentColor = "00FF00"; } if (componentBonus < 0) { componentColor = "FF0000"; } details.Add(new Text(Mod.Config.LocalizedText[ModConfig.LT_TT_COMPONENT], new object[] { componentColor, componentBonus }).ToString()); Mod.Log.Debug?.Write($"Component bonus is: {componentBonus}"); // --- LANCE --- int lanceBonus = 0; if (___LC != null) { lanceBonus = ___LC.lanceInitiativeModifier; } string lanceColor = "FFFFFF"; if (lanceBonus > 0) { lanceColor = "00FF00"; } if (lanceBonus < 0) { lanceColor = "FF0000"; } details.Add(new Text(Mod.Config.LocalizedText[ModConfig.LT_TT_LANCE], new object[] { lanceColor, lanceBonus }).ToString()); // --- PILOT --- // TODO: Get pilot modifiers from abilities - coordinate with BD Pilot selectedPilot = __instance.SelectedPilot.Pilot; int pilotBonus = 0; foreach (Ability ability in selectedPilot.PassiveAbilities) { foreach (EffectData effectData in ability.Def.EffectData) { if (effectData.effectType == EffectType.StatisticEffect && effectData.statisticData != null && effectData.statisticData.statName == "BaseInitiative") { int mod = Int32.Parse(effectData.statisticData.modValue) * -1; if (effectData.statisticData.operation == StatCollection.StatOperation.Int_Add) { pilotBonus += mod; } else if (effectData.statisticData.operation == StatCollection.StatOperation.Int_Subtract) { pilotBonus -= mod; } } } } string pilotColor = "FFFFFF"; if (pilotBonus > 0) { pilotColor = "00FF00"; } if (pilotBonus < 0) { pilotColor = "FF0000"; } details.Add(new Text(Mod.Config.LocalizedText[ModConfig.LT_TT_PILOT], new object[] { pilotColor, pilotBonus }).ToString()); // --- Badge --- int summaryInitLabel = initLabelVal + componentBonus + pilotBonus + lanceBonus; if (summaryInitLabel > Mod.MaxPhase) { summaryInitLabel = Mod.MaxPhase; } else if (summaryInitLabel < Mod.MinPhase) { summaryInitLabel = Mod.MinPhase; } ___initiativeText.SetText($"{summaryInitLabel}"); ___initiativeText.color = Color.black; ___initiativeColor.SetUIColor(UIColor.White); // --- Tooltip --- string tooltipTitle = $"{selectedMechDef.Name}: {selectedPilot.Name}"; string detailsS = String.Join("\n", details.ToArray()); string tooltipText = new Text(Mod.Config.LocalizedText[ModConfig.LT_LC_TT_SUMMARY], new object[] { detailsS, summaryInitLabel }).ToString(); BaseDescriptionDef initiativeData = new BaseDescriptionDef("LLS_MECH_TT", tooltipTitle, tooltipText, null); ___initiativeTooltip.enabled = true; ___initiativeTooltip.SetDefaultStateData(TooltipUtilities.GetStateDataFromObject(initiativeData)); } }
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); } }
// return false so original function does not get called. public static bool Prefix(LanceLoadoutSlot __instance, GameObject ___initiativeObj, TextMeshProUGUI ___initiativeText, UIColorRefTracker ___initiativeColor, HBSTooltip ___initiativeTooltip, LanceConfiguratorPanel ___LC) { if (___initiativeObj == null || ___initiativeText == null || ___initiativeColor == null) { return(false); } if (__instance.SelectedMech == null || __instance.SelectedMech.MechDef == null || __instance.SelectedMech.MechDef.Chassis == null) { ___initiativeObj.SetActive(false); return(false); } if (__instance.SelectedPilot == null || __instance.SelectedPilot.Pilot == null || __instance.SelectedPilot.Pilot.pilotDef == null) { ___initiativeObj.SetActive(false); return(false); } ___initiativeObj.SetActive(true); int num = 1; // default to assault phase int num2 = 0; // default to no modification by effects float f_walkSpeed = __instance.SelectedMech.MechDef.Chassis.MovementCapDef.MaxWalkDistance; if (f_walkSpeed >= TheEngineInitiative.Settings.MechPhaseSpecialMinSpeed) { num = 5; //special phase } else if (f_walkSpeed >= TheEngineInitiative.Settings.MechPhaseLightMinSpeed) { num = 4; //light phase } else if (f_walkSpeed >= TheEngineInitiative.Settings.MechPhaseMediumMinSpeed) { num = 3; //medium phase } else if (f_walkSpeed >= TheEngineInitiative.Settings.MechPhaseHeavyMinSpeed) { num = 2; //heavy phase } // check if pilot mods initiative if (__instance.SelectedPilot.Pilot.pilotDef.AbilityDefs != null) { foreach (AbilityDef abilityDef in __instance.SelectedPilot.Pilot.pilotDef.AbilityDefs) { foreach (EffectData effect in abilityDef.EffectData) { if (MechStatisticsRules.GetInitiativeModifierFromEffectData(effect, true, null) == 0) { num2 += MechStatisticsRules.GetInitiativeModifierFromEffectData(effect, false, null); } } } } // check if any of the mech's inventory changes initiative. if (__instance.SelectedMech.MechDef.Inventory != null) { foreach (MechComponentRef mechComponentRef in __instance.SelectedMech.MechDef.Inventory) { if (mechComponentRef.Def != null && mechComponentRef.Def.statusEffects != null) { foreach (EffectData effect2 in mechComponentRef.Def.statusEffects) { if (MechStatisticsRules.GetInitiativeModifierFromEffectData(effect2, true, null) == 0) { num2 += MechStatisticsRules.GetInitiativeModifierFromEffectData(effect2, false, null); } } } } } // is there a lance bonus? int num3 = 0; if (___LC != null) { num3 = ___LC.lanceInitiativeModifier; } num2 += num3; // make sure initiative is within the valid range. int num4 = Mathf.Clamp(num + num2, 1, 5); //set our text. ___initiativeText.SetText($"{num4}"); if (___initiativeTooltip != null) { // build the tooltip. Going to use the mech's name and tell where its speed puts it, initiative-wise. string tooltipTitle = $"{__instance.SelectedMech.MechDef.Name}"; string tooltipText = "A max walking speed of " + $"{f_walkSpeed}" + "m per turn means this mech moves in initiative phase " + $"{num}" + "."; // if there are effects, tell the player what they've changed initiative to. if (num2 != 0) { tooltipText += " Effects have modified this to phase " + $"{num4}" + "."; } BaseDescriptionDef initiativeData = new BaseDescriptionDef("MB_MIW_MECH_TT", tooltipTitle, tooltipText, null); ___initiativeTooltip.enabled = true; ___initiativeTooltip.SetDefaultStateData(TooltipUtilities.GetStateDataFromObject(initiativeData)); } // if we've been bumped up, make it gold, if bumped down, make it red, else white. ___initiativeColor.SetUIColor((num2 > 0) ? UIColor.Gold : ((num2 < 0) ? UIColor.Red : UIColor.White)); return(false); }