Skip to content

Commit

Permalink
Merge pull request #199 from DiplomacyTeam/dev
Browse files Browse the repository at this point in the history
v1.2.4 release
  • Loading branch information
artifixer committed Feb 10, 2023
2 parents 1d875b9 + 7cd297c commit a86689a
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 32 deletions.
2 changes: 1 addition & 1 deletion build/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!--Module Version-->
<PropertyGroup>
<Version>1.2.3</Version>
<Version>1.2.4</Version>
<GameVersion>1.0.0</GameVersion>
</PropertyGroup>

Expand Down
7 changes: 7 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
21 changes: 14 additions & 7 deletions src/Bannerlord.Diplomacy/CivilWar/RebelFactionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,22 +105,29 @@ public static IEnumerable<RebelFaction> 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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
15 changes: 12 additions & 3 deletions src/Bannerlord.Diplomacy/Events/DiplomacyEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public sealed class DiplomacyEvents
#if v100 || v101 || v102 || v103
private readonly MbEvent<WarDeclaredEvent> _warDeclared = new();
#endif
private readonly MbEvent<WarExhaustionEvent> _warExhaustionAdded = new();
private readonly MbEvent<WarExhaustionInitializedEvent> _warExhaustionInitialized = new();
private readonly MbEvent<WarExhaustionAddedEvent> _warExhaustionAdded = new();

public DiplomacyEvents()
{
Expand All @@ -39,6 +40,7 @@ public DiplomacyEvents()
_warDeclared,
#endif
_kingdomBannerChanged,
_warExhaustionInitialized,
_warExhaustionAdded
};
}
Expand All @@ -63,7 +65,9 @@ public DiplomacyEvents()

public static IMbEvent<Kingdom> KingdomBannerChanged => Instance._kingdomBannerChanged;

public static IMbEvent<WarExhaustionEvent> WarExhaustionAdded => Instance._warExhaustionAdded;
public static IMbEvent<WarExhaustionInitializedEvent> WarExhaustionInitialized => Instance._warExhaustionInitialized;

public static IMbEvent<WarExhaustionAddedEvent> WarExhaustionAdded => Instance._warExhaustionAdded;

internal void OnMessengerSent(Hero hero)
{
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions src/Bannerlord.Diplomacy/Events/WarExhaustionInitializedEvent.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
23 changes: 8 additions & 15 deletions src/Bannerlord.Diplomacy/ViewModel/WarExhaustionMapIndicatorVM.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Diplomacy.Events;

using System;

using TaleWorlds.CampaignSystem;
using TaleWorlds.Library;

Expand All @@ -16,13 +18,7 @@ public WarExhaustionMapIndicatorVM()
{
_kingdomsAtWar = new MBBindingList<WarExhaustionMapIndicatorItemVM>();
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;
Expand All @@ -33,29 +29,26 @@ 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)
foreach (var item in _kingdomsAtWar)
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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Diplomacy.Helpers;
using Diplomacy.Events;
using Diplomacy.Helpers;
using Diplomacy.WarExhaustion.EventRecords;

using System;
Expand Down Expand Up @@ -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));
}
}

Expand All @@ -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));
}
}

Expand Down

0 comments on commit a86689a

Please sign in to comment.