public static TextObject GetCooldownText(Type decisionType, float elapsedDaysUntilNow)
        {
            int        RemainingDays = (int)Math.Ceiling(AOCooldownManager.GetRequiredDecisionCooldown(decisionType) - elapsedDaysUntilNow);
            TextObject cooldownText  = new TextObject(DECISION_IS_ON_COOLDOWN);

            SetNumericVariable(cooldownText, "NUMBER_OF_DAYS", RemainingDays);
            return(cooldownText);
        }
 public override void SyncData(IDataStore dataStore)
 {
     dataStore.SyncData("_cooldownManager", ref _cooldownManager);
     if (dataStore.IsLoading)
     {
         if (_cooldownManager == null)
         {
             _cooldownManager = new AOCooldownManager();
         }
         _cooldownManager.Sync();
     }
 }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
0
        public static TextObject GetCooldownText(Type decisionType, float elapsedDaysUntilNow)
        {
            int        RemainingDays = (int)Math.Ceiling(AOCooldownManager.GetRequiredDecisionCooldown(decisionType) - elapsedDaysUntilNow);
            PluralForm pluralForm    = GetPluralForm(RemainingDays);
            var        attributes    = new Dictionary <string, TextObject>()
            {
                [PLURAL_FORM_TAG] = new TextObject(pluralForm == PluralForm.Plural ? 1 : 0), [OTHER_PLURAL_FORM_TAG] = new TextObject(pluralForm != PluralForm.Singular ? 1 : 0)
            };

            return(new TextObject(DECISION_IS_ON_COOLDOWN,
                                  new Dictionary <string, TextObject>()
            {
                ["NUMBER_OF_DAYS"] = new TextObject(RemainingDays, attributes)
            }));
        }
 public static void OnPolicySelectPatch(KingdomPolicyItemVM policy, KingdomPoliciesVM __instance)
 {
     try
     {
         if (SettingsHelper.SubSystemEnabled(SubSystemType.ElectionCooldownsForPlayer))
         {
             bool HasCooldown = AOCooldownManager.HasDecisionCooldown(new KingdomPolicyDecision(Clan.PlayerClan, policy.Policy, Clan.PlayerClan.Kingdom.ActivePolicies.Contains(policy.Policy)), out float elapsedDaysUntilNow);
             __instance.CanProposeOrDisavowPolicy     = __instance.CanProposeOrDisavowPolicy && !HasCooldown;
             __instance.ProposeActionExplanationText += HasCooldown ? "\n" + StringHelper.GetCooldownText(typeof(KingdomPolicyDecision), elapsedDaysUntilNow).ToString() : string.Empty;
         }
     }
     catch (Exception ex)
     {
         MethodInfo?methodInfo = MethodBase.GetCurrentMethod() as MethodInfo;
         DebugHelper.HandleException(ex, methodInfo, "Harmony patch for KingdomPoliciesVM. OnPolicySelect");
     }
 }
 public static void OnSetPeaceItemPatch(KingdomTruceItemVM item, KingdomDiplomacyVM __instance)
 {
     try
     {
         if (SettingsHelper.SubSystemEnabled(SubSystemType.ElectionCooldownsForPlayer))
         {
             bool HasCooldown = AOCooldownManager.HasDecisionCooldown(new DeclareWarDecision(Clan.PlayerClan, item.Faction2), out float elapsedDaysUntilNow);
             __instance.IsActionEnabled = __instance.IsActionEnabled && !HasCooldown;
             __instance.ProposeActionExplanationText += HasCooldown ? "\n" + StringHelper.GetCooldownText(typeof(DeclareWarDecision), elapsedDaysUntilNow).ToString() : string.Empty;
         }
     }
     catch (Exception ex)
     {
         MethodInfo?methodInfo = MethodBase.GetCurrentMethod() as MethodInfo;
         DebugHelper.HandleException(ex, methodInfo, "Harmony patch for KingdomDiplomacyVM. OnSetPeaceItem");
     }
 }
 public static void SetCurrentSelectedClanPatch(KingdomClanItemVM clan, KingdomClanVM __instance)
 {
     try
     {
         if (SettingsHelper.SubSystemEnabled(SubSystemType.ElectionCooldownsForPlayer))
         {
             bool HasCooldown = AOCooldownManager.HasDecisionCooldown(new ExpelClanFromKingdomDecision(Clan.PlayerClan, clan.Clan), out float elapsedDaysUntilNow);
             __instance.CanExpelCurrentClan         = __instance.CanExpelCurrentClan && !HasCooldown;
             __instance.ExpelActionExplanationText += HasCooldown ? "\n" + StringHelper.GetCooldownText(typeof(ExpelClanFromKingdomDecision), elapsedDaysUntilNow).ToString() : string.Empty;
         }
     }
     catch (Exception ex)
     {
         MethodInfo?methodInfo = MethodBase.GetCurrentMethod() as MethodInfo;
         DebugHelper.HandleException(ex, methodInfo, "Harmony patch for KingdomClanVM. SetCurrentSelectedClan");
     }
 }
Exemplo n.º 8
0
 public static void SetCurrentSelectedSettlementPatch(KingdomSettlementItemVM settlementItem, KingdomSettlementVM __instance)
 {
     try
     {
         if (SettingsHelper.SubSystemEnabled(SubSystemType.ElectionCooldownsForPlayer))
         {
             bool HasCooldown = AOCooldownManager.HasDecisionCooldown(new SettlementClaimantPreliminaryDecision(Clan.PlayerClan, settlementItem.Settlement), out float elapsedDaysUntilNow);
             __instance.CanAnnexCurrentSettlement   = __instance.CanAnnexCurrentSettlement && !HasCooldown;
             __instance.AnnexActionExplanationText += HasCooldown ? "\n" + StringHelper.GetCooldownText(typeof(SettlementClaimantPreliminaryDecision), elapsedDaysUntilNow).ToString() : string.Empty;
         }
     }
     catch (Exception ex)
     {
         MethodInfo methodInfo = MethodBase.GetCurrentMethod() as MethodInfo;
         DebugHelper.HandleException(ex, methodInfo, "Harmony patch for KingdomSettlementVM. SetCurrentSelectedSettlement");
     }
 }
        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);
            }
        }
        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)
                {
                    PolicyObject randomElement = DefaultPolicies.All.Where(x => !(SubSystemEnabled && AOCooldownManager.HasDecisionCooldown(new KingdomPolicyDecision(clan, x, kingdom.ActivePolicies.Contains(x))))
                                                                           ).ToArray().GetRandomElement();
                    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 AOCooldownBehavior()
 {
     this._cooldownManager = new AOCooldownManager();
 }