static bool Prefix(SGBarracksRosterList __instance, LocalizableText ___mechWarriorCount) { if (ModState.SimGameState == null) { return(true); // Only patch if we're in SimGame } int usedBerths = CrewHelper.UsedBerths(ModState.SimGameState.PilotRoster); Mod.Log.Debug?.Write($"Berths => used: {usedBerths} available: {ModState.SimGameState.GetMaxMechWarriors()}"); string text = new Localize.Text(Mod.LocalizedText.Labels[ModText.LT_Crew_Berths_Used], new object[] { usedBerths, ModState.SimGameState.GetMaxMechWarriors() }).ToString(); ___mechWarriorCount.SetText(text); return(false); }
static void Postfix(Pilot ___pilot, GameObject ___cantBuyMRBOverlay, HBSTooltip ___cantBuyToolTip, LocalizableText ___costText, UIColorRefTracker ___costTextColor) { if (ModState.SimGameState == null) { return; // Only patch if we're in SimGame } Mod.Log.Debug?.Write($"Refreshing availability for pilot: {___pilot.Name}"); // TODO: This may need to be improved, as it's used inside a loop. Maybe write to company stats? CrewDetails details = ModState.GetCrewDetails(___pilot.pilotDef); Mod.Log.Debug?.Write($" -- pilot requires: {details.Size} berths"); int usedBerths = CrewHelper.UsedBerths(ModState.SimGameState.PilotRoster); int availableBerths = ModState.SimGameState.GetMaxMechWarriors() - usedBerths; Mod.Log.Debug?.Write($"AvailableBerths: {availableBerths} = max: {ModState.SimGameState.GetMaxMechWarriors()} - used: {usedBerths}"); // Check berths limitations if (details.Size > availableBerths) { Mod.Log.Info?.Write($"Pilot {___pilot.Name} cannot be hired, not enough berths (needs {details.Size})"); ___cantBuyMRBOverlay.SetActive(true); HBSTooltipStateData tooltipStateData = new HBSTooltipStateData(); tooltipStateData.SetContextString($"DM.BaseDescriptionDefs[{ModConsts.Tooltip_NotEnoughBerths}]"); ___cantBuyToolTip.SetDefaultStateData(tooltipStateData); } // Check type limitations if (!CrewHelper.CanHireMoreCrewOfType(details)) { Mod.Log.Info?.Write($"Pilot {___pilot.Name} cannot be hired, too many of type already employed."); ___cantBuyMRBOverlay.SetActive(true); HBSTooltipStateData tooltipStateData = new HBSTooltipStateData(); tooltipStateData.SetContextString($"DM.BaseDescriptionDefs[{ModConsts.Tooltip_TooManyOfType}]"); ___cantBuyToolTip.SetDefaultStateData(tooltipStateData); } else { Mod.Log.Debug?.Write($"Pilot {___pilot.Name} can be hired, no limiations on max."); } // Set the prices //int purchaseCostAfterReputationModifier = ModState.SimGameState.CurSystem.GetPurchaseCostAfterReputationModifier( // ModState.SimGameState.GetMechWarriorHiringCost(___pilot.pilotDef) // ); // TODO: Apply system cost multiplier // Hiring cost is influenced by: // - current morale rating // - any faction alignment for units // - any reputation modifiers ___costText.SetText(SimGameState.GetCBillString(details.HiringBonus)); UIColor costColor = UIColor.Red; if (details.HiringBonus <= ModState.SimGameState.Funds) { costColor = UIColor.White; } ___costTextColor.SetUIColor(costColor); }