public static void Postfix( MechLabLocationWidget __instance, MechComponentRef cRef, WeaponDef wDef, bool isOriginalLocation, bool canBeAdded, ref LocationDef ___chassisLocationDef) { try { if (cRef == null || wDef == null || ___chassisLocationDef.Hardpoints == null) { return; } var hasOmni = ___chassisLocationDef.Hardpoints.Any(x => x.Omni); if (hasOmni) { __instance.ShowHighlightFrame(true, (!isOriginalLocation) ? ((!canBeAdded) ? UIColor.GoldHalf : UIColor.Gold) : UIColor.Blue); } } catch (Exception e) { Control.mod.Logger.LogError(e); } }
internal static bool ShowHighlightFrame( MechLabLocationWidget widget, bool isOriginalLocation, ref MechComponentRef cRef ) { if (cRef == null) { return(true); } // we only want to highlight once, CT is only called once if (widget.loadout.Location != ChassisLocations.CenterTorso) { return(true); } if (cRef.Flags <CCFlags>().NoRemove || cRef.IsFixed) { return(true); } // get the correct widget to highlight var nwidget = MechWidgetLocation(cRef.Def); if (nwidget == null) { return(true); } nwidget.ShowHighlightFrame(true, isOriginalLocation ? UIColor.Blue : UIColor.Gold); cRef = null; return(false); }
internal static void ChangeInstallationCosts(MechComponentRef mechComponent, WorkOrderEntry_InstallComponent workOrderEntry) { if (mechComponent == null) { return; } // removing is always fast and cheap if (workOrderEntry.DesiredLocation == ChassisLocations.None) { return; } var engine = mechComponent.GetEngineCoreRef(null); if (engine == null) { return; } var cbillCost = workOrderEntry.GetCBillCost(); var techCost = workOrderEntry.GetCost(); Control.calc.CalcInstallCosts(engine.CoreDef, ref cbillCost, ref techCost); var traverse = Traverse.Create(workOrderEntry); traverse.Field("CBillCost").SetValue(cbillCost); traverse.Field("Cost").SetValue(techCost); }
public bool need_remove(MechComponentRef item, MechDef mech) { if (!item.IsFixed) { return(false); } if (item.IsModuleFixed(mech)) { return(false); } if (!item.IsDefault()) { return(false); } if (item.Is <Category>(out var category)) { if (category.CategoryDescriptor.MaxEquiped > 0 || category.CategoryDescriptor.MaxEquipedPerLocation > 0) { return(true); } } return(false); }
internal bool Add(MechComponentDef def, ChassisLocations location = ChassisLocations.None, bool force = false) { // find location if (location == ChassisLocations.None || LocationCount(location) > 1) { location = FindSpaceAtLocations(def.InventorySize, def.AllowedLocations); if (location == ChassisLocations.None) { return(false); } } var newLocationUsage = GetUsedSlots(location) + def.InventorySize; if (!force && newLocationUsage > GetMaxSlots(location)) { return(false); } TotalUsage += def.InventorySize; LocationUsage[location] = newLocationUsage; if (def.Is <DynamicSlots>(out var ds)) { DynamicSlots.Add(ds); } var componentRef = new MechComponentRef(def.Description.Id, null, def.ComponentType, location); componentRef.DataManager = DataManager; componentRef.RefreshComponentDef(); Inventory.Add(componentRef); return(true); }
public string ValidateDrop(MechLabItemSlotElement drop_item, List <InvItem> new_inventory) { var mechDef = MechLabHelper.CurrentMechLab.ActiveMech; var errors1 = new Errors(); validator.ValidateMech(mechDef, errors1); var mechDef2 = new MechDef(mechDef); var inventory2 = new_inventory.Select(x => { var r = new MechComponentRef(x.Item); r.MountedLocation = x.Location; return(r); }).ToList(); mechDef2.SetInventory(inventory2.ToArray()); var errors2 = new Errors(); validator.ValidateMech(mechDef2, errors2); var newErrors = errors2.Except(errors1); return(newErrors.FirstOrDefault()?.Message ?? string.Empty); }
public static void Postfix(MechLabLocationWidget __instance, MechComponentRef newComponent, MechLabPanel ___mechLab) { var sim = UnityGameInstance.BattleTechGame.Simulation; if (sim == null) { ModState.IsComponentValidForRefit = true; return; } foreach (var tag in newComponent.Def.ComponentTags) { if (Mod.Config.Misc.MechLabRefitReqs.MechLabRefitReqs.ContainsKey(tag)) { if (!sim.PurchasedArgoUpgrades.Contains( Mod.Config.Misc.MechLabRefitReqs.MechLabRefitReqs[tag])) { sim.DataManager.ShipUpgradeDefs.TryGet( Mod.Config.Misc.MechLabRefitReqs.MechLabRefitReqs[tag], out ShipModuleUpgrade upgrade); var SetErrorMsg = Traverse.Create(__instance).Method("SetDropErrorMessage", new Type[] { typeof(string), typeof(object[]) }); SetErrorMsg.GetValue( $"Cannot fit {newComponent.Def.Description.Name} to unit, requires Argo upgrade {upgrade.Description.Name}.", new object[] {}); ModState.IsComponentValidForRefit = false; return; } } } ModState.IsComponentValidForRefit = true; }
private static bool IsReorderable(MechComponentRef c) { var def = c?.Def; if (def == null) { return(false); } if (c.IsFixed) { return(false); } if (!(def.ComponentType >= ComponentType.AmmunitionBox && def.ComponentType <= ComponentType.Upgrade)) { return(false); } // items in arms and legs are usually bound to a certain side, so lets ignore them from relocation if (MechDefBuilder.LocationCount(def.AllowedLocations) <= 2) { return(false); } if (def.Is <Category>(out var category) && category.CategoryDescriptor.UniqueForLocation) { return(false); } return(true); }
public void CheckForAndPerformUpgrade(MechComponentRef r, SimGameState s, UpgradeList l, ref float canFreeTonns, MechDef mech, List <string[]> changedAmmoTypes) { string baseid = r.Def.Description.Id; if (s.NetworkRandom.Float(0f, 1f) > l.UpgradePerComponentChance) { return; } string log = baseid; UpgradeList.UpgradeEntry ue = l.RollEntryFromMatchingSubList(baseid, s.NetworkRandom, s.CurrentDate, ref log, l.UpgradePerComponentChance); if (ue != null) { MechComponentDef d = s.GetComponentDefFromID(ue.ID); if (r.CanUpgrade(d, canFreeTonns, mech, r.MountedLocation, mech.Inventory)) { CheckChangedAmmo(r.Def, d, changedAmmoTypes); r.DoUpgrade(d, ref canFreeTonns); BTRandomMechComponentUpgrader_Init.Log.Log("changing " + log); } else { BTRandomMechComponentUpgrader_Init.Log.Log("cannot upgrade " + log); } } else { BTRandomMechComponentUpgrader_Init.Log.Log("upgrade unavailable " + log); } }
private bool ComponentIsPartOfDefaultLoadout(MechComponentRef componentRef) { var chassisDef = _adapter.MechLab.activeMechDef.Chassis; var mechDefs = _adapter.MechLab.dataManager.MechDefs; foreach (var key in mechDefs.Keys) { var mechDef = mechDefs.Get(key); if (mechDef.Chassis != chassisDef) { continue; } var location = _adapter.Loadout.Location; if (mechDef.Inventory.Any(c => c.MountedLocation == location && c.Def.PrefabIdentifier == componentRef.Def.PrefabIdentifier)) { //Control.mod.Logger.LogDebug( // "found component " + componentRef.Def.Description.Id // + " to be in use on mech " + mechDef.Description.Id // + " for location " + location); return(true); } } return(false); }
internal static void OnAddItemStat(SimGameState sim, MechComponentRef mechComponentRef) { if (mechComponentRef == null) { return; } //if (mechComponentRef.DamageLevel == ComponentDamageLevel.Destroyed) //{ // return; //} var engineRef = mechComponentRef.GetEngineRef(); if (engineRef == null) { return; } foreach (var componentDefID in engineRef.GetInternalComponents()) { //Control.mod.Logger.LogDebug("SimGameState.OnAddItemStat extracting componentDefID=" + componentDefID); sim.AddItemStat(componentDefID, typeof(HeatSinkDef), false); } }
internal static void FixSimGameUID(SimGameState sim, MechComponentRef componentRef) { if (sim == null) { return; } var engineRef = componentRef.GetEngineCoreRef(); if (engineRef == null) { return; } //Control.mod.Logger.LogDebug($"mechDef={Global.ActiveMechDef?.Name}"); if (engineRef.UUID != null) { //Control.mod.Logger.LogDebug($"engineRef.GetNewSimGameUID={engineRef.GetNewSimGameUID()}"); return; } engineRef.UUID = sim.GenerateSimGameUID(); componentRef.SetSimGameUID(engineRef.GetNewSimGameUID()); //Control.mod.Logger.LogDebug($"componentRef.SimGameUID={componentRef.SimGameUID}"); }
public void ModifyMech(MechDef mDef, SimGameState s, UpgradeList ulist, ref float canFreeTonns, List <string[]> changedAmmoTypes, MechDef fromData) { BTRandomMechComponentUpgrader_Init.Log.Log("checking addition sublists"); List <MechComponentRef> inv = mDef.Inventory.ToList(); foreach (UpgradeList.UpgradeEntry[] l in ulist.Additions) { if (s.NetworkRandom.Float(0f, 1f) < ulist.UpgradePerComponentChance) { string log = ""; UpgradeList.UpgradeEntry ue = ulist.RollEntryFromSubList(l, s.NetworkRandom, -1, s.CurrentDate, ref log, ulist.UpgradePerComponentChance); if (ue != null && !ue.ID.Equals("")) { MechComponentDef d = s.GetComponentDefFromID(ue.ID); ChassisLocations loc = mDef.SearchLocationToAddComponent(d, canFreeTonns, inv, null, ChassisLocations.None); if (loc == ChassisLocations.None) { BTRandomMechComponentUpgrader_Init.Log.Log("cannot add " + log); continue; } BTRandomMechComponentUpgrader_Init.Log.Log($"adding {log} into {loc}"); MechComponentRef r = new MechComponentRef(ue.ID, null, d.ComponentType, loc, -1, ComponentDamageLevel.Functional, false); r.SetComponentDef(d); inv.Add(r); canFreeTonns -= d.Tonnage; } else { BTRandomMechComponentUpgrader_Init.Log.Log("cannot add, nothing rolled " + log); } } } mDef.SetInventory(inv.ToArray()); }
public static void Postfix( MechComponentRef ___componentRef, SVGImage ___icon, LocalizableText ___nameText, LocalizableText ___bonusTextA, LocalizableText ___bonusTextB ) { try { // support no icon ___icon.gameObject.SetActive(!string.IsNullOrEmpty(___componentRef.Def.Description.Icon)); // support no name ___nameText.gameObject.SetActive(!string.IsNullOrEmpty(___componentRef.Def.Description.UIName)); // support null besides empty string ___bonusTextA.gameObject.SetActive(!string.IsNullOrEmpty(___componentRef.Def.BonusValueA)); ___bonusTextB.gameObject.SetActive(!string.IsNullOrEmpty(___componentRef.Def.BonusValueB)); } catch (Exception e) { Control.Logger.Error.Log(e); } }
public void ComponentInstallWorkOrder(MechComponentRef mechComponent, ChassisLocations newLocation, WorkOrderEntry_InstallComponent result) { var workOrderCosts = mechComponent.Def.GetComponent <WorkOrderCosts>(); if (workOrderCosts == null) { return; } if (newLocation == ChassisLocations.None) // remove { if (mechComponent.DamageLevel == ComponentDamageLevel.Destroyed) { ApplyCosts(result, workOrderCosts.RemoveDestroyed); } else { ApplyCosts(result, workOrderCosts.Remove); } } else // install { ApplyCosts(result, workOrderCosts.Install); } }
public static void FixCost( SimGameState __instance, MechComponentRef mechComponent, ChassisLocations newLocation, ChassisLocations previousLocation, string mechSimGameUID, WorkOrderEntry_InstallComponent __result) { try { Control.LogDebug(DType.InstallCost, $"SimGameState_CreateComponentInstallWorkOrder: for {mechComponent.ComponentDefID}"); Control.LogDebug(DType.InstallCost, $"-- from {previousLocation} to {newLocation}"); Control.LogDebug(DType.InstallCost, $"-- order {__result?.GetType().ToString() ?? "null"}"); if (__result == null) { Control.LogDebug(DType.InstallCost, "-- No order"); return; } if (__result.DesiredLocation == ChassisLocations.None) { var tr = Traverse.Create(__result); tr.Field <int>("Cost").Value = 0; } else { var tr = Traverse.Create(__result).Field <int>("Cost"); if (tr == null) { Control.LogDebug(DType.InstallCost, "SimGameState_CreateComponentInstallWorkOrder: traverce not created!"); return; } MechDef mechByID = __instance.GetMechByID(mechSimGameUID); #if CCDEBUG if (mechByID == null) { Control.LogDebug(DType.InstallCost, "-- no mech found!"); } #endif if (mechByID != null && mechByID.Chassis.ChassisTags.Contains(Control.Settings.OmniTechFlag)) { Control.LogDebug(DType.InstallCost, "-- mech is omni!"); tr.Value = (Control.Settings.OmniTechCostBySize ? mechComponent.Def.InventorySize / 2 : 1) * Control.Settings.OmniTechInstallCost; } if (tr.Value == 0) { tr.Value = 1; } } } catch (Exception e) { Control.LogError(e); } }
public static float CalculateCBillValue(MechDef mech) { float currentCBillValue = 0f; float num = 10000f; currentCBillValue = (float)mech.Chassis.Description.Cost; float num2 = 0f; num2 += mech.Head.CurrentArmor; num2 += mech.CenterTorso.CurrentArmor; num2 += mech.CenterTorso.CurrentRearArmor; num2 += mech.LeftTorso.CurrentArmor; num2 += mech.LeftTorso.CurrentRearArmor; num2 += mech.RightTorso.CurrentArmor; num2 += mech.RightTorso.CurrentRearArmor; num2 += mech.LeftArm.CurrentArmor; num2 += mech.RightArm.CurrentArmor; num2 += mech.LeftLeg.CurrentArmor; num2 += mech.RightLeg.CurrentArmor; num2 *= UnityGameInstance.BattleTechGame.MechStatisticsConstants.CBILLS_PER_ARMOR_POINT; currentCBillValue += num2; for (int i = 0; i < mech.Inventory.Length; i++) { MechComponentRef mechComponentRef = mech.Inventory[i]; currentCBillValue += (float)mechComponentRef.Def.Description.Cost; } currentCBillValue = Mathf.Round(currentCBillValue / num) * num; return(currentCBillValue); }
internal void Show(DynamicSlots slots, bool isReservedSlot) { var dataManager = UnityGameInstance.BattleTechGame.DataManager; var id = slots.Def.Description.Id; var type = slots.Def.ComponentType; var @ref = new MechComponentRef(id, null, type, ChassisLocations.None) { DataManager = dataManager }; @ref.RefreshComponentDef(); element.SetData(@ref, ChassisLocations.None, dataManager, null); slots.ApplyTo(element, isReservedSlot); // support template elements larger 1 element.ClearSpacers(); element.thisRectTransform.sizeDelta = new Vector2(element.thisRectTransform.sizeDelta.x, 32f); if (isReservedSlot) { ResetSolidBorder(); } else { HideSolidBorder(); } gameObject.SetActive(true); element.SetDraggable(false); }
public static bool IsModuleFixed(this MechComponentRef item, MechDef mech) { Control.LogDebug(DType.FixedCheck, $"IsModuleFixed: {item.ComponentDefID}"); if (!item.IsFixed) { Control.LogDebug(DType.FixedCheck, $"-- false: not fixed"); return(false); } if (mech.Chassis.FixedEquipment != null && mech.Chassis.FixedEquipment.Length > 0) { foreach (var mref in mech.Chassis.FixedEquipment) { if (mref.MountedLocation == item.MountedLocation && item.ComponentDefID == mref.ComponentDefID) { Control.LogDebug(DType.FixedCheck, $"-- true!"); return(true); } } } Control.LogDebug(DType.FixedCheck, $"-- false: not really fixed"); return(false); }
internal EngineRef(MechComponentRef mechComponentRef, EngineDef engineDef) { this.mechComponentRef = mechComponentRef; this.engineDef = engineDef; var text = mechComponentRef.SimGameUID; if (string.IsNullOrEmpty(text)) { if (text != null) { mechComponentRef.SetSimGameUID(null); } return; } var match = Regex.Match(text); if (!match.Success) { return; } UUID = string.IsNullOrEmpty(match.Groups[1].Value) ? null : match.Groups[1].Value; IsDHS = !string.IsNullOrEmpty(match.Groups[2].Value); AdditionalSHSCount = !string.IsNullOrEmpty(match.Groups[3].Value) ? int.Parse(match.Groups[3].Value) : 0; AdditionalDHSCount = !string.IsNullOrEmpty(match.Groups[4].Value) ? int.Parse(match.Groups[4].Value) : 0; }
internal void Show(DynamicSlots slots, bool isReservedSlot) { var dataManager = UnityGameInstance.BattleTechGame.DataManager; var id = slots.Def.Description.Id; var type = slots.Def.ComponentType; var @ref = new MechComponentRef(id, null, type, ChassisLocations.None) { DataManager = dataManager }; @ref.RefreshComponentDef(); element.SetData(@ref, ChassisLocations.None, dataManager, null); slots.ApplyTo(element, isReservedSlot); if (isReservedSlot) { ResetSolidBorder(); } else { HideSolidBorder(); } gameObject.SetActive(true); element.SetDraggable(false); }
public static void DoUpgrade(this MechComponentRef r, MechComponentDef d, ref float canFreeTonns) { canFreeTonns += r.Def.Tonnage; r.ComponentDefID = d.Description.Id; r.SetComponentDef(d); canFreeTonns -= r.Def.Tonnage; }
internal EngineCoreRef(MechComponentRef componentRef, EngineCoreDef coreDef) { CoreDef = coreDef; ComponentRef = componentRef; var text = componentRef.SimGameUID; if (string.IsNullOrEmpty(text)) { if (text != null) { componentRef.SetSimGameUID(null); } } else { var match = Regex.Match(text); if (match.Success) { UUID = string.IsNullOrEmpty(match.Groups[1].Value) ? null : match.Groups[1].Value; Properties = match.Groups[2].Value; } } if (HeatSinkDef == null) { HeatSinkDef = DataManager.GetDefaultEngineHeatSinkDef(); } }
internal EngineCoreRef(MechComponentRef componentRef, EngineCoreDef coreDef, EngineType engineType) { ComponentRef = componentRef; CoreDef = coreDef; Type = engineType; var text = componentRef.SimGameUID; if (string.IsNullOrEmpty(text)) { if (text != null) { componentRef.SetSimGameUID(null); } return; } var match = Regex.Match(text); if (!match.Success) { return; } UUID = string.IsNullOrEmpty(match.Groups[1].Value) ? null : match.Groups[1].Value; Properties = match.Groups[2].Value; }
private static void Postfix(MechComponentRef mechComponent, bool isOnMech, WorkOrderEntry_RepairComponent __result) { var mech = MechLabPanel_LoadMech.CurrentMech; if (mechComponent == null) { return; } float tpmod = 1; float cbmod = 1; Logger.LogDebug($"Module Repair Cost for {mechComponent.ComponentDefID}: "); Logger.LogDebug("***************************************"); foreach (var tag in ArmorRepair.ModSettings.RepairCostByTag) { if (mech != null && mech.Chassis.ChassisTags.Contains(tag.Tag)) { Logger.LogDebug($" Chassis {tag.Tag} mods tp:{tag.RepairTPCost:0.00} cb:{tag.RepairCBCost:0.00}"); tpmod *= tag.RepairTPCost; cbmod *= tag.RepairCBCost; } if (mechComponent.Def.ComponentTags.Contains(tag.Tag)) { Logger.LogDebug($" {mechComponent.ComponentDefID} {tag.Tag} mods tp:{tag.RepairTPCost:0.00} cb:{tag.RepairCBCost:0.00}"); tpmod *= tag.RepairTPCost; cbmod *= tag.RepairCBCost; } } if (tpmod != 1 || cbmod != 1) { var trav = new Traverse(__result); if (tpmod != 1) { var cost = trav.Field <int>("Cost"); int new_cost = Mathf.CeilToInt(cost.Value * tpmod); Logger.LogDebug($" TP cost: {cost.Value} * {tpmod:0.000} = {new_cost}"); cost.Value = new_cost; } if (cbmod != 1) { var cost = trav.Field <int>("CBillCost"); int new_cost = Mathf.CeilToInt(cost.Value * cbmod); Logger.LogDebug($" CBIll cost: {cost.Value} * {cbmod:0.000} = {new_cost}"); cost.Value = new_cost; } } else { Logger.LogDebug(" no need to adjust, return"); } Logger.LogDebug("***************************************"); }
public static ChassisLocations MountedLocation(this MechComponentRef componentRef) { if (componentRef.Flags <CCFlags>().HideFromEquip) { return(ChassisLocations.None); } return(componentRef.MountedLocation); }
public bool IsMechDestroyed(MechComponentRef component, MechDef mech) { if (DeathMethod == DeathMethod.NOT_SET) { return(false); } return(component.DamageLevel == ComponentDamageLevel.Destroyed); }
internal static void OnAddItemStat(SimGameState sim) { if (lastMechComponentRef == null) { return; } OnAddItemStat(sim, lastMechComponentRef); lastMechComponentRef = null; }
internal string GetPrefabName(MechComponentRef componentRef) { string value; if (mapping.TryGetValue(componentRef, out value)) { return(value); } return(null); }
public Change_Remove(MechComponentRef item, ChassisLocations location, bool already_applied = false) { this.ItemID = item.ComponentDefID; this.Location = location; if (already_applied) { Applied = true; this.item = item; } }