public static void Postfix(ref float __result, Town town, StatExplainer explanation = null)
        {
            var perk    = ActivePatch._perk;
            var totalHP = new ExplainedNumber(__result, explanation);

            PerkHelper.AddPerkBonusForTown(perk, town, ref totalHP);

            __result = totalHP.ResultNumber;
        }
 private void AddGarrisonOwnerPerkEffects(
     Settlement currentSettlement,
     ref ExplainedNumber result)
 {
     if (currentSettlement == null || !currentSettlement.IsTown)
     {
         return;
     }
     PerkHelper.AddPerkBonusForTown(DefaultPerks.TwoHanded.GarrisonCapacity, currentSettlement.Town, ref result);
 }
Ejemplo n.º 3
0
        public static void Postfix(ref float __result, Building building)
        {
            if (!building.BuildingType.IsDefaultProject)
            {
                return;
            }
            if (building.Town == null)
            {
                return;
            }

            var perk        = ActivePatch._perk;
            var totalEffect = new ExplainedNumber(__result);

            PerkHelper.AddPerkBonusForTown(perk, building.Town, ref totalEffect);
            __result = totalEffect.ResultNumber;
        }
Ejemplo n.º 4
0
 private void GetBattleXpBonusFromPerks(PartyBase party, ref ExplainedNumber xpToGain, CharacterObject troop)
 {
     if (party.IsMobile && party.MobileParty.LeaderHero != null)
     {
         if (!troop.IsArcher && party.MobileParty.HasPerk(DefaultPerks.OneHanded.Trainer, true))
         {
             xpToGain.AddFactor(DefaultPerks.OneHanded.Trainer.SecondaryBonus * 0.01f, DefaultPerks.OneHanded.Trainer.Name);
         }
         if (troop.IsInfantry)
         {
             if (party.MobileParty.HasPerk(DefaultPerks.OneHanded.CorpsACorps, false))
             {
                 xpToGain.AddFactor(DefaultPerks.OneHanded.CorpsACorps.PrimaryBonus * 0.01f, DefaultPerks.OneHanded.CorpsACorps.Name);
             }
             if (party.MobileParty.HasPerk(DefaultPerks.TwoHanded.BaptisedInBlood, true))
             {
                 xpToGain.AddFactor(DefaultPerks.TwoHanded.BaptisedInBlood.SecondaryBonus * 0.01f, DefaultPerks.TwoHanded.BaptisedInBlood.Name);
             }
         }
         if (party.MobileParty.HasPerk(DefaultPerks.OneHanded.LeadByExample, false))
         {
             xpToGain.AddFactor(DefaultPerks.OneHanded.LeadByExample.PrimaryBonus * 0.01f, DefaultPerks.OneHanded.LeadByExample.Name);
         }
         if (party.MobileParty.HasPerk(DefaultPerks.Leadership.Companions, false))
         {
             xpToGain.AddFactor(DefaultPerks.Leadership.Companions.PrimaryBonus * 0.01f, DefaultPerks.Leadership.Companions.Name);
         }
         if (troop.IsArcher && party.MobileParty.HasPerk(DefaultPerks.Crossbow.MountedCrossbowman, true))
         {
             xpToGain.AddFactor(DefaultPerks.Crossbow.MountedCrossbowman.SecondaryBonus * 0.01f, DefaultPerks.Crossbow.MountedCrossbowman.Name);
         }
     }
     if (party.IsMobile && party.MobileParty.IsGarrison)
     {
         Settlement currentSettlement = party.MobileParty.CurrentSettlement;
         if (((currentSettlement != null) ? currentSettlement.Town.Governor : null) != null)
         {
             PerkHelper.AddPerkBonusForTown(DefaultPerks.TwoHanded.Yadomejutsu, party.MobileParty.CurrentSettlement.Town, ref xpToGain);
             if (troop.IsMounted)
             {
                 PerkHelper.AddPerkBonusForTown(DefaultPerks.Polearm.Guards, party.MobileParty.CurrentSettlement.Town, ref xpToGain);
             }
         }
     }
 }
        public override int CalculatePartyWage(MobileParty mobileParty, bool applyWithdrawals)
        {
            if (!mobileParty.IsActive || mobileParty.IsMilitia)
            {
                return(0);
            }
            int wages = mobileParty.GetTotalWage(1f, (StatExplainer)null);

            if (mobileParty.IsMainParty && (mobileParty.CurrentSettlement != null | mobileParty.LastVisitedSettlement.GetTrackDistanceToMainAgent() <= 2.0f))
            {
                // player in settlement should have 2x wages so bring it half down
                wages /= 2;
            }
            else if (mobileParty.Party.Owner.Clan == Clan.PlayerClan && mobileParty.IsGarrison)
            {
                // player clan garrison has 2x wages so bring it half down
                wages /= 2;
            }
            else if (mobileParty.Party.Owner.Clan != Clan.PlayerClan)
            {
                // AI shouldn't have 4x wages so bring it back down
                wages /= 4;
            }
            if (mobileParty.IsGarrison)
            {
                wages = (int)((double)wages * 0.75);
            }

            ExplainedNumber bonuses = new ExplainedNumber((float)wages, (StringBuilder)null);

            if (mobileParty.CurrentSettlement != null && mobileParty.CurrentSettlement.IsTown)
            {
                PerkHelper.AddPerkBonusForTown(DefaultPerks.TwoHanded.ReducedWage, mobileParty.CurrentSettlement.Town, ref bonuses);
            }
            if (mobileParty.IsCaravan && mobileParty.LeaderHero != null && (mobileParty.Party.Owner.Clan.Leader != null && mobileParty.Party.Owner.Clan.Leader.GetPerkValue(DefaultPerks.Trade.CaravanMaster)))
            {
                PerkHelper.AddPerkBonusForCharacter(DefaultPerks.Trade.CaravanMaster, mobileParty.Party.Owner.Clan.Leader.CharacterObject, ref bonuses);
            }
            return((int)bonuses.ResultNumber);
        }
        public override void CalculateMilitiaSpawnRate(Settlement settlement, out float meleeTroopRate, out float rangedTroopRate, out float meleeEliteTroopRate, out float rangedEliteTroopRate)
        {
            meleeTroopRate       = 0.5f;
            rangedTroopRate      = 1f - meleeTroopRate;
            rangedEliteTroopRate = 0.1f;
            meleeEliteTroopRate  = 0.1f;
            if (settlement.IsTown && settlement.Town.Governor != null && settlement.Town.Governor.GetPerkValue(DefaultPerks.Leadership.CitizenMilitia) && settlement.Town.Governor.CurrentSettlement != null && settlement.Town.Governor.CurrentSettlement.IsTown && settlement.Town.Governor.CurrentSettlement.Town == settlement.Town)
            {
                rangedEliteTroopRate += DefaultPerks.Leadership.CitizenMilitia.PrimaryBonus / 100f;
                meleeEliteTroopRate  += DefaultPerks.Leadership.CitizenMilitia.PrimaryBonus / 100f;
            }
            if (settlement.IsTown && settlement.Town.Governor != null)
            {
                ExplainedNumber explainedNumber = new ExplainedNumber(0f, null);
                PerkHelper.AddPerkBonusForTown(DefaultPerks.OneHanded.StrongArms, settlement.Town, ref explainedNumber);
                rangedEliteTroopRate += explainedNumber.ResultNumber;
                meleeEliteTroopRate  += explainedNumber.ResultNumber;
            }

            rangedEliteTroopRate *= SettlementSetting.Instance.EliteTroopRate;
            meleeEliteTroopRate  *= SettlementSetting.Instance.EliteTroopRate;
        }
Ejemplo n.º 7
0
        public static bool Prefix(Hero hero)
        {
            bool   result        = true;
            bool   proceed       = false;
            bool   playerProceed = false;
            string text          = " has escaped";

            try
            {
                bool isPlayer = hero.IsPrisoner && hero.PartyBelongedToAsPrisoner != null &&
                                (hero.PartyBelongedToAsPrisoner.IsMobile &&
                                 hero.PartyBelongedToAsPrisoner == PartyBase.MainParty ||
                                 hero.PartyBelongedToAsPrisoner.IsSettlement &&
                                 hero.PartyBelongedToAsPrisoner.Settlement.OwnerClan == Clan.PlayerClan);

                bool  enable           = isPlayer || Support.settings.ai_applied;
                float generalChance    = enable ? (float)Support.settings.general_chance : 1;
                float travelChance     = enable ? (float)Support.settings.traveling_chance : 1;
                float settlementChance = enable ? (float)Support.settings.settlement_chance : 1;

                // ***************************************
                // Original method from decompiled source (except for commented lines)
                // ***************************************
                if (!hero.IsPrisoner || hero.PartyBelongedToAsPrisoner == null || hero == Hero.MainHero)
                {
                    return(false);
                }
                float baseNumber = 0.05f /**/ * generalChance /**/;  // general chance modificaiton
                if (hero.PartyBelongedToAsPrisoner.IsMobile && hero.PartyBelongedToAsPrisoner.MobileParty.CurrentSettlement == null)
                {
                    // travel chance modification
                    baseNumber *= (5f - (float)Math.Pow(Math.Min(81, hero.PartyBelongedToAsPrisoner.NumberOfHealthyMembers), 0.25)) /**/ * travelChance /**/;
                    /**/ text   = " slipped away from " + (hero.IsFemale ? "her" : "his") + " guards and escaped"; /**/
                }
                // settlement chance modification begin
                else if (hero.PartyBelongedToAsPrisoner.IsSettlement)
                {
                    baseNumber *= settlementChance;
                    text        = " is missing from " + (hero.IsFemale ? "her" : "his") + " cell";
                }
                // end
                if (hero.PartyBelongedToAsPrisoner == PartyBase.MainParty || hero.PartyBelongedToAsPrisoner.IsSettlement && hero.PartyBelongedToAsPrisoner.Settlement.OwnerClan == Clan.PlayerClan || hero.PartyBelongedToAsPrisoner.IsMobile && hero.PartyBelongedToAsPrisoner.MobileParty.CurrentSettlement != null && hero.PartyBelongedToAsPrisoner.MobileParty.CurrentSettlement.OwnerClan == Clan.PlayerClan)
                {
                    baseNumber *= 0.5f;
                }
                ExplainedNumber explainedNumber = new ExplainedNumber(baseNumber);
                if (hero.PartyBelongedToAsPrisoner.IsSettlement)
                {
                    if (hero.PartyBelongedToAsPrisoner.Settlement.IsTown)
                    {
                        PerkHelper.AddPerkBonusForTown(DefaultPerks.Riding.MountedPatrols, hero.PartyBelongedToAsPrisoner.Settlement.Town, ref explainedNumber);
                        PerkHelper.AddPerkBonusForTown(DefaultPerks.Roguery.SweetTalker, hero.PartyBelongedToAsPrisoner.Settlement.Town, ref explainedNumber);
                    }
                    if (hero.PartyBelongedToAsPrisoner.Settlement.IsTown || hero.PartyBelongedToAsPrisoner.Settlement.IsCastle)
                    {
                        PerkHelper.AddPerkBonusForTown(DefaultPerks.Engineering.PrisonArchitect, hero.PartyBelongedToAsPrisoner.Settlement.Town, ref explainedNumber);
                    }
                }
                if (hero.PartyBelongedToAsPrisoner.IsMobile)
                {
                    if (hero.Clan != null && hero.Clan.Leader != null && hero.Clan.Leader.GetPerkValue(DefaultPerks.Roguery.FleetFooted))
                    {
                        explainedNumber.AddFactor(DefaultPerks.Roguery.FleetFooted.SecondaryBonus);
                    }
                    if (hero.PartyBelongedToAsPrisoner.MobileParty.HasPerk(DefaultPerks.Riding.MountedPatrols))
                    {
                        PerkHelper.AddPerkBonusForParty(DefaultPerks.Riding.MountedPatrols, hero.PartyBelongedToAsPrisoner.MobileParty, true, ref explainedNumber);
                    }
                    if (hero.PartyBelongedToAsPrisoner.MobileParty.HasPerk(DefaultPerks.Roguery.RansomBroker))
                    {
                        PerkHelper.AddPerkBonusForParty(DefaultPerks.Roguery.RansomBroker, hero.PartyBelongedToAsPrisoner.MobileParty, false, ref explainedNumber);
                    }
                }
                if (hero.PartyBelongedToAsPrisoner.IsMobile && hero.PartyBelongedToAsPrisoner.MobileParty.HasPerk(DefaultPerks.Scouting.KeenSight, true))
                {
                    PerkHelper.AddPerkBonusForParty(DefaultPerks.Scouting.KeenSight, hero.PartyBelongedToAsPrisoner.MobileParty, false, ref explainedNumber);
                }
                if (MBRandom.RandomFloat >= explainedNumber.ResultNumber)
                {
                    // Relation modification begin
                    if (isPlayer && Support.settings.daily_penalty != 0)
                    {
                        Support.ChangeRelation(Hero.MainHero, hero, -Support.settings.daily_penalty);
                        Support.ChangeFamilyRelation(Hero.MainHero, hero, 0, -Support.settings.daily_penalty);
                    }
                    // end
                    return(false);
                }
                EndCaptivityAction.ApplyByEscape(hero);
                // Notification modification begin
                if (isPlayer)
                {
                    Support.LogMessage(hero.Name.ToString() + " " + text);
                }
                // end
                return(false);
            }
            catch (Exception exe) { }

            return(result);
        }
        public override void CalculateClanIncome(Clan clan, ref ExplainedNumber goldChange, bool applyWithdrawals = false)
        {
            // Gives (Clan not mercenary, is in faction, faction they're in is a kingdom, clan is not a ruling clan, and they have no fortifications) 100 gold per commander heroes
            if (!clan.IsUnderMercenaryService && clan.MapFaction != null && (clan.MapFaction.IsKingdomFaction && clan.Leader != clan.MapFaction.Leader) && clan.Fortifications.Count == 0)
            {
                TextObject desription = new TextObject("{=*} King's support", (Dictionary <string, TextObject>)null);
                int        welfare    = ((clan == Clan.PlayerClan ? 1 : 0) + clan.CommanderHeroes.Count) * 100;
                goldChange.Add((float)welfare, desription);
            }

            // INCOME FROM TOWN & CASTLE TAXES
            float totalTownTaxes = 0.0f;

            foreach (Town fortification in (IEnumerable <Town>)clan.Fortifications)
            {
                TextObject desription = new TextObject("{=YnvU7tWg} {PARTY_NAME} taxes", (Dictionary <string, TextObject>)null);
                desription.SetTextVariable("PARTY_NAME", fortification.Name);
                float townTax = (float)Campaign.Current.Models.SettlementTaxModel.CalculateTownTax(fortification, (StatExplainer)null) * 2f;
                if (!fortification.IsCastle)
                {
                    townTax *= 1.25f; // end result is 2.5x for towns but only 2x for castles
                }
                goldChange.Add(MathF.Round((townTax)), desription);
                totalTownTaxes += townTax;
            }
            if (clan.Kingdom != null && clan.Kingdom.RulingClan == clan && clan.Kingdom.ActivePolicies.Contains(DefaultPolicies.WarTax))
            {
                goldChange.Add(totalTownTaxes * 0.05f, DefaultPolicies.WarTax.Name);
            }

            // INCOME FROM MERCENARY SERVICE
            if (clan.IsUnderMercenaryService && clan.Leader != null && (clan.Leader.MapFaction.IsKingdomFaction && clan.Leader.MapFaction.Leader != null))
            {
                int num2   = (int)((double)clan.Influence * 0.100000001490116);
                int income = num2 * clan.MercenaryAwardMultiplier;
                goldChange.Add((float)income, HardmodeClanFinanceModel._mercnaryStr);
                if (applyWithdrawals)
                {
                    clan.Influence -= (float)num2;
                }
            }

            // INCOME FROM VILLAGES
            foreach (Village village in clan.Villages)
            {
                int accumulatedTradeTaxPayout = village.VillageState == Village.VillageStates.Looted || village.VillageState == Village.VillageStates.BeingRaided ? 0 : (int)((double)village.TradeTaxAccumulated / (double)this.RevenueSmoothenFraction());
                if (clan.Kingdom != null && clan.Kingdom.ActivePolicies.Contains(DefaultPolicies.LandTax))
                {
                    goldChange.Add((float)-accumulatedTradeTaxPayout * 0.05f, DefaultPolicies.LandTax.Name);
                }
                TextObject desription = new TextObject("{=YnvU7tWg} {PARTY_NAME} taxes", (Dictionary <string, TextObject>)null);
                desription.SetTextVariable("PARTY_NAME", village.Name);

                if (clan == Clan.PlayerClan)
                {
                    goldChange.Add(MathF.Round((float)accumulatedTradeTaxPayout * 0.7f), desription); // <-- 70% village income
                }
                else
                {
                    goldChange.Add((float)accumulatedTradeTaxPayout, desription);
                }

                if (applyWithdrawals)
                {
                    village.TradeTaxAccumulated -= accumulatedTradeTaxPayout;
                }
            }

            // INCOME FROM TOWN TARIFFS
            foreach (Town fortification in (IEnumerable <Town>)clan.Fortifications)
            {
                TextObject desription = new TextObject("{=oICap7jL} {SETTLEMENT_NAME} tariff", (Dictionary <string, TextObject>)null);
                desription.SetTextVariable("SETTLEMENT_NAME", fortification.Name);
                int townTradeTax = (int)((double)fortification.TradeTaxAccumulated / (double)this.RevenueSmoothenFraction());
                if (fortification.Governor != null && fortification.Governor.GetPerkValue(DefaultPerks.Trade.ContentTrades))
                {
                    ExplainedNumber bonuses = new ExplainedNumber((float)townTradeTax, (StringBuilder)null);
                    PerkHelper.AddPerkBonusForTown(DefaultPerks.Trade.ContentTrades, fortification, ref bonuses);
                    townTradeTax = MathF.Round(bonuses.ResultNumber);
                }
                goldChange.Add((float)townTradeTax, desription);
                if (applyWithdrawals)
                {
                    fortification.TradeTaxAccumulated -= townTradeTax;
                }
            }

            // INCOME FROM WORKSHOPS
            this.CalculateHeroIncomeFromWorkshops(clan.Leader, ref goldChange, applyWithdrawals);

            // INCOME FROM CARAVANS
            foreach (MobileParty party in clan.Parties)
            {
                if (party.IsActive && (party.IsLordParty || party.IsGarrison || party.IsCaravan))
                {
                    int amount = party.LeaderHero == null || party.LeaderHero == clan.Leader || (party.IsCaravan || party.LeaderHero.Gold < 10000) ? 0 : (int)((double)(party.LeaderHero.Gold - 10000) / 10.0);
                    if (party.IsCaravan)
                    {
                        amount = (int)((double)(party.PartyTradeGold - 10000) / 10.0);
                    }
                    if (amount > 0)
                    {
                        TextObject desription = new TextObject("{=uyvxafSw} {PARTY_NAME} exceed gold", (Dictionary <string, TextObject>)null);
                        desription.SetTextVariable("PARTY_NAME", party.Name);
                        goldChange.Add((float)amount, desription);
                        if (applyWithdrawals)
                        {
                            if (party.IsCaravan)
                            {
                                if (((party.LeaderHero == null || !party.LeaderHero.Clan.Leader.GetPerkValue(DefaultPerks.Trade.GreatInvestor) ? (party.Party.Owner?.Clan == null || party.Party.Owner.Clan == CampaignData.NeutralFaction || party.Party.Owner.Clan.Leader == null ? 0 : (party.Party.Owner.Clan.Leader.GetPerkValue(DefaultPerks.Trade.GreatInvestor) ? 1 : 0)) : 1) & (applyWithdrawals ? 1 : 0)) != 0)
                                {
                                    party.LeaderHero.Clan.AddRenown(DefaultPerks.Trade.GreatInvestor.PrimaryBonus, true);
                                }
                                party.PartyTradeGold -= amount;
                            }
                            else
                            {
                                GiveGoldAction.ApplyBetweenCharacters(party.LeaderHero, (Hero)null, amount, true);
                            }
                        }
                    }
                }
            }
        }