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 bool FixGetMechdef(ref ShopDefItem itemDef, Shop shop, bool isBulkAdd, bool isSelling, IMechLabDropTarget targetWidget, MechLabInventoryWidget_ListView ___inventoryWidget, bool ___isInBuyingState, SimGameState ___simState, SG_Shop_Screen __instance) { if (itemDef.Type == ShopItemType.Mech && !___isInBuyingState) { var dataManager = ___simState.DataManager; string guid8 = itemDef.GUID; if (dataManager.ChassisDefs.Exists(guid8)) { ChassisDef chassisDef = dataManager.ChassisDefs.Get(guid8); string newGUID = ___simState.GenerateSimGameUID(); var id = ChassisHandler.GetMDefFromCDef(guid8); MechDef stockMech = dataManager.MechDefs.Get(id); MechDef mechDef3 = new MechDef(chassisDef, newGUID, stockMech); mechDef3.Refresh(); if (mechDef3 != null) { InventoryDataObject_ShopFullMech inventoryDataObject_ShopFullMech2 = new InventoryDataObject_ShopFullMech(); inventoryDataObject_ShopFullMech2.Init(mechDef3, itemDef, shop, ___simState, dataManager, targetWidget, itemDef.Count, isSelling, new UnityAction <InventoryItemElement>(__instance.OnItemSelected)); ___inventoryWidget.AddItemToInventory(inventoryDataObject_ShopFullMech2, isBulkAdd); inventoryDataObject_ShopFullMech2.SetItemDraggable(false); } } return(false); } return(true); }
public static void Postfix(ChassisDef __instance) { try { ChassisHandler.OverrideChassisSettings(__instance); } catch (Exception e) { Control.Logger.Error.Log(e); } }
public static bool GetVehicleTags(ChassisDef chassis, DataManager dm, ref TagSet __result) { if (!chassis.IsVehicle()) { return(true); } var mid = ChassisHandler.GetMDefFromCDef(chassis.Description.Id); var mech = dm.VehicleDefs.Get(mid); if (mech == null) { Control.Instance.LogError("Cannot find vehicle with id " + mid); return(true); } __result = mech.VehicleTags; return(false); }
public static bool ReadyVehicle(MechBayPanel __instance, MechBayChassisUnitElement chassisElement, ref MechBayChassisUnitElement ___selectedChassis, MechBayRowGroupWidget ___bayGroupWidget) { try { var chassisDef = chassisElement.ChassisDef; if (!chassisDef.IsVehicle()) { return(true); } var id = chassisElement.ChassisDef.Description.Id; var sim = __instance.Sim; int start = sim.VehicleShift(); int end = start + sim.GetMaxActiveMechs(); int baySlot = -1; for (int i = start; i < end; i++) { MechDef mech_in_slot = null; if (!sim.ActiveMechs.TryGetValue(i, out mech_in_slot)) { sim.ReadyingMechs.TryGetValue(i, out mech_in_slot); } if (mech_in_slot == null) { baySlot = i; break; } } if (baySlot < 0) { Control.Instance.LogDebug(DInfo.General, "No Free vehicle slots for {0}", id); return(false); } var mid = ChassisHandler.GetMDefFromCDef(id); var sim_id = sim.GenerateSimGameUID(); var stock = __instance.DataManager.MechDefs.Get(mid); var mech = new MechDef(chassisDef, sim_id, stock); mech.SetInventory(stock.Inventory); WorkOrderEntry_ReadyMech workOrderEntry_ReadyMech = new WorkOrderEntry_ReadyMech( string.Format("ReadyMech-{0}", sim_id), Strings.T("Readying 'Mech - {0}", new object[] { chassisDef.Description.Name }), sim.Constants.Story.MechReadyTime, baySlot, mech, Strings.T( sim.Constants.Story.MechReadiedWorkOrderCompletedText, new object[] { chassisDef.Description.Name })); sim.MechLabQueue.Add(workOrderEntry_ReadyMech); sim.ReadyingMechs[baySlot] = mech; sim.RoomManager.AddWorkQueueEntry(workOrderEntry_ReadyMech); sim.UpdateMechLabWorkQueue(false); sim.RemoveItemStat(id, typeof(MechDef), false); AudioEventManager.PlayAudioEvent("audioeventdef_simgame_vo_barks", "workqueue_readymech", WwiseManager.GlobalAudioObject, null); ___selectedChassis = null; __instance.RefreshData(true); __instance.ViewBays(); __instance.SelectMech(___bayGroupWidget.GetMechUnitForSlot(baySlot), true); } catch (Exception e) { Control.Instance.LogError(e); } return(false); }
public static bool GetVehicleInfo(MechDef mech, ref ChassisHandler.mech_info __result) { if (!mech.IsVehicle()) { return(true); } __result = new ChassisHandler.mech_info(); string id = mech.Description.Id; var vehicle = UnityGameInstance.BattleTechGame.Simulation.DataManager.VehicleDefs.Get(id); var css = CustomSalvage.Control.Instance.Settings; int max_parts = UnityGameInstance.BattleTechGame.Simulation.Constants.Story.DefaultMechPartMax; int min_parts_special = Mathf.CeilToInt(max_parts * css.MinPartsToAssemblySpecial); var assembly = vehicle.Chassis.GetComponent <VAssemblyVariant>(); __result.Omni = !String.IsNullOrEmpty(Control.Instance.Settings.OmniTechTag) && vehicle.VehicleTags.Contains(Control.Instance.Settings.OmniTechTag); if (!Control.Instance.Settings.AllowFrankenTank) { __result.Excluded = true; } else if (assembly != null && assembly.Exclude) { __result.Excluded = true; } else if (assembly != null && assembly.Include) { __result.Excluded = false; } else if (css.ExcludeVariants.Contains(id)) { __result.Excluded = true; } else if (css.ExcludeTags.Any(extag => vehicle.VehicleTags.Contains(extag))) { __result.Excluded = true; } if (css.SpecialTags != null && css.SpecialTags.Length > 0) { foreach (var tag_info in css.SpecialTags) { if (vehicle.VehicleTags.Contains(tag_info.Tag)) { __result.MinParts = min_parts_special; __result.PriceMult *= tag_info.Mod; __result.Special = true; } } } if (__result.Omni) { __result.MinParts = 1; } if (assembly != null) { if (assembly.ReplacePriceMult) { __result.PriceMult = assembly.PriceMult; } else { __result.PriceMult *= assembly.PriceMult; } if (assembly.PartsMin >= 0) { __result.MinParts = Mathf.CeilToInt(max_parts * assembly.PartsMin); } } Control.Instance.LogDebug(DInfo.Assembly, "GetVehicle info for {0}", vehicle.Chassis.Description.Id); if (assembly != null) { Control.Instance.LogDebug(DInfo.Assembly, "-- " + assembly.ToString()); } else { Control.Instance.LogDebug(DInfo.Assembly, "-- VAssemblyVariant null, PID:", vehicle.Chassis.PrefabIdentifier); } __result.PrefabID = ChassisHandler.GetPrefabId(mech); return(false); }