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 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 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); }