diff --git a/build/common.props b/build/common.props
index 0c0e347b..cd3ebe84 100644
--- a/build/common.props
+++ b/build/common.props
@@ -2,7 +2,7 @@
- 1.2.3
+ 1.2.4
1.0.0
diff --git a/changelog.txt b/changelog.txt
index d0e50f10..5b8c0c77 100644
--- a/changelog.txt
+++ b/changelog.txt
@@ -1,4 +1,11 @@
---------------------------------------------------------------------------------------------------
+Version: 1.2.4
+Game Versions: v1.0.0,v1.0.1,v1.0.2,v1.0.3,v1.1.0
+* Fixed a crash after loading a save when attempting to fix any faulty factions.
+* Fixed a bug due to which the factions checkup did not always work as intended.
+* Fixed a bug where war exhaustion was still not initialized properly when declaring a war.
+* Fixed a bug due to which NAPs and Alliances were evaluated for the wrong side of the agreement.
+---------------------------------------------------------------------------------------------------
Version: 1.2.3
Game Versions: v1.0.0,v1.0.1,v1.0.2,v1.0.3,v1.1.0
* Fixed a bug where war exhaustion was not reseted when making peace and not initialized properly when declaring wars.
diff --git a/src/Bannerlord.Diplomacy/CivilWar/RebelFactionManager.cs b/src/Bannerlord.Diplomacy/CivilWar/RebelFactionManager.cs
index 12b5ddc2..dd32f4d9 100644
--- a/src/Bannerlord.Diplomacy/CivilWar/RebelFactionManager.cs
+++ b/src/Bannerlord.Diplomacy/CivilWar/RebelFactionManager.cs
@@ -105,22 +105,29 @@ public static IEnumerable GetRebelFaction(Kingdom kingdom)
internal void OnAfterSaveLoaded()
{
- var factionsToClean = AllRebelFactions.Values.SelectMany(x => x).Where(x => x.Clans.Any(clan => clan.IsEliminated)).ToList();
- var factionsToClear = factionsToClean.Where(x => x.Clans.Any(clan => !clan.IsEliminated)).ToList();
- //Eliminate dead factions
- foreach (var faction in factionsToClear)
+ //Remove factions of dead kingdoms
+ var keysToRemove = AllRebelFactions.Keys.Where(k => k.IsEliminated).ToList();
+ foreach (var keyToRemove in keysToRemove)
{
- DestroyRebelFaction(faction);
+ RebelFactions.Remove(keyToRemove);
}
- //Celar factions of dead clans
+ //Account for eliminated clans
+ var factionsToClean = AllRebelFactions.Values.SelectMany(x => x).Where(x => x.Clans.Any(clan => clan.IsEliminated)).ToList();
foreach (var faction in factionsToClean)
{
+ if (faction.Clans.All(clan => clan.IsEliminated))
+ {
+ //Destroy dead factions
+ DestroyRebelFaction(faction);
+ continue;
+ }
foreach (var clan in faction.Clans)
{
+ //Clear rest of the factions from dead clans
if (clan.IsEliminated) faction.RemoveClan(clan);
}
}
- //Fix factions that count as dead but not dead
+ //Fix factions that count as dead but not actually dead
var kingdomsToReanimate = DeadRebelKingdoms.Where(k => !k.IsEliminated).ToList();
foreach (var kingdom in kingdomsToReanimate)
{
diff --git a/src/Bannerlord.Diplomacy/DiplomaticAction/AbstractScoringModel.cs b/src/Bannerlord.Diplomacy/DiplomaticAction/AbstractScoringModel.cs
index 2ec05052..fff520ba 100644
--- a/src/Bannerlord.Diplomacy/DiplomaticAction/AbstractScoringModel.cs
+++ b/src/Bannerlord.Diplomacy/DiplomaticAction/AbstractScoringModel.cs
@@ -19,7 +19,7 @@ namespace Diplomacy.DiplomaticAction
protected AbstractScoringModel(IDiplomacyScores scores) => Scores = scores;
- public virtual ExplainedNumber GetScore(Kingdom otherKingdom, Kingdom ourKingdom, bool includeDesc = false)
+ public virtual ExplainedNumber GetScore(Kingdom ourKingdom, Kingdom otherKingdom, bool includeDesc = false)
{
var explainedNum = new ExplainedNumber(Scores.Base, includeDesc);
diff --git a/src/Bannerlord.Diplomacy/Events/DiplomacyEvents.cs b/src/Bannerlord.Diplomacy/Events/DiplomacyEvents.cs
index d1645713..d94adda1 100644
--- a/src/Bannerlord.Diplomacy/Events/DiplomacyEvents.cs
+++ b/src/Bannerlord.Diplomacy/Events/DiplomacyEvents.cs
@@ -22,7 +22,8 @@ public sealed class DiplomacyEvents
#if v100 || v101 || v102 || v103
private readonly MbEvent _warDeclared = new();
#endif
- private readonly MbEvent _warExhaustionAdded = new();
+ private readonly MbEvent _warExhaustionInitialized = new();
+ private readonly MbEvent _warExhaustionAdded = new();
public DiplomacyEvents()
{
@@ -39,6 +40,7 @@ public DiplomacyEvents()
_warDeclared,
#endif
_kingdomBannerChanged,
+ _warExhaustionInitialized,
_warExhaustionAdded
};
}
@@ -63,7 +65,9 @@ public DiplomacyEvents()
public static IMbEvent KingdomBannerChanged => Instance._kingdomBannerChanged;
- public static IMbEvent WarExhaustionAdded => Instance._warExhaustionAdded;
+ public static IMbEvent WarExhaustionInitialized => Instance._warExhaustionInitialized;
+
+ public static IMbEvent WarExhaustionAdded => Instance._warExhaustionAdded;
internal void OnMessengerSent(Hero hero)
{
@@ -107,7 +111,12 @@ internal void OnKingdomBannerChanged(Kingdom kingdom)
Instance._kingdomBannerChanged.Invoke(kingdom);
}
- internal void OnWarExhaustionAdded(WarExhaustionEvent warExhaustionEvent)
+ internal void OnWarExhaustionInitialized(WarExhaustionInitializedEvent warExhaustionEvent)
+ {
+ Instance._warExhaustionInitialized.Invoke(warExhaustionEvent);
+ }
+
+ internal void OnWarExhaustionAdded(WarExhaustionAddedEvent warExhaustionEvent)
{
Instance._warExhaustionAdded.Invoke(warExhaustionEvent);
}
diff --git a/src/Bannerlord.Diplomacy/Events/WarExhaustionEvent.cs b/src/Bannerlord.Diplomacy/Events/WarExhaustionAddedEvent.cs
similarity index 72%
rename from src/Bannerlord.Diplomacy/Events/WarExhaustionEvent.cs
rename to src/Bannerlord.Diplomacy/Events/WarExhaustionAddedEvent.cs
index 4079e4b8..2e6ce273 100644
--- a/src/Bannerlord.Diplomacy/Events/WarExhaustionEvent.cs
+++ b/src/Bannerlord.Diplomacy/Events/WarExhaustionAddedEvent.cs
@@ -4,9 +4,9 @@
namespace Diplomacy.Events
{
- public readonly struct WarExhaustionEvent
+ public readonly struct WarExhaustionAddedEvent
{
- public WarExhaustionEvent(Kingdom kingdom, Kingdom otherKingdom, WarExhaustionType warExhaustionType, float warExhaustionToAdd)
+ public WarExhaustionAddedEvent(Kingdom kingdom, Kingdom otherKingdom, WarExhaustionType warExhaustionType, float warExhaustionToAdd)
{
Kingdom = kingdom;
OtherKingdom = otherKingdom;
diff --git a/src/Bannerlord.Diplomacy/Events/WarExhaustionInitializedEvent.cs b/src/Bannerlord.Diplomacy/Events/WarExhaustionInitializedEvent.cs
new file mode 100644
index 00000000..d63089c5
--- /dev/null
+++ b/src/Bannerlord.Diplomacy/Events/WarExhaustionInitializedEvent.cs
@@ -0,0 +1,16 @@
+using TaleWorlds.CampaignSystem;
+
+namespace Diplomacy.Events
+{
+ public readonly struct WarExhaustionInitializedEvent
+ {
+ public WarExhaustionInitializedEvent(Kingdom kingdom, Kingdom otherKingdom)
+ {
+ Kingdom = kingdom;
+ OtherKingdom = otherKingdom;
+ }
+
+ public Kingdom Kingdom { get; }
+ public Kingdom OtherKingdom { get; }
+ }
+}
diff --git a/src/Bannerlord.Diplomacy/ViewModel/WarExhaustionMapIndicatorVM.cs b/src/Bannerlord.Diplomacy/ViewModel/WarExhaustionMapIndicatorVM.cs
index 1d60aae1..4f798c52 100644
--- a/src/Bannerlord.Diplomacy/ViewModel/WarExhaustionMapIndicatorVM.cs
+++ b/src/Bannerlord.Diplomacy/ViewModel/WarExhaustionMapIndicatorVM.cs
@@ -1,5 +1,7 @@
using Diplomacy.Events;
+using System;
+
using TaleWorlds.CampaignSystem;
using TaleWorlds.Library;
@@ -16,13 +18,7 @@ public WarExhaustionMapIndicatorVM()
{
_kingdomsAtWar = new MBBindingList();
RefreshValues();
-#if v100 || v101 || v102 || v103
- CampaignEvents.WarDeclared.AddNonSerializedListener(this, HandleStanceChange);
- CampaignEvents.MakePeace.AddNonSerializedListener(this, HandleStanceChange);
-#else
- CampaignEvents.WarDeclared.AddNonSerializedListener(this, (arg1, arg2, _) => HandleStanceChange(arg1, arg2));
- CampaignEvents.MakePeace.AddNonSerializedListener(this, (arg1, arg2, _) => HandleStanceChange(arg1, arg2));
-#endif
+ DiplomacyEvents.WarExhaustionInitialized.AddNonSerializedListener(this, HandleStanceChange);
CampaignEvents.ClanChangedKingdom.AddNonSerializedListener(this, (x, _, _, _, _) => HandleClanChangedKingdom(x));
DiplomacyEvents.WarExhaustionAdded.AddNonSerializedListener(this, HandleWarExhaustionChange);
Settings.Instance!.PropertyChanged += Settings_PropertyChanged;
@@ -33,7 +29,7 @@ private void HandleClanChangedKingdom(Clan clan)
if (Clan.PlayerClan == clan) RefreshValues();
}
- private void HandleWarExhaustionChange(WarExhaustionEvent warExhaustionEvent)
+ private void HandleWarExhaustionChange(WarExhaustionAddedEvent warExhaustionEvent)
{
var playerKingdom = Clan.PlayerClan.Kingdom;
if (warExhaustionEvent.Kingdom == playerKingdom || warExhaustionEvent.OtherKingdom == playerKingdom)
@@ -41,21 +37,18 @@ private void HandleWarExhaustionChange(WarExhaustionEvent warExhaustionEvent)
item.UpdateWarExhaustion();
}
- private void HandleStanceChange(IFaction arg1, IFaction arg2)
+ private void HandleStanceChange(WarExhaustionInitializedEvent warExhaustionEvent)
{
- if (Clan.PlayerClan.MapFaction is Kingdom playerKingdom
- && arg1 is Kingdom kingdom1
- && arg2 is Kingdom kingdom2
- && (kingdom1 == playerKingdom || kingdom2 == playerKingdom))
+ if (Clan.PlayerClan.MapFaction is Kingdom playerKingdom && (warExhaustionEvent.Kingdom == playerKingdom || warExhaustionEvent.OtherKingdom == playerKingdom))
RefreshValues();
}
public override void OnFinalize()
{
base.OnFinalize();
- CampaignEvents.WarDeclared.ClearListeners(this);
- CampaignEvents.MakePeace.ClearListeners(this);
+
CampaignEvents.ClanChangedKingdom.ClearListeners(this);
+ DiplomacyEvents.WarExhaustionInitialized.ClearListeners(this);
DiplomacyEvents.WarExhaustionAdded.ClearListeners(this);
}
diff --git a/src/Bannerlord.Diplomacy/WarExhaustion/WarExhaustionManager.EventHandling.cs b/src/Bannerlord.Diplomacy/WarExhaustion/WarExhaustionManager.EventHandling.cs
index ea2cf5f4..60ed004b 100644
--- a/src/Bannerlord.Diplomacy/WarExhaustion/WarExhaustionManager.EventHandling.cs
+++ b/src/Bannerlord.Diplomacy/WarExhaustion/WarExhaustionManager.EventHandling.cs
@@ -174,7 +174,7 @@ static void InvokeIfApplicableForValue(Kingdom kingdom1, Kingdom kingdom2, WarEx
{
if (warExhaustionToAdd != 0f)
{
- DiplomacyEvents.Instance.OnWarExhaustionAdded(new WarExhaustionEvent(kingdom1, kingdom2, warExhaustionType, warExhaustionToAdd));
+ DiplomacyEvents.Instance.OnWarExhaustionAdded(new WarExhaustionAddedEvent(kingdom1, kingdom2, warExhaustionType, warExhaustionToAdd));
}
}
}
diff --git a/src/Bannerlord.Diplomacy/WarExhaustion/WarExhaustionManager.cs b/src/Bannerlord.Diplomacy/WarExhaustion/WarExhaustionManager.cs
index 05ff0ac1..01a17ea9 100644
--- a/src/Bannerlord.Diplomacy/WarExhaustion/WarExhaustionManager.cs
+++ b/src/Bannerlord.Diplomacy/WarExhaustion/WarExhaustionManager.cs
@@ -1,4 +1,5 @@
-using Diplomacy.Helpers;
+using Diplomacy.Events;
+using Diplomacy.Helpers;
using Diplomacy.WarExhaustion.EventRecords;
using System;
@@ -83,6 +84,7 @@ public void ClearWarExhaustion(Kingdom kingdom1, Kingdom kingdom2)
_warExhaustionScores.Remove(key);
_warExhaustionRates.Remove(key);
_warExhaustionEventRecords.Remove(key);
+ DiplomacyEvents.Instance.OnWarExhaustionInitialized(new WarExhaustionInitializedEvent(kingdom1, kingdom2));
}
}
@@ -91,9 +93,10 @@ internal void RegisterWarExhaustion(Kingdom kingdom1, Kingdom kingdom2)
var key = CreateKey(kingdom1, kingdom2, out var kingdoms, checkStates: false);
if (key is not null)
{
- _warExhaustionRates[key] = new(0f, 0f, hasActiveQuest: !IsValidQuestState(kingdom1, kingdom2));
+ _warExhaustionScores[key] = new(0f, 0f, hasActiveQuest: !IsValidQuestState(kingdom1, kingdom2));
RegisterWarExhaustionMultiplier(kingdoms!);
_warExhaustionEventRecords[key] = new();
+ DiplomacyEvents.Instance.OnWarExhaustionInitialized(new WarExhaustionInitializedEvent(kingdom1, kingdom2));
}
}