Skip to content
This repository has been archived by the owner on Jul 17, 2023. It is now read-only.

Commit

Permalink
optimizations & fixes & bump version number
Browse files Browse the repository at this point in the history
  • Loading branch information
Cytraen committed Aug 3, 2020
1 parent 6266fc8 commit 8d5f3a5
Show file tree
Hide file tree
Showing 14 changed files with 108 additions and 143 deletions.
26 changes: 13 additions & 13 deletions Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
Copyright (C) 2020 ashakoor
This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -40,12 +40,12 @@ public static bool IsThisCharacterInPlayerClan(this CharacterObject character)

public static bool IsThisCharacterInPlayerArmy(this CharacterObject character)
{
return character?.HeroObject?.PartyBelongedTo?.Army?.IsPlayerInThisArmy() == true;
return character?.HeroObject?.IsThisHeroInPlayerArmy() == true;
}

public static bool IsThisCharacterInPlayerKingdom(this CharacterObject character)
{
return character?.HeroObject?.Clan?.Kingdom?.IsPlayerInThisKingdom() == true;
return character?.HeroObject?.Clan?.IsThisClanInPlayerKingdom() == true;
}
}

Expand All @@ -54,7 +54,7 @@ internal static partial class Extensions
{
public static bool IsThisHeroPlayerHero(this Hero hero)
{
return hero?.CharacterObject?.IsThisCharacterPlayerCharacter() == true;
return hero?.IsHumanPlayerCharacter == true;
}

public static bool IsThisHeroPlayerCompanion(this Hero hero)
Expand All @@ -69,7 +69,7 @@ public static bool IsThisHeroInPlayerClan(this Hero hero)

public static bool IsThisHeroInPlayerArmy(this Hero hero)
{
return hero?.PartyBelongedTo?.Army?.IsPlayerInThisArmy() == true;
return hero?.PartyBelongedTo?.IsThisPartyInPlayerArmy() == true;
}

public static bool IsThisHeroInPlayerKingdom(this Hero hero)
Expand All @@ -83,12 +83,12 @@ internal static partial class Extensions
{
public static bool IsPlayerLeadingThisParty(this PartyBase partyBase)
{
return partyBase?.LeaderHero?.IsThisHeroPlayerHero() == true;
return partyBase?.MobileParty?.IsPlayerLeadingThisParty() == true;
}

public static bool IsThisPartyInPlayerClan(this PartyBase partyBase)
{
return partyBase?.LeaderHero?.Clan?.IsPlayerLeadingThisClan() == true;
return partyBase?.Owner?.IsThisHeroPlayerHero() == true;
}

public static bool IsThisPartyInPlayerArmy(this PartyBase partyBase)
Expand All @@ -98,12 +98,12 @@ public static bool IsThisPartyInPlayerArmy(this PartyBase partyBase)

public static bool IsThisPartyInPlayerKingdom(this PartyBase partyBase)
{
return partyBase?.LeaderHero?.Clan?.Kingdom?.IsPlayerInThisKingdom() == true;
return partyBase?.Owner?.IsThisHeroInPlayerKingdom() == true;
}

public static bool IsThisPartyGarrison(this PartyBase party)
{
return party?.MobileParty?.IsGarrison() == true;
return party?.MobileParty?.IsThisPartyGarrison() == true;
}

public static bool IsPartyOwnedByPlayer(this PartyBase party)
Expand Down Expand Up @@ -132,7 +132,7 @@ public static bool IsPlayerLeadingThisParty(this MobileParty mobileParty)

public static bool IsThisPartyInPlayerClan(this MobileParty mobileParty)
{
return mobileParty?.LeaderHero?.Clan?.IsPlayerLeadingThisClan() == true;
return mobileParty?.LeaderHero?.IsThisHeroInPlayerClan() == true;
}

public static bool IsThisPartyInPlayerArmy(this MobileParty mobileParty)
Expand All @@ -142,10 +142,10 @@ public static bool IsThisPartyInPlayerArmy(this MobileParty mobileParty)

public static bool IsThisPartyInPlayerKingdom(this MobileParty mobileParty)
{
return mobileParty?.LeaderHero?.Clan?.Kingdom?.IsPlayerInThisKingdom() == true;
return mobileParty?.Party?.IsThisPartyInPlayerKingdom() == true;
}

public static bool IsGarrison(this MobileParty party)
public static bool IsThisPartyGarrison(this MobileParty party)
{
return party?.IsGarrison == true;
}
Expand Down Expand Up @@ -190,7 +190,7 @@ public static bool IsPlayerInThisArmy(this Army army)

public static bool IsPlayerLeadingThisArmy(this Army army)
{
return army?.LeaderParty?.LeaderHero?.IsThisHeroPlayerHero() == true;
return army?.LeaderParty?.IsPlayerLeadingThisParty() == true;
}

public static bool IsThisArmyInPlayerKingdom(this Army army)
Expand Down
42 changes: 0 additions & 42 deletions PatchAppliesTo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,48 +22,6 @@ namespace UnlimitLord
{
public class PatchAppliesTo
{
private readonly AppliesToEnum _applyEnum;

public PatchAppliesTo(AppliesToEnum applyEnum)
{
_applyEnum = applyEnum;
}

public AppliesToEnum GetWho()
{
return _applyEnum;
}

public override string ToString()
{
switch (_applyEnum)
{
case AppliesToEnum.PlayerOnly:
return "Player only";

case AppliesToEnum.PlayerCompanions:
return "Player and companions";

case AppliesToEnum.PlayerParty:
return "Player's party";

case AppliesToEnum.PlayerClan:
return "Player's clan";

case AppliesToEnum.PlayerArmy:
return "Player's army";

case AppliesToEnum.PlayerKingdom:
return "Player's kingdom";

case AppliesToEnum.Everyone:
return "Everyone";

default:
throw new NotSupportedException();
}
}

public static bool DoesPatchApply(AppliesToEnum @enum, CharacterObject character)
{
switch (@enum)
Expand Down
2 changes: 1 addition & 1 deletion Patches/CraftingCampaignBehaviorPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace UnlimitLord.Patches
internal static class CraftingCampaignBehaviorPatch
{
private static Settings Setting => Settings.Instance;
private static AppliesToEnum AppliesTo => Setting.CraftingStaminaAppliesTo.SelectedValue.GetWho();
private static AppliesToEnum AppliesTo => Setting.CraftingStaminaAppliesTo.SelectedValue;

[HarmonyPatch(typeof(CraftingCampaignBehavior), "GetMaxHeroCraftingStamina")]
internal static class MaximumStamina
Expand Down
2 changes: 1 addition & 1 deletion Patches/DefaultCharacterStatsModelPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal static class DefaultCharacterStatsModelPatch
{
private static Settings Setting => Settings.Instance;
private static bool Enabled => Setting.HeroHealthAmountEnabled;
private static AppliesToEnum AppliesTo => Setting.HeroHealthAmountAppliesTo.SelectedValue.GetWho();
private static AppliesToEnum AppliesTo => Setting.HeroHealthAmountAppliesTo.SelectedValue;
private static float Multiplier => Setting.HeroHealthAmountMultiplier;
private static int Minimum => Setting.MinimumHeroHealthAmount;
private static int Maximum => Setting.MaximumHeroHealthAmount;
Expand Down
4 changes: 2 additions & 2 deletions Patches/DefaultClanFinanceModelPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ internal static class DefaultClanFinanceModelPatch
{
private static Settings Setting => Settings.Instance;
private static bool Enabled => Setting.GarrisonWageEnabled;
private static AppliesToEnum AppliesTo => Setting.GarrisonWageAppliesTo.SelectedValue.GetWho();
private static AppliesToEnum AppliesTo => Setting.GarrisonWageAppliesTo.SelectedValue;
private static float Multiplier => Setting.GarrisonWageMultiplier;
private static int Minimum => Setting.MinimumGarrisonWage;
private static int Maximum => Setting.MaximumGarrisonWage;

internal static int Postfix(int result, MobileParty mobileParty)
{
if (!mobileParty.IsGarrison() || !PatchAppliesTo.DoesPatchApply(AppliesTo, mobileParty))
if (!mobileParty.IsThisPartyGarrison() || !PatchAppliesTo.DoesPatchApply(AppliesTo, mobileParty))
return result;

return Math.ClampInt((int)(result * Multiplier), Minimum, Maximum);
Expand Down
2 changes: 1 addition & 1 deletion Patches/DefaultClanTierModelPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal static class DefaultClanTierModelPatch
internal static class Party
{
private static bool Enabled => Setting.PartyAmountEnabled;
private static AppliesToEnum AppliesTo => Setting.PartyAmountAppliesTo.SelectedValue.GetWho();
private static AppliesToEnum AppliesTo => Setting.PartyAmountAppliesTo.SelectedValue;
private static float Multiplier => Setting.PartyAmountMultiplier;
private static int Minimum => Setting.MinimumPartyAmount;
private static int Maximum => Setting.MaximumPartyAmount;
Expand Down
2 changes: 1 addition & 1 deletion Patches/DefaultMobilePartyFoodConsumptionModelPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal static class Party
{
private static Settings Setting => Settings.Instance;
private static bool Enabled => Setting.PartyFoodConsumptionEnabled;
private static AppliesToEnum AppliesTo => Setting.PartyFoodConsumptionAppliesTo.SelectedValue.GetWho();
private static AppliesToEnum AppliesTo => Setting.PartyFoodConsumptionAppliesTo.SelectedValue;
private static float Multiplier => Setting.PartyFoodConsumptionMultiplier;
private static float Minimum => Setting.MinimumPartyFoodConsumption;
private static float Maximum => Setting.MaximumPartyFoodConsumption;
Expand Down
4 changes: 2 additions & 2 deletions Patches/DefaultPartyHealingModelPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal static class DefaultPartyHealingModelPatch
internal static class Troops
{
private static bool Enabled => Setting.TroopHealingRateEnabled;
private static AppliesToEnum AppliesTo => Setting.TroopHealingRateAppliesTo.SelectedValue.GetWho();
private static AppliesToEnum AppliesTo => Setting.TroopHealingRateAppliesTo.SelectedValue;
private static float Multiplier => Setting.TroopHealingRateMultiplier;
private static float Minimum => Setting.MinimumTroopHealingRate;
private static float Maximum => Setting.MaximumTroopHealingRate;
Expand All @@ -52,7 +52,7 @@ internal static bool Prepare()
internal static class Heroes
{
private static bool Enabled => Setting.HeroHealingRateEnabled;
private static AppliesToEnum AppliesTo => Setting.HeroHealingRateAppliesTo.SelectedValue.GetWho();
private static AppliesToEnum AppliesTo => Setting.HeroHealingRateAppliesTo.SelectedValue;
private static float Multiplier => Setting.HeroHealingRateMultiplier;
private static float Minimum => Setting.MinimumHeroHealingRate;
private static float Maximum => Setting.MaximumHeroHealingRate;
Expand Down
2 changes: 1 addition & 1 deletion Patches/DefaultPartyMoraleModelPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal static class DefaultPartyMoraleModelPatch
{
private static Settings Setting => Settings.Instance;
private static bool Enabled => Setting.MoraleEnabled;
private static AppliesToEnum AppliesTo => Setting.MoraleAppliesTo.SelectedValue.GetWho();
private static AppliesToEnum AppliesTo => Setting.MoraleAppliesTo.SelectedValue;
private static float Multiplier => Setting.MoraleMultiplier;
private static float Minimum => Setting.MinimumMorale;
private static float Maximum => Setting.MaximumMorale;
Expand Down
14 changes: 10 additions & 4 deletions Patches/DefaultPartySizeLimitModelPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal static class DefaultPartySizeLimitModelPatch
internal static class Castle
{
private static bool Enabled => Setting.CastleGarrisonSizeEnabled;
private static AppliesToEnum AppliesTo => Setting.CastleGarrisonSizeAppliesTo.SelectedValue.GetWho();
private static AppliesToEnum AppliesTo => Setting.CastleGarrisonSizeAppliesTo.SelectedValue;
private static float Multiplier => Setting.CastleGarrisonSizeMultiplier;
private static int Minimum => Setting.MinimumCastleGarrisonSize;
private static int Maximum => Setting.MaximumCastleGarrisonSize;
Expand All @@ -55,7 +55,7 @@ internal static bool Prepare()
internal static class Town
{
private static bool Enabled => Setting.TownGarrisonSizeEnabled;
private static AppliesToEnum AppliesTo => Setting.TownGarrisonSizeAppliesTo.SelectedValue.GetWho();
private static AppliesToEnum AppliesTo => Setting.TownGarrisonSizeAppliesTo.SelectedValue;
private static float Multiplier => Setting.TownGarrisonSizeMultiplier;
private static int Minimum => Setting.MinimumTownGarrisonSize;
private static int Maximum => Setting.MaximumTownGarrisonSize;
Expand All @@ -81,7 +81,7 @@ internal static bool Prepare()
internal static class Troops
{
private static bool Enabled => Setting.PartyTroopAmountEnabled;
private static AppliesToEnum AppliesTo => Setting.PartyTroopAmountAppliesTo.SelectedValue.GetWho();
private static AppliesToEnum AppliesTo => Setting.PartyTroopAmountAppliesTo.SelectedValue;
private static float Multiplier => Setting.PartyTroopAmountMultiplier;
private static int Minimum => Setting.MinimumPartyTroopAmount;
private static int Maximum => Setting.MaximumPartyTroopAmount;
Expand All @@ -91,6 +91,9 @@ internal static int Postfix(int result, PartyBase party, StatExplainer explanati
if (!PatchAppliesTo.DoesPatchApply(AppliesTo, party))
return result;

if (party.IsThisPartyGarrison())
return result;

return Math.ClampAndExplainInt((int)(result * Multiplier), explanation, Minimum, Maximum);
}

Expand All @@ -104,7 +107,7 @@ internal static bool Prepare()
internal static class Prisoners
{
private static bool Enabled => Setting.PartyPrisonerAmountEnabled;
private static AppliesToEnum AppliesTo => Setting.PartyPrisonerAmountAppliesTo.SelectedValue.GetWho();
private static AppliesToEnum AppliesTo => Setting.PartyPrisonerAmountAppliesTo.SelectedValue;
private static float Multiplier => Setting.PartyPrisonerAmountMultiplier;
private static int Minimum => Setting.MinimumPartyPrisonerAmount;
private static int Maximum => Setting.MaximumPartyPrisonerAmount;
Expand All @@ -114,6 +117,9 @@ internal static int Postfix(int result, PartyBase party, StatExplainer explanati
if (!PatchAppliesTo.DoesPatchApply(AppliesTo, party))
return result;

if (party.IsThisPartyGarrison())
return result;

return Math.ClampAndExplainInt((int)(result * Multiplier), explanation, Minimum, Maximum);
}

Expand Down
2 changes: 1 addition & 1 deletion Patches/DefaultPartySpeedCalculatingModelPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal static class DefaultPartySpeedCalculatingModelPatch
{
private static Settings Setting => Settings.Instance;
private static bool Enabled => Setting.MovementSpeedEnabled;
private static AppliesToEnum AppliesTo => Setting.MovementSpeedAppliesTo.SelectedValue.GetWho();
private static AppliesToEnum AppliesTo => Setting.MovementSpeedAppliesTo.SelectedValue;
private static float Multiplier => Setting.MovementSpeedMultiplier;
private static float Minimum => Setting.MinimumMovementSpeed;
private static float Maximum => Setting.MaximumMovementSpeed;
Expand Down
Loading

0 comments on commit 8d5f3a5

Please sign in to comment.