private static void AutoFixSlots(ChassisDef chassisDef) { var changes = Control.settings.AutoFixChassisDefSlotsChanges; if (changes == null) { return; } var adapter = new ChassisDefAdapter(chassisDef); var locations = adapter.Locations; if (lookupDictionary == null) { lookupDictionary = changes.ToDictionary(x => x.Location, x => x.Change); } for (var i = 0; i < locations.Length; i++) { var location = locations[i].Location; if (lookupDictionary.TryGetValue(location, out var change)) { ModifyInventorySlots(ref locations[i], location, change); } } adapter.refreshLocationReferences(); //Control.mod.Logger.LogDebug("AutoFixSlots InventorySlots=" + chassisDef.LeftTorso.InventorySlots); }
public static void SetColor(MechBayChassisUnitElement __instance, Image ___mechImage, TextMeshProUGUI ___partsText, TextMeshProUGUI ___partsLabelText, ChassisDef chassisDef, DataManager dataManager, int partsCount, int partsMax, int chassisQuantity) { try { if (partsCount != 0) { ___partsLabelText.SetText("Parts"); ___partsText.SetText($"{partsCount} / {partsMax}"); if (partsCount >= partsMax) { ___mechImage.color = Control.Settings.color_ready; } else { int min = ChassisHandler.GetInfo(chassisDef.Description.Id).MinParts; var list = ChassisHandler.GetCompatible(chassisDef.Description.Id); if (list == null) { ___mechImage.color = Control.Settings.color_exclude; } else if (list.Sum(i => ChassisHandler.GetCount(i.Description.Id)) >= partsMax && chassisDef.MechPartCount >= min) { ___mechImage.color = Control.Settings.color_variant; } else { ___mechImage.color = Control.Settings.color_notready; } } } else { ___mechImage.color = Control.Settings.color_stored; } var go = __instance.transform.Find("Representation/contents/storage_OverlayBars"); var mech = ChassisHandler.GetMech(chassisDef.Description.Id); if (Control.Settings.BGColors != null && Control.Settings.BGColors.Length > 0) { foreach (var color in Control.Settings.BGColors) { if (mech.MechTags.Contains(color.Tag)) { var tracker = go.GetComponent <UIColorRefTracker>(); tracker.SetUIColor(UIColor.Custom); tracker.OverrideWithColor(color.color); break; } } } } catch (Exception e) { Control.LogDebug("Error while get mechdef for " + chassisDef.Description.Id); } }
internal static TagSet eweTagSet = new TagSet(new string[] { "chassis_electronicWarfare" }); // Determined via inventory check for MechDefs but still needed for ChassisDefs // Helper internal static bool GetChassisClassification(ChassisDef chassisDef, out string cAbbr, out string cDesc) { if (chassisDef.ChassisTags.ContainsAny(starleagueTagSet)) { Logger.Debug($"[ChassisClassification.GetChassisClassification] ({chassisDef.Description.Id}) is a SLDF chassis"); cAbbr = starleagueAbbr; cDesc = starleagueDesc; return(true); } else if (chassisDef.ChassisTags.ContainsAny(prototypeTagSet)) { Logger.Debug($"[ChassisClassification.GetChassisClassification] ({chassisDef.Description.Id}) is a PROTOTYPE"); cAbbr = prototypeAbbr; cDesc = prototypeDesc; return(true); } else if (chassisDef.ChassisTags.ContainsAny(eweTagSet)) { Logger.Debug($"[ChassisClassification.GetChassisClassification] ({chassisDef.Description.Id}) has Electronic Warfare Equipment"); cAbbr = eweAbbr; cDesc = eweDesc; return(true); } else { cAbbr = null; cDesc = null; return(false); } }
public static void Postfix(TooltipPrefab_Chassis __instance, object data, TextMeshProUGUI ___descriptionText) { Mod.Log.Debug($"TP_C:SD - Init"); if (data != null && ___descriptionText != null) { ChassisDef chassisDef = (ChassisDef)data; double storageTons = Helper.CalculateChassisTonnage(chassisDef); // Calculate total tonnage costs SimGameState sgs = UnityGameInstance.BattleTechGame.Simulation; double totalTonnage = Helper.CalculateTonnageForAllMechParts(sgs); int storageCost = 0; if (totalTonnage > 0) { int totalCost = Helper.CalculateTotalForMechPartsCargo(sgs, totalTonnage); double tonnageFraction = storageTons / totalTonnage; storageCost = (int)Math.Ceiling(totalCost * tonnageFraction); } else { double factoredTonnage = Math.Ceiling(storageTons * Mod.Config.PartsFactor); double scaledTonnage = Math.Pow(factoredTonnage, Mod.Config.PartsExponent); storageCost = (int)(Mod.Config.PartsCostPerTon * scaledTonnage); } Text newDetails = new Text(chassisDef.Description.Details + $"\n\n<color=#FF0000>Cargo Cost:{SimGameState.GetCBillString(storageCost)} from {storageTons} tons</color>"); Mod.Log.Debug($" Setting details: {newDetails}u"); ___descriptionText.SetText(newDetails.ToString()); } else { Mod.Log.Debug($"TP_C:SD - Skipping"); } }
internal static void SetupCalculator(ChassisDef chassisDef, List <MechComponentRef> componentRefs) { if (chassisDef?.HardpointDataDef?.HardpointData == null) { return; } if (componentRefs == null || componentRefs.Count == 0) { return; } componentRefs = componentRefs .Where(c => c != null) .Where(c => c.ComponentDefType == ComponentType.Weapon) .Where(c => c.Def is WeaponDef) .ToList(); if (componentRefs.Count == 0) { return; } try { calculator = new WeaponComponentPrefabCalculator(chassisDef, componentRefs); } catch (Exception e) { Control.mod.Logger.LogError(e); } }
internal WeaponComponentPrefabCalculator(ChassisDef chassisDef, List <MechComponentRef> componentRefs, ChassisLocations location = ChassisLocations.All) { this.chassisDef = chassisDef; componentRefs = componentRefs .OrderByDescending(c => ((WeaponDef)c.Def).InventorySize) .ThenByDescending(c => ((WeaponDef)c.Def).Tonnage) .ThenByDescending(c => ((WeaponDef)c.Def).Damage) .ThenByDescending(c => c.ComponentDefID) .ToList(); if (!MechDefBuilder.Locations.Contains(location)) { location = ChassisLocations.All; } if (location == ChassisLocations.All) { foreach (var tlocation in MechDefBuilder.Locations) { var locationComponentRefs = componentRefs.Where(c => c.MountedLocation == tlocation).ToList(); CalculateMappingForLocation(tlocation, locationComponentRefs); } } else { CalculateMappingForLocation(location, componentRefs); } }
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 Mech BuildTestMech(float tonnage) { Mech mech = new Mech(); MechDef mechDef = new MechDef(); DescriptionDef descriptionDef = new DescriptionDef("foo", "bar", "raboof", "", 100, 0, true, "", "", ""); ChassisDef chassisDef = new ChassisDef(descriptionDef, "", "", "", "", "", tonnage, tonnage, WeightClass.ASSAULT, 0, 0, 0, 0, 0, 0, new float[] { 0 }, 0, 0, 0, 0, 0, true, 0, 0, 0, 0, 0, 0, 0, 0, new LocationDef[] { }, new MechComponentRef[] { }, new HBS.Collections.TagSet()); Traverse tonnageT = Traverse.Create(chassisDef).Property("Tonnage"); tonnageT.SetValue(tonnage); Traverse chassisT = Traverse.Create(mechDef).Field("_chassisDef"); chassisT.SetValue(chassisDef); Traverse mechDefT = Traverse.Create(mech).Property("MechDef"); mechDefT.SetValue(mechDef); mech = (Mech)InitAbstractActor(mech); return(mech); }
internal WeaponComponentPrefabCalculator(ChassisDef chassisDef, List <MechComponentRef> allComponentRefs, ChassisLocations location = ChassisLocations.All) { this.chassisDef = chassisDef; preMappedPrefabNames = allComponentRefs.Select(c => GetPredefinedPrefabName(c)).Where(x => x != null).ToHashSet(); var componentRefs = allComponentRefs .Where(c => c.ComponentDefType == ComponentType.Weapon) .Where(c => GetPredefinedPrefabName(c) == null) .OrderByDescending(c => c.Def.InventorySize) .ThenByDescending(c => c.Def.Tonnage) .ThenByDescending(c => ((WeaponDef)c.Def).Damage) .ThenByDescending(c => c.ComponentDefID) .ToList(); if (!MechDefBuilder.Locations.Contains(location)) { location = ChassisLocations.All; } if (location == ChassisLocations.All) { foreach (var tlocation in MechDefBuilder.Locations) { var localRefs = componentRefs.Where(c => c.MountedLocation == tlocation).ToList(); CalculateMappingForLocation(tlocation, localRefs); } } else { CalculateMappingForLocation(location, componentRefs); } }
private static void AutoFixChassisDef(ChassisDef chassisDef) { if (Control.settings.AutoFixChassisDefInitialTonnage) { SetOriginalTonnage(chassisDef); var tonnage = chassisDef.Tonnage * Control.settings.AutoFixChassisDefInitialToTotalTonnageFactor; var info = typeof(ChassisDef).GetProperty("InitialTonnage"); var value = Convert.ChangeType(tonnage, info.PropertyType); info.SetValue(chassisDef, value, null); } if (Control.settings.AutoFixChassisDefMaxJumpjets) { var coreDef = new EngineCoreDef { Rating = Control.settings.AutoFixChassisDefMaxJumpjetsRating }; var maxCount = Mathf.Min( Control.settings.AutoFixChassisDefMaxJumpjetsCount, coreDef.GetMovement(chassisDef.Tonnage).JumpJetCount ); var info = typeof(ChassisDef).GetProperty("MaxJumpjets"); var value = Convert.ChangeType(maxCount, info.PropertyType); info.SetValue(chassisDef, value, null); } }
private static void AutoFixChassisDef(ChassisDef chassisDef) { if (AutoFixerFeature.settings.ChassisDefInitialTonnage) { var tonnage = chassisDef.Tonnage * AutoFixerFeature.settings.ChassisDefInitialToTotalTonnageFactor; var info = typeof(ChassisDef).GetProperty("InitialTonnage"); var value = Convert.ChangeType(tonnage, info.PropertyType); info.SetValue(chassisDef, value, null); Control.Logger.Debug?.Log($"set InitialTonnage={tonnage}"); } if (AutoFixerFeature.settings.ChassisDefMaxJumpjets) { var coreDef = new EngineCoreDef { Rating = AutoFixerFeature.settings.ChassisDefMaxJumpjetsRating }; var maxCount = Mathf.Min( AutoFixerFeature.settings.ChassisDefMaxJumpjetsCount, coreDef.GetMovement(chassisDef.Tonnage).JumpJetCount ); var info = typeof(ChassisDef).GetProperty("MaxJumpjets"); var value = Convert.ChangeType(maxCount, info.PropertyType); info.SetValue(chassisDef, value, null); Control.Logger.Debug?.Log($"set MaxJumpjets={maxCount}"); } if (AutoFixerFeature.settings.ChassisDefArmorStructureRatio) { ArmorStructureRatioFeature.Shared.AutoFixChassisDef(chassisDef); } }
public static void PreparePopup(ChassisDef chassisDef, MechBayPanel mechbay, MechBayChassisInfoWidget widget, MechBayChassisUnitElement unitElement) { mechBay = mechbay; ChassisHandler.unitElement = unitElement; infoWidget = widget; chassis = chassisDef; mech = ChassisToMech[chassis.Description.Id]; }
public static Vector3 Get(ChassisDef def) { return(Get( identifier: def.Description.Id, tags: def.ChassisTags, type: typeof(Mech), prefab: def.PrefabBase)); }
public static void Postfix(ChassisDef __instance) { if (__instance.ChassisTags.Contains("mech_quirk_improvedsensorsbap")) { __instance.ChassisTags.Remove("mech_quirk_improvedsensorsbap"); __instance.ChassisTags.Add("mech_quirk_improvedsensors"); } }
public static bool IsVehicle(this ChassisDef chassis) { if (chassis == null || chassis.ChassisTags == null) { return(false); } return(chassis.ChassisTags.Contains(Control.Instance.Settings.FakeVehicleTag)); }
public static float?GetOriginalTonnage(ChassisDef chassisDef) { if (OriginalInitialTonnages.TryGetValue(chassisDef.Description.Id, out var value)) { return(value); } return(null); }
private static bool CheckChassisDef(ChassisDef def, string prefix) { if (def.Description == null || def.Description.Id == null) { return(false); } return(def.Description.Id.StartsWith(prefix)); }
private static void ScrapChassis(int num, ChassisDef p1, MechBayChassisInfoWidget widget, MechBayPanel mechBay) { for (int i = 0; i < num; i++) { UnityGameInstance.BattleTechGame.Simulation.ScrapInactiveMech(p1.Description.Id, true); } mechBay.RefreshData(false); mechBay.SelectChassis(null); }
public static T AddComponent <T>(this ChassisDef target, T component) where T : ICustom { if (component is SimpleCustom <ChassisDef> simple) { simple.Def = target; } Database.AddCustom(target, component); return(component); }
private static void SetOriginalTonnage(ChassisDef chassisDef) { if (OriginalInitialTonnages.ContainsKey(chassisDef.Description.Id)) { return; } OriginalInitialTonnages[chassisDef.Description.Id] = chassisDef.InitialTonnage; }
public static bool IsCCNoSalvage(this ChassisDef d) { object f = GetCCFlagsChassisDef(d); if (f != null) { return(CCFlagsGetNotSalvageable(f)); } return(false); }
internal static void OverrideChassisSettings(ChassisDef chassisDef) { if (Control.settings.AutoFixChassisDefSkip.Contains(chassisDef.Description.Id)) { return; } AutoFixInitialTonnage(chassisDef); AutoFixSlots(chassisDef); }
private ListElementControllerCompare(ListElementController_BASE_NotListView item) { salvageDef = item.salvageDef; componentDef = item.componentDef; ammoBoxDef = item.ammoBoxDef; weaponDef = item.weaponDef; mechDef = item.mechDef; chassisDef = item.chassisDef; shopDefItem = item.shopDefItem; }
public static int GetMechPartsRequiredByWeight(ChassisDef chassisDef) { int index = ((int)chassisDef.Tonnage) / 5 - 1; return(index >= PartsByWeightTable.Count ? PartsByWeightTable.Count : index < 0 ? PartsByWeightTable[0] : PartsByWeightTable[index]); }
public static void Postfix(ChassisDef __instance) { try { ChassisHandler.OverrideChassisSettings(__instance); } catch (Exception e) { Control.Logger.Error.Log(e); } }
private static void ScrapParts(int num, ChassisDef mech, MechBayChassisInfoWidget widget, MechBayPanel mechBay) { for (int i = 0; i < num; i++) { UnityGameInstance.BattleTechGame.Simulation.ScrapMechPart(mech.Description.Id, 1, UnityGameInstance.BattleTechGame.Simulation.Constants.Story.DefaultMechPartMax, true); } widget.SetData(mechBay, null); mechBay.RefreshData(false); mechBay.SelectChassis(null); }
public static T GetOrCreate <T>(this ChassisDef target, Func <T> factory) where T : ICustom { var result = target.GetComponent <T>(); if ((result is ExtendedDetails.ExtendedDetails ed) && ed.Def != target.Description) { ed.Def = target.Description; } return(result ?? target.AddComponent(factory.Invoke())); }
internal MechDefBuilder(ChassisDef chassisDef, List <MechComponentRef> inventory) { Chassis = chassisDef; Inventory = inventory; DataManager = UnityGameInstance.BattleTechGame.DataManager; TotalMax = Locations.Select(chassisDef.GetLocationDef).Sum(d => d.InventorySlots); CalculateStats(); Control.Logger.Debug?.Log(this); }
public static void Postfix(MechBayChassisInfoWidget __instance, ChassisDef ___selectedChassis, GameObject ___readyBtnObj, GameObject ___partsCountObj) { if (___selectedChassis == null) { return; } if (___selectedChassis.MechPartCount > 0) { ___readyBtnObj.SetActive(true); ___partsCountObj.SetActive(false); } }
internal static void OverrideChassisSettings(ChassisDef chassisDef) { if (chassisDef.ChassisTags.IgnoreAutofix()) { return; } Control.mod.Logger.Log($"Auto fixing chassisDef={chassisDef.Description.Id}"); AutoFixChassisDef(chassisDef); AutoFixSlots(chassisDef); }