Skip to content
This repository has been archived by the owner on Mar 29, 2022. It is now read-only.

Commit

Permalink
Refactor scouting lore perks
Browse files Browse the repository at this point in the history
Remove the creation of instances in contructors as it creates errors when running other configs not launching the game.
Add implementation for influential trader perk
  • Loading branch information
JoeFwd committed Jun 14, 2020
1 parent 641f33b commit 852ae0b
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 98 deletions.
9 changes: 4 additions & 5 deletions src/CommunityPatch/Patches/PartySpeedSubPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ namespace CommunityPatch.Patches {

public abstract class PartySpeedSubPatch<TPatch> : PerkPatchBase<TPatch>, IPartySpeed where TPatch : PartySpeedSubPatch<TPatch> {

private readonly IPartySpeed _modifyPartySpeed;

protected PartySpeedSubPatch(string perkId) : base(perkId)
=> _modifyPartySpeed = new ModifyPartySpeed(Perk);
protected PartySpeedSubPatch(string perkId) : base(perkId) { }

void IPartySpeed.ModifyFinalSpeed(MobileParty mobileParty, float baseSpeed, ref ExplainedNumber finalSpeed) {
IPartySpeed modifyPartySpeed = new ModifyPartySpeed(Perk);

if (IsPerkConditionFulfilled(mobileParty, baseSpeed, finalSpeed))
_modifyPartySpeed.ModifyFinalSpeed(mobileParty, baseSpeed, ref finalSpeed);
modifyPartySpeed.ModifyFinalSpeed(mobileParty, baseSpeed, ref finalSpeed);
}

protected virtual bool IsPerkConditionFulfilled(MobileParty mobileParty, float baseSpeed, ExplainedNumber finalSpeed)
Expand Down
2 changes: 1 addition & 1 deletion src/CommunityPatch/Patches/PerkPatchBase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using CommunityPatchAnalyzer;
using JetBrains.Annotations;
Expand Down Expand Up @@ -47,7 +48,6 @@ public PerkObject Perk {
_perk = PerkObjectHelpers.Load(_finder);

if (_perk == null) {
//throw new KeyNotFoundException($"Can't find the {PerkName} ({_perkId}) perk.");
CommunityPatchSubModule.Error($"Can't find the {PerkName} ({PerkId}) perk.");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,24 @@
using Patches;
using TaleWorlds.CampaignSystem;
using TaleWorlds.Core;
using static TaleWorlds.Core.TerrainType;

namespace CommunityPatch.Patches.Perks.Cunning.Scouting {

public class DesertLorePatch : PerkPatchBase<DesertLorePatch>, IPartySpeed, IDailyFoodConsumption {
public class DesertLorePatch : ScoutingLorePerk<DesertLorePatch> {

private readonly IDailyFoodConsumption _halfDailyFoodConsumption;
private readonly IPartySpeed _modifyPartySpeed;

public DesertLorePatch() : base("EeQv1qRD") {
_halfDailyFoodConsumption = new HalfDailyFoodConsumption(Perk);
_modifyPartySpeed = new ModifyPartySpeed(Perk);
}
public DesertLorePatch() : base("EeQv1qRD") { }

public override void Apply(Game game) {
Perk.SetPrimaryBonus(0.05f);
base.Apply(game);
}

public void ModifyFinalSpeed(MobileParty mobileParty, float baseSpeed, ref ExplainedNumber finalSpeed) {
if (mobileParty.IsInTerrainType(Desert))
_modifyPartySpeed.ModifyFinalSpeed(mobileParty, baseSpeed, ref finalSpeed);
public override void ModifyFinalSpeed(MobileParty mobileParty, float baseSpeed, ref ExplainedNumber finalSpeed) {
if (!mobileParty.IsInTerrainType(Desert))
return;
base.ModifyFinalSpeed(mobileParty, baseSpeed, ref finalSpeed);
}

public void ModifyDailyFoodConsumption(ref float dailyFoodConsumption, MobileParty mobileParty, StatExplainer dailyFoodConsumptionExplanation)
=> _halfDailyFoodConsumption.ModifyDailyFoodConsumption(ref dailyFoodConsumption, mobileParty, dailyFoodConsumptionExplanation);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,21 @@

namespace CommunityPatch.Patches.Perks.Cunning.Scouting {

namespace CommunityPatch.Patches.Perks.Cunning.Scouting {
public class ForcedMarchPatch : PerkPatchBase<ForcedMarchPatch>, IPartySpeed {

public class ForcedMarchPatch : PerkPatchBase<ForcedMarchPatch>, IPartySpeed {

private readonly IPartySpeed _modifyPartySpeed;

public ForcedMarchPatch() : base("jhZe9Mfo")
=> _modifyPartySpeed = new ModifyPartySpeed(Perk);

public override void Apply(Game game) {
Perk.SetPrimaryBonus(0.03f);
base.Apply(game);
}

public void ModifyFinalSpeed(MobileParty mobileParty, float baseSpeed, ref ExplainedNumber finalSpeed) {
if (mobileParty.Morale > 70f) {
_modifyPartySpeed.ModifyFinalSpeed(mobileParty, baseSpeed, ref finalSpeed);
}

}
public ForcedMarchPatch() : base("jhZe9Mfo") { }

public override void Apply(Game game) {
Perk.SetPrimaryBonus(0.03f);
base.Apply(game);
}

public void ModifyFinalSpeed(MobileParty mobileParty, float baseSpeed, ref ExplainedNumber finalSpeed) {
if (mobileParty.Morale <= 70f)
return;

IPartySpeed modifyPartySpeed = new ModifyPartySpeed(Perk);
modifyPartySpeed.ModifyFinalSpeed(mobileParty, baseSpeed, ref finalSpeed);
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,25 @@
using Patches;
using TaleWorlds.CampaignSystem;
using TaleWorlds.Core;
using static TaleWorlds.Core.TerrainType;

namespace CommunityPatch.Patches.Perks.Cunning.Scouting {

public class ForestLorePatch : PerkPatchBase<ForestLorePatch>, IPartySpeed, IDailyFoodConsumption {
public class ForestLorePatch : ScoutingLorePerk<ForestLorePatch> {

private readonly IDailyFoodConsumption _halfDailyFoodConsumption;
private readonly IPartySpeed _modifyPartySpeed;

public ForestLorePatch() : base("TgOwisdD") {
_halfDailyFoodConsumption = new HalfDailyFoodConsumption(Perk);
_modifyPartySpeed = new ModifyPartySpeed(Perk);
}
public ForestLorePatch() : base("TgOwisdD") { }

public override void Apply(Game game) {
Perk.SetPrimaryBonus(0.05f);
base.Apply(game);
}

public void ModifyFinalSpeed(MobileParty mobileParty, float baseSpeed, ref ExplainedNumber finalSpeed) {
if (mobileParty.IsInTerrainType(Forest))
_modifyPartySpeed.ModifyFinalSpeed(mobileParty, baseSpeed, ref finalSpeed);
public override void ModifyFinalSpeed(MobileParty mobileParty, float baseSpeed, ref ExplainedNumber finalSpeed) {
if (!mobileParty.IsInTerrainType(Forest))
return;

base.ModifyFinalSpeed(mobileParty, baseSpeed, ref finalSpeed);
}

public void ModifyDailyFoodConsumption(ref float dailyFoodConsumption, MobileParty mobileParty, StatExplainer dailyFoodConsumptionExplanation)
=> _halfDailyFoodConsumption.ModifyDailyFoodConsumption(ref dailyFoodConsumption, mobileParty, dailyFoodConsumptionExplanation);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ namespace CommunityPatch.Patches.Perks.Cunning.Scouting {

public class GrasslandNavigatorPatch : PerkPatchBase<GrasslandNavigatorPatch>, IPartySpeed {

private readonly IPartySpeed _modifyPartySpeed;

public GrasslandNavigatorPatch() : base("Ekqj9IFR")
=> _modifyPartySpeed = new ModifyPartySpeed(Perk);
public GrasslandNavigatorPatch() : base("Ekqj9IFR") { }

public override void Apply(Game game) {
Perk.SetPrimaryBonus(0.05f);
base.Apply(game);
}

public void ModifyFinalSpeed(MobileParty mobileParty, float baseSpeed, ref ExplainedNumber finalSpeed) {
if (!mobileParty.IsInSnowyTerrain() && mobileParty.IsInTerrainType(Plain) || mobileParty.IsInTerrainType(Steppe))
_modifyPartySpeed.ModifyFinalSpeed(mobileParty, baseSpeed, ref finalSpeed);
if (mobileParty.IsInSnowyTerrain() || !mobileParty.IsInTerrainType(Plain) && !mobileParty.IsInTerrainType(Steppe))
return;

IPartySpeed modifyPartySpeed = new ModifyPartySpeed(Perk);
modifyPartySpeed.ModifyFinalSpeed(mobileParty, baseSpeed, ref finalSpeed);
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,25 @@
using Patches;
using TaleWorlds.CampaignSystem;
using TaleWorlds.Core;

namespace CommunityPatch.Patches.Perks.Cunning.Scouting {

public class HillsLorePatch : PerkPatchBase<HillsLorePatch>, IPartySpeed, IDailyFoodConsumption {
public class HillsLorePatch : ScoutingLorePerk<HillsLorePatch> {

private readonly IDailyFoodConsumption _halfDailyFoodConsumption;
private readonly IPartySpeed _modifyPartySpeed;

public HillsLorePatch() : base("67UGQ0Kd") {
_halfDailyFoodConsumption = new HalfDailyFoodConsumption(Perk);
_modifyPartySpeed = new ModifyPartySpeed(Perk);
}
public HillsLorePatch() : base("67UGQ0Kd") { }

public override void Apply(Game game) {
Perk.SetPrimaryBonus(0.05f);
base.Apply(game);
}

public void ModifyFinalSpeed(MobileParty mobileParty, float baseSpeed, ref ExplainedNumber finalSpeed) {
if (mobileParty.IsInHillTerrain())
_modifyPartySpeed.ModifyFinalSpeed(mobileParty, baseSpeed, ref finalSpeed);
public override void ModifyFinalSpeed(MobileParty mobileParty, float baseSpeed, ref ExplainedNumber finalSpeed) {
if (!mobileParty.IsInHillTerrain())
return;

base.ModifyFinalSpeed(mobileParty, baseSpeed, ref finalSpeed);
}

public void ModifyDailyFoodConsumption(ref float dailyFoodConsumption, MobileParty mobileParty, StatExplainer dailyFoodConsumptionExplanation)
=> _halfDailyFoodConsumption.ModifyDailyFoodConsumption(ref dailyFoodConsumption, mobileParty, dailyFoodConsumptionExplanation);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,16 @@ namespace CommunityPatch.Patches.Perks.Cunning.Scouting {

public class LayOfTheLandPatch : PerkPatchBase<LayOfTheLandPatch>, IPartySpeed {

private readonly IPartySpeed _modifyPartySpeed;

public LayOfTheLandPatch() : base("P68GX3zY")
=> _modifyPartySpeed = new ModifyPartySpeed(Perk);

public LayOfTheLandPatch() : base("P68GX3zY") { }
public override void Apply(Game game) {
Perk.SetPrimaryBonus(0.03f);
base.Apply(game);
}

public void ModifyFinalSpeed(MobileParty mobileParty, float baseSpeed, ref ExplainedNumber finalSpeed)
// Party Member
=> _modifyPartySpeed.ModifyFinalSpeed(mobileParty, baseSpeed, ref finalSpeed);
public void ModifyFinalSpeed(MobileParty mobileParty, float baseSpeed, ref ExplainedNumber finalSpeed) {
IPartySpeed modifyPartySpeed = new ModifyPartySpeed(Perk);
modifyPartySpeed.ModifyFinalSpeed(mobileParty, baseSpeed, ref finalSpeed);
}

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,25 @@
using Patches;
using TaleWorlds.CampaignSystem;
using TaleWorlds.Core;
using static TaleWorlds.Core.TerrainType;

namespace CommunityPatch.Patches.Perks.Cunning.Scouting {

public class MarshesLorePatch : PerkPatchBase<MarshesLorePatch>, IPartySpeed, IDailyFoodConsumption {
public class MarshesLorePatch : ScoutingLorePerk<MarshesLorePatch> {

private readonly IDailyFoodConsumption _halfDailyFoodConsumption;
private readonly IPartySpeed _modifyPartySpeed;

public MarshesLorePatch() : base("ywmjNJnH") {
_halfDailyFoodConsumption = new HalfDailyFoodConsumption(Perk);
_modifyPartySpeed = new ModifyPartySpeed(Perk);
}
public MarshesLorePatch() : base("ywmjNJnH") { }

public override void Apply(Game game) {
Perk.SetPrimaryBonus(0.05f);
base.Apply(game);
}

public void ModifyFinalSpeed(MobileParty mobileParty, float baseSpeed, ref ExplainedNumber finalSpeed) {
if (mobileParty.IsInTerrainType(Swamp) || mobileParty.IsInTerrainType(ShallowRiver))
_modifyPartySpeed.ModifyFinalSpeed(mobileParty, baseSpeed, ref finalSpeed);
public override void ModifyFinalSpeed(MobileParty mobileParty, float baseSpeed, ref ExplainedNumber finalSpeed) {
if (!mobileParty.IsInTerrainType(Swamp) && !mobileParty.IsInTerrainType(ShallowRiver))
return;

base.ModifyFinalSpeed(mobileParty, baseSpeed, ref finalSpeed);
}

public void ModifyDailyFoodConsumption(ref float dailyFoodConsumption, MobileParty mobileParty, StatExplainer dailyFoodConsumptionExplanation)
=> _halfDailyFoodConsumption.ModifyDailyFoodConsumption(ref dailyFoodConsumption, mobileParty, dailyFoodConsumptionExplanation);

}

}
31 changes: 31 additions & 0 deletions src/CommunityPatch/Patches/Perks/Social/Trade/InfluentialTrader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Linq;
using TaleWorlds.CampaignSystem;
using TaleWorlds.Localization;

namespace CommunityPatch.Patches.Perks.Social.Trade {

public class InfluentialTrader : DailyInfluenceGainSubPatch<InfluentialTrader> {

public InfluentialTrader() : base("esgxog1B") { }

public override void ModifyDailyInfluenceGain(Clan clan, ref ExplainedNumber influenceChange) {
var perk = Perk;
if (perk == null || !(clan?.Leader?.GetPerkValue(perk) ?? false))
return;

var influenceBonus = 0.25f;
var caravans = clan.Leader.OwnedCaravans?.Count() ?? 0f;
var workshops = clan.Leader.OwnedWorkshops?.Count ?? 0f;
var extraCaravanInfluence = influenceBonus * caravans;
var extraWorkshopInfluence = influenceBonus * workshops;

if (extraCaravanInfluence > 0)
influenceChange.Add(extraCaravanInfluence, new TextObject(perk.Name + " (caravans)"));

if (extraWorkshopInfluence > 0)
influenceChange.Add(extraWorkshopInfluence, new TextObject(perk.Name + " (workshops)"));
}

}

}
22 changes: 22 additions & 0 deletions src/CommunityPatch/ScoutingLorePerk.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Patches;
using TaleWorlds.CampaignSystem;

namespace CommunityPatch.Patches {

public abstract class ScoutingLorePerk<TPatch> : PerkPatchBase<TPatch>, IPartySpeed, IDailyFoodConsumption where TPatch : ScoutingLorePerk<TPatch> {

protected ScoutingLorePerk(string perkId) : base(perkId) { }

public virtual void ModifyFinalSpeed(MobileParty mobileParty, float baseSpeed, ref ExplainedNumber finalSpeed) {
IPartySpeed modifyPartySpeed = new ModifyPartySpeed(Perk);
modifyPartySpeed.ModifyFinalSpeed(mobileParty, baseSpeed, ref finalSpeed);
}

public virtual void ModifyDailyFoodConsumption(ref float dailyFoodConsumption, MobileParty mobileParty, StatExplainer dailyFoodConsumptionExplanation) {
IDailyFoodConsumption halfDailyFoodConsumption = new HalfDailyFoodConsumption(Perk);
halfDailyFoodConsumption.ModifyDailyFoodConsumption(ref dailyFoodConsumption, mobileParty, dailyFoodConsumptionExplanation);
}

}

}

0 comments on commit 852ae0b

Please sign in to comment.