Пример #1
0
 private static void InitParty(MobileParty party, TextObject name, Clan faction, Settlement homeSettlement)
 {
     party.Name = name;
     if (faction.Leader == null)
     {
         party.Party.Owner = faction.Heroes.ToList().Count == 0? null : faction.Heroes.First();
     }
     else
     {
         party.Party.Owner = faction.Leader;
     }
     party.Party.Visuals.SetMapIconAsDirty();
     if (faction.Leader.HomeSettlement == null)
     {
         faction.UpdateHomeSettlement(homeSettlement);
     }
     party.ActualClan     = faction;
     party.HomeSettlement = homeSettlement;
     TaleWorldsCode.BanditsCampaignBehaviour.CreatePartyTrade(party);
     foreach (ItemObject itemObject in ItemObject.All)
     {
         if (itemObject.IsFood)
         {
             int num  = TaleWorldsCode.BanditsCampaignBehaviour.IsLooterFaction(party.MapFaction) ? 8 : 16;
             int num2 = MBRandom.RoundRandomized((float)party.MemberRoster.TotalManCount * (1f / (float)itemObject.Value) * (float)num * MBRandom.RandomFloat * MBRandom.RandomFloat * MBRandom.RandomFloat * MBRandom.RandomFloat);
             if (num2 > 0)
             {
                 party.ItemRoster.AddToCounts(itemObject, num2);
             }
         }
     }
 }
Пример #2
0
        public override int FindNumberOfTroopsToTakeFromGarrison(
            MobileParty mobileParty,
            Settlement settlement,
            float defaultIdealGarrisonStrengthPerWalledCenter = 0.0f)
        {
            MobileParty garrisonParty = settlement.Town.GarrisonParty;

            if (garrisonParty == null)
            {
                return(0);
            }
            float  totalStrength = garrisonParty.Party.TotalStrength;
            float  num1          = ((double)defaultIdealGarrisonStrengthPerWalledCenter > 0.100000001490116 ? defaultIdealGarrisonStrengthPerWalledCenter : FactionHelper.FindIdealGarrisonStrengthPerWalledCenter(mobileParty.MapFaction as Kingdom, settlement.OwnerClan)) * FactionHelper.OwnerClanEconomyEffectOnGarrisonSizeConstant(settlement.OwnerClan) * (settlement.IsTown ? 2f : 1f);
            float  num2          = (float)mobileParty.Party.PartySizeLimit * mobileParty.PaymentRatio / (float)mobileParty.Party.NumberOfAllMembers;
            double num3          = Math.Min(11.0, (double)num2 * Math.Sqrt((double)num2)) - 1.0;
            float  num4          = (float)Math.Pow((double)totalStrength / (double)num1, 1.5);
            float  num5          = mobileParty.LeaderHero.Clan.Leader == mobileParty.LeaderHero ? 2f : 1f;
            double num6          = (double)num4;
            int    num7          = MBRandom.RoundRandomized((float)(num3 * num6) * num5);
            int    num8          = 25 * (settlement.IsTown ? 2 : 1);

            if (num7 > garrisonParty.Party.MemberRoster.TotalRegulars - num8)
            {
                num7 = garrisonParty.Party.MemberRoster.TotalRegulars - num8;
            }
            return(num7);
        }
 private void DailyTick()
 {
     foreach (MobileParty mobileParty in MobileParty.All)
     {
         if (!mobileParty.IsBandit && mobileParty.IsPartyTradeActive && Utils.Utils.IsCustomSpawnsStringID(mobileParty.StringId))
         {
             mobileParty.PartyTradeGold = (int)((double)mobileParty.PartyTradeGold * 0.95 + (double)(50f * (float)mobileParty.Party.MemberRoster.TotalManCount * 0.05f));
             if (MBRandom.RandomFloat < 0.03f && mobileParty.MapEvent != null)
             {
                 foreach (ItemObject itemObject in ItemObject.All)
                 {
                     if (itemObject.IsFood)
                     {
                         int num  = 12;
                         int num2 = MBRandom.RoundRandomized((float)mobileParty.MemberRoster.TotalManCount * (1f / (float)itemObject.Value) * (float)num * MBRandom.RandomFloat * MBRandom.RandomFloat * MBRandom.RandomFloat * MBRandom.RandomFloat);
                         if (num2 > 0)
                         {
                             mobileParty.ItemRoster.AddToCounts(itemObject, num2, true);
                         }
                     }
                 }
             }
         }
     }
 }
        private static int FindNumberOfMercenariesToAdd()
        {
            float troopMultipler    = Settings.Settings.Instance.TroopMultiplier;
            int   minNumberOfTroops = Settings.Settings.Instance.MinNumberOfTroops;
            int   maxNumberOfTroops = Settings.Settings.Instance.MaxNumberOfTroops + 1;           // if set at 15 will never get 15 need this + 1
            float numOfMercs        = MBRandom.RandomInt(minNumberOfTroops, maxNumberOfTroops);

            numOfMercs *= troopMultipler;
            return(MBRandom.RoundRandomized(numOfMercs));
        }
 static bool Prefix(MobileParty mobileParty, ref int __result)
 {
     if (mobileParty != null && mobileParty.Party != null && mobileParty.Party.LeaderHero != null && mobileParty.Party.LeaderHero == Hero.MainHero)
     {
         int partySizeLimit = mobileParty.Party.PartySizeLimit;
         __result = MBRandom.RoundRandomized(((float)QuestPartySizeHelper.GetPartySize(mobileParty) - mobileParty.PaymentRatio * (float)partySizeLimit) * 0.2f);
         return(false);
     }
     else
     {
         return(true);
     }
 }
Пример #6
0
 public void GenerateFood(MobileParty patrolParty)
 {
     foreach (ItemObject itemObject in ItemObject.All)
     {
         if (itemObject.IsFood)
         {
             int foodAmount = MBRandom.RoundRandomized((float)patrolParty.MemberRoster.TotalManCount * (1f / (float)itemObject.Value) * (float)1 * MBRandom.RandomFloat * MBRandom.RandomFloat * MBRandom.RandomFloat * MBRandom.RandomFloat);
             if (foodAmount > 0)
             {
                 patrolParty.ItemRoster.AddToCounts(itemObject, foodAmount, true);
             }
         }
     }
 }
Пример #7
0
 public void generateFood(MobileParty recruiter)
 {
     foreach (ItemObject itemObject in ItemObject.All)
     {
         bool isFood = itemObject.IsFood;
         if (isFood)
         {
             int  num  = MBRandom.RoundRandomized((float)recruiter.MemberRoster.TotalManCount * (1f / (float)itemObject.Value) * 1f * MBRandom.RandomFloat * MBRandom.RandomFloat * MBRandom.RandomFloat * MBRandom.RandomFloat);
             bool flag = num > 0;
             if (flag)
             {
                 recruiter.ItemRoster.AddToCounts(itemObject, num, true);
             }
         }
     }
 }
Пример #8
0
        public static int GetExpectRelation(Hero hero, Clan clan, int daysToNow, bool hasFactor = true)
        {
            var bonus = GetTraitBonus(hero, clan.Leader) + GetTraitBonus(Hero.MainHero, clan.Leader);

            var addRelation = bonus * 10 * (daysToNow > 7 ? 1 : daysToNow / 7f);

            if (!hasFactor || addRelation == 0)
            {
                return((int)addRelation);
            }

            ExplainedNumber explainedNumber = new ExplainedNumber((float)addRelation, new StatExplainer(), null);

            Campaign.Current.Models.DiplomacyModel.GetRelationIncreaseFactor(Hero.MainHero, clan.Leader, ref explainedNumber);
            addRelation = MBRandom.RoundRandomized(explainedNumber.ResultNumber);
            return((int)addRelation);
        }
Пример #9
0
        private static TroopRoster ConstructTroopRoster(PartyTemplateObject pt, int troopNumberLimit = -1) //TODO implement troop number limit.
        {
            TroopRoster returned     = new TroopRoster();
            float       gameProcess  = MiscHelper.GetGameProcess();
            float       num          = 0.25f + 0.75f * gameProcess;
            int         num2         = MBRandom.RandomInt(2);
            float       num3         = (num2 == 0) ? MBRandom.RandomFloat : (MBRandom.RandomFloat * MBRandom.RandomFloat * MBRandom.RandomFloat * 4f);
            float       num4         = (num2 == 0) ? (num3 * 0.8f + 0.2f) : (1f + num3);
            float       randomFloat  = MBRandom.RandomFloat;
            float       randomFloat2 = MBRandom.RandomFloat;
            float       randomFloat3 = MBRandom.RandomFloat;

            for (int i = 0; i < pt.Stacks.Count; i++)
            {
                float f = (pt.Stacks.Count > 0) ? ((float)pt.Stacks[i].MinValue + num * num4 * randomFloat * (float)(pt.Stacks[i].MaxValue - pt.Stacks[i].MinValue)) : 0f;
                returned.AddToCounts(pt.Stacks[i].Character, MBRandom.RoundRandomized(f), false);
            }
            return(returned);
        }
        public static bool EconomyTweak_h_GetTownGoldChange(Town town, ref int __result)
        {
            int   gold = town.Gold;
            float num  = town.Prosperity;
            float num2 = (float)gold * 0.95f + num * EconomyTweak_h_globalConstants.EconomyTweak_h_MarketGoldProsperityRatio * EconomyTweak_h_globalConstants.EconomyTweak_h_ValueOfProsperity * 0.05f;
            int   num3 = MBRandom.RoundRandomized(num2 - (float)gold);

            __result = num3;
            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_GetTownGoldChange");
                }
                bool economyTweak_h_DebugDisplay = EconomyTweak_h_globalConstants.EconomyTweak_h_DebugDisplay;
                if (economyTweak_h_DebugDisplay)
                {
                    InformationManager.DisplayMessage(new InformationMessage("EconomyTweak_h_GetTownGoldChange"));
                }
                bool flag2 = EconomyTweak_h_globalConstants.EconomyTweak_h_DebugLevel > 1;
                if (flag2)
                {
                    using (StreamWriter streamWriter2 = File.AppendText(EconomyTweak_h_globalConstants.EconomyTweak_h_path + "EconomyTweak_h_log.txt"))
                    {
                        streamWriter2.WriteLine(string.Concat(new string[]
                        {
                            "town = ",
                            town.ToString(),
                            ", EconomyTweak_h_TownGold = ",
                            gold.ToString(),
                            ", EconomyTweak_h_TownProsperity = ",
                            num.ToString(),
                            ", EconomyTweak_h_GetTownGoldChange(result) = ",
                            __result.ToString()
                        }));
                    }
                }
            }
            return(false);
        }
Пример #11
0
        private static void SacrificeTroopsWithRatio(
            MobileParty mobileParty,
            float sacrifaceRatio)
        {
            int num1 = MBRandom.RoundRandomized((float)mobileParty.Party.NumberOfRegularMembers * sacrifaceRatio);

            for (int index = 0; index < num1; ++index)
            {
                float num2 = 100f;
                TroopRosterElement troopRosterElement1 = mobileParty.Party.MemberRoster.First <TroopRosterElement>();
                foreach (TroopRosterElement troopRosterElement2 in mobileParty.Party.MemberRoster)
                {
                    float num3 = (float)((double)troopRosterElement2.Character.Level - (troopRosterElement2.WoundedNumber > 0 ? 0.5 : 0.0) - (double)MBRandom.RandomFloat * 0.5);
                    if (!troopRosterElement2.Character.IsHero && (double)num3 < (double)num2 && troopRosterElement2.Number > 0)
                    {
                        num2 = num3;
                        troopRosterElement1 = troopRosterElement2;
                    }
                }
                mobileParty.MemberRoster.AddToCounts(troopRosterElement1.Character, -1, false, troopRosterElement1.WoundedNumber > 0 ? -1 : 0, 0, true, -1);
            }
        }
Пример #12
0
 public static void PartyReplenishFood(MobileParty mobileParty)
 {
     if (mobileParty.IsPartyTradeActive && mobileParty.Food < Mathf.Abs(mobileParty.FoodChange * 2))
     {
         mobileParty.PartyTradeGold = (int)((double)mobileParty.PartyTradeGold * 0.95 + (double)(50f * (float)mobileParty.Party.MemberRoster.TotalManCount * 0.05f));
         if (MBRandom.RandomFloat < 0.1f && mobileParty.MapEvent != null)
         {
             foreach (ItemObject itemObject in ItemObject.All)
             {
                 if (itemObject.IsFood)
                 {
                     int num  = 12;
                     int num2 = MBRandom.RoundRandomized((float)mobileParty.MemberRoster.TotalManCount * (1f / (float)itemObject.Value) * (float)num * MBRandom.RandomFloat * MBRandom.RandomFloat * MBRandom.RandomFloat * MBRandom.RandomFloat);
                     if (num2 > 0)
                     {
                         mobileParty.ItemRoster.AddToCounts(itemObject, num2, true);
                     }
                 }
             }
         }
     }
 }
Пример #13
0
        private static IEnumerable <ItemRosterElement> LootCasualties(ICollection <TroopRosterElement> shareFromCasualties, float lootFactor, bool playerWin = false)
        {
            EquipmentElement        equipmentElement;
            ItemModifier            randomModifierWithTarget;
            ItemModifier            itemModifier;
            ItemRoster              itemRosters       = new ItemRoster();
            List <EquipmentElement> equipmentElements = new List <EquipmentElement>();

            foreach (TroopRosterElement shareFromCasualty in shareFromCasualties)
            {
                //for (int i = 0; i < 1; i++)
                {
                    Equipment randomEquipment = GetRandomEquipment(shareFromCasualty.Character);
                    equipmentElements.Clear();
                    int   num       = MBRandom.RoundRandomized(lootFactor);
                    float lootSkill = lootFactor / .25f;

                    for (int j = 0; j < num; j++)
                    {
                        float expectedLootedItemValue = 30f;
                        if (playerWin)
                        {
                            float valLevel = (float)Math.Max(CharacterObject.PlayerCharacter.Level, shareFromCasualty.Character.Level);
                            expectedLootedItemValue = 0.8f * ((30f * lootFactor) + (float)(valLevel * valLevel));
                        }
                        else
                        {
                            expectedLootedItemValue = ItemHelper.GetExpectedLootedItemValue(shareFromCasualty.Character);
                        }
                        List <EquipmentElement> randomItems = GetRandomItems(randomEquipment, expectedLootedItemValue);
                        foreach (EquipmentElement randomItem in randomItems)
                        {
                            if (randomItem.Item != null && !randomItem.Item.NotMerchandise && equipmentElements.Count <EquipmentElement>((EquipmentElement x) => x.Item.Type == randomItem.Item.Type) == 0)
                            {
                                equipmentElements.Add(randomItem);
                            }
                        }
                    }
                    for (int k = 0; k < equipmentElements.Count; k++)
                    {
                        EquipmentElement  item = equipmentElements[k];
                        ItemRosterElement itemRosterElement = new ItemRosterElement(item.Item, 1, null);
                        float             single            = 30f; // ItemHelper.GetExpectedLootedItemValue(shareFromCasualty.Character);
                        if (playerWin)
                        {
                            float valLevel = (float)Math.Max(CharacterObject.PlayerCharacter.Level, shareFromCasualty.Character.Level);
                            single = 0.8f * (30f * lootFactor) + (float)(valLevel * valLevel);
                        }
                        else
                        {
                            single = ItemHelper.GetExpectedLootedItemValue(shareFromCasualty.Character);
                        }

                        EquipmentElement equipmentElement1 = itemRosterElement.EquipmentElement;
                        if (!equipmentElement1.Item.HasHorseComponent)
                        {
                            equipmentElement1 = itemRosterElement.EquipmentElement;
                            if (equipmentElement1.Item.HasArmorComponent)
                            {
                                equipmentElement1 = itemRosterElement.EquipmentElement;
                                equipmentElement  = itemRosterElement.EquipmentElement;
                                ItemModifierGroup itemModifierGroup = equipmentElement.Item.ArmorComponent.ItemModifierGroup;
                                if (itemModifierGroup != null)
                                {
                                    equipmentElement         = itemRosterElement.EquipmentElement;
                                    randomModifierWithTarget = itemModifierGroup.GetRandomModifierWithTarget(single / (float)equipmentElement.GetBaseValue(), 1f);
                                }
                                else
                                {
                                    randomModifierWithTarget = null;
                                }
                                equipmentElement1.SetModifier(randomModifierWithTarget);
                            }
                        }
                        else
                        {
                            equipmentElement1 = itemRosterElement.EquipmentElement;
                            equipmentElement  = itemRosterElement.EquipmentElement;
                            ItemModifierGroup itemModifierGroup1 = equipmentElement.Item.HorseComponent.ItemModifierGroup;
                            if (itemModifierGroup1 != null)
                            {
                                equipmentElement = itemRosterElement.EquipmentElement;
                                itemModifier     = itemModifierGroup1.GetRandomModifierWithTarget(single / (float)equipmentElement.GetBaseValue(), 1f);
                            }
                            else
                            {
                                itemModifier = null;
                            }
                            equipmentElement1.SetModifier(itemModifier);
                        }
                        itemRosters.Add(itemRosterElement);
                    }
                }
            }
            return(itemRosters);
        }
Пример #14
0
        private IEnumerable <ItemRosterElement> LootCasualties(ICollection <TroopRosterElement> shareFromCasualties, float lootFactor)
        {
            EquipmentElement        equipmentElement;
            ItemModifier            randomModifierWithTarget;
            ItemModifier            itemModifier;
            ItemRoster              itemRosters       = new ItemRoster();
            List <EquipmentElement> equipmentElements = new List <EquipmentElement>();

            foreach (TroopRosterElement shareFromCasualty in shareFromCasualties)
            {
                for (int i = 0; i < 1; i++)
                {
                    Equipment randomEquipment = LootCollector.GetRandomEquipment(shareFromCasualty.Character);
                    equipmentElements.Clear();
                    int num = MBRandom.RoundRandomized(lootFactor);
                    for (int j = 0; j < num; j++)
                    {
                        float            expectedLootedItemValue = ItemHelper.GetExpectedLootedItemValue(shareFromCasualty.Character);
                        EquipmentElement randomItem = randomEquipment.GetRandomItem(expectedLootedItemValue);
                        if (randomItem.Item != null && !randomItem.Item.NotMerchandise && equipmentElements.Count <EquipmentElement>((EquipmentElement x) => x.Item.Type == randomItem.Item.Type) == 0)
                        {
                            equipmentElements.Add(randomItem);
                        }
                    }
                    for (int k = 0; k < equipmentElements.Count; k++)
                    {
                        EquipmentElement  item = equipmentElements[k];
                        ItemRosterElement itemRosterElement = new ItemRosterElement(item.Item, 1, null);
                        float             single            = ItemHelper.GetExpectedLootedItemValue(shareFromCasualty.Character);
                        EquipmentElement  equipmentElement1 = itemRosterElement.EquipmentElement;
                        if (!equipmentElement1.Item.HasHorseComponent)
                        {
                            equipmentElement1 = itemRosterElement.EquipmentElement;
                            if (equipmentElement1.Item.HasArmorComponent)
                            {
                                equipmentElement1 = itemRosterElement.EquipmentElement;
                                equipmentElement  = itemRosterElement.EquipmentElement;
                                ItemModifierGroup itemModifierGroup = equipmentElement.Item.ArmorComponent.ItemModifierGroup;
                                if (itemModifierGroup != null)
                                {
                                    equipmentElement         = itemRosterElement.EquipmentElement;
                                    randomModifierWithTarget = itemModifierGroup.GetRandomModifierWithTarget(single / (float)equipmentElement.GetBaseValue(), 1f);
                                }
                                else
                                {
                                    randomModifierWithTarget = null;
                                }
                                equipmentElement1.SetModifier(randomModifierWithTarget);
                            }
                        }
                        else
                        {
                            equipmentElement1 = itemRosterElement.EquipmentElement;
                            equipmentElement  = itemRosterElement.EquipmentElement;
                            ItemModifierGroup itemModifierGroup1 = equipmentElement.Item.HorseComponent.ItemModifierGroup;
                            if (itemModifierGroup1 != null)
                            {
                                equipmentElement = itemRosterElement.EquipmentElement;
                                itemModifier     = itemModifierGroup1.GetRandomModifierWithTarget(single / (float)equipmentElement.GetBaseValue(), 1f);
                            }
                            else
                            {
                                itemModifier = null;
                            }
                            equipmentElement1.SetModifier(itemModifier);
                        }
                        itemRosters.Add(itemRosterElement);
                    }
                }
            }
            return(itemRosters);
        }
Пример #15
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);
        }
        public override int FindNumberOfTroopsToLeaveToGarrison(MobileParty mobileParty, Settlement settlement)
        {
            MobileParty garrisonParty    = settlement.Town.GarrisonParty;
            float       garrisonStrength = 0f;

            if (garrisonParty is not null)
            {
                garrisonStrength = garrisonParty.Party.TotalStrength;
            }
            float num2 = FactionHelper.FindIdealGarrisonStrengthPerWalledCenter(mobileParty.MapFaction as Kingdom, settlement.OwnerClan) * FactionHelper.OwnerClanEconomyEffectOnGarrisonSizeConstant(settlement.OwnerClan) * (settlement.IsTown ? 2f : 1f);
            int   result;

            if ((settlement.OwnerClan.Leader == Hero.MainHero && (mobileParty.LeaderHero == null || mobileParty.LeaderHero.Clan != Clan.PlayerClan)) || (double)garrisonStrength >= (double)num2)
            {
                result = 0;
            }
            else
            {
                int   numberOfRegularMembers = mobileParty.Party.NumberOfRegularMembers;
                float woundedRatio           = (float)(1.0 + (double)mobileParty.Party.NumberOfWoundedRegularMembers / (double)mobileParty.Party.NumberOfRegularMembers);
                float num4  = (float)mobileParty.Party.PartySizeLimit * mobileParty.PaymentRatio;
                float num5  = (float)(Math.Pow((double)Math.Min(2f, (float)numberOfRegularMembers / num4), 1.20000004768372) * 0.75);
                float num6  = (float)((1.0 - (double)garrisonStrength / (double)num2) * (1.0 - (double)garrisonStrength / (double)num2));
                bool  flag3 = mobileParty.Army != null;
                if (flag3)
                {
                    num6 = Math.Min(num6, 0.5f);
                }
                float num7  = 0.5f;
                bool  flag4 = settlement.OwnerClan == mobileParty.Leader.HeroObject.Clan || settlement.OwnerClan == mobileParty.Party.Owner.MapFaction.Leader.Clan;
                if (flag4)
                {
                    num7 = 1f;
                }
                float        num8 = (mobileParty.Army != null) ? 1.25f : 1f;
                float        num9 = 1f;
                List <float> list = new List <float>(5);
                for (int i = 0; i < 5; i++)
                {
                    list.Add(Campaign.MapDiagonal * Campaign.MapDiagonal);
                }
                foreach (Kingdom kingdom in Kingdom.All)
                {
                    bool flag5 = kingdom.IsKingdomFaction && mobileParty.MapFaction.IsAtWarWith(kingdom);
                    if (flag5)
                    {
                        foreach (Settlement settlement2 in kingdom.Settlements)
                        {
                            float num10 = settlement2.Position2D.DistanceSquared(mobileParty.Position2D);
                            for (int j = 0; j < 5; j++)
                            {
                                bool flag6 = (double)num10 < (double)list[j];
                                if (flag6)
                                {
                                    for (int k = 4; k >= j + 1; k--)
                                    {
                                        list[k] = list[k - 1];
                                    }
                                    list[j] = num10;
                                    break;
                                }
                            }
                        }
                    }
                }
                float num11 = 0f;
                for (int l = 0; l < 5; l++)
                {
                    num11 += (float)Math.Sqrt((double)list[l]);
                }
                float  num12 = num11 / 5f;
                double num13 = (double)Math.Max(0f, Math.Min((float)((double)Campaign.MapDiagonal / 15.0 - (double)Campaign.MapDiagonal / 30.0), num12 - Campaign.MapDiagonal / 30f)) / ((double)Campaign.MapDiagonal / 15.0 - (double)Campaign.MapDiagonal / 30.0);
                float  num14 = Math.Min(0.7f, num9 * num5 * num6 * num7 * num8 * woundedRatio);
                result = MBRandom.RoundRandomized((float)numberOfRegularMembers * num14);
            }
            return(result);
        }
Пример #17
0
        public override int FindNumberOfTroopsToLeaveToGarrison(MobileParty mobileParty, Settlement settlement)
        {
            if (SettlementGarrisonSetting.Instance.DisablePlayerClanLeaveTroopToGarrison && mobileParty.LeaderHero != null && mobileParty.LeaderHero.Clan == Clan.PlayerClan)
            {
                return(0);
            }

            MobileParty garrisonParty = settlement.Town.GarrisonParty;
            float       num           = 0f;

            if (garrisonParty != null)
            {
                num = garrisonParty.Party.TotalStrength;
            }
            float num2 = FactionHelper.FindIdealGarrisonStrengthPerWalledCenter(mobileParty.MapFaction as Kingdom, settlement.OwnerClan);
            float num3 = FactionHelper.OwnerClanEconomyEffectOnGarrisonSizeConstant(settlement.OwnerClan);
            float num4 = FactionHelper.SettlementProsperityEffectOnGarrisonSizeConstant(settlement);

            num2 *= num3;
            num2 *= num4;
            if ((settlement.OwnerClan.Leader != Hero.MainHero || (mobileParty.LeaderHero != null && mobileParty.LeaderHero.Clan == Clan.PlayerClan)) && num < num2)
            {
                int   numberOfRegularMembers = mobileParty.Party.NumberOfRegularMembers;
                float num5 = 1f + (float)mobileParty.Party.NumberOfWoundedRegularMembers / (float)mobileParty.Party.NumberOfRegularMembers;
                float num6 = (float)mobileParty.Party.PartySizeLimit * mobileParty.PaymentRatio;
                float num7 = (float)(Math.Pow((double)Math.Min(2f, (float)numberOfRegularMembers / num6), 1.2000000476837158) * 0.75);
                float num8 = (1f - num / num2) * (1f - num / num2);
                if (mobileParty.Army != null)
                {
                    num8 = Math.Min(num8, 0.5f);
                }
                float num9 = 0.5f;
                if (settlement.OwnerClan == mobileParty.Leader.HeroObject.Clan || settlement.OwnerClan == mobileParty.Party.Owner.MapFaction.Leader.Clan)
                {
                    num9 = 1f;
                }
                float        num10 = (mobileParty.Army != null) ? 1.25f : 1f;
                float        num11 = 1f;
                List <float> list  = new List <float>(5);
                for (int i = 0; i < 5; i++)
                {
                    list.Add(Campaign.MapDiagonal * Campaign.MapDiagonal);
                }
                foreach (Kingdom kingdom in Kingdom.All)
                {
                    if (kingdom.IsKingdomFaction && mobileParty.MapFaction.IsAtWarWith(kingdom))
                    {
                        foreach (Settlement settlement2 in kingdom.Settlements)
                        {
                            float num12 = settlement2.Position2D.DistanceSquared(mobileParty.Position2D);
                            for (int j = 0; j < 5; j++)
                            {
                                if (num12 < list[j])
                                {
                                    for (int k = 4; k >= j + 1; k--)
                                    {
                                        list[k] = list[k - 1];
                                    }
                                    list[j] = num12;
                                    break;
                                }
                            }
                        }
                    }
                }
                float num13 = 0f;
                for (int l = 0; l < 5; l++)
                {
                    num13 += (float)Math.Sqrt((double)list[l]);
                }
                num13 /= 5f;
                float num14 = Math.Max(0f, Math.Min(Campaign.MapDiagonal / 15f - Campaign.MapDiagonal / 30f, num13 - Campaign.MapDiagonal / 30f));
                float num15 = Campaign.MapDiagonal / 15f - Campaign.MapDiagonal / 30f;
                float num16 = num14 / num15;
                float num17 = Math.Min(0.7f, num11 * num7 * num8 * num9 * num10 * num5);
                return(MBRandom.RoundRandomized((float)numberOfRegularMembers * num17));
            }
            return(0);
        }
        public static void EconomyTweak_h_CalculateProsperityChange(Town fortification, StatExplainer explanation, ref float __result)
        {
            int             gold             = fortification.Gold;
            float           num              = fortification.Prosperity;
            float           foodChange       = fortification.FoodChange;
            float           foodStocks       = fortification.FoodStocks;
            float           value            = 0f;
            float           num2             = 0f;
            int             num3             = 0;
            float           value2           = 0f;
            ExplainedNumber explainedNumber  = new ExplainedNumber(0f, explanation, null);
            ExplainedNumber explainedNumber2 = new ExplainedNumber(0f, explanation, null);
            ExplainedNumber explainedNumber3 = new ExplainedNumber(0f, explanation, null);
            bool            flag             = !fortification.IsCastle;

            if (flag)
            {
                bool flag2 = EconomyTweak_h_Dictionaries.EconomyTweak_h_TownDemandFulfilledDictionary.ContainsKey(fortification);
                if (flag2)
                {
                    TextObject desription = new TextObject("Demands Fulfilled", null);
                    bool       flag3      = EconomyTweak_h_Dictionaries.EconomyTweak_h_TownDemandFulfilledDictionary[fortification] < 0f;
                    if (flag3)
                    {
                        value = MathF.Pow(-EconomyTweak_h_Dictionaries.EconomyTweak_h_TownDemandFulfilledDictionary[fortification], EconomyTweak_h_globalConstants.EconomyTweak_h_TownDemandFulfilledProsperityExpValue);
                    }
                    else
                    {
                        value = MathF.Pow(EconomyTweak_h_Dictionaries.EconomyTweak_h_TownDemandFulfilledDictionary[fortification], EconomyTweak_h_globalConstants.EconomyTweak_h_TownDemandFulfilledProsperityExpValue);
                    }
                    value = MathF.Clamp(value, -num * 0.05f, num * 0.05f);
                    explainedNumber.Add(value, desription, null);
                    __result += explainedNumber.ResultNumber;
                }
                num2 = (float)gold * 0.95f + num * EconomyTweak_h_globalConstants.EconomyTweak_h_MarketGoldProsperityRatio * EconomyTweak_h_globalConstants.EconomyTweak_h_ValueOfProsperity * 0.05f;
                num3 = MBRandom.RoundRandomized(num2 - (float)gold);
                num2 = (float)(gold - num3) * 0.95f + num * EconomyTweak_h_globalConstants.EconomyTweak_h_MarketGoldProsperityRatio * EconomyTweak_h_globalConstants.EconomyTweak_h_ValueOfProsperity * 0.05f;
                num3 = MBRandom.RoundRandomized(num2 - (float)gold);
                bool   flag4 = num3 < 0;
                string value3;
                if (flag4)
                {
                    value3 = "Currency Investment";
                }
                else
                {
                    value3 = "Currency Withdrawal";
                }
                TextObject desription2 = new TextObject(value3, null);
                explainedNumber2.Add((float)(-(float)num3) / EconomyTweak_h_globalConstants.EconomyTweak_h_ValueOfProsperity, desription2, null);
                __result += explainedNumber2.ResultNumber;
            }
            float num4  = foodStocks + foodChange * (float)EconomyTweak_h_globalConstants.EconomyTweak_h_OptimalStockPeriodFood - num / 50f;
            bool  flag5 = foodChange < 0f || num4 < 0f;

            if (flag5)
            {
                TextObject desription3 = new TextObject("Food Supply Shortage", null);
                value2 = MathF.Clamp(foodChange - MathF.Pow(-Math.Min(0f, num4), EconomyTweak_h_globalConstants.EconomyTweak_h_FoodShortageProsperityExpValue), -num * 0.05f, 0f);
                explainedNumber3.Add(value2, desription3, null);
                __result += explainedNumber3.ResultNumber;
            }
            bool flag6 = EconomyTweak_h_globalConstants.EconomyTweak_h_DebugLevel > 0;

            if (flag6)
            {
                using (StreamWriter streamWriter = File.AppendText(EconomyTweak_h_globalConstants.EconomyTweak_h_path + "EconomyTweak_h_log.txt"))
                {
                    streamWriter.WriteLine("EconomyTweak_h_CalculateProsperityChange");
                }
                bool economyTweak_h_DebugDisplay = EconomyTweak_h_globalConstants.EconomyTweak_h_DebugDisplay;
                if (economyTweak_h_DebugDisplay)
                {
                    InformationManager.DisplayMessage(new InformationMessage("EconomyTweak_h_CalculateProsperityChange"));
                }
                bool flag7 = EconomyTweak_h_globalConstants.EconomyTweak_h_DebugLevel > 1;
                if (flag7)
                {
                    using (StreamWriter streamWriter2 = File.AppendText(EconomyTweak_h_globalConstants.EconomyTweak_h_path + "EconomyTweak_h_log.txt"))
                    {
                        streamWriter2.WriteLine(string.Concat(new string[]
                        {
                            "fortification = ",
                            fortification.ToString(),
                            ", EconomyTweak_h_TownProsperity = ",
                            num.ToString(),
                            ", EconomyTweak_h_TownGold = ",
                            gold.ToString(),
                            ", EconomyTweak_h_TownDemandFulfilledValue = ",
                            value.ToString(),
                            ", explainedNumber_TownDemandFulfilled = ",
                            explainedNumber.ResultNumber.ToString(),
                            ", EconomyTweak_h_TargetGold = ",
                            num2.ToString(),
                            ", EconomyTweak_h_TargetGoldChange = ",
                            num3.ToString(),
                            ", explainedNumber_TargetGoldChange = ",
                            explainedNumber2.ResultNumber.ToString(),
                            ", EconomyTweak_h_FoodChange = ",
                            foodChange.ToString(),
                            ", EconomyTweak_h_FoodStocks = ",
                            foodStocks.ToString(),
                            ", EconomyTweak_h_FoodShortageProsperity = ",
                            value2.ToString(),
                            ", explainedNumber_FoodShortageProsperity = ",
                            explainedNumber3.ResultNumber.ToString(),
                            ", EconomyTweak_h_CalculateProsperityChange(result) = ",
                            __result.ToString()
                        }));
                    }
                }
            }
        }
        public override int FindNumberOfTroopsToLeaveToGarrison(
            MobileParty mobileParty,
            Settlement settlement)
        {
            MobileParty garrisonParty = settlement.Town.GarrisonParty;
            float       num1          = 0.0f;

            if (garrisonParty != null)
            {
                num1 = garrisonParty.Party.TotalStrength;
            }
            float num2 = FactionHelper.FindIdealGarrisonStrengthPerWalledCenter(mobileParty.MapFaction as Kingdom, settlement.OwnerClan) * FactionHelper.OwnerClanEconomyEffectOnGarrisonSizeConstant(settlement.OwnerClan) * (settlement.IsTown ? 2f : 1f);

            if (settlement.OwnerClan.Leader == Hero.MainHero && (mobileParty.LeaderHero == null || mobileParty.LeaderHero.Clan != Clan.PlayerClan) || (double)num1 >= (double)num2)
            {
                return(0);
            }
            int   ofRegularMembers = mobileParty.Party.NumberOfRegularMembers;
            float num3             = (float)(1.0 + (double)mobileParty.Party.NumberOfWoundedRegularMembers / (double)mobileParty.Party.NumberOfRegularMembers);
            float num4             = (float)mobileParty.Party.PartySizeLimit * mobileParty.PaymentRatio;
            float num5             = (float)(Math.Pow((double)Math.Min(2f, (float)ofRegularMembers / num4), 1.20000004768372) * 0.75);
            float val1             = (float)((1.0 - (double)num1 / (double)num2) * (1.0 - (double)num1 / (double)num2));

            if (mobileParty.Army != null)
            {
                val1 = Math.Min(val1, 0.5f);
            }
            float num6 = 0.5f;

            if (settlement.OwnerClan == mobileParty.Leader.HeroObject.Clan || settlement.OwnerClan == mobileParty.Party.Owner.MapFaction.Leader.Clan)
            {
                num6 = 1f;
            }
            float        num7      = mobileParty.Army != null ? 1.25f : 1f;
            float        num8      = 1f;
            List <float> floatList = new List <float>(5);

            for (int index = 0; index < 5; ++index)
            {
                floatList.Add(Campaign.MapDiagonal * Campaign.MapDiagonal);
            }
            foreach (Kingdom kingdom in Kingdom.All)
            {
                if (kingdom.IsKingdomFaction && mobileParty.MapFaction.IsAtWarWith((IFaction)kingdom))
                {
                    foreach (Settlement settlement1 in kingdom.Settlements)
                    {
                        float num9 = settlement1.Position2D.DistanceSquared(mobileParty.Position2D);
                        for (int index1 = 0; index1 < 5; ++index1)
                        {
                            if ((double)num9 < (double)floatList[index1])
                            {
                                for (int index2 = 4; index2 >= index1 + 1; --index2)
                                {
                                    floatList[index2] = floatList[index2 - 1];
                                }
                                floatList[index1] = num9;
                                break;
                            }
                        }
                    }
                }
            }
            float num10 = 0.0f;

            for (int index = 0; index < 5; ++index)
            {
                num10 += (float)Math.Sqrt((double)floatList[index]);
            }
            float  num11 = num10 / 5f;
            double num12 = (double)Math.Max(0.0f, Math.Min((float)((double)Campaign.MapDiagonal / 15.0 - (double)Campaign.MapDiagonal / 30.0), num11 - Campaign.MapDiagonal / 30f)) / ((double)Campaign.MapDiagonal / 15.0 - (double)Campaign.MapDiagonal / 30.0);
            float  num13 = Math.Min(0.7f, num8 * num5 * val1 * num6 * num7 * num3);

            return(MBRandom.RoundRandomized((float)ofRegularMembers * num13));
        }
Пример #20
0
 public virtual int RoundRandomized(float f) => MBRandom.RoundRandomized(f);