public static void Postfix(MechLabInventoryWidget __instance, float ___mechTonnage,
                                   List <InventoryItemElement_NotListView> ___localInventory)
        {
            foreach (var item in ___localInventory)
            {
                MechComponentDef component = null;

                if (item.controller != null)
                {
                    component = item.controller.componentDef;
                }
                else if (item.ComponentRef != null)
                {
                    component = item.ComponentRef.Def;
                }

                if (component != null && component.IsStructure())
                {
                    var tonnage = component.GetStructureWeight();
//                    Control.mod.Logger.Log(string.Format("[{0}] found structure {1} {2}/{3}", Time.realtimeSinceStartup,
//                       component.Description.Id, tonnage, ___mechTonnage));
                    item.gameObject.SetActive(
                        (___mechTonnage < 0 ||
                         ___mechTonnage == tonnage) && item.gameObject.activeSelf
                        );
                }
            }
        }
示例#2
0
        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);
        }
示例#3
0
        // only allow one engine core
        internal static void EngineCoreValidateAdd(
            MechComponentDef newComponentDef,
            List <MechLabItemSlotElement> localInventory,
            ref string dropErrorMessage,
            ref bool result)
        {
            try
            {
                if (!newComponentDef.IsEngineCore())
                {
                    return;
                }

                var existingEngine = localInventory.Select(c => c.ComponentRef).GetEngineCoreRef();
                if (existingEngine == null)
                {
                    return;
                }

                dropErrorMessage = string.Format("Cannot add {0}: Engine core is already installed", newComponentDef.Description.Name);
                result           = false;
            }
            catch (Exception e)
            {
                Control.mod.Logger.LogError(e);
            }
        }
示例#4
0
 public static bool IsCategory(this MechComponentDef cdef, string categoryid, out Category category)
 {
     category = cdef.GetComponents <Category>().FirstOrDefault(c => c.CategoryID == categoryid);
     return(category != null);
     // Is<Category>
     // GetComponent<Category>
 }
示例#5
0
        public static bool IsCategory(this MechComponentDef cdef, string category)
        {
            return(cdef.GetComponents <Category>().Any(c => c.CategoryID == category));

            // Is<Category>
            // GetComponent<Category>
        }
        private static void AddUpgradeToSalvage(Contract __instance, MechComponentDef d, SimGameState s, List <SalvageDef> sal)
        {
            string lootable = d.GetCCLootableItem();

            if (lootable != null)
            {
                MechComponentDef l = s.DataManager.GetComponentDefFromID(lootable);
                if (l != null)
                {
                    d = l;
                }
            }
            if (IsBlacklisted(d))
            {
                SimpleMechAssembly_Main.Log.LogError("skipping, cause its blacklisted");
                return;
            }
            try
            {
                __instance.AddMechComponentToSalvage(sal, d, ComponentDamageLevel.Functional, false, s.Constants, s.NetworkRandom, true);
            }
            catch (Exception e)
            {
                SimpleMechAssembly_Main.Log.LogError("failed to add mech component");
                SimpleMechAssembly_Main.Log.LogException(e);
                GenericPopupBuilder.Create("SMA add component error", "Please delete your .modtek folder (so everything gets regenerated next start).\nIf it still happens afterwards, please report.").AddButton("ok", null, true, null).Render();
            }
        }
示例#7
0
        public void AdjustTooltipWeapon(TooltipPrefab_Weapon tooltipInstance, MechComponentDef mechComponentDef)
        {
            var tooltip       = new TooltipPrefab_WeaponAdapter(tooltipInstance);
            var reservedSlots = 0;

            if (mechComponentDef.Is <Weights>(out var weights))
            {
                reservedSlots += weights.ReservedSlots;
                var mechDef = Global.ActiveMechDef;
                if (mechDef != null)
                {
                    var tonnageChanges = CalculateWeightChanges(mechDef, weights);
                    tooltip.tonnage.text = FormatChanges(mechComponentDef.Tonnage, tonnageChanges);
                }
            }

            if (mechComponentDef.Is <DynamicSlots.DynamicSlots>(out var dynamicSlots))
            {
                reservedSlots += dynamicSlots.ReservedSlots;
            }

            if (reservedSlots > 0)
            {
                tooltip.slots.text = $"{mechComponentDef.InventorySize} + {reservedSlots}";
            }
        }
示例#8
0
 public static void Record_CompDependenciesLoaded(MechComponentDef __instance, bool __result)
 {
     if (__result && __instance.statusEffects != null && __instance.statusEffects.Length > 0)
     {
         LoadedComp.Add(__instance);
     }
 }
示例#9
0
 public static bool Skip_CheckCompDependenciesAfterLoad(MechComponentDef __instance)
 {
     try {
         if (UnpatchManager)
         {
             return(true);
         }
         MechComponentDef me = __instance;
         if (checkingComp == null)
         {
             if (me.statusEffects != null && me.statusEffects.Length > 0 && LoadedComp.Contains(me))
             {
                 if (DebugLog)
                 {
                     Trace("Skipping MechComponentDef check {0} because already finished loading.", GetName(me));
                 }
                 return(false);
             }
             if (DebugLog)
             {
                 Verbo("Allowing MechComponentDef verify {0}.", GetName(me));
             }
             checkingComp = __instance;
             return(true);
         }
         if (DebugLog)
         {
             Trace("Skipping MechComponentDef check {0} because checking {1}.", GetName(me), GetName(checkingComp));
         }
         return(false);
     }                 catch (Exception ex) { return(Error(ex)); }
 }
示例#10
0
    public static bool Prefix(MechLabPanel __instance, MechComponentDef def, ref bool __result, bool ___isDebugLab)
    {
        try
        {
            var tags = def.ComponentTags;

            if (__instance.IsSimGame)
            {
                __result = true;
            }
            else if (!___isDebugLab && tags.Contains(MechValidationRules.ComponentTag_Debug))
            {
                __result = false;
            }
            else if (tags.Contains(MechValidationRules.Tag_Blacklisted))
            {
                __result = false;
            }
            else if (tags.ContainsAny(TagManagerFeature.Shared.Settings.SkirmishWhitelistTagSet))
            {
                __result = true;
            }
            else
            {
                __result = false;
            }
            return(false);
        }
        catch (Exception e)
        {
            Control.Logger.Error.Log(e);
        }

        return(true);
    }
示例#11
0
 public static void Cleanup_CheckCompDependenciesAfterLoad(MechComponentDef __instance)
 {
     if (checkingComp == __instance)
     {
         checkingComp = null;
     }
 }
        internal static void Postfix(
            ref LocationLoadoutDef ___loadout,
            ref MechLabPanel ___mechLab,
            MechComponentDef newComponentDef,
            ref bool __result)
        {
            try
            {
                if (!__result)
                {
                    return;
                }

                var chassisDef = ___mechLab?.activeMechDef?.Chassis;

                if (chassisDef == null)
                {
                    return;
                }

                var location = ___loadout.Location;
                if (location == ChassisLocations.None)
                {
                    return;
                }

                __result = OmniSlotsFeature.Shared.ValidateAddSimple(chassisDef, location, newComponentDef);
            }
            catch (Exception e)
            {
                Control.Logger.Error.Log(e);
            }
        }
示例#13
0
 public void AdjustTooltipWeapon(TooltipPrefab_Weapon tooltip, MechComponentDef componentDef)
 {
     foreach (var cc in componentDef.GetComponents <IAdjustTooltipWeapon>())
     {
         cc.AdjustTooltipWeapon(tooltip, componentDef);
     }
 }
示例#14
0
        internal void AdjustComponentDef(MechComponentDef def)
        {
            if (change == null)
            {
                return;
            }

            if (!identifier.IsCustomType(def))
            {
                return;
            }

            var newTonnage = change.Change(def.Tonnage);

            if (newTonnage < 0)
            {
                return;
            }

            var value     = newTonnage;
            var propInfo  = typeof(UpgradeDef).GetProperty("Tonnage");
            var propValue = Convert.ChangeType(value, propInfo.PropertyType);

            propInfo.SetValue(def, propValue, null);
        }
示例#15
0
        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);
            }
        }
示例#16
0
        public static SalvageDef CreateComponent(SimGameConstants sc, Contract c, MechComponentDef mc)
        {
            SalvageDef salvageDef = new SalvageDef();

            if (mc.ComponentType == ComponentType.Weapon)
            {
                WeaponDef weaponDef = mc as WeaponDef;
                salvageDef.MechComponentDef = weaponDef;

                salvageDef.Description   = new DescriptionDef(weaponDef.Description);
                salvageDef.RewardID      = c.GenerateRewardUID();
                salvageDef.Type          = SalvageDef.SalvageType.COMPONENT;
                salvageDef.ComponentType = weaponDef.ComponentType;
                salvageDef.Damaged       = false;
                salvageDef.Weight        = sc.Salvage.DefaultWeaponWeight;
                salvageDef.Count         = 1;

                return(salvageDef);
            }
            else
            {
                salvageDef.MechComponentDef = mc;

                salvageDef.Description   = new DescriptionDef(mc.Description);
                salvageDef.RewardID      = c.GenerateRewardUID();
                salvageDef.Type          = SalvageDef.SalvageType.COMPONENT;
                salvageDef.ComponentType = mc.ComponentType;
                salvageDef.Damaged       = false;
                salvageDef.Weight        = sc.Salvage.DefaultComponentWeight;
                salvageDef.Count         = 1;

                return(salvageDef);
            }
        }
 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;
 }
示例#18
0
        internal static void AddPassiveStatisticEffectIfMissing(this MechComponentDef def, StatisticEffectData statisticData)
        {
            if (def.statusEffects != null && def.statusEffects.Any(x => statisticData.statName == x.statisticData.statName))
            {
                // passive effect already exists
                return;
            }

            var effectData = new EffectData
            {
                effectType = EffectType.StatisticEffect,
                nature     = EffectNature.Buff
            };

            effectData.durationData = new EffectDurationData
            {
                duration   = -1,
                stackLimit = -1
            };

            effectData.targetingData = new EffectTargetingData
            {
                effectTriggerType = EffectTriggerType.Passive,
                effectTargetType  = EffectTargetType.Creator
            };

            var id = def.Description.Id + "_" + statisticData.statName;

            effectData.Description   = new BaseDescriptionDef(id, statisticData.statName, "", null);
            effectData.statisticData = statisticData;

            var statusEffects = def.statusEffects == null ? new[] { effectData } : def.statusEffects.Append(effectData).ToArray();

            def.SetEffectData(statusEffects);
        }
        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 void AdjustTooltip(TooltipPrefab_Equipment tooltip, MechComponentDef componentDef)
 {
     foreach (var cc in componentDef.GetComponents <IAdjustTooltip>())
     {
         cc.AdjustTooltip(tooltip, componentDef);
     }
 }
示例#21
0
        internal void ManageComponentTags(MechComponentDef def)
        {
            var tags = def.ComponentTags;

            if (Settings.LostechStockWeaponVariantFix &&
                def is WeaponDef &&
                !def.Description.Id.EndsWith("-STOCK") &&
                tags.Contains(MechValidationRules.ComponentTag_LosTech))
            {
                //Control.mod.Logger.LogDebug($"LostechStockWeaponVariantFix {def.Description.Id}");

                tags.Remove(MechValidationRules.ComponentTag_Stock);
                tags.Add(MechValidationRules.ComponentTag_Variant);
            }

            if (Check(tags, Settings.WhitelistComponentTagSet))
            {
                //Control.mod.Logger.LogDebug($"WhitelistComponentTags {def.Description.Id}");
                tags.Remove(MechValidationRules.Tag_Blacklisted);
            }

            if (Check(tags, Settings.BlacklistComponentTagSet))
            {
                //Control.mod.Logger.LogDebug($"BlacklistComponentTags {def.Description.Id}");
                tags.Add(MechValidationRules.Tag_Blacklisted);
            }
        }
示例#22
0
        // only allow one engine part per specific location
        internal static void ValidateAdd(
            MechComponentDef newComponentDef,
            List <MechLabItemSlotElement> localInventory,
            ref string dropErrorMessage,
            ref bool result)
        {
            try
            {
                if (!newComponentDef.IsEnginePart())
                {
                    return;
                }

                var existingEngine = localInventory
                                     .Where(x => x != null)
                                     .Select(x => x.ComponentRef)
                                     .FirstOrDefault(x => x != null && x.Def != null && x.Def.IsEnginePart());

                if (existingEngine == null)
                {
                    return;
                }

                dropErrorMessage = String.Format("Cannot add {0}: An engine part is already installed", newComponentDef.Description.Name);
                result           = false;
            }
            catch (Exception e)
            {
                Control.mod.Logger.LogError(e);
            }
        }
示例#23
0
        public static bool Prefix(Contract __instance, SimGameConstants sc, MechComponentDef def)
        {
            if (def.ComponentTags.Contains("BLACKLISTED"))
            {
                return(false);
            }

            SalvageDef salvageDef = new SalvageDef();

            salvageDef.MechComponentDef = def;
            salvageDef.Description      = new DescriptionDef(def.Description);
            salvageDef.RewardID         = __instance.GenerateRewardUID();
            salvageDef.Type             = SalvageDef.SalvageType.COMPONENT;
            salvageDef.ComponentType    = def.ComponentType;
            salvageDef.Damaged          = false;
            salvageDef.Weight           = sc.Salvage.DefaultComponentWeight;
            salvageDef.Count            = 1;
            if (def.Description.Rarity < sc.Salvage.ItemAutoCullLevel)
            {
                if ((bool)Traverse.Create(__instance).Method("IsSalvageInContent", new Type[] { typeof(SalvageDef) }).GetValue(salvageDef))
                {
                    var foo = (List <SalvageDef>)Traverse.Create(__instance).Field("finalPotentialSalvage").GetValue();
                    foo.Add(salvageDef);
                    return(false);
                }
            }
            else
            {
                Logger.Log(string.Format("CULLED ILLEGAL MECH COMPONENT ({0}) of RARITY ({1}). From Random Upgrade? {2}.", def.Description.Id, def.Description.Rarity, false));
            }
            return(false);
        }
示例#24
0
        // allow gyro upgrades to be 1 slot and still only be added once
        internal static void ValidateAdd(
            MechComponentDef newComponentDef,
            List <MechLabItemSlotElement> localInventory,
            ref string dropErrorMessage,
            ref bool result)
        {
            try
            {
                if (!result)
                {
                    return;
                }

                if (!newComponentDef.IsCenterTorsoUpgrade())
                {
                    return;
                }

                if (localInventory.Select(x => x.ComponentRef).All(x => x == null || !x.Def.IsCenterTorsoUpgrade()))
                {
                    return;
                }

                dropErrorMessage = String.Format("Cannot add {0}: A gyro is already installed", newComponentDef.Description.Name);
                result           = false;
            }
            catch (Exception e)
            {
                Control.mod.Logger.LogError(e);
            }
        }
        internal void AdjustComponentDef(MechComponentDef def)
        {
            if (change == null)
            {
                return;
            }

            if (!identifier.IsCustomType(def))
            {
                return;
            }

            var newSize = change.Change(def.InventorySize);

            if (!newSize.HasValue)
            {
                return;
            }

            var value     = newSize.Value;
            var propInfo  = typeof(UpgradeDef).GetProperty("InventorySize");
            var propValue = Convert.ChangeType(value, propInfo.PropertyType);

            propInfo.SetValue(def, propValue, null);
        }
示例#26
0
        public void AdjustTooltip(TooltipPrefab_Equipment tooltip, MechComponentDef componentDef)
        {
            var adapter = new TooltipPrefab_EquipmentAdapter(tooltip);

            //GUILogUtils.LogHierarchy(tooltip.transform);
            adapter.ShowBonuses = false;
        }
示例#27
0
        internal EngineDef(MechComponentDef componentDef)
        {
            var match = EngineNameRegex.Match(componentDef.Description.Id);

            Type   = (EngineType)Enum.Parse(typeof(EngineType), match.Groups[1].Value, true);
            Rating = int.Parse(match.Groups[2].Value);
            Def    = componentDef;
        }
示例#28
0
        //These patches and methods will dynamically upgrade the weapons and equipment on the OpFor.
        //[HarmonyPatch(typeof(UnitSpawnPointGameLogic), "SpawnMech")]
        //public static class UnitSpawnPointGameLogic_SpawnMech_Patch
        //{
        //    public static void Postfix(UnitSpawnPointGameLogic __instance, ref Mech __result)
        //    {
        //        if (!Core.Settings.UpgradeItems)
        //            return;
        //        var tempMechInventory = new List<MechComponentRef>(__result.MechDef.Inventory).ToArray();
        //        int i = 0;
        //        foreach (var component in tempMechInventory)
        //        {
        //            if (component.ComponentDefType == ComponentType.Weapon && component.Def.ComponentTags.Contains("component_type_stock"))
        //            {
        //                Traverse.Create(__result.MechDef.Inventory[i]).Property("Def").
        //                    SetValue(UpgradeWeapons(__instance.Combat.ActiveContract, component.Def));
        //            }
        //            if (component.ComponentDefType == ComponentType.Upgrade && component.Def.ComponentTags.Contains("component_type_stock"))
        //                Traverse.Create(__result.MechDef.Inventory[i]).Property("Def").
        //                    SetValue(UpgradeUpgrades(__instance.Combat.ActiveContract, component.Def));
        //            i++;
        //        }

        //    }
        //}

        //[HarmonyPatch(typeof(UnitSpawnPointGameLogic), "SpawnVehicle")]
        //public static class UnitSpawnPointGameLogic_SpawnVehicle_Patch
        //{
        //    public static void Postfix(UnitSpawnPointGameLogic __instance, ref Vehicle __result)
        //    {
        //        if (!Core.Settings.UpgradeItems)
        //            return;

        //        var tempMechInventory = new List<VehicleComponentRef>(__result.VehicleDef.Inventory).ToArray();
        //        int i = 0;
        //        foreach (var component in tempMechInventory)
        //        {
        //            if (component.ComponentDefType == ComponentType.Weapon && component.Def.ComponentTags.Contains("component_type_stock"))
        //            {
        //                Traverse.Create(__result.VehicleDef.Inventory.ElementAt(i)).Property("Def").
        //                    SetValue(UpgradeWeapons(__instance.Combat.ActiveContract, component.Def));
        //            }
        //            if (component.ComponentDefType == ComponentType.Upgrade && component.Def.ComponentTags.Contains("component_type_stock"))
        //                Traverse.Create(__result.VehicleDef.Inventory.ElementAt(i)).Property("Def").
        //                    SetValue(UpgradeUpgrades(__instance.Combat.ActiveContract, component.Def));
        //            i++;
        //        }
        //    }
        //}

        //[HarmonyPatch(typeof(UnitSpawnPointGameLogic), "SpawnTurret")]
        //public static class UnitSpawnPointGameLogic_SpawnTurret_Patch
        //{
        //    public static void Postfix(UnitSpawnPointGameLogic __instance, ref Turret __result)
        //    {
        //        if (!Core.Settings.UpgradeItems)
        //            return;

        //        var tempMechInventory = new List<TurretComponentRef>(__result.TurretDef.Inventory).ToArray();
        //        int i = 0;
        //        foreach (var component in tempMechInventory)
        //        {
        //            if (component.ComponentDefType == ComponentType.Weapon && component.Def.ComponentTags.Contains("component_type_stock"))
        //            {
        //                Traverse.Create(__result.TurretDef.Inventory.ElementAt(i)).Property("Def").
        //                    SetValue(UpgradeWeapons(__instance.Combat.ActiveContract, component.Def));
        //            }
        //            if (component.ComponentDefType == ComponentType.Upgrade && component.Def.ComponentTags.Contains("component_type_stock"))
        //                Traverse.Create(__result.TurretDef.Inventory.ElementAt(i)).Property("Def").
        //                    SetValue(UpgradeUpgrades(__instance.Combat.ActiveContract, component.Def));
        //            i++;
        //        }
        //    }
        //}

        public static MechComponentDef UpgradeUpgrades(Contract contract, MechComponentDef def)
        {
            var    sc   = UnityGameInstance.BattleTechGame.Simulation.Constants;
            var    rand = new Random();
            double num  = rand.Next();
            float  num1 = ((float)contract.Override.finalDifficulty + Core.Settings.EliteRareUpgradeChance) / Core.Settings.UpgradeChanceDivisor;
            float  num2 = ((float)contract.Override.finalDifficulty + Core.Settings.VeryRareUpgradeChance) / Core.Settings.UpgradeChanceDivisor;
            float  num3 = ((float)contract.Override.finalDifficulty + Core.Settings.RareUpgradeChance) / Core.Settings.UpgradeChanceDivisor;

            float[] array = null;
            Logger.LogDebug("Rarity Roll for Upgrades: " + num.ToString());
            Logger.LogDebug("   " + num1 + " Needed for Elite" + num2 + " Needed for Very Rare; " + num3 + " Needed for Rare");
            MechComponentDef mechComponentDef = def;

            if (mechComponentDef.ComponentTags.Contains("BLACKLISTED"))
            {
                return(mechComponentDef);
            }

            if (num < num1)
            {
                Logger.LogDebug("Elite Rare Upgrade.");
                array = Core.Settings.EliteRareUpgradeLevel;
            }
            else if (num < num2)
            {
                Logger.LogDebug("Very Rare Upgrade.");
                array = Core.Settings.VeryRareUpgradeLevel;
            }
            else if (num < num3)
            {
                Logger.LogDebug("Rare Upgrade.");
                array = Core.Settings.RareUpgradeLevel;
            }
            if (array != null)
            {
                string upgradeTag = def.ComponentTags.FirstOrDefault(x => x.StartsWith("BR_UpgradeTag"));
                if (upgradeTag == null)
                {
                    return(mechComponentDef);
                }
                List <UpgradeDef_MDD> upgradesByRarityAndOwnership = MetadataDatabase.Instance.GetUpgradesByRarityAndOwnership(array);
                if (upgradesByRarityAndOwnership != null && upgradesByRarityAndOwnership.Count > 0)
                {
                    var DataManager = (DataManager)Traverse.Create(contract).Field("dataManager").GetValue();
                    upgradesByRarityAndOwnership.Shuffle();
                    foreach (var upgradeDef_MDD in upgradesByRarityAndOwnership)
                    {
                        var tempMCD = DataManager.UpgradeDefs.Get(upgradeDef_MDD.UpgradeDefID);
                        if (tempMCD.ComponentTags.Contains(upgradeTag))
                        {
                            return(tempMCD);
                        }
                    }
                }
            }
            return(mechComponentDef);
        }
 public static T AddComponent <T>(this MechComponentDef target, T component) where T : ICustom
 {
     if (component is SimpleCustom <MechComponentDef> simple)
     {
         simple.Def = target;
     }
     Database.AddCustom(target, component);
     return(component);
 }
示例#30
0
        internal EngineDef(MechComponentDef componentDef)
        {
            var id    = componentDef.Description.Id;
            var match = EngineNameRegex.Match(id);

            Type   = Control.settings.EngineTypes.FirstOrDefault(c => id.StartsWith(c.Prefix));
            Rating = int.Parse(match.Groups[2].Value);
            Def    = componentDef;
        }