Skip to content

Commit

Permalink
Merge pull request #227 from DiplomacyTeam/dev
Browse files Browse the repository at this point in the history
v1.2.6 release
  • Loading branch information
artifixer authored Aug 5, 2023
2 parents 2c5559a + 11c5972 commit ddd942f
Show file tree
Hide file tree
Showing 16 changed files with 92 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dotnet-format-daily.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
16 changes: 8 additions & 8 deletions build/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@

<!--Module Version-->
<PropertyGroup>
<Version>1.2.5</Version>
<Version>1.2.6</Version>
<GameVersion>1.0.0</GameVersion>
</PropertyGroup>

<!-- Versions of Major Dependencies (For Package References & SubModule.xml Substitution) -->
<PropertyGroup>
<!--BuildResources Version-->
<BuildResourcesVersion>1.0.1.92</BuildResourcesVersion>
<BuildResourcesVersion>1.1.0.102</BuildResourcesVersion>
<!--Harmony Version-->
<HarmonyVersion>2.2.2</HarmonyVersion>
<!--ButterLib Version-->
<ButterLibVersion>2.6.3</ButterLibVersion>
<ButterLibVersion>2.8.11</ButterLibVersion>
<!--MCM Version-->
<MCMVersion>5.5.5</MCMVersion>
<MCMVersion>5.9.1</MCMVersion>
<!--UIExtenderEx Version-->
<UIExtenderExVersion>2.6.0</UIExtenderExVersion>
<UIExtenderExVersion>2.8.0</UIExtenderExVersion>
<!--BUTRShared Version-->
<BUTRSharedVersion>3.0.0.134</BUTRSharedVersion>
<BUTRSharedVersion>3.0.0.137</BUTRSharedVersion>
<!--BUTRModuleManager Version-->
<BUTRModuleManagerVersion>5.0.198</BUTRModuleManagerVersion>
<BUTRModuleManagerVersion>5.0.209</BUTRModuleManagerVersion>
<!--ModuleLoader Version-->
<BUTRModuleLoaderVersion>1.0.1.44</BUTRModuleLoaderVersion>
<!--Harmony Extensions Version-->
<HarmonyExtensionsVersion>3.2.0.75</HarmonyExtensionsVersion>
<HarmonyExtensionsVersion>3.2.0.77</HarmonyExtensionsVersion>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
Expand Down
5 changes: 5 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
8 changes: 8 additions & 0 deletions src/Bannerlord.Diplomacy/Actions/GiveGoldToKingdomAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)
{
Expand Down
4 changes: 4 additions & 0 deletions src/Bannerlord.Diplomacy/Actions/GrantFiefAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using Microsoft.Extensions.Logging;

using System;
using System.Linq;

using TaleWorlds.CampaignSystem;
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,36 +66,52 @@ 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)
{
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
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Bannerlord.Diplomacy/CivilWar/Factions/RebelFaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ protected IEnumerable<Tuple<TextObject, float>> CalculateTraitScore(Clan clan, R

protected override Tuple<TextObject, float> GetRelationshipScoreWithTarget(Clan clan, RebelFaction rebelFaction)
{
var mercyMultiplier = 1 - (clan.Leader.GetTraitLevel(DefaultTraits.Mercy) * 0.25f);
if (clan?.Leader is null)
new Tuple<TextObject, float>(_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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down
4 changes: 4 additions & 0 deletions src/Bannerlord.Diplomacy/Patches/RebelKingdomPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ internal sealed class RebelKingdomPatches : PatchClass<RebelKingdomPatches>
{
protected override IEnumerable<Patch> 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"),
Expand Down
6 changes: 6 additions & 0 deletions src/Bannerlord.Diplomacy/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,15 @@ class Settings : AttributeGlobalSettings<Settings>
[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)]
Expand Down
4 changes: 4 additions & 0 deletions src/Bannerlord.Diplomacy/ViewModel/GrantFiefItemVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ public GrantFiefItemVM(Settlement settlement, Hero targetHero, Action<GrantFiefI
}
else if (settlement.IsCastle)
{
#if v100 || v101 || v102 || v103 || v110 || v111 || v112 || v113 || v114 || v115
Prosperity = (int) Math.Round(settlement.Prosperity);
#else
Prosperity = (int) Math.Round(settlement.Town.Prosperity);
#endif
IconPath = "";
}
Garrison = Settlement.Town.GarrisonParty?.Party.NumberOfAllMembers ?? 0;
Expand Down
3 changes: 3 additions & 0 deletions src/Bannerlord.Diplomacy/ViewModel/RebelFactionsVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ public void OnCreateFaction()
inquiryElements,
true,
1,
#if v120 || v121 || v122 || v123
1,
#endif
GameTexts.FindText("str_ok").ToString(),
GameTexts.FindText("str_cancel").ToString(),
HandleCreateFaction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@
<string id="TfxLCxcD" text="Gives the player the option to claim a settlement that they have taken rather than let it go to an election." />
<string id="8VKC3jtN" text="Enable Fiefless Kingdom Elimination" />
<string id="TlymwwPZ" text="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." />
<string id="w8Hi9jJf" text="Delay Fiefless Kingdom Elimination" />
<string id="GDctI4Kd" text="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." />
<string id="ZRlNvsev" text="Minimum War Duration in Days" />
<string id="vuFT5ns8" text="The minimum duration (in days) that a war can last before proposing peace. Default value is 21 (quarter of a standard game year)." />
<string id="4MzQHMVj" text="Declare War Cooldown in Days" />
Expand Down
9 changes: 9 additions & 0 deletions supported-game-versions.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit ddd942f

Please sign in to comment.