From aeb906fe1db78b2b00ad964e3f54ed0e2d4ac21c Mon Sep 17 00:00:00 2001 From: Alexey Chernyshov Date: Sat, 5 Aug 2023 13:18:42 +0300 Subject: [PATCH 1/2] Adapted for latest game versions --- build/common.props | 16 ++++++++-------- changelog.txt | 5 +++++ .../Actions/GiveGoldToKingdomAction.cs | 8 ++++++++ .../Actions/GrantFiefAction.cs | 4 ++++ .../CampaignBehaviors/WarExhaustionBehavior.cs | 13 +++++++++++++ .../Actions/ChangeKingdomBannerAction.cs | 16 ++++++++++++++++ .../CivilWar/Factions/RebelFaction.cs | 2 +- .../Scoring/ChangeRulerFactionScoreBase.cs | 5 ++++- .../WarPeace/Conditions/NoSiegeCondition.cs | 4 ++++ .../Patches/RebelKingdomPatches.cs | 4 ++++ src/Bannerlord.Diplomacy/Settings.cs | 6 ++++++ .../ViewModel/GrantFiefItemVM.cs | 4 ++++ .../ViewModel/RebelFactionsVM.cs | 3 +++ .../Languages/std_module_strings_xml.xml | 2 ++ supported-game-versions.txt | 9 +++++++++ 15 files changed, 91 insertions(+), 10 deletions(-) diff --git a/build/common.props b/build/common.props index 2a2c0ed8..2c23c7d9 100644 --- a/build/common.props +++ b/build/common.props @@ -2,30 +2,30 @@ - 1.2.5 + 1.2.6 1.0.0 - 1.0.1.92 + 1.1.0.102 2.2.2 - 2.6.3 + 2.8.11 - 5.5.5 + 5.9.1 - 2.6.0 + 2.8.0 - 3.0.0.134 + 3.0.0.137 - 5.0.198 + 5.0.209 1.0.1.44 - 3.2.0.75 + 3.2.0.77 net472 diff --git a/changelog.txt b/changelog.txt index f6057eca..c690104d 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,4 +1,9 @@ --------------------------------------------------------------------------------------------------- +Version: 1.2.6 +Game Versions: v1.0.0,v1.0.1,v1.0.2,v1.0.3,v1.1.0,v1.1.1,v1.1.2,v1.1.3,v1.1.4,v1.1.5,v1.2.0,v1.2.1,v1.2.2,v1.2.3 +* Adapted for latest game versions. +* Reworked Diplomacy Kingdom Elimination option description and implementation for v1.2.X game versions. +--------------------------------------------------------------------------------------------------- Version: 1.2.5 Game Versions: v1.0.0,v1.0.1,v1.0.2,v1.0.3,v1.1.0 * Fixed a crash on making peace when War Exhaustion is disabled. diff --git a/src/Bannerlord.Diplomacy/Actions/GiveGoldToKingdomAction.cs b/src/Bannerlord.Diplomacy/Actions/GiveGoldToKingdomAction.cs index 9a0017dc..3580126c 100644 --- a/src/Bannerlord.Diplomacy/Actions/GiveGoldToKingdomAction.cs +++ b/src/Bannerlord.Diplomacy/Actions/GiveGoldToKingdomAction.cs @@ -62,7 +62,11 @@ private static void GetMoneyFromGiver(Kingdom giverKingdom, int amount, WalletTy { foreach ((var settlement, var amountToCoverBySettlement) in MBMath.DistributeShares(amountToCover, giverKingdom.Settlements.Where(s => s.IsCastle || s.IsTown), CalculateSettlementShare)) { +#if v100 || v101 || v102 || v103 || v110 || v111 || v112 || v113 || v114 || v115 settlement.Prosperity -= amountToCoverBySettlement / GoldPerProsperity; +#else + settlement.Town.Prosperity -= amountToCoverBySettlement / GoldPerProsperity; +#endif } amount = tolerableAmount; } @@ -141,7 +145,11 @@ private static void GiveGoldToKingdom(int gold, Kingdom kingdom) private static int CalculateShare(Clan clan) => Math.Max(clan.Tier / 2, 1) + (clan == clan.Kingdom?.Leader?.Clan ? 1 : 0); private static int CalculateMercenaryShare(Clan clan) => Math.Max((int) clan.Influence, 1); +#if v100 || v101 || v102 || v103 || v110 || v111 || v112 || v113 || v114 || v115 private static int CalculateSettlementShare(Settlement settlement) => Math.Max((int) settlement.Prosperity, 1); +#else + private static int CalculateSettlementShare(Settlement settlement) => Math.Max((int) settlement.Town.Prosperity, 1); +#endif public static void ApplyFromHeroToKingdom(Hero giverHero, Kingdom kingdom, int amount) { diff --git a/src/Bannerlord.Diplomacy/Actions/GrantFiefAction.cs b/src/Bannerlord.Diplomacy/Actions/GrantFiefAction.cs index ac7b63d7..04a4fc92 100644 --- a/src/Bannerlord.Diplomacy/Actions/GrantFiefAction.cs +++ b/src/Bannerlord.Diplomacy/Actions/GrantFiefAction.cs @@ -51,7 +51,11 @@ private static int CalculateBaseRelationChange(Settlement settlement) { // TODO: Consider basing the relationship change with the granted clan upon the fief's value // normalized to the average fief value in the kingdom. +#if v100 || v101 || v102 || v103 || v110 || v111 || v112 || v113 || v114 || v115 var baseRelationChange = (int) Math.Round(Math.Max(5, Math.Log(settlement.Prosperity / 1000, 1.1f))); +#else + var baseRelationChange = (int) Math.Round(Math.Max(5, Math.Log(settlement.Town.Prosperity / 1000, 1.1f))); +#endif return (int) (baseRelationChange * Settings.Instance!.GrantFiefPositiveRelationMultiplier); } diff --git a/src/Bannerlord.Diplomacy/CampaignBehaviors/WarExhaustionBehavior.cs b/src/Bannerlord.Diplomacy/CampaignBehaviors/WarExhaustionBehavior.cs index aa142ea1..df5914e0 100644 --- a/src/Bannerlord.Diplomacy/CampaignBehaviors/WarExhaustionBehavior.cs +++ b/src/Bannerlord.Diplomacy/CampaignBehaviors/WarExhaustionBehavior.cs @@ -2,6 +2,7 @@ using Microsoft.Extensions.Logging; +using System; using System.Linq; using TaleWorlds.CampaignSystem; @@ -38,7 +39,19 @@ public override void RegisterEvents() CampaignEvents.MakePeace.AddNonSerializedListener(this, ClearWarExhaustion); CampaignEvents.OnGameLoadFinishedEvent.AddNonSerializedListener(this, OnGameLoadFinished); + +#if v120 || v121 || v122 || v123 + CampaignEvents.CanKingdomBeDiscontinuedEvent.AddNonSerializedListener(this, CanKingdomBeDiscontinued); +#endif + } + +#if v120 || v121 || v122 || v123 + private void CanKingdomBeDiscontinued(Kingdom kingdom, ref bool result) + { + if (Settings.Instance!.EnableKingdomElimination) + result = false; //TODO: Probably should move on to vanila kingdom dispatching when making peace } +#endif #if v100 || v101 || v102 || v103 private void ClearWarExhaustion(IFaction faction1, IFaction faction2) diff --git a/src/Bannerlord.Diplomacy/CivilWar/Actions/ChangeKingdomBannerAction.cs b/src/Bannerlord.Diplomacy/CivilWar/Actions/ChangeKingdomBannerAction.cs index 59e7da1f..904a471a 100644 --- a/src/Bannerlord.Diplomacy/CivilWar/Actions/ChangeKingdomBannerAction.cs +++ b/src/Bannerlord.Diplomacy/CivilWar/Actions/ChangeKingdomBannerAction.cs @@ -66,28 +66,40 @@ public static void Apply(Kingdom kingdom, uint backgroundColor, uint sigilColor) if (clanKingdom == kingdom) { +#if v100 || v101 || v102 || v103 || v110 || v111 || v112 || v113 || v114 || v115 var visuals = mobileParty.Party!.Visuals; if (visuals != null) { visuals.SetMapIconAsDirty(); } +#else + mobileParty.Party!.SetVisualAsDirty(); +#endif } } foreach (var settlement in kingdom.Settlements) { +#if v100 || v101 || v102 || v103 || v110 || v111 || v112 || v113 || v114 || v115 var visuals = settlement.Party.Visuals; if (visuals != null) { visuals.SetMapIconAsDirty(); } +#else + settlement.Party?.SetVisualAsDirty(); +#endif if (settlement.IsVillage && settlement.Village.VillagerPartyComponent != null) { var party = settlement.Village.VillagerPartyComponent.MobileParty.Party; if (party != null) { +#if v100 || v101 || v102 || v103 || v110 || v111 || v112 || v113 || v114 || v115 party.Visuals.SetMapIconAsDirty(); +#else + party.SetVisualAsDirty(); +#endif } } else if ((settlement.IsCastle || settlement.IsTown) && settlement.Town.GarrisonParty != null) @@ -95,7 +107,11 @@ public static void Apply(Kingdom kingdom, uint backgroundColor, uint sigilColor) var party = settlement.Town.GarrisonParty.Party; if (party != null) { +#if v100 || v101 || v102 || v103 || v110 || v111 || v112 || v113 || v114 || v115 party.Visuals.SetMapIconAsDirty(); +#else + party.SetVisualAsDirty(); +#endif } } } diff --git a/src/Bannerlord.Diplomacy/CivilWar/Factions/RebelFaction.cs b/src/Bannerlord.Diplomacy/CivilWar/Factions/RebelFaction.cs index d83ad47a..cc63dd3d 100644 --- a/src/Bannerlord.Diplomacy/CivilWar/Factions/RebelFaction.cs +++ b/src/Bannerlord.Diplomacy/CivilWar/Factions/RebelFaction.cs @@ -129,7 +129,7 @@ public void StartRebellion(Kingdom rebelKingdom) public void AddClan(Clan clan) { - if (!_participatingClans.Contains(clan)) + if (clan != null && !_participatingClans.Contains(clan)) _participatingClans.Add(clan); } diff --git a/src/Bannerlord.Diplomacy/CivilWar/Scoring/ChangeRulerFactionScoreBase.cs b/src/Bannerlord.Diplomacy/CivilWar/Scoring/ChangeRulerFactionScoreBase.cs index 1486f96f..b9001edb 100644 --- a/src/Bannerlord.Diplomacy/CivilWar/Scoring/ChangeRulerFactionScoreBase.cs +++ b/src/Bannerlord.Diplomacy/CivilWar/Scoring/ChangeRulerFactionScoreBase.cs @@ -56,7 +56,10 @@ protected IEnumerable> CalculateTraitScore(Clan clan, R protected override Tuple GetRelationshipScoreWithTarget(Clan clan, RebelFaction rebelFaction) { - var mercyMultiplier = 1 - (clan.Leader.GetTraitLevel(DefaultTraits.Mercy) * 0.25f); + if (clan?.Leader is null) + new Tuple(_TRelationsFactionTarget, 0); + + var mercyMultiplier = 1 - (clan!.Leader!.GetTraitLevel(DefaultTraits.Mercy) * 0.25f); var relationshipWithRuler = clan.GetRelationWithClan(clan.Kingdom.RulingClan); var relationshipWithRulerAdj = relationshipWithRuler <= 0 ? relationshipWithRuler * mercyMultiplier : relationshipWithRuler; diff --git a/src/Bannerlord.Diplomacy/DiplomaticAction/WarPeace/Conditions/NoSiegeCondition.cs b/src/Bannerlord.Diplomacy/DiplomaticAction/WarPeace/Conditions/NoSiegeCondition.cs index e17203b8..390c504e 100644 --- a/src/Bannerlord.Diplomacy/DiplomaticAction/WarPeace/Conditions/NoSiegeCondition.cs +++ b/src/Bannerlord.Diplomacy/DiplomaticAction/WarPeace/Conditions/NoSiegeCondition.cs @@ -15,7 +15,11 @@ public bool ApplyCondition(Kingdom kingdom, Kingdom otherKingdom, out TextObject if (kingdom == playerKingdom || otherKingdom == playerKingdom) { var besiegedKingdom = PlayerSiege.PlayerSiegeEvent?.BesiegedSettlement?.OwnerClan.Kingdom; +#if v100 || v101 || v102 || v103 || v110 || v111 || v112 || v113 || v114 || v115 var besiegingKingdom = PlayerSiege.PlayerSiegeEvent?.BesiegerCamp?.BesiegerParty.LeaderHero.MapFaction as Kingdom; +#else + var besiegingKingdom = PlayerSiege.PlayerSiegeEvent?.BesiegerCamp?.LeaderParty.LeaderHero.MapFaction as Kingdom; +#endif if ((besiegedKingdom == playerKingdom || besiegingKingdom == playerKingdom) && (besiegedKingdom == otherKingdom || besiegingKingdom == otherKingdom)) { diff --git a/src/Bannerlord.Diplomacy/Patches/RebelKingdomPatches.cs b/src/Bannerlord.Diplomacy/Patches/RebelKingdomPatches.cs index ef01439a..d5e1bc96 100644 --- a/src/Bannerlord.Diplomacy/Patches/RebelKingdomPatches.cs +++ b/src/Bannerlord.Diplomacy/Patches/RebelKingdomPatches.cs @@ -16,7 +16,11 @@ internal sealed class RebelKingdomPatches : PatchClass { protected override IEnumerable Prepare() { +#if v100 || v101 || v102 || v103 || v110 || v111 || v112 || v113 || v114 || v115 var conversationBehaviorType = Type.GetType("SandBox.CampaignBehaviors.LordConversationsCampaignBehavior, SandBox, Version=1.0.0.0, Culture=neutral")!; +#else + var conversationBehaviorType = Type.GetType("TaleWorlds.CampaignSystem.CampaignBehaviors.LordConversationsCampaignBehavior, TaleWorlds.CampaignSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")!; +#endif return new Patch[] { new Postfix(nameof(PreventOtherActionsConversation), conversationBehaviorType, "conversation_lord_request_mission_ask_on_condition"), diff --git a/src/Bannerlord.Diplomacy/Settings.cs b/src/Bannerlord.Diplomacy/Settings.cs index b6f494c0..2e991223 100644 --- a/src/Bannerlord.Diplomacy/Settings.cs +++ b/src/Bannerlord.Diplomacy/Settings.cs @@ -38,9 +38,15 @@ class Settings : AttributeGlobalSettings [SettingPropertyGroup(HeadingKingdomDiplomacy)] public bool EnableFiefFirstRight { get; set; } = true; +#if v100 || v101 || v102 || v103 || v110 || v111 || v112 || v113 || v114 || v115 [SettingPropertyBool("{=8VKC3jtN}Enable Fiefless Kingdom Elimination", Order = 10, RequireRestart = false, HintText = "{=TlymwwPZ}If enabled, kingdoms without any fiefs are destroyed when they sign a peace treaty ending the last ongoing war they participate in. Default value is enabled.")] [SettingPropertyGroup(HeadingKingdomDiplomacy)] public bool EnableKingdomElimination { get; set; } = true; +#else + [SettingPropertyBool("{=w8Hi9jJf}Delay Fiefless Kingdom Elimination", Order = 10, RequireRestart = false, HintText = "{=GDctI4Kd}If enabled, kingdoms without any fiefs will only be destroyed when they sign a peace treaty ending the last ongoing war they are involved in, not immediately after they lose their last fief. Default value is enabled.")] + [SettingPropertyGroup(HeadingKingdomDiplomacy)] + public bool EnableKingdomElimination { get; set; } = true; +#endif [SettingPropertyInteger("{=ZRlNvsev}Minimum War Duration in Days", 0, 500, Order = 20, RequireRestart = false, HintText = "{=vuFT5ns8}The minimum duration (in days) that a war can last before proposing peace. Default value is 21 (quarter of a standard game year).")] [SettingPropertyGroup(HeadingKingdomDiplomacy)] diff --git a/src/Bannerlord.Diplomacy/ViewModel/GrantFiefItemVM.cs b/src/Bannerlord.Diplomacy/ViewModel/GrantFiefItemVM.cs index 1c037805..4b1eb801 100644 --- a/src/Bannerlord.Diplomacy/ViewModel/GrantFiefItemVM.cs +++ b/src/Bannerlord.Diplomacy/ViewModel/GrantFiefItemVM.cs @@ -30,7 +30,11 @@ public GrantFiefItemVM(Settlement settlement, Hero targetHero, Action + + diff --git a/supported-game-versions.txt b/supported-game-versions.txt index 6f097c9c..4430573f 100644 --- a/supported-game-versions.txt +++ b/supported-game-versions.txt @@ -1,3 +1,12 @@ +v1.2.3 +v1.2.2 +v1.2.1 +v1.2.0 +v1.1.5 +v1.1.4 +v1.1.3 +v1.1.2 +v1.1.1 v1.1.0 v1.0.3 v1.0.2 From 4d8ba746330dfee05cae47e1d1c553db08b73b5d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 5 Aug 2023 10:22:39 +0000 Subject: [PATCH 2/2] Bump butr/actions-code-format-setup from 1.5 to 1.7 Bumps [butr/actions-code-format-setup](https://github.com/butr/actions-code-format-setup) from 1.5 to 1.7. - [Release notes](https://github.com/butr/actions-code-format-setup/releases) - [Commits](https://github.com/butr/actions-code-format-setup/compare/v1.5...v1.7) --- updated-dependencies: - dependency-name: butr/actions-code-format-setup dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/dotnet-format-daily.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dotnet-format-daily.yml b/.github/workflows/dotnet-format-daily.yml index db77d5e6..1d9775ed 100644 --- a/.github/workflows/dotnet-format-daily.yml +++ b/.github/workflows/dotnet-format-daily.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Code Formatting - uses: butr/actions-code-format-setup@v1.5 + uses: butr/actions-code-format-setup@v1.7 with: workspace: "src/Bannerlord.Diplomacy.sln" github-token: ${{ secrets.GITHUB_TOKEN }}