static bool Prefix(SGNavigationActiveFactionWidget __instance, List <string> activeFactions, string OwnerFaction, List <HBSButton> ___FactionButtons, List <Image> ___FactionIcons, SimGameState ___simState) { try { ___FactionButtons.ForEach(delegate(HBSButton btn) { btn.gameObject.SetActive(false); }); int index = 0; foreach (string faction in activeFactions) { FactionDef factionDef = FactionEnumeration.GetFactionByName(faction).FactionDef; ___FactionIcons[index].sprite = factionDef.GetSprite(); HBSTooltip component = ___FactionIcons[index].GetComponent <HBSTooltip>(); if (component != null) { component.SetDefaultStateData(TooltipUtilities.GetStateDataFromObject(factionDef)); } ___FactionButtons[index].SetState(ButtonState.Enabled, false); ___FactionButtons[index].gameObject.SetActive(true); index++; } return(false); } catch (Exception e) { Logger.LogError(e); return(true); } }
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(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 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 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)); } }
public static void Postfix(SGBarracksSkillPip __instance, string type, int index, bool hasPassives, AbilityDef ability) { if (!hasPassives) { return; } var simGame = LazySingletonBehavior <UnityGameInstance> .Instance.Game.Simulation; if (simGame == null) { return; } // get the abilities that are not primary var abilities = simGame.GetAbilityDefFromTree(type, index).Where(x => !x.IsPrimaryAbility).ToList(); // gets the first ability that has a tooltip var passiveAbility = abilities.Find(x => !(string.IsNullOrEmpty(x.Description.Name) || string.IsNullOrEmpty(x.Description.Details))); // clear the dot on tooltip-less dots if (passiveAbility == null) { Traverse.Create(__instance).Field("skillPassiveTraitDot").GetValue <SVGImage>().gameObject.SetActive(false); } if (passiveAbility != null) { __instance.gameObject.FindFirstChildNamed("obj-pip").GetComponent <HBSTooltip>() .SetDefaultStateData(TooltipUtilities.GetStateDataFromObject(passiveAbility.Description)); } }
public static void Postfix(SGBarracksMWDetailPanel __instance, Pilot p, SGBarracksAdvancementPanel ___advancement ) { var sim = UnityGameInstance.BattleTechGame.Simulation; var gunPips = Traverse.Create(___advancement).Field("gunPips").GetValue <List <SGBarracksSkillPip> >(); var pilotPips = Traverse.Create(___advancement).Field("pilotPips").GetValue <List <SGBarracksSkillPip> >(); var gutPips = Traverse.Create(___advancement).Field("gutPips").GetValue <List <SGBarracksSkillPip> >(); var tacPips = Traverse.Create(___advancement).Field("tacPips").GetValue <List <SGBarracksSkillPip> >(); var abilityDefs = p.pilotDef.AbilityDefs.Where(x => x.IsPrimaryAbility == true); //loop through abilities the pilot has, and place those ability icons/tooltips in the appropriate pip slot. foreach (AbilityDef ability in abilityDefs) { if (ability.ReqSkill == SkillType.Gunnery) { Traverse.Create(gunPips[ability.ReqSkillLevel - 1]).Field("abilityIcon").GetValue <SVGImage>().vectorGraphics = ability.AbilityIcon; Traverse.Create(gunPips[ability.ReqSkillLevel - 1]).Field("AbilityTooltip").GetValue <HBSTooltip>() .SetDefaultStateData(TooltipUtilities.GetStateDataFromObject(ability.Description)); } } foreach (AbilityDef ability in abilityDefs) { if (ability.ReqSkill == SkillType.Piloting) { Traverse.Create(pilotPips[ability.ReqSkillLevel - 1]).Field("abilityIcon").GetValue <SVGImage>().vectorGraphics = ability.AbilityIcon; Traverse.Create(pilotPips[ability.ReqSkillLevel - 1]).Field("AbilityTooltip").GetValue <HBSTooltip>() .SetDefaultStateData(TooltipUtilities.GetStateDataFromObject(ability.Description)); } } foreach (AbilityDef ability in abilityDefs) { if (ability.ReqSkill == SkillType.Guts) { Traverse.Create(gutPips[ability.ReqSkillLevel - 1]).Field("abilityIcon").GetValue <SVGImage>().vectorGraphics = ability.AbilityIcon; Traverse.Create(gutPips[ability.ReqSkillLevel - 1]).Field("AbilityTooltip").GetValue <HBSTooltip>() .SetDefaultStateData(TooltipUtilities.GetStateDataFromObject(ability.Description)); } } foreach (AbilityDef ability in abilityDefs) { if (ability.ReqSkill == SkillType.Tactics) { Traverse.Create(tacPips[ability.ReqSkillLevel - 1]).Field("abilityIcon").GetValue <SVGImage>().vectorGraphics = ability.AbilityIcon; Traverse.Create(tacPips[ability.ReqSkillLevel - 1]).Field("AbilityTooltip").GetValue <HBSTooltip>() .SetDefaultStateData(TooltipUtilities.GetStateDataFromObject(ability.Description)); } } }
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 void Postfix(HBSTagView __instance, TagSet tagSet, GameContext context) { if (!Pre_Control.settings.MechBonding) { return; } if (tagSet.Contains("PQ_Mech_Mastery")) { bool HasTattoo = PilotHolder.pilotDef.PilotTags.Any(x => x.StartsWith("PQ_Pilot_GUID")); if (!HasTattoo) { return; } string PilotTattoo = PilotHolder.pilotDef.PilotTags.First(x => x.StartsWith("PQ_Pilot_GUID")); if (!MechBonding.PilotsAndMechs.Keys.Contains(PilotTattoo) || MechBonding.PilotsAndMechs[PilotTattoo].Count() == 0) { return; } var MechExperience = MechBonding.PilotsAndMechs[PilotTattoo]; var BondedMech = MechExperience.Aggregate((l, r) => l.Value > r.Value ? l : r).Key; string MasteryTier = ""; if (MechExperience[BondedMech] >= Pre_Control.settings.Tier4) { MasteryTier = "Elite "; } else if (MechExperience[BondedMech] >= Pre_Control.settings.Tier3) { MasteryTier = "Veteran "; } else if (MechExperience[BondedMech] >= Pre_Control.settings.Tier2) { MasteryTier = "Regular "; } else if (MechExperience[BondedMech] >= Pre_Control.settings.Tier1) { MasteryTier = "Green "; } string DescriptionName = MasteryTier + " 'Mech Pilot"; var item = new TagDataStruct("HACK_GENCON_UNIT", true, true, "name", DescriptionName, "description"); string contextItem = string.Format("{0}[{1}]", "TDSF", item.Tag); string friendlyName = item.FriendlyName; var itemTT = TooltipUtilities.GetGameContextTooltipString(contextItem, friendlyName); __instance.AddTag(itemTT, item.FriendlyName); } }
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)); }
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)); } }
// 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 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(SGContractsWidget __instance, Contract contract, HBSTooltip ___ContractTypeTooltip) { string arg; if (contract.IsPriorityContract) { arg = "Priority"; } else { arg = contract.Override.ContractTypeValue.Name; } var text2 = string.Format("ContractType{0}", arg); text2.Replace(" ", null); var specDesc = Descriptions.GetMissionSpecializationDescription(contract.Override.ContractTypeValue.Name); if (!string.IsNullOrEmpty(text2) && sim.DataManager.Exists(BattleTechResourceType.BaseDescriptionDef, text2)) { var def2 = sim.DataManager.BaseDescriptionDefs.Get(text2); if (!string.IsNullOrEmpty(specDesc)) { if (!def2.Details.Contains(specDesc)) { var details = def2.GetLocalizedDetails(); details.Append(specDesc); var deets = details.ToString(); Traverse.Create(def2).Field("localizedDetails").SetValue(details); Traverse.Create(def2).Property("Details").SetValue(deets); } } ___ContractTypeTooltip.SetDefaultStateData(TooltipUtilities.GetStateDataFromObject(def2)); } }
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 bool Prefix( SGBarracksAdvancementPanel __instance, Pilot ___curPilot, List <SGBarracksSkillPip> ___gunPips, List <SGBarracksSkillPip> ___pilotPips, List <SGBarracksSkillPip> ___gutPips, List <SGBarracksSkillPip> ___tacPips, string type, int value) { try { if (modSettings.debugXP == true) { ___curPilot.AddExperience(0, "", 100000); } var sim = UnityGameInstance.BattleTechGame.Simulation; var pips = new Dictionary <string, List <SGBarracksSkillPip> > { { "Gunnery", ___gunPips }, { "Piloting", ___pilotPips }, { "Guts", ___gutPips }, { "Tactics", ___tacPips }, }; // removal of pip if (___curPilot.StatCollection.GetValue <int>(type) > value) { Trace($"Removing {type} {value}"); Trace(pips[type][value].Ability); Helpers.SetTempPilotSkill(type, value, -sim.GetLevelCost(value)); ___curPilot.pilotDef.abilityDefNames.Do(Trace); Log("\n"); Helpers.ForceResetCharacter(__instance); // Traverse.Create(__instance).Method("ForceResetCharacter").GetValue(); return(false); } // add non-ability pip if (!Traverse.Create(pips[type][value]).Field("hasAbility").GetValue <bool>()) { Trace("Non-ability pip"); Helpers.SetTempPilotSkill(type, value, sim.GetLevelCost(value)); ___curPilot.pilotDef.abilityDefNames.Do(Trace); Trace("\n"); return(false); } // Ability pips // build complete list of defs from HBS and imported json // var abilityDefs = Helpers.ModAbilities // .Where(x => x.ReqSkillLevel == value + 1 && x.ReqSkill.ToString() == type).ToList(); var abilityDictionaries = sim.AbilityTree.Select(x => x.Value).ToList(); //List<AbilityDef> abilityDefs = sim.GetAbilityDefFromTree(type, value); //does same thing as below? var abilityDefs = new List <AbilityDef>(); foreach (var abilityDictionary in abilityDictionaries) { abilityDefs.AddRange(abilityDictionary[value].Where(x => x.ReqSkill.ToString() == type)); } // don't create choice popups with 1 option if (abilityDefs.Count <= 1) { Trace($"Single ability for {type}|{value}, skipping"); Helpers.SetTempPilotSkill(type, value, sim.GetLevelCost(value)); return(false); } // prevents which were ability buttons before other primaries were selected from being abilities // not every ability button is visible all the time var curButton = Traverse.Create(pips[type][value]).Field("curButton").GetValue <HBSDOTweenToggle>(); var skillButton = Traverse.Create(pips[type][value]).Field("skillButton").GetValue <HBSDOTweenToggle>(); if (curButton != skillButton) { Trace(new string('=', 50)); Trace("curButton != skillButton"); Helpers.SetTempPilotSkill(type, value, sim.GetLevelCost(value)); return(false); } // dynamic buttons based on available abilities //new code below// //new code below for ability requirements List <string> pilotAbilityDefNames = ___curPilot.pilotDef.abilityDefNames; var abilityFilter = modSettings.abilityReqs.Values.SelectMany(x => x).ToList(); List <AbilityDef> abilitiesWithReqs = abilityDefs.Where(ability => abilityFilter.Any(filter => filter.Equals(ability.Id))).ToList(); var abilityDefsForDesc = new List <AbilityDef>(); abilityDefsForDesc.AddRange(abilityDefs); foreach (var abilityWithReq in abilitiesWithReqs) { if (!pilotAbilityDefNames.Contains(modSettings.abilityReqs.FirstOrDefault(x => x.Value.Contains(abilityWithReq.Id)).Key)) { abilityDefs.Remove(abilityWithReq); } } //original code continues below// string abilityDescs = null; foreach (var abilityDefDesc in abilityDefsForDesc) { if (abilityDefs.Contains(abilityDefDesc)) { string abilityID = abilityDefDesc.Id + "Desc"; string abilityName = abilityDefDesc.Description.Name; if (modSettings.usePopUpsForAbilityDesc == true) { abilityDescs += "[[DM.BaseDescriptionDefs[" + abilityID + "],<b>" + abilityName + "</b>]]" + "\n\n"; } else { abilityDescs += "<color=#33f9ff>" + abilityDefDesc.Description.Name + ": </color>" + abilityDefDesc.Description.Details + "\n\n"; } } else { var dm = UnityGameInstance.BattleTechGame.DataManager; string abilityID = abilityDefDesc.Id + "Desc"; string abilityName = abilityDefDesc.Description.Name; var reqAbilityName = modSettings.abilityReqs.FirstOrDefault(x => x.Value.Contains(abilityDefDesc.Id)).Key; var allAbilities = new List <AbilityDef>(); allAbilities = sim.AbilityTree[type].SelectMany(x => x.Value).ToList(); // allAbilities.AddRange(Traverse.Create(dm).Field("abilityDefs").GetValue<List<AbilityDef>>()); var reqAbility = allAbilities.Find(x => x.Id == reqAbilityName); if (modSettings.usePopUpsForAbilityDesc == true) { //abilityDescs += "<color=#FF0000>(Requirements Unmet)</color> " + "[[DM.BaseDescriptionDefs[" + abilityID + "],<b>" + abilityName + "</b>]]" + "\n\n"; abilityDescs += "<color=#FF0000> Requires <u>" + reqAbility.Description.Name + "</u></color> " + "[[DM.BaseDescriptionDefs[" + abilityID + "],<b>" + abilityName + "</b>]]" + "\n\n"; } else { //abilityDescs += "<color=#FF0000>(Requirements Unmet)</color> " + "<color=#0000FF>" + abilityDefDesc.Description.Name + ": </color>" + abilityDefDesc.Description.Details + "\n\n"; abilityDescs += "<color=#FF0000> Requires <u>" + reqAbility.Description.Name + "</u></color> " + "<color=#33f9ff>" + abilityDefDesc.Description.Name + ": </color>" + abilityDefDesc.Description.Details + "\n\n"; } } } var popup = GenericPopupBuilder .Create("Select an ability", abilityDescs) .AddFader(); popup.AlwaysOnTop = true; var pip = pips[type][value]; foreach (var abilityDef in abilityDefs) { popup.AddButton(abilityDef.Description.Name, () => { // have to change the Ability so SetPips later, SetActiveAbilityVisible works Traverse.Create(pip).Field("thisAbility").SetValue(abilityDef); Traverse.Create(pip).Field("abilityIcon").GetValue <SVGImage>().vectorGraphics = abilityDef.AbilityIcon; Traverse.Create(pip).Field("AbilityTooltip").GetValue <HBSTooltip>() .SetDefaultStateData(TooltipUtilities.GetStateDataFromObject(abilityDef.Description)); Helpers.SetTempPilotSkill(type, value, sim.GetLevelCost(value), abilityDef); }); } popup.Render(); } catch (Exception ex) { Log(ex); } return(false); }
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 AddVariantsToDescriptions( MechBayChassisInfoWidget __instance, ChassisDef ___selectedChassis, TextMeshProUGUI ___mechDetails, HBSTooltip ___chassisStorageTooltip, GameObject ___readyBtnObj, GameObject ___partsCountObj, TextMeshProUGUI ___partsCountText) { if (___selectedChassis == null) { return; } if (!Control.Settings.AssemblyVariants) { return; } var list = ChassisHandler.GetCompatible(___selectedChassis.Description.Id); if (___selectedChassis.MechPartCount != 0) { int min = ChassisHandler.GetInfo(___selectedChassis.Description.Id).MinParts; if (___selectedChassis.MechPartCount >= ___selectedChassis.MechPartMax) { ___readyBtnObj.SetActive(true); ___partsCountObj.SetActive(false); ___chassisStorageTooltip.SetDefaultStateData(TooltipUtilities.GetStateDataFromObject("Enough parts to assemble: Press Ready to move to a Bay")); } else { if (list == null || ___selectedChassis.MechPartCount < min || list.Sum(i => ChassisHandler.GetCount(i.Description.Id)) < ___selectedChassis.MechPartMax) { ___readyBtnObj.SetActive(false); ___partsCountObj.SetActive(true); ___partsCountText.SetText($"{___selectedChassis.MechPartCount} / {___selectedChassis.MechPartMax}"); ___chassisStorageTooltip.SetDefaultStateData(TooltipUtilities.GetStateDataFromObject($"Chassis still needs at least {min} base and total {___selectedChassis.MechPartMax} compatible parts to be completed")); } else { ___readyBtnObj.SetActive(true); ___partsCountObj.SetActive(false); ___chassisStorageTooltip.SetDefaultStateData(TooltipUtilities.GetStateDataFromObject("Chassis can by assembled using other parts: Press Ready to move to a Bay")); } } } else { ___readyBtnObj.SetActive(true); ___partsCountObj.SetActive(false); ___chassisStorageTooltip.SetDefaultStateData(TooltipUtilities.GetStateDataFromObject("Chassis in storage: Press Ready to move to a Bay")); } string add = ""; if (list == null) { add = $"\n<color=#FFFF00>Special mech: cannot be assembled using other variants</color>"; } else if (list.Count > 1) { add = $"\n<color=#32CD32>Compatible with owned variants:"; if (list.Count > Control.Settings.MaxVariantsInDescription + 1) { int showed = 0; foreach (var mechDef in list) { if (mechDef.ChassisID == ___selectedChassis.Description.Id) { continue; } add += "\n" + new Text(mechDef.Description.UIName).ToString(); showed += 1; if (showed == Control.Settings.MaxVariantsInDescription - 1) { break; } } add += $"\n and {Control.Settings.MaxVariantsInDescription - showed} other variants</color>"; } else { foreach (var mechDef in list) { if (mechDef.ChassisID == ___selectedChassis.Description.Id) { continue; } add += "\n" + new Text(mechDef.Description.UIName).ToString(); } add += "</color>"; } } ___mechDetails.SetText(___mechDetails.text + add); }
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)); } }
// 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); }
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)); } }
public static bool Prefix( SGBarracksAdvancementPanel __instance, Pilot ___curPilot, List <SGBarracksSkillPip> ___gunPips, List <SGBarracksSkillPip> ___pilotPips, List <SGBarracksSkillPip> ___gutPips, List <SGBarracksSkillPip> ___tacPips, string type, int value) { try { ___curPilot.AddExperience(0, "", 100000); var sim = UnityGameInstance.BattleTechGame.Simulation; var pips = new Dictionary <string, List <SGBarracksSkillPip> > { { "Gunnery", ___gunPips }, { "Piloting", ___pilotPips }, { "Guts", ___gutPips }, { "Tactics", ___tacPips }, }; // removal of pip if (___curPilot.StatCollection.GetValue <int>(type) > value) { Trace($"Removing {type} {value}"); Trace(pips[type][value].Ability); Helpers.SetTempPilotSkill(type, value, -sim.GetLevelCost(value)); ___curPilot.pilotDef.abilityDefNames.Do(Trace); Log("\n"); Helpers.ForceResetCharacter(__instance); Traverse.Create(__instance).Method("ForceResetCharacter").GetValue(); return(false); } // add non-ability pip if (!Traverse.Create(pips[type][value]).Field("hasAbility").GetValue <bool>()) { Trace("Non-ability pip"); Helpers.SetTempPilotSkill(type, value, sim.GetLevelCost(value)); ___curPilot.pilotDef.abilityDefNames.Do(Trace); Trace("\n"); return(false); } // Ability pips // build complete list of defs from HBS and imported json // var abilityDefs = Helpers.ModAbilities // .Where(x => x.ReqSkillLevel == value + 1 && x.ReqSkill.ToString() == type).ToList(); var abilityDefs = new List <AbilityDef>(); var abilityDictionaries = sim.AbilityTree.Select(x => x.Value).ToList(); foreach (var abilityDictionary in abilityDictionaries) { abilityDefs.AddRange(abilityDictionary[value].Where(x => x.ReqSkill.ToString() == type)); } // don't create choice popups with 1 option if (abilityDefs.Count <= 1) { Trace($"Single ability for {type}|{value}, skipping"); Helpers.SetTempPilotSkill(type, value, sim.GetLevelCost(value)); return(false); } // prevents which were ability buttons before other primaries were selected from being abilities // not every ability button is visible all the time var curButton = Traverse.Create(pips[type][value]).Field("curButton").GetValue <HBSDOTweenToggle>(); var skillButton = Traverse.Create(pips[type][value]).Field("skillButton").GetValue <HBSDOTweenToggle>(); if (curButton != skillButton) { Trace(new string('=', 50)); Trace("curButton != skillButton"); Helpers.SetTempPilotSkill(type, value, sim.GetLevelCost(value)); return(false); } // dynamic buttons based on available abilities string abilityDescs = null; foreach (var abilityDef in abilityDefs) { string abilityID = abilityDef.Id + "Desc"; string abilityName = abilityDef.Description.Name; if (Mod.modSettings.usePopUpsForAbilityDesc == true) { abilityDescs += "[[DM.BaseDescriptionDefs[" + abilityID + "],<b>" + abilityName + "</b>]]" + "\n\n"; } else { abilityDescs += abilityDef.Description.Name + ": " + abilityDef.Description.Details + "\n\n"; } } var popup = GenericPopupBuilder .Create("Select an ability", abilityDescs) .AddFader(); popup.AlwaysOnTop = true; var pip = pips[type][value]; foreach (var abilityDef in abilityDefs) { popup.AddButton(abilityDef.Description.Name, () => { // have to change the Ability so SetPips later, SetActiveAbilityVisible works Traverse.Create(pip).Field("thisAbility").SetValue(abilityDef); Traverse.Create(pip).Field("abilityIcon").GetValue <SVGImage>().vectorGraphics = abilityDef.AbilityIcon; Traverse.Create(pip).Field("AbilityTooltip").GetValue <HBSTooltip>() .SetDefaultStateData(TooltipUtilities.GetStateDataFromObject(abilityDef.Description)); Helpers.SetTempPilotSkill(type, value, sim.GetLevelCost(value), abilityDef); }); } popup.Render(); } catch (Exception ex) { Log(ex); } return(false); }