Example #1
0
        private static bool Prefix(CraftingCampaignBehavior __instance)
        {
            if (!ForgeOverhaulConfig.ConfigSettings.RestrictPartUnlockPerCategoryEnabled)             //meh code
            {
                return(true);
            }
            Traverse.Create(__instance).Method("EnsureParts").GetValue();
            var           allParts          = (CraftingPiece[])Traverse.Create(__instance).Field("_allCraftingParts").GetValue();
            var           openedParts       = (List <CraftingPiece>)Traverse.Create(__instance).Field("_openedParts").GetValue();
            int           totalPartCount    = allParts.Length;
            int           unlockedPartCount = openedParts.Count;
            SmithingModel smithingModel     = Campaign.Current.Models.SmithingModel;

            CraftingPiece[] array = (from x in allParts
                                     where !openedParts.Contains(x) && RememberLastDesignFix.LastWeaponCrafted.WeaponDesign.Template.Pieces.Contains(x)
                                     select x).ToArray <CraftingPiece>();
            if (array.Length != 0)
            {
                CraftingPiece craftingPiece = MBRandom.ChooseWeighted <CraftingPiece>(array, (CraftingPiece x) => smithingModel.GetProbabalityToOpenPart(x));
                if (craftingPiece != null)
                {
                    Traverse.Create(__instance).Method("OpenPart", craftingPiece).GetValue();
                }
            }
            return(false);
        }
Example #2
0
        public static ItemObject GetTournamentPrizeVanilla(Settlement settlement)
        {
            float minValue = 1000f;
            float maxValue = 5000f;

            if (TournamentXPSettings.Instance.TownPrizeMinMaxAffectsVanilla)
            {
                minValue = TournamentPrizePoolBehavior.GetMinPrizeValue();
                maxValue = TournamentPrizePoolBehavior.GetMaxPrizeValue();
            }

            string[] strArray = new String[] { "winds_fury_sword_t3", "bone_crusher_mace_t3", "tyrhung_sword_t3", "pernach_mace_t3", "early_retirement_2hsword_t3", "black_heart_2haxe_t3", "knights_fall_mace_t3", "the_scalpel_sword_t3", "judgement_mace_t3", "dawnbreaker_sword_t3", "ambassador_sword_t3", "heavy_nasalhelm_over_imperial_mail", "closed_desert_helmet", "sturgian_helmet_closed", "full_helm_over_laced_coif", "desert_mail_coif", "heavy_nasalhelm_over_imperial_mail", "plumed_nomad_helmet", "eastern_studded_shoulders", "ridged_northernhelm", "armored_bearskin", "noble_horse_southern", "noble_horse_imperial", "noble_horse_western", "noble_horse_eastern", "noble_horse_battania", "noble_horse_northern", "special_camel" };

            ItemObject obj        = Game.Current.ObjectManager.GetObject <ItemObject>(strArray.GetRandomElement <string>());
            ItemObject itemObject = MBRandom.ChooseWeighted <ItemObject>(ItemObject.All, (ItemObject item) =>
            {
                if ((float)item.Value > minValue * (item.IsMountable ? 0.5f : 1f))
                {
                    if (TournamentXPSettings.Instance.EnablePrizeTypeFilterToLists)
                    {
                        var validPizeTypes = TournamentPrizePoolBehavior.GetActivePrizeTypes();

                        if ((float)item.Value < maxValue * (item.IsMountable ? 0.5f : 1f) && item.Culture == settlement.Town.Culture &&
                            validPizeTypes.Contains(item.ItemType)
                            )
                        {
                            return(1f);
                        }
                    }
                    else if ((float)item.Value < maxValue * (item.IsMountable ? 0.5f : 1f) && item.Culture == settlement.Town.Culture && (item.IsCraftedWeapon || item.IsMountable || item.ArmorComponent != null))
                    {
                        return(1f);
                    }
                }
                return(0f);
            }) ?? MBRandom.ChooseWeighted <ItemObject>(ItemObject.All, (ItemObject item) =>
            {
                if ((float)item.Value > minValue * (item.IsMountable ? 0.5f : 1f))
                {
                    if ((float)item.Value < maxValue * (item.IsMountable ? 0.5f : 1f) && (item.IsCraftedWeapon || item.IsMountable || item.ArmorComponent != null))
                    {
                        return(1f);
                    }
                }
                return(0f);
            });

            if (itemObject == null)
            {
                return(obj);
            }
            return(itemObject);
        }
Example #3
0
        /*
         * This is a fix for a native bug where the weight function causes MBRandom.ChooseWeight to return null, which means
         * that there is no skillObject passed to HeroDeveloper.AddFocus
         */
        static bool Prefix(Hero hero)
        {
            List <SkillObject> list = (from x in SkillObject.All
                                       where hero.HeroDeveloper.GetFocus(x) < 5
                                       select x).ToList();

            Func <SkillObject, float> weightFunction;

            while (hero.HeroDeveloper.UnspentFocusPoints > 0 && list.Any <SkillObject>())
            {
                IEnumerable <SkillObject> candidates = list;
                weightFunction = (SkillObject skill) => Math.Max(1f, (float)(hero.GetSkillValue(skill) + 20 - 20 * hero.HeroDeveloper.GetFocus(skill)));

                SkillObject skillObject = MBRandom.ChooseWeighted <SkillObject>(candidates, weightFunction);

                hero.HeroDeveloper.AddFocus(skillObject, 1, true);

                if (hero.HeroDeveloper.GetFocus(skillObject) == 5)
                {
                    list.Remove(skillObject);
                }
            }
            return(false);
        }
 public virtual T ChooseWeighted <T>(IEnumerable <T> candidates, Func <T, float> weightFunction, out int chosenIndex) => MBRandom.ChooseWeighted <T>(candidates, weightFunction, out chosenIndex);
 public virtual T ChooseWeighted <T>(IEnumerable <T> candidates, Func <T, float> weightFunction) => MBRandom.ChooseWeighted <T>(candidates, weightFunction);
Example #6
0
        private static bool GetTournamentPrize(TournamentGame __instance, ref ItemObject __result)
        {
            if (!TournamentSetting.Instance.PrizeEnabled)
            {
                return(true);
            }

            string[] e = new string[]
            {
                "noble_horse_southern",
                "noble_horse_imperial",
                "noble_horse_western",
                "noble_horse_eastern",
                "noble_horse_battania",
                "noble_horse_northern",
                "special_camel",
                "noble_horse"
            };

            ItemObject @object = Game.Current.ObjectManager.GetObject <ItemObject>(e.GetRandomElement());

            if (MBRandom.RandomFloat < 0.15f)
            {
                __result = @object;
                return(false);
            }

            var culture = __instance.Town.Culture;

            var days = Campaign.Current.CampaignStartTime.ElapsedDaysUntilNow;
            var mul  = Math.Sqrt((days + 100) / 100);


            ItemObject itemObject = MBRandom.ChooseWeighted(ItemObject.All, delegate(ItemObject item)
            {
                if ((float)item.Value <= 1600f * (item.IsMountable ? 0.5f : mul * 1f) || (float)item.Value >= 5000f * (item.IsMountable ? 0.5f : mul * 1f) || item.Culture != __instance.Town.Culture || item.IsPlayerCraft() || (!item.IsCraftedWeapon && !item.IsMountable && item.ArmorComponent == null))
                {
                    return(0f);
                }
                return(1f);
            });

            //if (itemObject == null)
            //{
            //    itemObject = MBRandom.ChooseWeighted<ItemObject>(ItemObject.All, delegate (ItemObject item)
            //    {
            //        if ((float)item.Value <= mul * 1600f * (item.IsMountable ? 0.5f : 1f) || (float)item.Value >= mul * 5000f * (item.IsMountable ? 0.5f : 1f) || item.IsPlayerCraft() || item.IsCraftedWeapon || (!item.IsCraftedWeapon && !item.IsMountable && item.ArmorComponent == null))
            //        {
            //            return 0f;
            //        }
            //        return 1f;
            //    });
            //}
            if (itemObject == null)
            {
                __result = @object;
                return(false);
            }
            __result = itemObject;
            return(false);
        }