Skip to content

Commit

Permalink
Codestyle fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
artifixer committed May 15, 2024
1 parent 6b8c5c3 commit 01b79e1
Show file tree
Hide file tree
Showing 18 changed files with 23 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ private void OnHeroKilled(Hero victim, Hero killer, KillCharacterAction.KillChar
_warExhaustionManager.AddHeroPerishedWarExhaustion(kingdoms, victim, killer.PartyBelongedTo?.Name ?? effector!.Name, detail);
}


private static bool VerifyEventSides(PartyBase attackerSideLeaderParty, PartyBase defenderSideLeaderParty, out Kingdom? attacker, out Kingdom? defender)
{
if ((attackerSideLeaderParty.IsMobile && (attackerSideLeaderParty.MobileParty?.IsBandit ?? false)) || (defenderSideLeaderParty.IsMobile && (defenderSideLeaderParty.MobileParty?.IsBandit ?? false))
Expand All @@ -195,7 +194,7 @@ private static bool VerifyEventSides(PartyBase attackerSideLeaderParty, PartyBas

private static bool VerifyEventSides(PartyBase effectorSideParty, Hero effectedSideHero, out Kingdom? effector, out Kingdom? effected)
{
if (effectorSideParty.IsMobile && (effectorSideParty.MobileParty?.IsBandit ?? false)
if ((effectorSideParty.IsMobile && (effectorSideParty.MobileParty?.IsBandit ?? false))
|| effectorSideParty.MapFaction == null || effectorSideParty.MapFaction.IsBanditFaction
|| effectedSideHero.MapFaction == null || effectedSideHero.MapFaction.IsBanditFaction
|| effectorSideParty.MapFaction is not Kingdom effectorKingdom || effectedSideHero.MapFaction is not Kingdom effectedKingdom
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private static uint GetUniqueSigilColor(uint backgroundColor)
.Where(x => !currentSigilColors.Contains(x))
.ToList();

if (colors.Any())
if (colors.Count > 0)
selectedColor = colors.GetRandomElementInefficiently();
}

Expand Down
4 changes: 2 additions & 2 deletions src/Bannerlord.Diplomacy/CivilWar/FactionNameGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public static TextObject GenerateKingdomName(RebelFaction rebelFaction)
string? kingdomTitle;
var culture = rebelFaction.Clans.Where(x => !x.IsEliminated).Select(x => x.Culture.StringId).GroupBy(x => x).OrderByDescending(x => x.Count()).First().Key;
CultureToKingdomTitles.TryGetValue(culture, out var cultureTitles);
if (cultureTitles is not null && cultureTitles.Any() && MBRandom.RandomFloat < 0.5)
if (cultureTitles is not null && cultureTitles.Count > 0 && MBRandom.RandomFloat < 0.5)
{
kingdomTitle = ResolveTitle(cultureTitles);
}
Expand All @@ -299,7 +299,7 @@ public static TextObject GenerateKingdomName(RebelFaction rebelFaction)
kingdomTitle = ResolveTitle(CommonKingdomTitles);
}

var kingdomName = CultureToKingdomNames.TryGetValue(culture, out var value) && value.Any() ? new TextObject(value.GetRandomElement()) : rebelFaction.SponsorClan.Name;
var kingdomName = CultureToKingdomNames.TryGetValue(culture, out var value) && value.Count > 0 ? new TextObject(value.GetRandomElement()) : rebelFaction.SponsorClan.Name;

return new TextObject(kingdomTitle, new Dictionary<string, object> { { "CLAN_NAME", kingdomName } });
}
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 @@ -138,7 +138,7 @@ public void RemoveClan(Clan clan)
if (_participatingClans.Contains(clan))
{
var remainingClanList = _participatingClans.Where(x => x != clan && !x.IsEliminated).ToList();
if (!remainingClanList.Any())
if (remainingClanList.Count <= 0)
{
RebelFactionManager.DestroyRebelFaction(this);
return;
Expand Down
2 changes: 1 addition & 1 deletion src/Bannerlord.Diplomacy/CivilWar/RebelFactionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public static Kingdom GetCivilWarLoser(Kingdom kingdomMakingPeace, Kingdom other
{
return (WarExhaustionManager.Instance?.GetWarResult(kingdomMakingPeace, otherKingdom) ?? WarExhaustionManager.WarResult.None) switch
{
WarExhaustionManager.WarResult.Tie when kingdomMakingPeace.Fiefs.Any() => TributeHelper.GetBaseValueForTrubute(kingdomMakingPeace, otherKingdom) < 0 ? otherKingdom : kingdomMakingPeace,
WarExhaustionManager.WarResult.Tie when kingdomMakingPeace.Fiefs.Count > 0 => TributeHelper.GetBaseValueForTrubute(kingdomMakingPeace, otherKingdom) < 0 ? otherKingdom : kingdomMakingPeace,
>= WarExhaustionManager.WarResult.PyrrhicVictory => otherKingdom,
_ => kingdomMakingPeace,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private static void GetNotificationInquiryTitleAndBody(Kingdom kingdomMakingPeac
var rebelIsMakingPeace = kingdomMakingPeace.IsRebelKingdomOf(otherKingdom);
var originalIsMakingPeace = otherKingdom.IsRebelKingdomOf(kingdomMakingPeace);

if (!isATie && rebelIsMakingPeace || originalIsMakingPeace)
if ((!isATie && rebelIsMakingPeace) || originalIsMakingPeace)
{
var strRebelArgs = new Dictionary<string, object>
{
Expand All @@ -105,7 +105,6 @@ private static void GetNotificationInquiryTitleAndBody(Kingdom kingdomMakingPeac
return;
}


var strArgs = new Dictionary<string, object>
{
{"ORGANIZATIONAL_EXPENSES", diplomacyCost.GoldCost.Value},
Expand Down Expand Up @@ -208,7 +207,7 @@ private static string GetPeaceInquiryText(Kingdom kingdomMakingPeace, Kingdom ot
var rebelIsMakingPeace = kingdomMakingPeace.IsRebelKingdomOf(otherKingdom);
var originalIsMakingPeace = otherKingdom.IsRebelKingdomOf(kingdomMakingPeace);

if (!isATie && rebelIsMakingPeace || originalIsMakingPeace)
if ((!isATie && rebelIsMakingPeace) || originalIsMakingPeace)
{
var strRebelArgs = new Dictionary<string, object>
{
Expand Down Expand Up @@ -336,7 +335,7 @@ private static bool ShouldAnyFiefsBeReturned(Kingdom kingdomMakingPeace, Kingdom
if (!Settings.Instance!.EnableWarExhaustion || !Settings.Instance!.EnableFiefRepatriation || !WarExhaustionManager.Instance!.HasMaxWarExhaustion(kingdomMakingPeace, otherKingdom))
return false;

if (!kingdomMakingPeace.Fiefs.Any())
if (kingdomMakingPeace.Fiefs.Count <= 0)
return false;

if (kingdomMakingPeace.IsRebelKingdomOf(otherKingdom) || (otherKingdom.IsRebelKingdomOf(kingdomMakingPeace) && kingdomMakingPeace.GetRebelFactions().Any(x => x.RebelKingdom == otherKingdom && x is not SecessionFaction)))
Expand Down
4 changes: 2 additions & 2 deletions src/Bannerlord.Diplomacy/Helpers/MessageHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static void SendFailedActionMessage(string action, List<string> exception
{
var sb = new StringBuilder();
sb.Append(action);
if (exceptions.Any()) sb.Append(exceptions.First());
if (exceptions.Count > 0) sb.Append(exceptions.First());

InformationManager.DisplayMessage(new InformationMessage(sb.ToString()));
}
Expand All @@ -22,7 +22,7 @@ public static void SendFailedActionMessage(string action, List<TextObject> excep
{
var sb = new StringBuilder();
sb.Append(action);
if (exceptions.Any()) sb.Append(exceptions.First());
if (exceptions.Count > 0) sb.Append(exceptions.First());

InformationManager.DisplayMessage(new InformationMessage(sb.ToString()));
}
Expand Down
4 changes: 2 additions & 2 deletions src/Bannerlord.Diplomacy/Messengers/MessengerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ public void SendMessengerWithCost(Hero targetHero, GoldCost diplomacyCost)

public static bool IsTargetHeroAvailable(Hero targetHero)
{
var available = targetHero.IsActive || targetHero.IsWanderer && targetHero.HeroState == Hero.CharacterStates.NotSpawned;
var available = targetHero.IsActive || (targetHero.IsWanderer && targetHero.HeroState == Hero.CharacterStates.NotSpawned);
return available && !targetHero.IsHumanPlayerCharacter;
}

Expand All @@ -362,7 +362,7 @@ public static bool IsTargetHeroAvailable(Hero targetHero, out TextObject excepti
return false;
}

var available = targetHero.IsActive || targetHero.IsWanderer && targetHero.HeroState == Hero.CharacterStates.NotSpawned;
var available = targetHero.IsActive || (targetHero.IsWanderer && targetHero.HeroState == Hero.CharacterStates.NotSpawned);
if (!available)
{
exception = new("{=bLR91Eob}{REASON}The messenger won't be able to reach the addressee.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public override bool IsWarDecisionAllowedBetweenKingdoms(Kingdom kingdom1, Kingd
if (isWarDecisionAllowed)
{
var listExceptions = DeclareWarConditions.Instance.CanApplyExceptions(kingdom1, kingdom2, bypassCosts: true);
if (listExceptions is not null && listExceptions.Any())
if (listExceptions is not null && listExceptions.Count > 0)
{
reason = listExceptions.FirstOrDefault() ?? TextObject.Empty;
isWarDecisionAllowed = false;
Expand All @@ -56,7 +56,7 @@ public override bool IsPeaceDecisionAllowedBetweenKingdoms(Kingdom kingdom1, Kin
if (isPeaceDecisionAllowed)
{
var listExceptions = MakePeaceConditions.Instance.CanApplyExceptions(kingdom1, kingdom2, bypassCosts: true);
if (listExceptions is not null && listExceptions.Any())
if (listExceptions is not null && listExceptions.Count > 0)
{
reason = listExceptions.FirstOrDefault() ?? TextObject.Empty;
isPeaceDecisionAllowed = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ public override int Compare(GrantFiefItemVM? x, GrantFiefItemVM? y)
{
if (_isAcending)
{

return Comparer<string?>.Default.Compare(x?.Settlement.Name.ToString(), y?.Settlement.Name.ToString());
}
return Comparer<string?>.Default.Compare(y?.Settlement.Name.ToString(), x?.Settlement.Name.ToString());
Expand All @@ -201,7 +200,6 @@ public override int Compare(GrantFiefItemVM? x, GrantFiefItemVM? y)
{
if (_isAcending)
{

return Comparer<string?>.Default.Compare(x?.Settlement.OwnerClan?.Name.ToString(), y?.Settlement.OwnerClan?.Name.ToString());
}
return Comparer<string?>.Default.Compare(y?.Settlement.OwnerClan?.Name.ToString(), x?.Settlement.OwnerClan?.Name.ToString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private BasicTooltipViewModel UpdateValueHint(int factionIndex, WarExhaustionBre
};

var list = new List<TooltipProperty>();
if (factionEventRecords is not null && factionEventRecords.Any())
if (factionEventRecords is not null && factionEventRecords.Count > 0)
{
list.Add(new TooltipProperty(Text, factionValue > 0 ? factionValue.ToString() : string.Empty, 0, false, TooltipProperty.TooltipPropertyFlags.Title));
foreach (var (eventDescription, exhaustionValue) in factionEventRecords)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,5 @@ public DiplomacyPanelPrefabExtension()
[PrefabExtensionXmlDocument]
[UsedImplicitly]
public XmlDocument GetPrefabExtension() => _document;

}
}
2 changes: 0 additions & 2 deletions src/Bannerlord.Diplomacy/ViewModelMixin/KingdomClanVMMixin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ namespace Diplomacy.ViewModelMixin
[UsedImplicitly]
internal sealed class KingdomClanVMMixin : BaseViewModelMixin<KingdomClanVM>
{

private bool _canGrantFiefToClan;
private readonly GrantFiefInterface _grantFiefInterface;
private readonly DonateGoldInterface _donateGoldInterface;
Expand All @@ -46,7 +45,6 @@ public KingdomClanVMMixin(KingdomClanVM vm) : base(vm)
RefreshCanGrantFief();
}


public override void OnFinalize()
{
base.OnFinalize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ internal sealed class KingdomDiplomacyVMMixin : BaseViewModelMixin<KingdomDiplom
private static readonly TextObject _TOverview = new("{=OvbY5qxL}Overview");
private static readonly TextObject _TDiplomacy = new("{=Q2vXbwvC}Diplomacy");


private string _numOfPlayerAlliancesText = null!;


private MBBindingList<KingdomTruceItemVM> _playerAlliances;
private bool _showOverview;
private bool _showStats;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private void UpdateActionAvailability()
["TRIBUTE_GET"] = tributeValue < 0 ? 1 : 0,
["TRIBUTE"] = Math.Abs(tributeValue),
}),
["FIEFS_TO_RETURN"] = new TextObject(_TFiefs, new() { ["FIEFS_ANY"] = KingdomPeaceAction.GetFiefsSuitableToBeReturned(_faction1, _faction2).Any() ? 1 : 0 }),
["FIEFS_TO_RETURN"] = new TextObject(_TFiefs, new() { ["FIEFS_ANY"] = KingdomPeaceAction.GetFiefsSuitableToBeReturned(_faction1, _faction2).Count > 0 ? 1 : 0 }),
}).ToString();
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public WarExhaustionEventRecord(CampaignTime eventDate, int faction1Value, float

protected static TextObject? FindTextWithVariation(string textToFind)
{
int variationSeparatorIdx = textToFind.LastIndexOf(".");
int variationSeparatorIdx = textToFind.LastIndexOf('.');
if (variationSeparatorIdx > 0)
{
var id = textToFind.Substring(0, variationSeparatorIdx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ internal List<WarExhaustionBreakdown> GetWarExhaustionBreakdown(Kingdom kingdom1
private static void GetBreakdownByEventType(WarExhaustionType warExhaustionType, List<WarExhaustionBreakdown> result, List<WarExhaustionEventRecord> warExhaustionEventRecords, bool reversedKeyOrder, bool useValue = false, bool addIfEmpty = true)
{
var eventRecords = warExhaustionEventRecords.Where(r => r.WarExhaustionType == warExhaustionType).OrderBy(r => r.EventDate).ToList();
if (!eventRecords.Any() && !addIfEmpty)
if (eventRecords.Count <= 0 && !addIfEmpty)
return;

int valueFaction1 = 0, valueFaction2 = 0;
Expand Down Expand Up @@ -127,7 +127,7 @@ private static void GetBreakdownByEventType(WarExhaustionType warExhaustionType,
var recordsToShow = originalList.OrderByDescending(rec => rec.EventDate).Take(Settings.Instance!.MaxShownBreakdownEntries).OrderBy(rec => rec.EventDate).ToList();
var recordsToSummarize = originalList.Except(recordsToShow).OrderBy(rec => rec.EventDate).ToList();

if (!recordsToSummarize.Any())
if (recordsToSummarize.Count <= 0)
return recordsToShow.Select(x => (x.EventDescription, x.ExhaustionValue)).ToList();

CampaignTime minDate = CampaignTime.Never, maxDate = CampaignTime.Zero; float totalValue = 0f; int recordCount = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ private WarExhaustionRecord GetDailyWarExhaustionDelta(Kingdoms kingdoms, Campai
GetWarExhaustionPerDay(out var warExhaustionPerDay, out var warExhaustionPerDayOccupied);
var faction1 = kingdoms.ReversedKeyOrder ? kingdoms.Kingdom2 : kingdoms.Kingdom1;
var faction2 = kingdoms.ReversedKeyOrder ? kingdoms.Kingdom1 : kingdoms.Kingdom2;
var faction1IsOccupied = !faction1.Fiefs.Any();
var faction2IsOccupied = !faction2.Fiefs.Any();
var faction1IsOccupied = faction1.Fiefs.Count <= 0;
var faction2IsOccupied = faction2.Fiefs.Count <= 0;
var faction1WarExhaustion = faction1IsOccupied ? warExhaustionPerDayOccupied : warExhaustionPerDay;
var faction2WarExhaustion = faction2IsOccupied ? warExhaustionPerDayOccupied : warExhaustionPerDay;
var hasActiveQuest = !IsValidQuestState(kingdoms.Kingdom1, kingdoms.Kingdom2);
Expand Down Expand Up @@ -708,7 +708,7 @@ private static void AddOccupationEventForFaction(IFaction faction, CampaignTime

private CampaignTime GetLastOccupationDate(Kingdom kingdom, out IFaction? effector)
{
if (!kingdom.Fiefs.Any())
if (kingdom.Fiefs.Count <= 0)
{
for (int index = Campaign.Current.LogEntryHistory.GameActionLogs.Count - 1; index >= 0; --index)
{
Expand Down

0 comments on commit 01b79e1

Please sign in to comment.