public static object ModifyFunds(TsEnvironment env, object[] inputs) { int operation = env.ToInt(inputs[0]); int amount = env.ToInt(inputs[1]); Main.Logger.Log($"[ModifyFunds] Operation '{operation}' with amount '{amount}'.'"); SimGameState simulation = UnityGameInstance.BattleTechGame.Simulation; if (operation == 0) // ADD { simulation.AddFunds(amount); } else if (operation == 1) // REMOVE { simulation.AddFunds(-amount); } else { Main.Logger.LogError($"[ModifyFunds] Unknown operation type of '{operation}'"); return(null); } Main.Logger.Log($"[ModifyFunds] Funds modified."); return(null); }
public static bool ScrapActiveVehicle(int baySlot, MechDef def, SimGameState __instance) { if (!def.IsVehicle()) { return(true); } if (def == null || (baySlot > 0 && !__instance.ActiveMechs.ContainsKey(baySlot))) { return(false); } var locations = new Traverse(def).Field <LocationLoadoutDef[]> ("Locations").Value; Control.Instance.LogDebug(DInfo.Debug, "Scrapping {0}", def.Description.Id); foreach (var location in locations) { Control.Instance.LogDebug(DInfo.Debug, "-- {0} - {1}", location.Location, location.DamageLevel); } if (__instance.ActiveMechs.ContainsKey(baySlot)) { __instance.ActiveMechs.Remove(baySlot); } __instance.AddFunds(Mathf.RoundToInt((float)def.Description.Cost * __instance.Constants.Finances.MechScrapModifier), "Scrapping", true, true); return(false); }
/* Submits a Mech Lab Work Order to the game's Mech Lab queue to actually be processed */ public static void SubmitWorkOrder(SimGameState simGame, WorkOrderEntry_MechLab newMechLabWorkOrder) { try { Logger.LogDebug("Begin SubmitWorkOrder(): "); // Now that all WO subentries are added, insert the base MechLab work order to the game's Mech Lab Work Order Queue as the highest priority (index 0) simGame.MechLabQueue.Insert(0, newMechLabWorkOrder); // Call this to properly Initialize the base Mech Lab WO and make it visible in the Mech Lab queue UI / timeline etc. simGame.InitializeMechLabEntry(newMechLabWorkOrder, newMechLabWorkOrder.GetCBillCost()); // Force an update of the Mech Lab queue, false is to tell it a day isn't passing. simGame.UpdateMechLabWorkQueue(false); // Simple cost debugging for the log foreach (WorkOrderEntry subEntries in newMechLabWorkOrder.SubEntries) { Logger.LogDebug(subEntries.Description + " Repair Tech Costs: " + subEntries.GetCost()); } Logger.LogInfo(simGame.GetMechByID(newMechLabWorkOrder.MechID).Name + " Repair Costs are - techCost: " + newMechLabWorkOrder.GetCost() + " | CBill Cost: " + newMechLabWorkOrder.GetCBillCost()); Logger.LogInfo("====================================================================="); // Deduct the total CBill costs of the WO from player inventory. For some reason this isn't done automatically via the HBS WO system. simGame.AddFunds(-newMechLabWorkOrder.GetCBillCost(), "ArmorRepair", true); } catch (Exception ex) { Logger.LogError(ex); } }
public static bool ScrapVehiclePart(string id, float partCount, float partMax, bool pay, SimGameState __instance, ref bool __result) { var mid = CustomSalvage.ChassisHandler.GetMDefFromCDef(id); Control.Instance.LogDebug(DInfo.General, "Scrapping {2}x{0}/{1}", id, mid, partCount); __result = false; if (__instance.GetItemCount(mid, "MECHPART", SimGameState.ItemCountType.UNDAMAGED_ONLY) > 0) { var sim = new Traverse(__instance); sim.Method("RemoveItemStat", new Type[] { typeof(string), typeof(string), typeof(bool) }, new object[] { mid, "MECHPART", false }).GetValue(); __result = true; if (pay) { if (!__instance.DataManager.Exists(BattleTechResourceType.ChassisDef, id)) { __result = false; return(false); } int val = Mathf.RoundToInt((float)__instance.DataManager.ChassisDefs.Get(id).Description.Cost *__instance.Constants.Finances.MechScrapModifier *(partCount / partMax)); __instance.AddFunds(val, "Scrapping", true, true); } } return(false); }
public static bool ScrapInactiveVehicle(string id, bool pay, SimGameState __instance, ref bool __result) { if (!__instance.DataManager.Exists(BattleTechResourceType.ChassisDef, id)) { return(true); } var def = __instance.DataManager.ChassisDefs.Get(id); if (!def.IsVehicle()) { return(true); } __result = false; if (__instance.GetItemCount(id, typeof(MechDef), SimGameState.ItemCountType.UNDAMAGED_ONLY) > 0) { __instance.RemoveItemStat(id, typeof(MechDef), false); __result = true; if (pay) { var mdef = __instance.DataManager.MechDefs.Get(ChassisHandler.GetMDefFromCDef(id)); __instance.AddFunds(Mathf.RoundToInt((float)mdef.Description.Cost * __instance.Constants.Finances.MechScrapModifier), "Scrapping", true, true); } } return(false); }
public static void Postfix(SimGameState __instance) { float cost = 0; foreach (MechDef mechdef in __instance.ActiveMechs.Values) { cost += mechdef.Description.Cost * RngStart.Settings.MechPercentageStartingCost / 100; } __instance.AddFunds(-(int)cost, null, false); }
public void stealAmount(Pilot pilot, SimGameState sim) { int stealChance = 0; int stealAmount = 0; int stealChance2 = 0; int stealAmount2 = 0; List <PilotQuirk> pilotQuirks = getQuirks(pilot); foreach (PilotQuirk quirk in pilotQuirks) { foreach (QuirkEffect effect in quirk.quirkEffects) { if (effect.type == EQuirkEffectType.CriminalEffect) { stealChance += (int)effect.modifier; stealAmount += (int)effect.secondaryModifier; } else if (effect.type == EQuirkEffectType.CriminalEffect2) { stealChance2 += (int)effect.modifier; stealAmount2 += (int)effect.secondaryModifier; } } } Random random = new Random(); int roll = random.Next(1, 101); if (roll < stealChance) { Main.modLog.LogMessage($"Pilot {pilot.Callsign}, steals: {stealAmount}"); sim.AddFunds(stealAmount * -1, null, true); } roll = random.Next(1, 101); if (roll < stealChance2) { Main.modLog.LogMessage($"Pilot {pilot.Callsign}, steals: {stealAmount2}"); sim.AddFunds(stealAmount2 * -1, null, true); } }
static bool Prefix(Shop __instance, ref bool __result, string id, ShopItemType type, bool isDamaged, int cost) { try { SimGameState Sim = (SimGameState)ReflectionHelper.GetPrivateField(__instance, "Sim"); Type type2; if (type == ShopItemType.MechPart) { ReflectionHelper.InvokePrivateMethode(Sim, "RemoveItemStat", new object[] { id, "MECHPART", false }); Sim.AddFunds(cost, "Store", true); __result = true; return(false); } if (type == ShopItemType.Mech || type == ShopItemType.Chassis_DEPRECATED) { type2 = typeof(MechDef); } else { ComponentType componentType = Shop.ShopItemTypeToComponentType(type); type2 = SimGameState.GetTypeFromComponent(componentType); } int itemCount = Sim.GetItemCount(id, type2, (!isDamaged) ? SimGameState.ItemCountType.UNDAMAGED_ONLY : SimGameState.ItemCountType.DAMAGED_ONLY); if (itemCount < 1) { Logger.LogLine("Count 0"); __result = false; return(false); } Sim.AddFunds(cost, "Store", true); Sim.RemoveItemStat(id, type2, isDamaged); __result = true; return(false); } catch (Exception e) { Logger.LogError(e); return(false); } }
private static void ShowLongTomSpecial(SimGameState s) { s.CompanyTags.Add("bullshark_cac_lt_upgrade"); s.InterruptQueue.QueuePauseNotification("Yangs Offer", $"Hey, Boss. We have a Bull Shark and I found a Long Tom on the local market. Give me {SimGameState.GetCBillString(10000000)} and a lot of time, and I replace the Thumper with it.", s.GetCrewPortrait(SimGameCrew.Crew_Yang), "", () => { RemoveBullshark(s); AddBullsharkLT(s); s.AddFunds(-10000000, null, true, true); }, "OK", () => { s.CompanyTags.Remove("bullshark_cac_lt_upgrade"); }, "Cancel"); }
public static void Postfix(SimGameState __instance) { if (Main.Settings.MechPercentageStartingCost <= 0) { return; } float cost = 0; foreach (MechDef mech in __instance.ActiveMechs.Values) { cost += mech.Description.Cost * (0.01f * Main.Settings.MechPercentageStartingCost); } __instance.AddFunds(-(int)cost, null, false); }
static bool Prefix(SimGameState __instance, int quarterPassed) { try { int expenditures = __instance.GetExpenditures(false); if (Fields.warmission) { expenditures /= 2; } __instance.AddFunds(-expenditures * quarterPassed, "SimGame_Monthly", false); if (!__instance.IsGameOverCondition(false)) { SimGameInterruptManager interruptQueue = (SimGameInterruptManager)AccessTools.Field(typeof(SimGameState), "interruptQueue").GetValue(__instance); interruptQueue.QueueFinancialReport(); } __instance.RoomManager.RefreshDisplay(); AccessTools.Method(typeof(SimGameState), "OnNewQuarterBegin").Invoke(__instance, new object[] { }); return(false); } catch (Exception e) { Logger.LogError(e); return(true); } }
public static void Add(string param) { SimGameState simGameState = SceneSingletonBehavior <UnityGameInstance> .Instance.Game.Simulation; if (param == "help") { string help = ""; help += "• This command will add funds to your company"; help += Environment.NewLine; help += "• Params: the desired amount of c-bills"; help += Environment.NewLine; help += "• Example: '/funds 3000000'"; PopupHelper.Info(help); return; } string message = ""; if (!int.TryParse(param, out int cbills) || cbills <= 0) { message = $"Param is not a positive number."; Logger.Debug($"[Cheater_Funds_Add] {message}"); PopupHelper.Info(message); return; } simGameState.AddFunds(cbills, null, true); message = $"Added {cbills} C-Bills to company."; Logger.Debug($"[Cheater_Funds_Add] {message}"); PopupHelper.Info(message); }
private static void RespecAndRefresh(SGBarracksMWDetailPanel __instance, Pilot pilot) { Logger.Log($"==============================================================="); Logger.Log($"Before:\t{pilot.pilotDef.ExperienceSpent}, {pilot.pilotDef.ExperienceUnspent}"); Logger.Log($"Skill:\t{pilot.pilotDef.SkillGunnery}, {pilot.pilotDef.SkillPiloting}, {pilot.pilotDef.SkillGuts}, {pilot.pilotDef.SkillTactics}"); Logger.Log($"Base:\t{pilot.pilotDef.BaseGunnery}, {pilot.pilotDef.BasePiloting}, {pilot.pilotDef.BaseGuts}, {pilot.pilotDef.BaseTactics}"); Logger.Log($"Bonus:\t{pilot.pilotDef.BonusGunnery}, {pilot.pilotDef.BonusPiloting}, {pilot.pilotDef.BonusGuts}, {pilot.pilotDef.BonusTactics}"); SimGameState sim = UnityGameInstance.BattleTechGame.Simulation; int cost = GetRespecCost(sim, pilot); int days = GetRespecInjuryDays(sim, pilot) + sim.GetPilotTimeoutTimeRemaining(pilot); RespecPilot(pilot); sim.AddFunds(-cost); // currently bugged: AddInjuryDays(sim, pilot, days); pilot.pilotDef.SetTimeoutTime(days); pilot.pilotDef.PilotTags.Add("pilot_lightinjury"); sim.RefreshInjuries(); pilot.pilotDef.PilotTags.Add("HasRetrained"); __instance.DisplayPilot(pilot); __instance.ForceRefreshImmediate(); sim.RoomManager.RefreshDisplay(); Logger.Log($"==============================================================="); Logger.Log($"cost: {cost}, days: {days}"); Logger.Log($"==============================================================="); Logger.Log($"After:\t{pilot.pilotDef.ExperienceSpent}, {pilot.pilotDef.ExperienceUnspent}"); Logger.Log($"Skill:\t{pilot.pilotDef.SkillGunnery}, {pilot.pilotDef.SkillPiloting}, {pilot.pilotDef.SkillGuts}, {pilot.pilotDef.SkillTactics}"); Logger.Log($"Base:\t{pilot.pilotDef.BaseGunnery}, {pilot.pilotDef.BasePiloting}, {pilot.pilotDef.BaseGuts}, {pilot.pilotDef.BaseTactics}"); Logger.Log($"Bonus:\t{pilot.pilotDef.BonusGunnery}, {pilot.pilotDef.BonusPiloting}, {pilot.pilotDef.BonusGuts}, {pilot.pilotDef.BonusTactics}"); //invoking private method: sim.RespecPilot(pilot); // bugged method!!! //typeof(ToHit).GetMethod("RespecPilot", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).Invoke(sim, new object[] { pilot }); //pilot.AddExperience(0, "respec", experienceSpent); }
public static void PerformMechAssemblyStorePopup(SimGameState s, MechDef d, Action onClose) { WwiseManager.PostEvent(AudioEventList_ui.ui_sim_popup_newChassis, WwiseManager.GlobalAudioObject, null, null); MechDef toAdd = PerformMechAssembly(s, d); int mechbay; if (toAdd.IsVehicle()) { mechbay = CUIntegration.GetFirstFreeMechBay(s, d); // vehicle bay, +100 or something similar } else { mechbay = s.GetFirstFreeMechBay(); } GenericPopupBuilder pop = GenericPopupBuilder.Create($"{d.GetMechOmniVehicle()} Assembled", $"Yang: [[DM.MechDefs[{d.Description.Id}],{d.Chassis.Description.UIName} {d.Chassis.VariantName}]] finished!\n{d.Chassis.YangsThoughts}\n\n"); pop.AddButton("storage", delegate { StoreMech(s, toAdd); CallMessages(s, toAdd); Log.Log("direct storage"); onClose?.Invoke(); }, true, null); if (mechbay < 0) // no space - direct storage { pop.Body += $"We have no space for a new {d.GetMechOmniVehicle()}, so it goes into storage."; } else { pop.Body += "Should I put it into storage or ready it for combat?"; pop.AddButton("ready it", delegate { if (Settings.AssembledMechsNeedReadying) { ReadyMech(s, toAdd, mechbay); CallMessages(s, toAdd); } else { s.AddMech(mechbay, toAdd, true, false, false); CallMessages(s, toAdd); } Log.Log("added to bay " + mechbay); onClose?.Invoke(); }, true, null); } if (s.IsSellingAllowed()) { int cost = toAdd.GetMechSellCost(s); pop.Body += $"\n\nDarius: We could also sell it for {SimGameState.GetCBillString(cost)}, although Yang would certanly not like it."; pop.AddButton("sell it", delegate { s.AddFunds(cost, "Store", true, true); Log.Log("sold for " + cost); s.CompanyStats.ModifyStat("Mission", 0, "COMPANY_MechsAdded", StatCollection.StatOperation.Int_Add, 1, -1, true); CallMessages(s, toAdd); onClose?.Invoke(); }, true, null); } pop.AddFader(new UIColorRef?(LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.PopupBackfill), 0f, true); pop.Render(); }
public static void DisputeAction(Contract contract, AAR_SalvageScreen salvageScreen, Dispute dispute) { Mod.Log.Info($"Player disputed holdback."); SimGameState sgs = UnityGameInstance.BattleTechGame.Simulation; Mod.Log.Info($" Dispute legal fees:{dispute.MRBFees}"); sgs.AddFunds(dispute.MRBFees, $"MRB Legal Fees re: {contract.Name}", false); Dispute.Outcome outcome = dispute.GetOutcome(); if (outcome == Dispute.Outcome.SUCCESS) { Mod.Log.Info($"DISPUTE SUCCESS: Player keeps disputed salvage and gains {dispute.Picks} items from compensation pool."); // Update quantities of compensation parts Mod.Log.Debug(" -- Updating quantities on compensation parts."); List <string> compItemsDesc = new List <string>(); int loopCount = 0; foreach (SalvageDef compSDef in State.CompensationParts) { if (loopCount < dispute.Picks) { loopCount++; } else { break; } Mod.Log.Debug($" compensation salvageDef:{compSDef.Description.Name} with quantity:{compSDef.Count}"); foreach (SalvageDef sDef in State.PotentialSalvage) { Mod.Log.Debug($" salvageDef:{sDef.Description.Name} with quantity:{sDef.Count}"); if (compSDef.RewardID == sDef.RewardID) { Mod.Log.Debug($" Matched compensation target, updating quantity to: {compSDef.Count + sDef.Count}"); compItemsDesc.Add($"{compSDef.Description.Name} [QTY:{compSDef.Count}]"); sDef.Count = sDef.Count + compSDef.Count; break; } } } string compDescs = " -" + string.Join("\n -", compItemsDesc.ToArray()); // Display the confirmation screen GenericPopupBuilder.Create( "SUCCESSFUL DISPUTE", $"<b>Cause 193 of the negotiated mercenary contract clearly states...</b>\n\n" + $"Your laywer deftly defend your claim with the MRB. You keep your salvage, and gain the following compensation items:" + $"\n\n{compDescs}\n\n" ) .AddButton("OK") .Render(); } else { Mod.Log.Info($"DISPUTE FAILURE: Player loses disputed items, and {dispute.Picks} items from the salvage pool."); // Remove the disputed items Mod.Log.Debug(" -- Removing disputed items."); foreach (SalvageDef sDef in State.HeldbackParts) { Helper.RemoveSalvage(sDef); } // Update quantities of compensation parts Mod.Log.Debug(" -- Determining dispute failure picks."); List <SalvageDef> disputePicks = new List <SalvageDef>(); List <SalvageDef> components = State.PotentialSalvage.Where(sd => sd.Type == SalvageDef.SalvageType.COMPONENT).ToList(); components.Sort(new Helper.SalvageDefByCostDescendingComparer()); int loopCount = 0; foreach (SalvageDef compDef in components) { if (loopCount < dispute.Picks) { loopCount++; } else { break; } Mod.Log.Debug($" dispute fail salvageDef:{compDef.Description.Name} with quantity:{compDef.Count}"); disputePicks.Add(compDef); State.PotentialSalvage.Remove(compDef); } List <string> heldbackItemsDesc = new List <string>(); foreach (SalvageDef sDef in State.HeldbackParts) { heldbackItemsDesc.Add($"{sDef.Description.Name} [QTY:{sDef.Count}]"); } string heldbackDescs = " -" + string.Join("\n -", heldbackItemsDesc.ToArray()); List <string> disputeDesc = new List <string>(); foreach (SalvageDef sDef in disputePicks) { disputeDesc.Add($"{sDef.Description.Name} [QTY:{sDef.Count}]"); } string disputeDescs = " -" + string.Join("\n -", disputeDesc.ToArray()); // Display the configmration screen GenericPopupBuilder.Create( "FAILED DISPUTE", $"<b>Judge</b>: Counselor, what evidence do you offer for this new plea of insanity?\n\n" + $"<b>Attorney</b>: Well, for one, they done hired me to represent them.\n\n" + $"<b>Judge</b>: Insanity plea is accepted.\n\n" + $"{State.Employer}'s legal team completely ran away with the proceeding, painting {sgs.CompanyName} in the worst possible light." + $"You lose salvage rights to all of the following:" + $"\n\n{heldbackDescs}\n\n" + $"In addition they claim the following as compensation for legal fees:" + $"\n\n{disputeDescs}\n\n" ) .AddButton("OK") .Render(); } // Roll up any remaining salvage and widget-tize it List <SalvageDef> rolledUpSalvage = Helper.RollupSalvage(State.PotentialSalvage); Helper.CalculateAndAddAvailableSalvage(salvageScreen, rolledUpSalvage); State.Reset(); }
public static void Postfix(SimGameState __instance) { foreach (Pilot pilot in __instance.PilotRoster) { var rng = new System.Random(); int Roll = rng.Next(1, 100); if (pilot.pilotDef.PilotTags.Contains("pilot_unstable")) { if (Roll <= 33) { pilot.pilotDef.PilotTags.Add("pilot_morale_high"); pilot.pilotDef.PilotTags.Remove("pilot_morale_low"); } else if (Roll > 33 && Roll <= 66) { pilot.pilotDef.PilotTags.Add("pilot_morale_low"); pilot.pilotDef.PilotTags.Remove("pilot_morale_high"); } else { pilot.pilotDef.PilotTags.Remove("pilot_morale_low"); pilot.pilotDef.PilotTags.Remove("pilot_morale_high"); } } } bool honest = false; foreach (Pilot pilot in __instance.PilotRoster) { if (pilot.pilotDef.PilotTags.Contains("pilot_honest")) { honest = true; } } foreach (Pilot pilot in __instance.PilotRoster) { if (pilot.pilotDef.PilotTags.Contains("pilot_criminal") && !honest) { var rng = new System.Random(); int Roll = rng.Next(1, 101); if (Roll < settings.pilot_criminal_StealPercent) { __instance.AddFunds(settings.pilot_criminal_StealAmount, null, true); } } } if (settings.IsSaveGame) { foreach (Pilot pilot in __instance.PilotRoster) { if (pilot.pilotDef.PilotTags.Contains("pilot_tech") && !settings.pilot_tech_vanillaTech) { __instance.CompanyStats.ModifyStat <int>("SimGame", 0, "MechTechSkill", StatCollection.StatOperation.Int_Add, settings.pilot_tech_TechBonus, -1, true); } else if (settings.pilot_tech_vanillaTech) { int TechCount = 0; foreach (Pilot techpilot in __instance.PilotRoster) { if (pilot.pilotDef.PilotTags.Contains("pilot_tech")) { TechCount = TechCount + 1; } } int TechAdd = TechCount / settings.pilot_tech_TechsNeeded; __instance.CompanyStats.ModifyStat <int>("SimGame", 0, "MechTechSkill", StatCollection.StatOperation.Int_Add, settings.pilot_tech_TechBonus, -1, true); } if (pilot.pilotDef.PilotTags.Contains("pilot_disgraced")) { __instance.CompanyStats.ModifyStat <int>("SimGame", 0, "Morale", StatCollection.StatOperation.Int_Add, settings.pilot_disgraced_MoralePenalty, -1, true); } if (pilot.pilotDef.PilotTags.Contains("pilot_honest")) { __instance.CompanyStats.ModifyStat <int>("SimGame", 0, "Morale", StatCollection.StatOperation.Int_Add, settings.pilot_honest_MoraleBonus, -1, true); } if (pilot.pilotDef.PilotTags.Contains("pilot_dishonest")) { __instance.CompanyStats.ModifyStat <int>("SimGame", 0, "Morale", StatCollection.StatOperation.Int_Add, settings.pilot_dishonest_MoralePenalty, -1, true); } } } }
// Clone of SoldMultipleItems public void BuyMultipleItems(int quantityBought) { Mod.Log.Debug("BH:BMI entered."); //bool isNotStoreOrSalvage = shopIDO.GetItemType() != MechLabDraggableItemType.StorePart && // shopIDO.GetItemType() != MechLabDraggableItemType.SalvagePart; //if (simGameState.InMechLabStore() || !isNotStoreOrSalvage) { // Mod.Logger.Info($"BH:BMI - in the mech lab store, or the part isn't a store part or salvage (is {shopIDO.GetItemType()}). Aborting!"); // return; //} ShopDefItem toBuySDI = shopIDO.shopDefItem; // Look for the item in the store inventory Shop itemShop = shopIDO.GetShop(); List <ShopDefItem> activeInventory = itemShop.ActiveInventory; Shop.PurchaseType storePT = toBuySDI.IsInfinite ? Shop.PurchaseType.Normal : Shop.PurchaseType.Special; ShopDefItem storeSDI = activeInventory.Find((ShopDefItem cachedItem) => cachedItem.ID == toBuySDI.ID && cachedItem.Type == shopIDO.shopDefItem.Type); if (storeSDI == null) { Mod.Log.Info("BH:BMI - item not found in store inventory. Aborting!"); return; } // Check the price int itemPrice = itemShop.GetPrice(storeSDI, storePT, itemShop.ThisShopType); Mod.Log.Info($"BH:BMI - itemPrice:{itemPrice} for purchaseType:{storePT}"); int purchasePrice = itemPrice * quantityBought; if (purchasePrice > simGameState.Funds) { Mod.Log.Info($"BH:BMI - purchasePrice:{purchasePrice} (itemPrice:{itemPrice} x quantity:{quantityBought}) > funds: {simGameState.Funds}. Aborting!"); return; } // Check the quantity available if (storePT != Shop.PurchaseType.Normal) { if (storeSDI.Count < quantityBought) { Mod.Log.Info($"BH:BMI - store has quantity {storeSDI.Count} in inventory, but {quantityBought} was requested. Aborting!"); return; } storeSDI.Count -= quantityBought; if (storeSDI.Count < 1) { Mod.Log.Debug($"BH:BMI - Store count below 1, removing!"); activeInventory.Remove(storeSDI); } Mod.Log.Debug($"BH:BMI - Reduced store count by {quantityBought} to {storeSDI.Count}!"); } for (int i = 0; i < quantityBought; i++) { // Decrement the price simGameState.AddFunds(-itemPrice, null, true, true); simGameState.AddFromShopDefItem(storeSDI, false, itemPrice, SimGamePurchaseMessage.TransactionType.Purchase); Mod.Log.Debug($"BH:BMI - Reducing funds by -{itemPrice} and adding 1 of {storeSDI.ID}"); if (!toBuySDI.IsInfinite) { if (shopIDO.quantity > 1) { shopIDO.ModifyQuantity(-1); Mod.Log.Debug($"BH:BMI - reducing shop inventory by 1 to {shopIDO.quantity}"); } else { Mod.Log.Debug($"BH:BMI - shop inventory below 1, removing!"); inventoryWidget.RemoveDataItem(shopIDO); if (shopIDO != null) { shopIDO.Pool(); } shopIDO = null; } } } inventoryWidget.RefreshInventoryList(); Mod.Log.Debug("BH:BMI - Updating all money spots"); shopScreen.UpdateMoneySpot(); shopScreen.RefreshAllMoneyListings(); if (toBuySDI.Type == ShopItemType.MechPart) { shopScreen.OnItemSelected(inventoryWidget.GetSelectedViewItem()); } Mod.Log.Debug("BH:BMI - triggering iron man save"); Traverse ironManT = Traverse.Create(shopScreen).Field("triggerIronManAutoSave"); ironManT.SetValue(true); }
static void Postfix(SimGameState __instance, PilotDef def) { Mod.Log.Info?.Write($"Adding new pilot def: {def} to roster."); CrewDetails details = ModState.GetCrewDetails(def); // Add any mechtech, medtech, or aerospace points if (details.IsAerospaceCrew) { // Track our skill points Mod.Log.Info?.Write($" -- crew is aerospace, adding: {details.Value} aerospace skill"); __instance.CompanyStats.ModifyStat <int>(null, -1, ModStats.Aerospace_Skill, StatCollection.StatOperation.Int_Add, details.Value); // Track the crew count __instance.CompanyStats.ModifyStat <int>(null, -1, ModStats.CrewCount_Aerospace, StatCollection.StatOperation.Int_Add, 1); } else if (details.IsMechTechCrew) { Mod.Log.Info?.Write($" -- crew is mechtech, adding: {details.Value} mechtech skill"); __instance.CompanyStats.ModifyStat <int>(null, -1, ModStats.HBS_Company_MechTech_Skill, StatCollection.StatOperation.Int_Add, details.Value); // Track the crew count __instance.CompanyStats.ModifyStat <int>(null, -1, ModStats.CrewCount_MechTechs, StatCollection.StatOperation.Int_Add, 1); } else if (details.IsMechWarrior) { // Track the crew count __instance.CompanyStats.ModifyStat <int>(null, -1, ModStats.CrewCount_MechWarriors, StatCollection.StatOperation.Int_Add, 1); } else if (details.IsMedTechCrew) { Mod.Log.Info?.Write($" -- crew is medtech, adding: {details.Value} medtech skill"); __instance.CompanyStats.ModifyStat <int>(null, -1, ModStats.HBS_Company_MedTech_Skill, StatCollection.StatOperation.Int_Add, details.Value); // Track the crew count __instance.CompanyStats.ModifyStat <int>(null, -1, ModStats.CrewCount_MedTechs, StatCollection.StatOperation.Int_Add, 1); } else if (details.IsVehicleCrew) { // Track the crew count __instance.CompanyStats.ModifyStat <int>(null, -1, ModStats.CrewCount_VehicleCrews, StatCollection.StatOperation.Int_Add, 1); } if (ModState.IsHiringFlow) { // We are a real hire, not from initial spawn Mod.Log.Debug?.Write(" -- performing hiring checks."); // An actual hire versus start-of-game initialization. Revert the costs previously applied in HirePilot int purchaseCostAfterReputationModifier = __instance.CurSystem.GetPurchaseCostAfterReputationModifier(__instance.GetMechWarriorHiringCost(def)); __instance.AddFunds(purchaseCostAfterReputationModifier, null, true, true); // Apply their hiring bonus Mod.Log.Info?.Write($"Hiring crew for bonus: {details.AdjustedBonus}"); __instance.AddFunds(-details.AdjustedBonus, null, true, true); // Only refresh if we're actually in game __instance.RoomManager.RefreshTimeline(false); __instance.RoomManager.RefreshDisplay(); } // DEBUG Mod.Log.Debug?.Write($"ITERATING TAGS ON DEF"); foreach (string tag in def.PilotTags) { Mod.Log.Debug?.Write($" -- tag: {tag}"); } }
public static void DisputeAction(Contract contract, AAR_SalvageScreen salvageScreen, Dispute dispute) { Mod.Log.Info($"Player disputed holdback."); SimGameState sgs = UnityGameInstance.BattleTechGame.Simulation; Mod.Log.Info($" Dispute legal fees:{dispute.MRBFees}"); sgs.AddFunds(dispute.MRBFees, $"MRB Legal Fees re: {contract.Name}", false); Dispute.Outcome outcome = dispute.GetOutcome(); if (outcome == Dispute.Outcome.SUCCESS) { Mod.Log.Info($"DISPUTE SUCCESS: Player keeps disputed salvage and gains {dispute.Picks} items from compensation pool."); // Update quantities of compensation parts Mod.Log.Debug(" -- Updating quantities on compensation parts."); List <string> compItemsDesc = new List <string>(); int loopCount = 0; foreach (SalvageDef compSDef in ModState.CompensationParts) { if (loopCount < dispute.Picks) { loopCount++; } else { break; } Mod.Log.Debug($" compensation salvageDef:{compSDef.Description.Name} with quantity:{compSDef.Count}"); foreach (SalvageDef sDef in ModState.PotentialSalvage) { Mod.Log.Debug($" salvageDef:{sDef.Description.Name} with quantity:{sDef.Count}"); if (compSDef.RewardID == sDef.RewardID) { Mod.Log.Debug($" Matched compensation target, updating quantity to: {compSDef.Count + sDef.Count}"); string localItemName = new Text(compSDef.Description.Name).ToString(); string localItemAndQuantity = new Text( Mod.Config.DialogText[ModConfig.DT_ITEM_AND_QUANTITY], new object[] { localItemName, compSDef.Count } ).ToString(); compItemsDesc.Add(localItemAndQuantity); sDef.Count = sDef.Count + compSDef.Count; break; } } } string compDescs = " -" + string.Join("\n -", compItemsDesc.ToArray()); // Display the confirmation screen string localDialogTitle = new Text(Mod.Config.DialogText[ModConfig.DT_SUCCESS_TITLE]).ToString(); string localDialogText = new Text( Mod.Config.DialogText[ModConfig.DT_SUCCESS_TEXT], new object[] { compDescs } ).ToString(); string localButtonOk = new Text(Mod.Config.DialogText[ModConfig.DT_BUTTON_OK]).ToString(); GenericPopupBuilder.Create(localDialogTitle, localDialogText) .AddButton("OK") .Render(); } else { Mod.Log.Info($"DISPUTE FAILURE: Player loses disputed items, and {dispute.Picks} items from the salvage pool."); // Remove the disputed items Mod.Log.Debug(" -- Removing disputed items."); foreach (SalvageDef sDef in ModState.HeldbackParts) { Helper.RemoveSalvage(sDef); } // Update quantities of compensation parts Mod.Log.Debug(" -- Determining dispute failure picks."); List <SalvageDef> disputePicks = new List <SalvageDef>(); List <SalvageDef> components = ModState.PotentialSalvage.Where(sd => sd.Type == SalvageDef.SalvageType.COMPONENT).ToList(); components.Sort(new Helper.SalvageDefByCostDescendingComparer()); int loopCount = 0; foreach (SalvageDef compDef in components) { if (loopCount < dispute.Picks) { loopCount++; } else { break; } Mod.Log.Debug($" dispute fail salvageDef:{compDef.Description.Name} with quantity:{compDef.Count}"); disputePicks.Add(compDef); ModState.PotentialSalvage.Remove(compDef); } List <string> heldbackItemsDesc = new List <string>(); foreach (SalvageDef sDef in ModState.HeldbackParts) { heldbackItemsDesc.Add($"{sDef.Description.Name} [QTY:{sDef.Count}]"); } string heldbackDescs = " -" + string.Join("\n -", heldbackItemsDesc.ToArray()); List <string> disputeDesc = new List <string>(); foreach (SalvageDef sDef in disputePicks) { disputeDesc.Add($"{sDef.Description.Name} [QTY:{sDef.Count}]"); } string disputeDescs = " -" + string.Join("\n -", disputeDesc.ToArray()); // Display the configmration screen string localDialogTitle = new Text(Mod.Config.DialogText[ModConfig.DT_FAILED_TITLE]).ToString(); string localDialogText = new Text( Mod.Config.DialogText[ModConfig.DT_FAILED_TEXT], new object[] { ModState.Employer, sgs.CompanyName, heldbackDescs, disputeDescs }).ToString(); string localButtonOk = new Text(Mod.Config.DialogText[ModConfig.DT_BUTTON_OK]).ToString(); GenericPopupBuilder.Create(localDialogTitle, localDialogText) .AddButton(localButtonOk) .Render(); } // Roll up any remaining salvage and widget-tize it List <SalvageDef> rolledUpSalvage = Helper.RollupSalvage(ModState.PotentialSalvage); Helper.CalculateAndAddAvailableSalvage(salvageScreen, rolledUpSalvage); ModState.Reset(); }