Ejemplo n.º 1
0
        public static bool Prefix(Clan clan, ref KingdomDecision __result, KingdomDecisionProposalBehavior __instance) //Bool prefixes compete with each other and skip others, as well as original, if return false
        {
            try
            {
                bool SubSystemEnabled   = SettingsHelper.SubSystemEnabled(SubSystemType.ElectionCooldowns, clan) || SettingsHelper.SubSystemEnabled(SubSystemType.DecisionSupportRebalance, clan);
                bool SystemDebugEnabled = SettingsHelper.SystemDebugEnabled(AOSystems.PoliticsRebalance, DebugType.General, clan);

                if (!SubSystemEnabled && !SystemDebugEnabled)
                {
                    return(true);
                }

                Kingdom kingdom = clan.Kingdom;
                __result = null;
                if (kingdom.UnresolvedDecisions.FirstOrDefault(x => x is SettlementClaimantPreliminaryDecision) == null && clan.Influence >= 300.0)
                {
                    bool possessionsFactorApplied = SettingsHelper.SubSystemEnabled(SubSystemType.AnnexationSupportRebalance, clan) &&
                                                    Settings.Instance.AnnexSupportCalculationMethod.SelectedValue.EnumValue.HasFlag(FiefOwnershipConsideration.PossessionsFactor) &&
                                                    Settings.Instance.FiefsDeemedFairBaseline.SelectedValue.EnumValue != NumberOfFiefsCalculationMethod.WithoutRestrictions;
                    Clan randomClan = kingdom.Clans.Where(x => x != clan &&
                                                          x.Fortifications.Count > 0 &&
                                                          (x.GetRelationWithClan(clan) < -25 || (possessionsFactorApplied && Campaign.Current.GetAOGameModels().DecisionSupportScoringModel.GetNumberOfFiefsDeemedFair(x) < x.Fortifications.Count)) &&
                                                          x.Fortifications.FirstOrDefault(f => !(SubSystemEnabled && AOCooldownManager.HasDecisionCooldown(new SettlementClaimantPreliminaryDecision(clan, f.Settlement)))) != null
                                                          ).ToArray().GetRandomElement();

                    Town randomFortification = SettingsHelper.SubSystemEnabled(SubSystemType.ElectionCooldowns, clan)
              ? clan.Fortifications.Where(f => !(AOCooldownManager.HasDecisionCooldown(new SettlementClaimantPreliminaryDecision(clan, f.Settlement)))).ToArray().GetRandomElement()
              : clan.Fortifications.ToArray().GetRandomElement();

                    //ConsiderAnnexDelegate deConsiderAnnex = AccessHelper.GetDelegate<ConsiderAnnexDelegate, KingdomDecisionProposalBehavior>(__instance, "ConsiderAnnex");
                    if (randomClan != null && deConsiderAnnex(__instance, clan, kingdom, randomClan, randomFortification))
                    {
                        __result = new SettlementClaimantPreliminaryDecision(clan, randomFortification.Settlement);
                    }

                    if (SystemDebugEnabled)
                    {
                        PoliticsDebugHelper.PrepareConsiderationDebugMessage(clan, randomFortification, __result, out TextObject debugLogMessage);
                        MessageHelper.SimpleMessage(debugLogMessage);
                    }
                }

                return(false);
            }
            catch (Exception ex)
            {
                MethodInfo methodInfo = MethodBase.GetCurrentMethod() as MethodInfo;
                DebugHelper.HandleException(ex, methodInfo, "Harmony patch for KingdomDecisionProposalBehavior. GetRandomAnnexationDecision");
                return(true);
            }
        }
Ejemplo n.º 2
0
        public static bool Prefix(Clan clan, ref KingdomDecision?__result, KingdomDecisionProposalBehavior __instance) //Bool prefixes compete with each other and skip others, as well as original, if return false
        {
            try
            {
                bool SubSystemEnabled   = SettingsHelper.SubSystemEnabled(SubSystemType.ElectionCooldowns, clan);
                bool SystemDebugEnabled = SettingsHelper.SystemDebugEnabled(AOSystems.PoliticsRebalance, DebugType.General, clan);

                if (!SubSystemEnabled && !SystemDebugEnabled)
                {
                    return(true);
                }

                Kingdom kingdom = clan.Kingdom;
                __result = null;
                if (kingdom.UnresolvedDecisions.FirstOrDefault(x => x is KingdomPolicyDecision) == null && clan.Influence >= 200.0)
                {
#if STABLE
                    PolicyObject randomElement = DefaultPolicies.All.Where(x => !(SubSystemEnabled && AOCooldownManager.HasDecisionCooldown(new KingdomPolicyDecision(clan, x, kingdom.ActivePolicies.Contains(x))))
                                                                           ).ToArray().GetRandomElement();
#else
                    PolicyObject randomElement = PolicyObject.All.Where(x => !(SubSystemEnabled && AOCooldownManager.HasDecisionCooldown(new KingdomPolicyDecision(clan, x, kingdom.ActivePolicies.Contains(x))))
                                                                        ).ToArray().GetRandomElement();
#endif
                    bool revertPolicy = kingdom.ActivePolicies.Contains(randomElement);

                    //ConsiderPolicyDelegate deConsiderPolicy = AccessHelper.GetDelegate<ConsiderPolicyDelegate, KingdomDecisionProposalBehavior>(__instance, "ConsiderPolicy");
                    if (randomElement != null && deConsiderPolicy !(__instance, clan, kingdom, randomElement, revertPolicy))
                    {
                        __result = new KingdomPolicyDecision(clan, randomElement, revertPolicy);
                    }

                    if (SystemDebugEnabled)
                    {
                        PoliticsDebugHelper.PrepareConsiderationDebugMessage(clan, randomElement, __result, out TextObject debugLogMessage);
                        MessageHelper.SimpleMessage(debugLogMessage);
                    }
                }

                return(false);
            }
            catch (Exception ex)
            {
                MethodInfo?methodInfo = MethodBase.GetCurrentMethod() as MethodInfo;
                DebugHelper.HandleException(ex, methodInfo, "Harmony patch for KingdomDecisionProposalBehavior. GetRandomPolicyDecision");
                return(true);
            }
        }
        public static bool Prefix(Clan clan, ref KingdomDecision __result, KingdomDecisionProposalBehavior __instance) //Bool prefixes compete with each other and skip others, as well as original, if return false
        {
            try
            {
                bool SubSystemEnabled   = SettingsHelper.SubSystemEnabled(SubSystemType.ElectionCooldowns, clan);
                bool SystemDebugEnabled = SettingsHelper.SystemDebugEnabled(AOSystems.PoliticsRebalance, DebugType.General, clan);

                if (!SubSystemEnabled && !SystemDebugEnabled)
                {
                    return(true);
                }

                Kingdom kingdom = clan.Kingdom;
                __result = null;
                if (kingdom.UnresolvedDecisions.FirstOrDefault(x => x is DeclareWarDecision) == null)
                {
                    Kingdom randomElement = Kingdom.All.Where(x => x != kingdom &&
                                                              !x.IsAtWarWith(kingdom) &&
                                                              x.GetStanceWith(kingdom).PeaceDeclarationDate.ElapsedDaysUntilNow > 20.0 &&
                                                              !(SubSystemEnabled && AOCooldownManager.HasDecisionCooldown(new DeclareWarDecision(clan, x)))
                                                              ).ToArray().GetRandomElement();

                    //ConsiderWarDelegate deConsiderWar = AccessHelper.GetDelegate<ConsiderWarDelegate, KingdomDecisionProposalBehavior>(__instance, "ConsiderWar");
                    if (randomElement != null && deConsiderWar(__instance, clan, kingdom, randomElement))
                    {
                        __result = new DeclareWarDecision(clan, randomElement);
                    }

                    if (SystemDebugEnabled)
                    {
                        PoliticsDebugHelper.PrepareConsiderationDebugMessage(ConsiderationType.DeclaringWar, clan, randomElement, __result, out TextObject debugLogMessage);
                        MessageHelper.SimpleMessage(debugLogMessage);
                    }
                }
                return(false);
            }
            catch (Exception ex)
            {
                MethodInfo methodInfo = MethodBase.GetCurrentMethod() as MethodInfo;
                DebugHelper.HandleException(ex, methodInfo, "Harmony patch for KingdomDecisionProposalBehavior. GetRandomWarDecision");
                return(true);
            }
        }
        public static bool Prefix(Clan clan, ref KingdomDecision?__result, KingdomDecisionProposalBehavior __instance) //Bool prefixes compete with each other and skip others, as well as original, if return false
        {
            try
            {
                bool SubSystemEnabled   = SettingsHelper.SubSystemEnabled(SubSystemType.ElectionCooldowns, clan);
                bool SystemDebugEnabled = SettingsHelper.SystemDebugEnabled(AOSystems.PoliticsRebalance, DebugType.General, clan);

                if (!SubSystemEnabled && !SystemDebugEnabled)
                {
                    return(true);
                }

                Kingdom kingdom = clan.Kingdom;
                __result = null;
                if (kingdom.UnresolvedDecisions.FirstOrDefault(x => x is MakePeaceKingdomDecision) == null)
                {
                    Kingdom randomElement = Kingdom.All.Where(x => x.IsAtWarWith(kingdom) &&
                                                              x != Clan.PlayerClan.Kingdom &&
                                                              !(SubSystemEnabled && AOCooldownManager.HasDecisionCooldown(new MakePeaceKingdomDecision(clan, x, applyResults: false)))
                                                              ).ToArray().GetRandomElement();

                    if (randomElement != null && deConsiderPeace !(__instance, clan, randomElement.RulingClan, kingdom, randomElement, out MakePeaceKingdomDecision decision))
                    {
                        __result = decision;
                    }

                    if (SystemDebugEnabled)
                    {
                        PoliticsDebugHelper.PrepareConsiderationDebugMessage(ConsiderationType.MakingPeace, clan, randomElement, __result, out TextObject debugLogMessage);
                        MessageHelper.SimpleMessage(debugLogMessage);
                    }
                }
                return(false);
            }
            catch (Exception ex)
            {
                MethodInfo?methodInfo = MethodBase.GetCurrentMethod() as MethodInfo;
                DebugHelper.HandleException(ex, methodInfo, "Harmony patch for KingdomDecisionProposalBehavior. GetRandomPeaceDecision");
                return(true);
            }
        }