コード例 #1
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);
        }
コード例 #2
0
        public static void PrizeSelectConsequence(MenuCallbackArgs args)
        {
            try
            {
                List <InquiryElement> prizeElements  = new List <InquiryElement>();
                TournamentGame        tournamentGame = Campaign.Current.TournamentManager.GetTournamentGame(Settlement.CurrentSettlement.Town);
                TournamentPrizePool   currentPool    = GetTournamentPrizePool(Settlement.CurrentSettlement);

                if (currentPool.Prizes.Count < TournamentXPSettings.Instance.NumberOfPrizeOptions)
                {
                    ItemObject prize = GenerateTournamentPrize(tournamentGame, currentPool, true);
                }

                //  InformationManager.Clear();
                foreach (ItemRosterElement ire in currentPool.Prizes)
                {
                    var p = ire.EquipmentElement;
                    try
                    {
                        var ii = new ImageIdentifier(p.Item.StringId, ImageIdentifierType.Item, p.GetModifiedItemName().ToString());
                        // prizeElements.Add(new InquiryElement(p.Item.StringId, ii, true, p.Item.ToToolTipTextObject().ToString()));
                        prizeElements.Add(new InquiryElement(
                                              p.Item.StringId,
                                              p.GetModifiedItemName().ToString(),
                                              ii,
                                              true,
                                              p.ToToolTipTextObject().ToString()
                                              ));
                    }
                    catch (Exception ex)
                    {
                        ErrorLog.Log("ERROR: Tournament Prize System\nFailed to add prize element to display" + p.Item.StringId);
                        ErrorLog.Log(ex.ToStringFull());
                    }
                }
                if (prizeElements.Count > 0)
                {
                    string     info  = "{=tourn012}You can choose an item from the list below as your reward if you win the tournament!";
                    TextObject descr = new TextObject(info);

                    if (TournamentXPSettings.Instance.DebugMode)
                    {
                        info  = "Town:{TOWN}\nMin:{MIN}\nMax:{MAX}\nProsperity:{PROSPERITY}\nTypes:{TYPES}";
                        descr = new TextObject(info);
                        descr.SetTextVariable("TOWN", currentPool.Town.Name);
                        descr.SetTextVariable("MIN", TournamentPrizePoolBehavior.GetMinPrizeValue().ToString());
                        descr.SetTextVariable("MAX", TournamentPrizePoolBehavior.GetMaxPrizeValue().ToString());
                        descr.SetTextVariable("PROSPERITY", currentPool.Town.GetProsperityLevel().ToString());
                        var types = "";
                        foreach (var t in TournamentPrizePoolBehavior.GetActivePrizeTypes())
                        {
                            types += t.ToString() + ", ";
                        }
                        types = types.Substring(0, types.Length - 2);
                        descr.SetTextVariable("TYPES", types);
                    }

                    InformationManager.ShowMultiSelectionInquiry(new MultiSelectionInquiryData(
                                                                     new TextObject("{=tourn005}Tournament Prize Selection").ToString(), descr.ToString(), prizeElements, true, true, new TextObject("{=tourn006}OK").ToString(), new TextObject("{=tourn007}Cancel").ToString(),
                                                                     new Action <List <InquiryElement> >(OnSelectPrize), new Action <List <InquiryElement> >(OnDeSelectPrize)), true);
                    try
                    {
                        GameMenu.SwitchToMenu("town_arena");
                    }
                    catch (Exception ex)
                    {
                        ErrorLog.Log("ERROR: BMTournamentXP: Select Prize: Refresh Menu");
                        ErrorLog.Log(ex.ToStringFull());
                    }
                }
                else
                {
                    InformationManager.ShowInquiry(new InquiryData("Tournament Prize Selection", "You should not be seeing this.  Something went wrong generating the prize list. Your item restrictions may be set too narrow.", true, false, "OK", "", null, null));
                }
            }
            catch (Exception ex)
            {
                ErrorLog.Log("ERROR: BMTournamentXP: Tournament Prize Selection");
                ErrorLog.Log(ex.ToStringFull());
            }
        }
コード例 #3
0
        public static List <string> GetItemStringsRevised(TournamentGame tournamentGame, List <ItemObject.ItemTypeEnum> validTypes)
        {
            int prizeMin = MathF.Floor(TournamentPrizePoolBehavior.GetMinPrizeValue() * .7f);
            int prizeMax = MathF.Ceiling(TournamentPrizePoolBehavior.GetMaxPrizeValue() * 1.5f);

            List <string> allitems = new List <string>();

            if (TournamentXPSettings.Instance.PrizeListIncludeLegacy)
            {
                var legacyItems = _legacyItems.AsEnumerable();
                if (TournamentXPSettings.Instance.PrizeFilterCultureLegacyItems)
                {
                    legacyItems = legacyItems.Where(x => x.Culture == tournamentGame.Town.Culture);
                }
                if (TournamentXPSettings.Instance.PrizeFilterValueLegacyItems)
                {
                    legacyItems = legacyItems.Where(x => x.Value >= prizeMin && x.Value <= prizeMax);
                }
                if (TournamentXPSettings.Instance.PrizeFilterItemTypesLegacyItems)
                {
                    legacyItems = legacyItems.Where(x => validTypes.Contains(x.ItemType));
                }
                allitems = allitems.Concat(legacyItems.Select(x => x.StringId)).ToList();
            }
            if (TournamentXPSettings.Instance.PrizeListIncludeCustom && TournamentPrizePoolBehavior.CustomTournamentItems != null && TournamentPrizePoolBehavior.CustomTournamentItems.Count > 0)
            {
                try
                {
                    var customItems = _customItems.AsEnumerable();
                    if (TournamentXPSettings.Instance.PrizeFilterCultureCustomItems)
                    {
                        customItems = customItems.Where(x => x.Culture == tournamentGame.Town.Culture);
                    }
                    if (TournamentXPSettings.Instance.PrizeFilterValueCustomItems)
                    {
                        customItems = customItems.Where(x => x.Value >= prizeMin && x.Value <= prizeMax);
                    }
                    if (TournamentXPSettings.Instance.PrizeFilterItemTypesCustomItems)
                    {
                        customItems = customItems.Where(x => validTypes.Contains(x.ItemType));
                    }

                    allitems = allitems.Concat(customItems.Select(x => x.StringId).ToList()).ToList();
                }
                catch (Exception ex)
                {
                    ErrorLog.Log("Error adding custom items to prize pool.");
                    ErrorLog.Log(ex.ToStringFull());
                }
            }
            if (TournamentXPSettings.Instance.PrizeListIncludeTown)
            {
                var roster = tournamentGame.Town.Owner.ItemRoster;
                roster.RemoveZeroCounts();
                var townItems = roster.Where(x => x.Amount > 0 && !x.EquipmentElement.Item.NotMerchandise).Select(x => x.EquipmentElement.Item);

                if (TournamentXPSettings.Instance.PrizeFilterCultureTownItems)
                {
                    townItems = townItems.Where(x => x.Culture == tournamentGame.Town.Culture);
                }
                if (TournamentXPSettings.Instance.PrizeFilterValueTownItems)
                {
                    townItems = townItems.Where(x => x.Value >= prizeMin && x.Value <= prizeMax);
                }
                if (TournamentXPSettings.Instance.PrizeFilterItemTypesTownItems)
                {
                    townItems = townItems.Where(x => validTypes.Contains(x.ItemType));
                }

                allitems = allitems.Concat(townItems.Select(x => x.StringId)).ToList();
            }
            if (TournamentXPSettings.Instance.PrizeListIncludeVanilla)
            {
                var vanillaItems = ItemObject.All.AsEnumerable();
                if (TournamentXPSettings.Instance.PrizeFilterCultureStandardItems)
                {
                    vanillaItems = vanillaItems.Where(x => x.Culture == tournamentGame.Town.Culture);
                }
                if (TournamentXPSettings.Instance.PrizeFilterValueStandardItems)
                {
                    vanillaItems = vanillaItems.Where(x => x.Value >= prizeMin && x.Value <= prizeMax);
                }
                if (TournamentXPSettings.Instance.PrizeFilterItemTypesStandardItems)
                {
                    vanillaItems = vanillaItems.Where(x => validTypes.Contains(x.ItemType));
                }
                allitems = allitems.Concat(vanillaItems.Select(x => x.StringId)).ToList();
            }

            if (allitems.Count == 0)
            {
                //Alert - fix it somehow
                MessageBox.Show("TournamentXPanded Error:\nYour filters are too strict, no items are found to populate the tournaments with. Check your settings to allow for a wider choice.  Generally, this can only occur if you've set the lists to only allow for custom items, and those items are not loaded correctly.\nYou can enable debug mode to view additional diagnostics, to help determine if you items are loading or not.");
                ErrorLog.Log("Error populating Tournament Prizes\n");
            }

            return(allitems);
        }
コード例 #4
0
        public static List <string> GetItemStringsRevised(TournamentGame tournamentGame, List <ItemObject.ItemTypeEnum> validTypes)
        {
            int prizeMin = MathF.Floor(TournamentPrizePoolBehavior.GetMinPrizeValue() * .7f);
            int prizeMax = MathF.Ceiling(TournamentPrizePoolBehavior.GetMaxPrizeValue() * 1.5f);

            List <string> allitems = new List <string>();

            if (TournamentXPSettings.Instance.PrizeListIncludeLegacy)
            {
                var legacyItems = _legacyItems.AsEnumerable();
                if (TournamentXPSettings.Instance.PrizeFilterCultureLegacyItems)
                {
                    legacyItems = legacyItems.Where(x => x.Culture == tournamentGame.Town.Culture);
                }
                if (TournamentXPSettings.Instance.PrizeFilterValueLegacyItems)
                {
                    legacyItems = legacyItems.Where(x => x.Value >= prizeMin && x.Value <= prizeMax);
                }
                if (TournamentXPSettings.Instance.PrizeFilterItemTypesLegacyItems)
                {
                    legacyItems = legacyItems.Where(x => validTypes.Contains(x.ItemType));
                }
                allitems = allitems.Concat(legacyItems.Select(x => x.StringId)).ToList();
            }
            if (TournamentXPSettings.Instance.PrizeListIncludeCustom && TournamentPrizePoolBehavior.CustomTournamentItems != null && TournamentPrizePoolBehavior.CustomTournamentItems.Count > 0)
            {
                try
                {
                    var customItems = _customItems.AsEnumerable();
                    if (TournamentXPSettings.Instance.PrizeFilterCultureCustomItems)
                    {
                        customItems = customItems.Where(x => x.Culture == tournamentGame.Town.Culture);
                    }
                    if (TournamentXPSettings.Instance.PrizeFilterValueCustomItems)
                    {
                        customItems = customItems.Where(x => x.Value >= prizeMin && x.Value <= prizeMax);
                    }
                    if (TournamentXPSettings.Instance.PrizeFilterItemTypesCustomItems)
                    {
                        customItems = customItems.Where(x => validTypes.Contains(x.ItemType));
                    }

                    allitems = allitems.Concat(customItems.Select(x => x.StringId).ToList()).ToList();
                }
                catch (Exception ex)
                {
                    ErrorLog.Log("Error adding custom items to prize pool.");
                    ErrorLog.Log(ex.ToStringFull());
                }
            }
            if (TournamentXPSettings.Instance.PrizeListIncludeTown)
            {
                var roster = tournamentGame.Town.Owner.ItemRoster;
                roster.RemoveZeroCounts();
                var townItems = roster.Where(x => x.Amount > 0 && !x.EquipmentElement.Item.NotMerchandise).Select(x => x.EquipmentElement.Item);

                if (TournamentXPSettings.Instance.PrizeFilterCultureTownItems)
                {
                    townItems = townItems.Where(x => x.Culture == tournamentGame.Town.Culture);
                }
                if (TournamentXPSettings.Instance.PrizeFilterValueTownItems)
                {
                    townItems = townItems.Where(x => x.Value >= prizeMin && x.Value <= prizeMax);
                }
                if (TournamentXPSettings.Instance.PrizeFilterItemTypesTownItems)
                {
                    townItems = townItems.Where(x => validTypes.Contains(x.ItemType));
                }

                allitems = allitems.Concat(townItems.Select(x => x.StringId)).ToList();
            }
            if (TournamentXPSettings.Instance.PrizeListIncludeVanilla)
            {
                var vanillaItems = ItemObject.All.AsEnumerable();
                if (TournamentXPSettings.Instance.PrizeFilterCultureStandardItems)
                {
                    vanillaItems = vanillaItems.Where(x => x.Culture == tournamentGame.Town.Culture);
                }
                if (TournamentXPSettings.Instance.PrizeFilterValueStandardItems)
                {
                    vanillaItems = vanillaItems.Where(x => x.Value >= prizeMin && x.Value <= prizeMax);
                }
                if (TournamentXPSettings.Instance.PrizeFilterItemTypesStandardItems)
                {
                    vanillaItems = vanillaItems.Where(x => validTypes.Contains(x.ItemType));
                }
                allitems = allitems.Concat(vanillaItems.Select(x => x.StringId)).ToList();
            }

            if (allitems.Count == 0)
            {
                //Alert - fix it somehow
            }

            return(allitems);
        }
コード例 #5
0
        public static List <string> GetItemStringsRevised(TournamentGame tournamentGame, List <ItemObject.ItemTypeEnum> validTypes)
        {
            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" };
            List <string> allitems = new List <string>();

            if (TournamentXPSettings.Instance.PrizeListIncludeLegacy)
            {
                allitems = allitems.Concat(strArray.ToList()).ToList();
            }
            if (TournamentXPSettings.Instance.PrizeListIncludeCustom && TournamentPrizePoolBehavior.CustomTourneyItems != null && TournamentPrizePoolBehavior.CustomTourneyItems.Count > 0)
            {
                try
                {
                    var customItems = TournamentPrizePoolBehavior.CustomTourneyItems.Where(x => validTypes.Contains(x.ItemType));
                    if (TournamentXPSettings.Instance.TownPrizeMinMaxAffectsCustom)
                    {
                        customItems = customItems.Where(x => x.Value >= MathF.Floor(TournamentPrizePoolBehavior.GetMinPrizeValue()) && x.Value <= MathF.Ceiling(TournamentPrizePoolBehavior.GetMaxPrizeValue()));
                    }
                    allitems = allitems.Concat(customItems.Select(x => x.StringId).ToList()).ToList();
                }
                catch (Exception ex)
                {
                    ErrorLog.Log("Error adding custom items to prize pool.");
                    ErrorLog.Log(ex.ToStringFull());
                }
            }
            if (TournamentXPSettings.Instance.PrizeListIncludeTown)
            {
                int _minValue = 1600;
                int _maxValue = 5000;
                _minValue = TournamentPrizePoolBehavior.GetMinPrizeValue();
                _maxValue = TournamentPrizePoolBehavior.GetMaxPrizeValue();
                var townItems = GetValidTownItems(tournamentGame, _minValue, _maxValue, validTypes);
                allitems = allitems.Concat(townItems).ToList();
            }
            if (TournamentXPSettings.Instance.PrizeListIncludeVanilla)
            {
                int _minValue = 1600;
                int _maxValue = 5000;

                List <string> vanillaItems;
                if (TournamentXPSettings.Instance.TownPrizeMinMaxAffectsVanilla)
                {
                    _minValue = TournamentPrizePoolBehavior.GetMinPrizeValue();
                    _maxValue = TournamentPrizePoolBehavior.GetMaxPrizeValue();
                }
                vanillaItems = ItemObject.All.Where(x => x.Culture == tournamentGame.Town.Settlement.Culture && validTypes.Contains(x.ItemType) && x.Value >= _minValue && x.Value <= _maxValue).Select(x => x.StringId).ToList();
                if (vanillaItems.Count == 0)
                {
                    vanillaItems = ItemObject.All.Where(x => validTypes.Contains(x.ItemType) && x.Value >= _minValue && x.Value <= _maxValue).Select(x => x.StringId).ToList();
                }

                allitems = allitems.Concat(vanillaItems).ToList();
            }
            if (allitems.Count == 0)
            {
                return(strArray.ToList());
            }

            return(allitems);
        }