Ejemplo n.º 1
0
        private void ArmouryOnConsequence(MenuCallbackArgs args)
        {
            ItemRoster itemRoster = new ItemRoster();
            string     culture    = Settlement.CurrentSettlement.Culture.StringId;

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

            CULTURE_TO_ITEMS_DICT.TryGetValue(culture, out cultureItems);

            int itemSelectionCount = RANDOM.Next(MIN_ITEM_SELECTION_COUNT, MAX_ITEM_SELECTION_COUNT);

            for (int i = 0; i < itemSelectionCount; i++)
            {
                ItemObject cultureItem = MBObjectManager.Instance.GetObject <ItemObject>(cultureItems.GetRandomElement());
                if (cultureItem != null)
                {
                    itemRoster.AddToCounts(cultureItem, RANDOM.Next(MIN_ITEM_COUNT, MAX_ITEM_COUNT));
                }
                ItemObject swadianItem = MBObjectManager.Instance.GetObject <ItemObject>(SWADIAN_ITEMS.GetRandomElement());
                if (swadianItem != null)
                {
                    itemRoster.AddToCounts(swadianItem, RANDOM.Next(MIN_ITEM_COUNT, MAX_ITEM_COUNT));
                }
            }

            InventoryManager.OpenScreenAsTrade(itemRoster, Settlement.CurrentSettlement.Town, InventoryManager.InventoryCategoryType.None, null);
        }
Ejemplo n.º 2
0
        private static void SplitRosters(MobileParty original, TroopRoster troops1, TroopRoster troops2,
                                         TroopRoster prisoners1, TroopRoster prisoners2, ItemRoster inventory1, ItemRoster inventory2)
        {
            //Mod.Log($"Processing troops: {original.MemberRoster.Count} types, {original.MemberRoster.TotalManCount} in total");
            foreach (var rosterElement in original.MemberRoster.GetTroopRoster().Where(x => x.Character.HeroObject is null))
            {
                SplitRosters(troops1, troops2, rosterElement);
            }

            if (original.PrisonRoster.TotalManCount > 0)
            {
                //Mod.Log($"Processing prisoners: {original.PrisonRoster.Count} types, {original.PrisonRoster.TotalManCount} in total");
                foreach (var rosterElement in original.PrisonRoster.GetTroopRoster())
                {
                    SplitRosters(prisoners1, prisoners2, rosterElement);
                }
            }

            foreach (var item in original.ItemRoster)
            {
                if (string.IsNullOrEmpty(item.EquipmentElement.Item?.Name?.ToString()))
                {
                    Mod.Log("Bad item: " + item.EquipmentElement);
                    continue;
                }

                var half = Math.Max(1, item.Amount / 2);
                inventory1.AddToCounts(item.EquipmentElement, half);
                var remainder = item.Amount % 2;
                inventory2.AddToCounts(item.EquipmentElement, half + remainder);
            }
        }
Ejemplo n.º 3
0
        public static void Postfix(PartyScreenLogic.PartyCommand command)
        {
            DropChance      dc         = new DropChance();
            double          dropChance = dc.CalculateChance();
            Random          random     = new Random();
            CharacterObject character  = command.Character;

            for (int index = 0; index < 12; ++index)
            {
                try
                {
                    if (random.NextDouble() < dropChance)
                    {
                        EquipmentElement equipmentElement = character.Equipment.GetEquipmentFromSlot((EquipmentIndex)index);
                        if (equipmentElement.Item != null)
                        {
                            ItemRoster itemRoster = PartyBase.MainParty.ItemRoster;
                            equipmentElement = character.Equipment.GetEquipmentFromSlot((EquipmentIndex)index);

                            itemRoster.AddToCounts(equipmentElement.Item, 1, true);

                            SubModule.WriteDebugMessage(equipmentElement.Item.Name.ToString() + " was looted");
                        }
                    }
                }
                catch (Exception ex)
                {
                    SubModule.WriteDebugMessage(ex.Message);
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Fills the <paramref name="armoury"/> with items of given <paramref name="cultureName"/>, if found.
        /// </summary>
        private void PopulateItemList(ItemRoster armoury, string cultureName)
        {
            XElement cultureElement = _settings.Descendants(cultureName.ToProper()).FirstOrDefault();

            if (cultureElement is null)
            {
                return;
            }

            IEnumerable <XElement> cultureItems = cultureElement.Descendants("Item");

            if (cultureItems.Count() < 1)
            {
                return;
            }

            foreach (XElement item in cultureItems)
            {
                try {
                    int        rng       = MBRandom.RandomInt(item.Attribute("minCount").ToInt(), item.Attribute("maxCount").ToInt());
                    string     itemId    = item.Attribute("name").Value;
                    ItemObject itemToAdd = MBObjectManager.Instance.GetObject <ItemObject>(itemId);

                    armoury.AddToCounts(itemToAdd, rng);
                } catch { }
            }
        }
Ejemplo n.º 5
0
 public static void Initialize(
     ref ItemRoster leftItemRoster,
     ref MobileParty party,
     ref bool isTrading,
     ref bool isSpecialActionsPermitted,
     ref CharacterObject initialCharacterOfRightRoster,
     ref InventoryManager.InventoryCategoryType merchantItemType,
     ref IMarketData marketData,
     ref bool useBasePrices,
     ref TextObject leftRosterName)
 {
     try
     {
         if (party.IsPlayerParty() &&
             !isTrading &&
             !Game.Current.CheatMode &&
             BannerlordCheatsSettings.Instance?.NativeItemSpawning == true)
         {
             var objectTypeList = Game.Current.ObjectManager.GetObjectTypeList <ItemObject>();
             for (var index = 0; index != objectTypeList.Count; ++index)
             {
                 var itemObject = objectTypeList[index];
                 leftItemRoster.AddToCounts(itemObject, 10);
             }
         }
     }
     catch (Exception e)
     {
         SubModule.LogError(e, typeof(NativeItemSpawning));
     }
 }
 public static void ConsumeFood(int amount, PartyBase party)
 {
     if (amount <= 0)
     {
         return;
     }
     else
     {
         ItemRoster itemRoster = party.ItemRoster;
         int        FoodAmount = MoreSettlementActionHelper.GetFoodAmount(PartyBase.MainParty);
         int        number     = rng.Next(1, FoodAmount);
         int        count      = 0;
         for (int i = itemRoster.Count - 1; i >= 0; i--)
         {
             if (itemRoster[i].EquipmentElement.Item.IsFood)
             {
                 count += itemRoster[i].Amount;
                 if (number <= count)
                 {
                     itemRoster.AddToCounts(itemRoster[i].EquipmentElement.Item, -1);
                     break;
                 }
             }
         }
         ConsumeFood(amount - 1, party);
     }
 }
Ejemplo n.º 7
0
        public static void Postfix(PartyScreenLogic.PartyCommand command)
        {
            Random          random    = new Random();
            CharacterObject character = command.Character;

            for (int i = 0; i < 12; i++)
            {
                if (character.HeroObject.BattleEquipment[i].Item != null)
                {
                    ItemRoster       itemRoster = PartyBase.MainParty.ItemRoster;
                    EquipmentElement item       = character.HeroObject.BattleEquipment[i];
                    itemRoster.AddToCounts(item.Item, 1, true);
                    item = character.HeroObject.BattleEquipment[i];
                    InformationManager.DisplayMessage(new InformationMessage(string.Concat(item.Item.Name.ToString(), " Added to inventory")));
                }
            }
        }
        public void LootStolenGoods(Settlement settlement, int ammountFromProsperity, int goodsQuantity)
        {
            try
            {
                ItemRoster itemRoster = new ItemRoster();

                int lootQuantity        = MathF.Ceiling(((float)(ammountFromProsperity * goodsQuantity / 100)));
                int cheapestAnimalValue = 50;       //used to pick the cheapest animal availiable first

                while (lootQuantity > 0 && settlement.ItemRoster.Count > 0)
                {
                    int itemSeed = MBRandom.RandomInt();
                    for (int j = 0; j < settlement.ItemRoster.Count; j++)
                    {
                        ItemRosterElement itemRosterElement = settlement.ItemRoster[(j + itemSeed) % settlement.ItemRoster.Count];
                        ItemObject        item = itemRosterElement.EquipmentElement.Item;
                        if (!itemRosterElement.IsEmpty && lootQuantity > 0)
                        {
                            if (item.IsTradeGood)
                            {
                                int randomAmmount = MBRandom.RandomInt(Math.Min(lootQuantity, itemRosterElement.Amount) - 1) + 1;
                                settlement.ItemRoster.AddToCounts(item, -randomAmmount, true);
                                itemRoster.AddToCounts(item, randomAmmount, true);
                                lootQuantity -= randomAmmount;
                            }
                            else if (item.IsAnimal || item.IsMountable)
                            {
                                if (item.Value <= cheapestAnimalValue)
                                {
                                    int randomAmmount = MBRandom.RandomInt(Math.Min(lootQuantity, itemRosterElement.Amount) - 1) + 1;
                                    settlement.ItemRoster.AddToCounts(item, -randomAmmount, true);
                                    itemRoster.AddToCounts(item, randomAmmount, true);
                                    lootQuantity -= randomAmmount;
                                }
                                else
                                {
                                    cheapestAnimalValue += 100;
                                }
                            }
                        }
                    }
                }

                KleptomaniaSubModule.Log.Info("Stealing | Total number of stolen goods: " + itemRoster.Count.ToString());
                if (KleptomaniaSubModule.settings.DebugInfo)
                {
                    InformationManager.DisplayMessage(new InformationMessage("Total number of stolen goods: " + itemRoster.Count.ToString(), Colors.Yellow));
                }
                InventoryManager.OpenScreenAsLoot(new Dictionary <PartyBase, ItemRoster>
                {
                    {
                        PartyBase.MainParty,
                        itemRoster
                    }
                });
            }
            catch (Exception ex)
            {
                InformationManager.DisplayMessage(new InformationMessage("Kleptomania: An error occured on LootStolenGoods. Check the Log file.", Colors.Red));
                KleptomaniaSubModule.Log.Info("Stealing | Exception in LootStolenGoods: " + ex.Message);
            }
        }
Ejemplo n.º 9
0
        public static bool EconomyTweak_h_MakeConsumption(Town town, Dictionary <ItemCategory, float> categoryDemand, Dictionary <ItemCategory, int> saleLog)
        {
            bool flag = EconomyTweak_h_globalConstants.EconomyTweak_h_DebugLevel > 0;

            if (flag)
            {
                using (StreamWriter streamWriter = File.AppendText(EconomyTweak_h_globalConstants.EconomyTweak_h_path + "EconomyTweak_h_log.txt"))
                {
                    streamWriter.WriteLine("EconomyTweak_h_MakeConsumption");
                }
                bool economyTweak_h_DebugDisplay = EconomyTweak_h_globalConstants.EconomyTweak_h_DebugDisplay;
                if (economyTweak_h_DebugDisplay)
                {
                    InformationManager.DisplayMessage(new InformationMessage("EconomyTweak_h_MakeConsumption"));
                }
            }
            EconomyTweak_h_Dictionaries.EconomyTweak_h_TownDemandFulfilledDictionary[town] = 0f;
            saleLog.Clear();
            TownMarketData marketData = town.MarketData;
            ItemRoster     itemRoster = town.Owner.ItemRoster;
            List <int>     list       = Enumerable.Range(0, itemRoster.Count - 1).ToList <int>();

            list.Shuffle <int>();
            foreach (int num in list)
            {
                ItemObject itemAtIndex = itemRoster.GetItemAtIndex(num);
                if (itemAtIndex is not null)
                {
                    int          elementNumber = itemRoster.GetElementNumber(num);
                    ItemCategory itemCategory  = itemAtIndex.GetItemCategory();
                    float        num2          = categoryDemand[itemCategory];
                    bool         flag2         = EconomyTweak_h_Dictionaries.EconomyTweak_h_TownCategoryWorkshopPriceFactorDictionary.ContainsKey(new ValueTuple <Town, ItemCategory>(town, itemCategory));
                    if (flag2)
                    {
                        num2 /= EconomyTweak_h_Dictionaries.EconomyTweak_h_TownCategoryWorkshopPriceFactorDictionary[new ValueTuple <Town, ItemCategory>(town, itemCategory)];
                    }
                    bool flag3 = EconomyTweak_h_Dictionaries.EconomyTweak_h_TownCategoryProsperityPriceFactorDictionary.ContainsKey(new ValueTuple <Town, ItemCategory>(town, itemCategory));
                    if (flag3)
                    {
                        num2 /= EconomyTweak_h_Dictionaries.EconomyTweak_h_TownCategoryProsperityPriceFactorDictionary[new ValueTuple <Town, ItemCategory>(town, itemCategory)];
                    }
                    float num3  = (float)EconomyTweak_h_globalConstants.EconomyTweak_h_OptimalStockPeriodOverconsumption * num2 / (float)itemAtIndex.Value;
                    float num4  = num2;
                    bool  flag4 = (float)elementNumber > num3;
                    if (flag4)
                    {
                        num4 = (float)MBRandom.RoundRandomized(num4 * (float)elementNumber / num3);
                    }
                    bool flag5 = num4 > 0.01f;
                    if (flag5)
                    {
                        int  price = marketData.GetPrice(itemAtIndex, null, false, null);
                        int  num5  = MBRandom.RoundRandomized(num4 / (float)itemAtIndex.Value);
                        int  num6  = num5;
                        bool flag6 = num5 > elementNumber;
                        if (flag6)
                        {
                            num6 = elementNumber;
                        }
                        bool flag7 = num6 > elementNumber;
                        if (flag7)
                        {
                            num6 = elementNumber;
                        }
                        //itemRoster.AddToCountsAtIndex(num, -num6);
                        itemRoster.AddToCounts(itemAtIndex, -num6);
                        town.ChangeGold(num6 * price);
                        int num7 = 0;
                        saleLog.TryGetValue(itemCategory, out num7);
                        saleLog[itemCategory] = num7 + num6;
                        bool isTradeGood = itemCategory.IsTradeGood;
                        if (isTradeGood)
                        {
                            EconomyTweak_h_Dictionaries.EconomyTweak_h_TownDemandFulfilledAdd(town, (float)(num6 * itemAtIndex.Value) / EconomyTweak_h_globalConstants.EconomyTweak_h_ValueOfProsperity);
                        }
                        categoryDemand[itemCategory] = (float)((num5 - num6) * itemAtIndex.Value);
                        bool flag8 = EconomyTweak_h_globalConstants.EconomyTweak_h_DebugLevel > 1;
                        if (flag8)
                        {
                            using (StreamWriter streamWriter2 = File.AppendText(EconomyTweak_h_globalConstants.EconomyTweak_h_path + "EconomyTweak_h_log.txt"))
                            {
                                streamWriter2.WriteLine(string.Concat(new string[]
                                {
                                    "EconomyTweak_h_MakeConsumption itemRoster.Count, i = ",
                                    num.ToString(),
                                    ": , town = ",
                                    town.ToString(),
                                    ", itemAtIndex.Name = ",
                                    itemAtIndex.Name.ToString(),
                                    ", itemAtIndex.Value = ",
                                    itemAtIndex.Value.ToString(),
                                    ", elementNumber = ",
                                    elementNumber.ToString(),
                                    ", itemCategory = ",
                                    itemCategory.ToString(),
                                    ", DemandValue(num) = ",
                                    num4.ToString(),
                                    ", DemandCount(num2) = ",
                                    num5.ToString(),
                                    ", DemandCountAvail(num3) = ",
                                    num6.ToString(),
                                    ", SoldBefore(num4) = ",
                                    num7.ToString(),
                                    ", categoryDemand[itemCategory] = ",
                                    categoryDemand[itemCategory].ToString()
                                }));
                            }
                        }
                    }
                }
            }
            foreach (ItemObject item in ItemObject.All)
            {
                ItemCategory itemCategory2 = item.GetItemCategory();
                bool         flag9         = categoryDemand[itemCategory2] > 0f;
                if (flag9)
                {
                    bool isTradeGood2 = itemCategory2.IsTradeGood;
                    if (isTradeGood2)
                    {
                        EconomyTweak_h_Dictionaries.EconomyTweak_h_TownDemandFulfilledAdd(town, -categoryDemand[itemCategory2] / EconomyTweak_h_globalConstants.EconomyTweak_h_ValueOfProsperity);
                        categoryDemand[itemCategory2] = 0f;
                    }
                }
            }
            //itemRoster.RemoveZeroCounts();
            typeof(ItemRoster).GetMethod("RemoveZeroCounts", BindingFlags.NonPublic | BindingFlags.Static).Invoke(null, null);
            List <Town.SellLog> list2 = new List <Town.SellLog>();

            foreach (KeyValuePair <ItemCategory, int> keyValuePair in saleLog)
            {
                bool flag10 = keyValuePair.Value > 0;
                if (flag10)
                {
                    list2.Add(new Town.SellLog(keyValuePair.Key, keyValuePair.Value));
                }
            }
            Town.SellLog[] value = new Town.SellLog[0];
            value = list2.ToArray <Town.SellLog>();
            FieldInfo field = typeof(Town).GetField("_soldItems", BindingFlags.Instance | BindingFlags.NonPublic);

            field.SetValue(town, value);
            bool flag11 = EconomyTweak_h_globalConstants.EconomyTweak_h_DebugLevel > 1;

            if (flag11)
            {
                foreach (Town.SellLog sellLog in town.SoldItems)
                {
                    using (StreamWriter streamWriter3 = File.AppendText(EconomyTweak_h_globalConstants.EconomyTweak_h_path + "EconomyTweak_h_log.txt"))
                    {
                        streamWriter3.WriteLine(string.Concat(new string[]
                        {
                            "EconomyTweak_h_MakeConsumption town.SoldItems: town = ",
                            town.ToString(),
                            ", sellLog.Category = ",
                            sellLog.Category.ToString(),
                            ", sellLog.Number = ",
                            sellLog.Number.ToString()
                        }));
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 10
0
        private void armory_on_consequence(MenuCallbackArgs args)
        {
            Clan OwnerClan = Settlement.CurrentSettlement.OwnerClan;

            string sDisplayMessageTitle = "",
                   sDisplayMessageBody  = "";

            float fCostOfAdmissionGold      = 0f,
                  fCostOfAdmissionInfluence = 0f;

            bool bPlayerRulesTown   = false,
                 bPlayerIsVassal    = false,
                 bPlayerIsMercenary = false,
                 bShowEntryOption   = true;

            if (OwnerClan.Leader == Hero.MainHero)
            {
                bPlayerRulesTown = true;
            }
            else if (OwnerClan.Kingdom == Clan.PlayerClan.Kingdom && Clan.PlayerClan.Kingdom != null)
            {
                if (Hero.MainHero == OwnerClan.Kingdom.Leader) //Player is the ruler of the kingdom
                {
                    bPlayerRulesTown = true;
                }
                else
                {
                    if (Clan.PlayerClan.IsUnderMercenaryService)
                    {
                        bPlayerIsMercenary = true;
                    }
                    else
                    {
                        bPlayerIsVassal = true;
                    }
                }
            }

            // Influence fee calculation
            if ((bPlayerIsVassal && !Settings.Instance.bVassalPaysWithGoldToo) || (bPlayerRulesTown &&
                                                                                   Settings.Instance.bEvenRulersShouldPay && !Settings.Instance.bRulersPayGold))
            {
                fCostOfAdmissionInfluence = Settings.Instance.bIgnoreTownProsperityForAdmission
                    ? Settings.Instance.iFlatAdmissionCostInfluence
                    : Settlement.CurrentSettlement.Prosperity / 100;

                if (bPlayerRulesTown)
                {
                    fCostOfAdmissionInfluence *= Settings.Instance.fPercentageOfCostForRuler;
                }
            }

            // Gold fee calculation
            if ((!bPlayerRulesTown && !bPlayerIsVassal) ||
                (bPlayerIsVassal && Settings.Instance.bVassalPaysWithGoldToo) || (bPlayerRulesTown &&
                                                                                  Settings.Instance.bEvenRulersShouldPay && Settings.Instance.bRulersPayGold))
            {
                fCostOfAdmissionGold = Settings.Instance.bIgnoreTownProsperityForAdmission
                    ? Settings.Instance.iFlatAdmissionCostGold
                    : Settlement.CurrentSettlement.Prosperity;

                if (bPlayerIsMercenary)
                {
                    fCostOfAdmissionGold *= Settings.Instance.fPercentageOfGoldForMercenary;
                }

                if (bPlayerIsVassal)
                {
                    fCostOfAdmissionGold *= Settings.Instance.fPercentageOfGoldForVassal;
                }

                if (bPlayerRulesTown)
                {
                    fCostOfAdmissionGold *= Settings.Instance.fPercentageOfCostForRuler;
                }
            }


            if (Settings.Instance.bRelationshipModifiesAdmissionCost && OwnerClan.Leader != Hero.MainHero)
            {
                fCostOfAdmissionGold      -= fCostOfAdmissionGold * (int)OwnerClan.Leader.GetRelationWithPlayer() / 100;
                fCostOfAdmissionInfluence -=
                    fCostOfAdmissionInfluence * (int)OwnerClan.Leader.GetRelationWithPlayer() / 100;
            }

            fCostOfAdmissionGold -= fCostOfAdmissionGold % 100; // Clean up the entry fee in gold cost to be in hundreds

            int iCostOfAdmissionGold = fCostOfAdmissionGold > 0
                ? (int)Math.Min(Settings.Instance.iMaxCostOfAdmissionGold,
                                Math.Max(fCostOfAdmissionGold, Settings.Instance.iMinCostOfAdmissionGold))
                : 0;
            int iCostOfAdmissionInfluence = fCostOfAdmissionInfluence > 0
                ? (int)Math.Min(Settings.Instance.iMaxCostOfAdmissionInfluence,
                                Math.Max(fCostOfAdmissionInfluence, Settings.Instance.iMinCostOfAdmissionInfluence))
                : 0;


            if (bPlayerRulesTown)
            {
                sDisplayMessageTitle += new TextObject("{=kRA_welcome_ruler}Welcome to The Royal Armoury, Mylord!\n")
                                        .ToString();

                if (!Settings.Instance.bEvenRulersShouldPay)
                {
                    iCostOfAdmissionGold      = 0;
                    iCostOfAdmissionInfluence = 0;
                }
            }

            if (Settings.Instance.bProsperityAffectsItemSelection && (!Settings.Instance.bUnlimitedSelectionIfFree ||
                                                                      iCostOfAdmissionGold > 0 ||
                                                                      iCostOfAdmissionInfluence > 0))
            {
                var selection =
                    new TextObject(
                        "{=kRA_selection}The item selection variety is expected to be {SEL} ({PERCENT}).\n \n");

                int iSelectionPercentage =
                    (int)((Settlement.CurrentSettlement.Prosperity - Settings.Instance.iMinProsperityForAnyItem) /
                          (Settings.Instance.iProsperityForGuaranteedItem -
                           Settings.Instance.iMinProsperityForAnyItem) *
                          100);
                iSelectionPercentage = Math.Min(100, Math.Max(0, iSelectionPercentage));

                var sel = new TextObject(
                    "{=kRA_sel_none}non existent, as besides some scrawny mice, the Armory is mostly empty");
                switch (iSelectionPercentage)
                {
                case int i when i >= 100:
                    sel = new TextObject("{=kRA_sel_100}Impeccable");
                    break;

                case int i when(i >= 80 && i < 100):
                    sel = new TextObject("{=kRA_sel_80}Excellent");

                    break;

                case int i when(i >= 60 && i < 80):
                    sel = new TextObject("{=kRA_sel_60}Above Average");

                    break;

                case int i when(i >= 40 && i < 60):
                    sel = new TextObject("{=kRA_sel_40}Average");

                    break;

                case int i when(i >= 20 && i < 40):
                    sel = new TextObject("{=kRA_sel_20}Below Average");

                    break;

                case int i when(i >= 10 && i < 20):
                    sel = new TextObject("{=kRA_sel_10}Poor");

                    break;

                case int i when(i > 0 && i < 10):
                    sel = new TextObject("{=kRA_sel_0}Abysmal");

                    break;

                case int i when(i <= 0):
                    break;
                }

                selection.SetTextVariable("SEL", sel);
                selection.SetTextVariable("PERCENT", iSelectionPercentage);
                sDisplayMessageBody += selection.ToString();
            }

            if (iCostOfAdmissionGold == 0 && iCostOfAdmissionInfluence == 0)
            {
                if (!bPlayerRulesTown)
                {
                    sDisplayMessageTitle += new TextObject("{=kRA_access_free}You can freely enter, sir.");
                }
            }
            else
            {
                if (bPlayerIsMercenary)
                {
                    sDisplayMessageTitle += new TextObject("{=kRA_access_merc}You are a mercenary for the kingdom.\n");
                }

                if (bPlayerIsVassal)
                {
                    sDisplayMessageTitle += new TextObject("{=kRA_access_vassal}You are a vassal of the kingdom.\n");
                }

                sDisplayMessageTitle += new TextObject("{=kRA_access_cost}Accessing The Royal Armoury costs ");

                if (iCostOfAdmissionGold > 0)
                {
                    sDisplayMessageTitle +=
                        iCostOfAdmissionGold.ToString() + new TextObject("{=kRA_access_cost_g} gold");
                }

                if (iCostOfAdmissionInfluence > 0)
                {
                    sDisplayMessageTitle += iCostOfAdmissionInfluence.ToString() +
                                            new TextObject("{=kRA_access_cost_i} influence");
                }

                if ((Hero.MainHero.Gold < iCostOfAdmissionGold && iCostOfAdmissionGold > 0) ||
                    (Hero.MainHero.Clan.Influence < iCostOfAdmissionInfluence && iCostOfAdmissionInfluence > 0))
                {
                    if (bPlayerRulesTown)
                    {
                        sDisplayMessageBody +=
                            new TextObject(
                                "{=kRA_cannot_enter_ruler}This is really embarassing, Sire, alas I cannot let You in.\n \n");
                    }
                    else
                    {
                        sDisplayMessageBody +=
                            new TextObject("{=kRA_cannot_enter}You cannot afford to enter now.\n \n");
                    }

                    bShowEntryOption = false;
                }

                if (Settings.Instance.bRelationshipModifiesAdmissionCost && OwnerClan.Leader != Hero.MainHero)
                {
                    var text = new TextObject(
                        "{=kRA_cost_info}To lower the costs (gold or influence) improve your relations with {CLAN_LEADER_NAME} of clan {CLAN_NAME} (currently at {CLAN_LEADER_RELATION}). \n");
                    text.SetTextVariable("CLAN_NAME", OwnerClan.Name);
                    text.SetTextVariable("CLAN_LEADER_NAME", OwnerClan.Leader.Name);
                    text.SetTextVariable("CLAN_LEADER_GENDER", OwnerClan.Leader.IsFemale ? 1 : 0);
                    text.SetTextVariable("CLAN_LEADER_RELATION", OwnerClan.Leader.GetRelationWithPlayer().ToString());
                    text.SetTextVariable("INFLUENCE_ICON", "{=!}<img src=\"Icons\\Influence@2x\">");
                    sDisplayMessageBody += text;
                }

                TextObject discount;
                if (Settings.Instance.fPercentageOfGoldForMercenary < 1)
                {
                    discount = new TextObject(
                        "{=kRA_disc_merc_yes}Discounts are available to mercenaries (pay only {COST} %). ");
                }
                else
                {
                    discount = new TextObject("{=kRA_disc_merc_no}Mercenaries pay {COST} %. ");
                }

                discount.SetTextVariable("COST", Settings.Instance.fPercentageOfGoldForMercenary * 100);
                sDisplayMessageBody += discount;


                if (!Settings.Instance.bVassalPaysWithGoldToo)
                {
                    sDisplayMessageBody +=
                        new TextObject("{=kRA_vassal_pay_i}As a vassal, you would pay with influence. ");
                }
                else
                {
                    sDisplayMessageBody += new TextObject("{=kRA_vassal_pay_g}As a vassal, you would pay with gold. ");

                    if (Settings.Instance.fPercentageOfGoldForVassal < 1)
                    {
                        discount = new TextObject(
                            "{=kRA_disc_vassal_yes}Discounts are available to vassals (pay only {COST} %). ");
                    }
                    else
                    {
                        discount = new TextObject("{=kRA_disc_vassal_no}Vassals pay {COST} %. ");
                    }

                    discount.SetTextVariable("COST", Settings.Instance.fPercentageOfGoldForVassal * 100);
                    sDisplayMessageBody += discount;
                }


                int prosperity = 0;
                if (Settings.Instance.bIgnoreTownProsperityForAdmission)
                {
                    sDisplayMessageBody +=
                        new TextObject("{=kRA_pros_fee_no}Town prosperity has NO effect on the entry fee, ");
                }
                else
                {
                    sDisplayMessageBody += new TextObject("{=kRA_pros_fee_yes}Town prosperity affects the entry fee, ");
                    prosperity           = 1;
                }

                var variety =
                    new TextObject("{=kRA_pros_sel}and does {EFFECTS_VAR_TEXT}affect item selection variety. ");
                variety.SetTextVariable("EFFECTS_ENTRY", prosperity);

                if (Settings.Instance.bProsperityAffectsItemSelection)
                {
                    variety.SetTextVariable("EFFECTS_VAR", 1);
                    variety.SetTextVariable("EFFECTS_VAR_TEXT", "");
                }
                else
                {
                    variety.SetTextVariable("EFFECTS_VAR", 0);
                    variety.SetTextVariable("EFFECTS_VAR_TEXT", new TextObject("{=kRA_pros_sel_not}NOT ").ToString());
                }

                sDisplayMessageBody += variety;

                if (!Settings.Instance.bEvenRulersShouldPay)
                {
                    sDisplayMessageBody +=
                        new TextObject("{=kRA_fee_ruler}\nUltimately, ruling the town grants free entry. ");
                }
            }

            InformationManager.ShowInquiry(
                new InquiryData(
                    sDisplayMessageTitle,
                    sDisplayMessageBody,
                    bShowEntryOption, true,
                    new TextObject("{=kRA_enter}Enter").ToString(),
                    new TextObject("{=kRA_leave}Leave").ToString(),
                    () =>
            {
                Hero.MainHero.ChangeHeroGold(-iCostOfAdmissionGold);
                Hero.MainHero.Clan.Influence -= iCostOfAdmissionInfluence;

                ItemRoster armoury = new ItemRoster();

                MD5 md5Hasher = MD5.Create();
                var hashed    =
                    md5Hasher.ComputeHash(
                        System.Text.Encoding.UTF8.GetBytes(Settlement.CurrentSettlement.Name.ToString()));
                var iRandSeed = BitConverter.ToInt32(hashed, 0);
                iRandSeed    += (int)(Settlement.CurrentSettlement.Prosperity /
                                      Settings.Instance.iProsperityChangeNeededForNewStock);

                Random random = new Random(Settings.Instance.bPreserveRandomSeedForStock
                            ? iRandSeed
                            : (int)DateTime.Now.Ticks);

                foreach (ItemObject item in ItemObject.All)
                {
                    if (!item.IsCraftedByPlayer || Settings.Instance.bShowCraftedItems)
                    {
                        if ((item.Culture == Settlement.CurrentSettlement.Culture ||
                             !Settings.Instance.bFilterByCulture ||
                             (item.Culture == null &&
                              Settings.Instance.bShowCultureMissingItems))         // Culture filters
                            &&
                            (
                                (Settings.Instance.bCostOrValueForItemEnough &&
                                 (item.Value >= Settings.Instance.iLowestValueItemInArmory || item.Appearance >=
                                  Settings.Instance
                                  .fLowestAppearanceItemInArmory))                // Cost OR Value is enough?
                                ||
                                (!Settings.Instance.bCostOrValueForItemEnough &&
                                 (item.Value >= Settings.Instance.iLowestValueItemInArmory && item.Appearance >=
                                  Settings.Instance
                                  .fLowestAppearanceItemInArmory))                // Cost AND value is needed?
                            )
                            )
                        {
                            if ((Settings.Instance.bUnlimitedSelectionIfFree && iCostOfAdmissionGold == 0 &&
                                 iCostOfAdmissionInfluence == 0) ||
                                !Settings.Instance.bProsperityAffectsItemSelection)
                            {
                                armoury.AddToCounts(item, 99);
                            }
                            else
                            {
                                float fItemChanceToAppearBasedOnValueAndRarity = Math.Max(1,
                                                                                          Math.Min(
                                                                                              (item.Appearance - Settings.Instance.fLowestAppearanceItemInArmory) *
                                                                                              (item.Value - Settings.Instance.iLowestValueItemInArmory), 500000) /
                                                                                          1000); // normalize to a number between 1 to 500
                                int iHalfOfProsperityDifference =
                                    (Settings.Instance.iProsperityForGuaranteedItem -
                                     Settings.Instance.iMinProsperityForAnyItem) / 2;
                                fItemChanceToAppearBasedOnValueAndRarity *= iHalfOfProsperityDifference / 500;

                                int iRandMax = Settings.Instance.iProsperityForGuaranteedItem -
                                               (Settings.Instance.bItemValueAndRarityAffectsChanceToShow
                                                           ? iHalfOfProsperityDifference
                                                           : 0);

                                int iItemChanceToAppear =
                                    random.Next(Settings.Instance.iMinProsperityForAnyItem, iRandMax);

                                if (Settings.Instance.bItemValueAndRarityAffectsChanceToShow)
                                {
                                    iItemChanceToAppear += (int)fItemChanceToAppearBasedOnValueAndRarity;
                                }

                                if (Settlement.CurrentSettlement.Prosperity >= iItemChanceToAppear)
                                {
                                    float fMaxItemsPossible =
                                        Settings.Instance.bRandomizeQuantityBasedOnProsperity
                                                    ? (Settlement.CurrentSettlement.Prosperity / 1000)
                                                    : Settings.Instance.iItemAvailableQuantity;
                                    float fItemsToAdd = Settings.Instance.bRandomizeItemAvailableQuantity
                                                ? random.Next(1, (int)fMaxItemsPossible + 1)
                                                : Settings.Instance.iItemAvailableQuantity;
                                    fItemsToAdd += Settings.Instance.bRandomizeQuantityBasedOnProsperity
                                                ? (Settlement.CurrentSettlement.Prosperity / 4000)
                                                : 0;

                                    if (Settings.Instance.bItemValueAndRarityAffectsChanceToShow)
                                    {
                                        fItemsToAdd = Math.Max(1,
                                                               fItemsToAdd / Math.Max(1, item.Appearance * item.Value / 100000));
                                    }

                                    armoury.AddToCounts(item, (int)fItemsToAdd);
                                }
                            }
                        }
                    }
                }

                InventoryManager.OpenScreenAsTrade(armoury, Settlement.CurrentSettlement.Town);
            },
                    null,
                    ""),
                true);
        }