Example #1
0
        private static void Postfix(Army.ArmyTypes missionType, PartyThinkParams p)
        {
            if (missionType != Army.ArmyTypes.Besieger)
            {
                return;
            }
            MobileParty mobilePartyOf = p.MobilePartyOf;

            if (mobilePartyOf?.Army?.LeaderParty != mobilePartyOf || mobilePartyOf?.LeaderHero?.Clan?.Kingdom == null)
            {
                return;
            }
            Dictionary <AIBehaviorTuple, float> dictionary = new Dictionary <AIBehaviorTuple, float>(10);
            float      num1           = 99999f;
            Settlement fromSettlement = mobilePartyOf.LeaderHero.HomeSettlement ?? mobilePartyOf.LastVisitedSettlement;

            if (fromSettlement == null)
            {
                return;
            }
            Settlement settlement = (Settlement)null;

            foreach (KeyValuePair <AIBehaviorTuple, float> aiBehaviorScore in p.AIBehaviorScores)
            {
                if ((double)aiBehaviorScore.Value > 0.0 && aiBehaviorScore.Key.AiBehavior == AiBehavior.BesiegeSettlement && (aiBehaviorScore.Key.Party != null && aiBehaviorScore.Key.Party is Settlement))
                {
                    dictionary.Add(aiBehaviorScore.Key, aiBehaviorScore.Value);
                    float distance = Campaign.Current.Models.MapDistanceModel.GetDistance(fromSettlement, aiBehaviorScore.Key.Party as Settlement);
                    if ((double)distance < (double)num1)
                    {
                        num1       = distance;
                        settlement = aiBehaviorScore.Key.Party as Settlement;
                    }
                }
            }
            foreach (KeyValuePair <AIBehaviorTuple, float> keyValuePair in dictionary)
            {
                Settlement party    = keyValuePair.Key.Party as Settlement;
                float      distance = Campaign.Current.Models.MapDistanceModel.GetDistance(fromSettlement, party);
                float      num2     = keyValuePair.Value * 1.2f * Math.Max(0.0f, (float)(1.0 - ((double)distance - (double)num1) / (party.Culture != mobilePartyOf.LeaderHero.Culture || settlement.Culture == mobilePartyOf.LeaderHero.Culture ? (double)Campaign.AverageDistanceBetweenTwoTowns / 3.0 : (double)Campaign.AverageDistanceBetweenTwoTowns)));
                p.AIBehaviorScores[keyValuePair.Key] = num2;
            }
        }
        private static void Postfix(
            DefaultTargetScoreCalculatingModel __instance,
            Settlement targetSettlement,
            Army.ArmyTypes missionType,
            MobileParty mobileParty,
            float ourStrength,
            ref float __result)
        {
            if (mobileParty.LeaderHero == null)
            {
                return;
            }
            switch (missionType)
            {
            case Army.ArmyTypes.Besieger:
                if (targetSettlement.OwnerClan != null)
                {
                    float num = Math.Max(Math.Min((float)targetSettlement.OwnerClan.Leader.GetRelation(mobileParty.LeaderHero) / 20f, 1f), -1f);
                    __result *= (float)(1.0 - (double)num * ((double)num > 0.0 ? 1.0 - (double)Config.Value.RelationSiegingPositiveMultMin : (double)Config.Value.RelationSiegingNegativeMultMax - 1.0));
                }
                if (targetSettlement.Culture != mobileParty.MapFaction.Culture)
                {
                    break;
                }
                __result *= Config.Value.SameCultureSiegingMult;
                break;

            case Army.ArmyTypes.Raider:
                if (targetSettlement.OwnerClan != null)
                {
                    float num = Math.Max(Math.Min((float)targetSettlement.OwnerClan.Leader.GetRelation(mobileParty.LeaderHero) / 20f, 1f), -1f);
                    __result *= (float)(1.0 - (double)num * ((double)num > 0.0 ? 1.0 - (double)Config.Value.RelationRaidingPositiveMultMin : (double)Config.Value.RelationRaidingNegativeMultMax - 1.0));
                }
                if (targetSettlement.Culture != mobileParty.LeaderHero.Culture && targetSettlement.Culture != mobileParty.MapFaction.Culture)
                {
                    break;
                }
                __result *= Config.Value.SameCultureRaidingMult;
                break;
            }
        }