private void RegisterKingdomDecisionConcluded(KingdomDecision decision, DecisionOutcome chosenOutcome, bool isPlayerInvolved) { if (AOCooldownManager.SupportedDecisionTypes.Contains(decision.GetType())) { _cooldownManager.UpdateKingdomDecisionHistory(decision, chosenOutcome, CampaignTime.Now); } }
public static void Getter(ref DecisionOutcome __instance, ref float __result) { if (__instance.SupporterList.Any(x => x.IsPlayer) && BannerlordCheatsSettings.Instance.KingdomDecisionWeightMultiplier > 1) { __result *= BannerlordCheatsSettings.Instance.KingdomDecisionWeightMultiplier; } }
static void PostFix(DecisionOutcome candidateOutcome, ref float __result) { var clanAsDecisionOutcome = AccessTools.TypeByName("TaleWorlds.CampaignSystem.Election.SettlementClaimantDecision.ClanAsDecisionOutcome"); var clan = (Clan)clanAsDecisionOutcome.GetProperty("Clan").GetValue(candidateOutcome); if (clan == Clan.PlayerClan) { __result *= 2; } }
public void UpdateKingdomDecisionHistory(KingdomDecision decision, DecisionOutcome chosenOutcome, CampaignTime conclusionTime) { if (SupportedDecisionTypes.Contains(decision.GetType())) { if (_KingdomDecisionHistory.ContainsKey(decision)) { _KingdomDecisionHistory.Remove(decision); } _KingdomDecisionHistory[decision] = new KingdomDecisionConclusion(chosenOutcome, conclusionTime); } else { throw new ArgumentException(string.Format("{0} is not supported KingdomDecision type", decision.GetType().FullName), nameof(decision)); } }
public static void Getter(ref DecisionOutcome __instance, ref float __result) { try { if (__instance.SupporterList.Any(x => x.IsPlayer) && BannerlordCheatsSettings.Instance?.KingdomDecisionWeightMultiplier > 1f) { __result *= BannerlordCheatsSettings.Instance.KingdomDecisionWeightMultiplier; } } catch (Exception e) { SubModule.LogError(e, typeof(KingdomDecisionWeightMultiplier)); } }
public static void GetInfluenceRequiredToOverrideKingdomDecision( ref DecisionOutcome popularOption, ref DecisionOutcome overridingOption, ref KingdomDecision decision, ref int __result) { try { if (BannerlordCheatsSettings.Instance?.DecisionOverrideInfluenceCostPercentage < 100f) { var factor = BannerlordCheatsSettings.Instance.DecisionOverrideInfluenceCostPercentage / 100.0f; var newValue = __result * factor; __result = (int)Math.Round(newValue); } } catch (Exception e) { SubModule.LogError(e, typeof(DecisionOverrideInfluenceCostPercentage)); } }
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"); } }
private double GetSupportScoreOfDecisionMaker(DecisionMaker decisionMaker, DeclareWarDecision declareWarDecision, DecisionOutcome possibleOutcome) { double traitScore = decisionMaker.Hero.GetTraitLevel(DefaultTraits.Valor) * 20 - decisionMaker.Hero.GetTraitLevel(DefaultTraits.Mercy) * 10; double relationshipFactorValue = Settings.Instance.WarSupportCalculationMethod.SelectedValue.EnumValue.HasFlag(PeaceAndWarConsideration.RelationshipFactor) ? CalculateRelationshipFactor(decisionMaker, declareWarDecision.FactionToDeclareWarOn) * Settings.Instance.DeclareWarRelationshipFactorStrength : 0; double tributeFactorValue = Settings.Instance.WarSupportCalculationMethod.SelectedValue.EnumValue.HasFlag(PeaceAndWarConsideration.TributeFactor) ? CalculateTributeFactor(decisionMaker, declareWarDecision.FactionToDeclareWarOn) * Settings.Instance.DeclareWarTributeFactorStrength : 0; return(FieldAccessHelper.ShouldWarBeDeclaredByRef(possibleOutcome) ? traitScore - relationshipFactorValue + tributeFactorValue : -traitScore + relationshipFactorValue - tributeFactorValue); }
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; } } }
/* * 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)), });
private float GetGeneralSupportScore(Clan clan, DeclareWarDecision declareWarDecision, DecisionOutcome possibleOutcome) { int valueForClan = new DeclareWarBarterable(declareWarDecision.Kingdom, declareWarDecision.FactionToDeclareWarOn).GetValueForFaction(clan); float situationalFactorValue = 0; if (Settings.Instance.WarSupportCalculationMethod.SelectedValue.EnumValue.HasFlag(PeaceAndWarConsideration.SituationalFactor)) { situationalFactorValue = ApplySituationalFactor(declareWarDecision, ref valueForClan); } return(FieldAccessHelper.ShouldWarBeDeclaredByRef(possibleOutcome) ? valueForClan * Campaign.Current.Models.DiplomacyModel.DenarsToInfluence() + situationalFactorValue : -valueForClan *Campaign.Current.Models.DiplomacyModel.DenarsToInfluence() - situationalFactorValue); }
//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); }
protected virtual float GetCollectiveSupportScore(Clan clan, KingdomDecision decision, DecisionOutcome possibleOutcome) { Dictionary <DecisionMaker, double> personalScores = GetDecisionMakersSupportScores(clan, decision, possibleOutcome); return(personalScores.Count <= 1 ? (float)personalScores.FirstOrDefault().Value : (float)(personalScores.Sum(x => x.Value) / personalScores.Sum(x => x.Key.DecisionWeight))); }
protected abstract double GetSupportScoreOfDecisionMaker(DecisionMaker decisionMaker, KingdomDecision decision, DecisionOutcome possibleOutcome);
public virtual float DetermineSupport(Hero hero, KingdomDecision decision, DecisionOutcome possibleOutcome) { return(GetGeneralSupportScore(hero.Clan, decision, possibleOutcome) + (float)GetSupportScoreOfDecisionMaker(new DecisionMaker(hero, 1), decision, possibleOutcome)); }
private void EndDecision(DecisionOutcome outcome) { // May need to expand this to make it possible to do other stuff depending on outcome. currentlyProcessedDecision = null; }
private float GetGeneralSupportScore(Clan clan, SettlementClaimantDecision claimantDecision, DecisionOutcome possibleOutcome) { return(0f); }
//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); }
private float GetGeneralSupportScore(Clan clan, SettlementClaimantPreliminaryDecision annexationDecision, DecisionOutcome possibleOutcome) { throw new NotImplementedException(); }
public KingdomDecisionConclusion(DecisionOutcome outcome, CampaignTime conclusionTime) { ChosenOutcome = outcome; ConclusionTime = conclusionTime; }
private double GetSupportScoreOfDecisionMaker(DecisionMaker decisionMaker, SettlementClaimantDecision claimantDecision, DecisionOutcome possibleOutcome) { double nativeScore = CalculateNativeForSettlementClaimantDecision(decisionMaker, claimantDecision, possibleOutcome); /* * double possessionsFactorValue = Settings.Instance.WarSupportCalculationMethod.SelectedValue.EnumValue.HasFlag(FiefOwnershipConsideration.PossessionsFactor) * ? CalculateRelationshipFactor(decisionMaker, declareWarDecision.FactionToDeclareWarOn) * Settings.Instance.FiefOwnershipPossessionsFactorStrength * : 0; */ return(nativeScore); }
public virtual float DetermineSupport(Clan clan, KingdomDecision decision, DecisionOutcome possibleOutcome) { return(GetGeneralSupportScore(clan, decision, possibleOutcome) + GetCollectiveSupportScore(clan, decision, possibleOutcome)); }
private double GetSupportScoreOfDecisionMaker(DecisionMaker decisionMaker, SettlementClaimantPreliminaryDecision annexationDecision, DecisionOutcome possibleOutcome) { throw new NotImplementedException(); }
protected abstract float GetGeneralSupportScore(Clan clan, KingdomDecision decision, DecisionOutcome possibleOutcome);
//CalculateNativeForSettlementClaimantDecision private double CalculateNativeForSettlementClaimantDecision(DecisionMaker decisionMaker, SettlementClaimantDecision claimantDecision, DecisionOutcome possibleOutcome) { float initialMeritScore = possibleOutcome.InitialMerit * MathF.Clamp(1f + decisionMaker.Hero.GetTraitLevel(DefaultTraits.Honor), 0f, 2f); float basicScoreForOutcome; int calculatingTraitLevel = MBMath.ClampInt(decisionMaker.Hero.GetTraitLevel(DefaultTraits.Calculating), -2, 2); bool outcomeIsClanOfDM = FieldAccessHelper.ClanAsDecisionOutcomeByRef(possibleOutcome) == decisionMaker.Hero.Clan; if (outcomeIsClanOfDM) { float settlementValueForFaction = claimantDecision.Settlement.GetSettlementValueForFaction(decisionMaker.Hero.Clan); basicScoreForOutcome = initialMeritScore + 0.2f * settlementValueForFaction * Campaign.Current.Models.DiplomacyModel.DenarsToInfluence(); } else { float relationBetweenClans = !outcomeIsClanOfDM?FactionManager.GetRelationBetweenClans(FieldAccessHelper.ClanAsDecisionOutcomeByRef(possibleOutcome), decisionMaker.Hero.Clan) : 100f; basicScoreForOutcome = initialMeritScore * MathF.Clamp(1f + calculatingTraitLevel, 0f, 2f) + relationBetweenClans * 0.2f * calculatingTraitLevel; } double calculatingModifier = (1.0 - (calculatingTraitLevel > 0 ? 0.4 - Math.Min(2f, calculatingTraitLevel) * 0.1 : 0.4 + Math.Min(2f, Math.Abs(calculatingTraitLevel)) * 0.1) * 1.5); return(basicScoreForOutcome * calculatingModifier * (outcomeIsClanOfDM ? 2f : 1f)); }
protected virtual Dictionary <DecisionMaker, double> GetDecisionMakersSupportScores(Clan clan, KingdomDecision decision, DecisionOutcome possibleOutcome) { return(GetDecisionMakers(clan).ToDictionary(keySelector: dm => dm, elementSelector: dm => GetSupportScoreOfDecisionMaker(dm, decision, possibleOutcome))); }
protected override double GetSupportScoreOfDecisionMaker(DecisionMaker decisionMaker, KingdomDecision decision, DecisionOutcome possibleOutcome) { switch (decision) { case MakePeaceKingdomDecision makePeaceDecision: return(GetSupportScoreOfDecisionMaker(decisionMaker, makePeaceDecision, possibleOutcome) * decisionMaker.DecisionWeight); case DeclareWarDecision declareWarDecision: return(GetSupportScoreOfDecisionMaker(decisionMaker, declareWarDecision, possibleOutcome) * decisionMaker.DecisionWeight); case SettlementClaimantDecision claimantDecision: return(GetSupportScoreOfDecisionMaker(decisionMaker, claimantDecision, possibleOutcome) * decisionMaker.DecisionWeight); case SettlementClaimantPreliminaryDecision annexationDecision: return(GetSupportScoreOfDecisionMaker(decisionMaker, annexationDecision, possibleOutcome) * decisionMaker.DecisionWeight); default: throw new ArgumentOutOfRangeException(nameof(decision), string.Format("Kingdom decision of type {0} is not supported.", decision.GetType().FullName)); } }
private static float GetBaseCompensationCost(ODCostCalculationMethod calculationMethod, DecisionOutcome popularOption, DecisionOutcome overridingOption, KingdomDecision decision) { float PopularOptionSupportPoints = popularOption.TotalSupportPoints; float OverridingOptionSupportPoints = overridingOption.TotalSupportPoints + 3f; return(calculationMethod switch { ODCostCalculationMethod.FlatInfluenceOverride => popularOption.SupporterList.Sum(sup => decision.GetInfluenceCostOfSupport(sup.SupportWeight)), ODCostCalculationMethod.SlightlyFavor => (PopularOptionSupportPoints - OverridingOptionSupportPoints) * decision.GetInfluenceCostOfSupport(Supporter.SupportWeights.SlightlyFavor), ODCostCalculationMethod.StronglyFavor => (PopularOptionSupportPoints - OverridingOptionSupportPoints) * decision.GetInfluenceCostOfSupport(Supporter.SupportWeights.StronglyFavor), ODCostCalculationMethod.FullyPush => (PopularOptionSupportPoints - OverridingOptionSupportPoints) * decision.GetInfluenceCostOfSupport(Supporter.SupportWeights.FullyPush), _ => throw new ArgumentOutOfRangeException(nameof(Settings.Instance.OverrideDecisionCostCalculationMethod.SelectedValue.EnumValue), Settings.Instance !.OverrideDecisionCostCalculationMethod.SelectedValue.EnumValue, null), });
public static void Postfix(DecisionOutcome popularOption, DecisionOutcome overridingOption, KingdomDecision decision, ref int __result) { try { bool SubSystemEnabled = SettingsHelper.SubSystemEnabled(SubSystemType.ElectionRebalance, decision.Kingdom); bool SystemDebugEnabled = SettingsHelper.SystemDebugEnabled(AOSystems.PoliticsRebalance, DebugType.Technical, decision.Kingdom); if (!SubSystemEnabled && !SystemDebugEnabled) { if (SettingsHelper.SubSystemEnabled(SubSystemType.FreeDecisionOverriding)) { __result = 0; } return; } float PopularOptionSupportPoints = popularOption.TotalSupportPoints; float OverridingOptionSupportPoints = overridingOption.TotalSupportPoints; float CalculatedResult = 0.0f; if (decision.Kingdom.RulingClan == Clan.PlayerClan) { CalculatedResult += ApplySupport(ref PopularOptionSupportPoints, ref OverridingOptionSupportPoints, decision); } float LackingPointsCompensationCost = 0; if (PopularOptionSupportPoints > OverridingOptionSupportPoints) { LackingPointsCompensationCost = GetBaseCompensationCost(Settings.Instance.OverrideDecisionCostCalculationMethod.SelectedValue.EnumValue, popularOption, overridingOption, decision); if (decision.Kingdom.ActivePolicies.Contains(DefaultPolicies.RoyalPrivilege)) { LackingPointsCompensationCost *= 0.8f; } if (decision.Kingdom.RulingClan != Clan.PlayerClan) { LackingPointsCompensationCost *= 0.8f; } CalculatedResult += LackingPointsCompensationCost; } if (SettingsHelper.SubSystemEnabled(SubSystemType.FreeDecisionOverriding)) { CalculatedResult = 0f; } if (SystemDebugEnabled) { string InfluenceRequiredDebugInfo = string.Format("DefaultClanPoliticsModel - InfluenceRequiredToOverrideKingdomDecision. Kingdom: {0}. Decision: {1}. PopularOption: {2}. OverridingOption: {3}. " + "PopularOptionSupportPoints = {4}. OverridingOptionSupportPoints = {5}. " + "OverrideDecisionCostCalculationMethod: {6}. LackingPointsCompensationCost = {7}. " + "Royal Privilege modifier: {8}. NPC modifier: {9}. Free of charge cheat modifier: {10} " + "CalculatedResult = {11}. NativeResult = {12}", decision.Kingdom.Name, decision.GetGeneralTitle(), popularOption.GetDecisionTitle(), overridingOption.GetDecisionTitle(), PopularOptionSupportPoints, OverridingOptionSupportPoints, Settings.Instance.OverrideDecisionCostCalculationMethod.SelectedValue, LackingPointsCompensationCost, GetModifierApplied(decision.Kingdom.ActivePolicies.Contains(DefaultPolicies.RoyalPrivilege)), GetModifierApplied(decision.Kingdom.RulingClan != Clan.PlayerClan), GetModifierApplied(SettingsHelper.SubSystemEnabled(SubSystemType.FreeDecisionOverriding)), CalculatedResult.ToString("N"), __result.ToString("N")); MessageHelper.TechnicalMessage(InfluenceRequiredDebugInfo); } if (SubSystemEnabled) { __result = (int)CalculatedResult; } } catch (Exception ex) { MethodInfo methodInfo = MethodBase.GetCurrentMethod() as MethodInfo; DebugHelper.HandleException(ex, methodInfo, "Harmony patch for DefaultClanPoliticsModel. GetInfluenceRequiredToOverrideKingdomDecision"); } }