示例#1
0
        public static void DetermineSupport(MakePeaceKingdomDecision __instance, ref float __result, Clan clan, DecisionOutcome possibleOutcome)
        {
            var test1 = new PeaceBarterable(__instance.Kingdom, __instance.FactionToMakePeaceWith, CampaignTime.Years(1f)).GetValueForFaction(clan);

            //InformationManager.DisplayMessage(new InformationMessage(__instance.FactionToMakePeaceWith.Name.ToString() + ":" + test1.ToString()));

            var shouldPeaceBeDeclared = (bool)possibleOutcome.GetType().GetField("ShouldPeaceBeDeclared", BindingFlags.Instance | BindingFlags.Public).GetValue(possibleOutcome);

            if (DiplomacySetting.Instance.EnableMakePeaceStrategyPlus)
            {
                var atWars = (from x in clan.Kingdom.Stances
                              where x.IsAtWar && x.Faction1.IsKingdomFaction && x.Faction2.IsKingdomFaction
                              select x).ToArray <StanceLink>();

                //var plus = 2 * atWars.Length * (float)(new PeaceBarterable(__instance.Kingdom, __instance.FactionToMakePeaceWith, CampaignTime.Years(1f)).GetValueForFaction(clan)) * Campaign.Current.Models.DiplomacyModel.DenarsToInfluence();

                var plus = 1f;

                var settlementsOccupyed = DiplomacySetting.GetFactionSettlementOccupyedByFaction(clan.MapFaction, __instance.FactionToMakePeaceWith).Sum(a => a.IsCastle ? 2 : 3);
                plus *= settlementsOccupyed == 0 ? 0f : (float)Math.Sqrt(settlementsOccupyed);

                StanceLink stanceWith = clan.MapFaction.GetStanceWith(__instance.FactionToMakePeaceWith);

                var toDays = stanceWith.WarStartDate.ElapsedDaysUntilNow;
                //兼容旧档
                if (toDays > 2000)
                {
                    Traverse.Create(stanceWith).Property("WarStartDate").SetValue(CampaignTime.Now);
                    toDays = stanceWith.WarStartDate.ElapsedDaysUntilNow;
                }
                var daysFactor = Math.Min(9, toDays < 20 ? 1 : toDays / 20f);
                var factor     = Math.Max(0, daysFactor - plus);

                var clanMercy = clan.Leader.GetTraitLevel(DefaultTraits.Mercy) * 20;

                if (shouldPeaceBeDeclared)
                {
                    __result += Math.Abs(__result) / 10 * (factor) + clanMercy;
                }
                else
                {
                    //  __result -= Math.Abs(__result) / 10 * (resultFactor) - clanMercy;
                }
            }

            if (__instance.ProposerClan == Clan.PlayerClan && DiplomacySetting.Instance.RelationEffectOfMakePeaceDecision > 0 && __result >= 0)
            {
                var relation = CharacterRelationManager.GetHeroRelation(Hero.MainHero, clan.Leader);
                relation = relation > 0 ? relation : 0;

                if (shouldPeaceBeDeclared)
                {
                    __result += Math.Abs(__result) * DiplomacySetting.Instance.RelationEffectOfMakePeaceDecision * relation / 100f;
                }
                else
                {
                    __result -= Math.Abs(__result) * DiplomacySetting.Instance.RelationEffectOfMakePeaceDecision / 10 * relation / 100f;
                }
            }
        }
示例#2
0
        /*
         * public override int GetNumberOfFiefsDesired(DecisionMaker decisionMaker)
         * {
         * int baseNumber = CalculateBaseNumberOfFiefs(decisionMaker.Hero.Clan, Settings.Instance!.DesiredFiefsBaseline.SelectedValue.EnumValue);
         * return baseNumber >= 0
         *    ? Math.Max(0, baseNumber + Settings.Instance.DesiredFiefsModifier + CalculateTraitsModifierForDesiredFiefs(decisionMaker, Settings.Instance.DesiredFiefsBaseline.SelectedValue.EnumValue))
         *    : baseNumber;
         * }
         *
         * public override int GetNumberOfFiefsDeemedFair(Clan clan)
         * {
         * int baseNumber = CalculateBaseNumberOfFiefs(clan, Settings.Instance!.FiefsDeemedFairBaseline.SelectedValue.EnumValue);
         * return baseNumber >= 0
         *    ? Math.Max(0, baseNumber + Settings.Instance.FiefsDeemedFairModifier)
         *    : baseNumber;
         * }
         */

        //Protected overrides
        protected override float GetGeneralSupportScore(Clan clan, KingdomDecision decision, DecisionOutcome possibleOutcome)
        {
            return(decision switch
            {
                MakePeaceKingdomDecision makePeaceDecision => GetGeneralSupportScore(clan, makePeaceDecision, possibleOutcome),
                DeclareWarDecision declareWarDecision => GetGeneralSupportScore(clan, declareWarDecision, possibleOutcome),
                SettlementClaimantDecision claimantDecision => GetGeneralSupportScore(clan, claimantDecision, possibleOutcome),
                SettlementClaimantPreliminaryDecision annexationDecision => GetGeneralSupportScore(clan, annexationDecision, possibleOutcome),
                _ => throw new ArgumentOutOfRangeException(nameof(decision), string.Format("Kingdom decision of type {0} is not supported.", decision.GetType().FullName)),
            });
 public static int GetRequiredDecisionCooldown(KingdomDecision decision)
 {
     return(decision switch
     {
         MakePeaceKingdomDecision _ => Settings.Instance !.MakePeaceDecisionCooldown,
         DeclareWarDecision _ => Settings.Instance !.DeclareWarDecisionCooldown,
         ExpelClanFromKingdomDecision _ => Settings.Instance !.ExpelClanDecisionCooldown,
         KingdomPolicyDecision _ => Settings.Instance !.KingdomPolicyDecisionCooldown,
         SettlementClaimantPreliminaryDecision _ => Settings.Instance !.AnnexationDecisionCooldown,
         _ => throw new ArgumentException(string.Format("{0} is not supported KingdomDecision type", decision.GetType().FullName), nameof(decision)),
     });
        //GetGeneralSupportScore internal - per decision type
        private float GetGeneralSupportScore(Clan clan, MakePeaceKingdomDecision makePeaceDecision, DecisionOutcome possibleOutcome)
        {
            int valueForClan = new PeaceBarterable(makePeaceDecision.Kingdom, makePeaceDecision.FactionToMakePeaceWith, CampaignTime.Years(1f)).GetValueForFaction(clan) - Campaign.Current.Models.DiplomacyModel.GetValueOfDailyTribute(makePeaceDecision.DailyTributeToBePaid);

            float situationalFactorValue = 0;

            if (Settings.Instance.PeaceSupportCalculationMethod.SelectedValue.EnumValue.HasFlag(PeaceAndWarConsideration.SituationalFactor))
            {
                situationalFactorValue = ApplySituationalFactor(makePeaceDecision, ref valueForClan);
            }

            return(FieldAccessHelper.ShouldPeaceBeDeclaredByRef(possibleOutcome)
          ? valueForClan * Campaign.Current.Models.DiplomacyModel.DenarsToInfluence() + situationalFactorValue
          : -valueForClan *Campaign.Current.Models.DiplomacyModel.DenarsToInfluence() - situationalFactorValue);
        }
 private bool InternalEquals(KingdomDecision decision1, KingdomDecision decision2)
 {
     if (decision1.GetType() != decision2.GetType())
     {
         return(false);
     }
     return(decision1 switch
     {
         MakePeaceKingdomDecision peaceDecision1 => peaceDecision1.FactionToMakePeaceWith == ((MakePeaceKingdomDecision)decision2).FactionToMakePeaceWith,
         DeclareWarDecision warDecision1 => warDecision1.FactionToDeclareWarOn == ((DeclareWarDecision)decision2).FactionToDeclareWarOn,
         ExpelClanFromKingdomDecision expelDecision1 => expelDecision1.ClanToExpel == ((ExpelClanFromKingdomDecision)decision2).ClanToExpel,
         KingdomPolicyDecision policyDecision1 => policyDecision1.Policy == ((KingdomPolicyDecision)decision2).Policy,
         SettlementClaimantPreliminaryDecision annexationDecision1 => annexationDecision1.Settlement == ((SettlementClaimantPreliminaryDecision)decision2).Settlement,
         _ => throw new ArgumentException(string.Format("{0} is not supported KingdomDecision type", decision1.GetType().FullName), nameof(decision1)),
     });
        //GetSupportScoreOfDecisionMaker internal - per decision type
        private double GetSupportScoreOfDecisionMaker(DecisionMaker decisionMaker, MakePeaceKingdomDecision makePeaceDecision, DecisionOutcome possibleOutcome)
        {
            double traitScore = decisionMaker.Hero.GetTraitLevel(DefaultTraits.Mercy) * 10;

            double relationshipFactorValue = Settings.Instance.PeaceSupportCalculationMethod.SelectedValue.EnumValue.HasFlag(PeaceAndWarConsideration.RelationshipFactor)
          ? CalculateRelationshipFactor(decisionMaker, makePeaceDecision.FactionToMakePeaceWith) * Settings.Instance.MakePeaceRelationshipFactorStrength
          : 0;

            double tributeFactorValue = Settings.Instance.PeaceSupportCalculationMethod.SelectedValue.EnumValue.HasFlag(PeaceAndWarConsideration.TributeFactor)
          ? CalculateTributeFactor(decisionMaker, makePeaceDecision.FactionToMakePeaceWith, makePeaceDecision.DailyTributeToBePaid) * Settings.Instance.MakePeaceTributeFactorStrength
          : 0;

            return(FieldAccessHelper.ShouldPeaceBeDeclaredByRef(possibleOutcome)
          ? traitScore + relationshipFactorValue - tributeFactorValue
          : -traitScore - relationshipFactorValue + tributeFactorValue);
        }
 public static void Postfix(Clan clan, DecisionOutcome possibleOutcome, ref float __result, MakePeaceKingdomDecision __instance)
 {
     try
     {
         float newResult = Campaign.Current.GetAOGameModels().DecisionSupportScoringModel.DetermineSupport(clan, __instance, possibleOutcome);
         if (SettingsHelper.SystemDebugEnabled(AOSystems.PoliticsRebalance, DebugType.Technical, clan))
         {
             MessageHelper.TechnicalMessage(string.Format("Support of {0} for {1} making peace with {2}.\nNative result = {3}. Rebalanced result = {4}",
                                                          clan.Name,
                                                          FieldAccessHelper.ShouldPeaceBeDeclaredByRef(possibleOutcome) ? "accepting" : "denying",
                                                          __instance.FactionToMakePeaceWith, __result, newResult));
         }
         if (SettingsHelper.SubSystemEnabled(SubSystemType.MakePeaceSupportRebalance, clan))
         {
             __result = newResult;
         }
     }
     catch (Exception ex)
     {
         MethodInfo methodInfo = MethodBase.GetCurrentMethod() as MethodInfo;
         DebugHelper.HandleException(ex, methodInfo, "Harmony patch for MakePeaceKingdomDecision. DetermineSupport");
     }
 }
        public static bool ConsiderPeacePatch(Clan clan, Clan otherClan, Kingdom kingdom, IFaction otherFaction, out MakePeaceKingdomDecision decision, bool __result)
        {
            decision = null;
            Kingdom otherKingdom = otherFaction as Kingdom;

            if (otherKingdom != null && !WarAndPeaceConditions.CanProposePeace(kingdom, otherKingdom))
            {
                __result = false;
                return(false);
            }
            else
            {
                return(true);
            }
        }
 //ApplySituationalFactor - per decision type
 private float ApplySituationalFactor(MakePeaceKingdomDecision makePeaceDecision, ref int valueForClan)
 {
     (float value, int multiplier) = CalculateSituationalFactor(makePeaceDecision.Kingdom, makePeaceDecision.FactionToMakePeaceWith);
     valueForClan /= multiplier;
     return(value * Settings.Instance.MakePeaceSituationalFactorStrength);
 }
示例#10
0
        public static bool ConsiderPeacePatch(Clan clan, Clan otherClan, Kingdom kingdom, IFaction otherFaction, out MakePeaceKingdomDecision decision, bool __result)
        {
            decision = null;
            Kingdom otherKingdom = otherFaction as Kingdom;

            if (otherKingdom != null && !MakePeaceConditions.Instance.CanApply(kingdom, otherKingdom, bypassCosts: true))
            {
                __result = false;
                return(false);
            }
            else
            {
                return(true);
            }
        }