RimWorld

RimWorld

Replace Higher Tech Traders
Showing 1-3 of 3 entries
Update: 17 Apr, 2024 @ 6:51pm

[Auto-generated text]: Update on 4/17/2024 8:52:01 PM.

Update: 17 Apr, 2024 @ 3:20pm

[Auto-generated text]: Update on 4/17/2024 5:20:44 PM.
using System.Linq;
using HarmonyLib;
using RimWorld;
using Verse;

[StaticConstructorOnStartup]
internal static class HarmonyPatches
{
static HarmonyPatches()
{
var harmony = new Harmony("SummerSausages2");
harmony.PatchAll();
}
}

[HarmonyPatch(typeof(IncidentWorker_TraderCaravanArrival), "TryExecuteWorker")]
public static class AdjustTraderTechLevelPatch
{
[HarmonyPrefix]
public static bool Prefix(ref IncidentParms parms)
{
if (parms.target is Map map && parms.faction != null)
{
TechLevel playerTech = Faction.OfPlayer.def.techLevel;
TechLevel traderTech = parms.faction.def.techLevel;

if (playerTech + 1 < traderTech)
{
var suitableFactions = Find.FactionManager.AllFactions
.Where(f => f.def.techLevel <= playerTech && f.def.humanlikeFaction && f != Faction.OfPlayer)
.ToList();

if (suitableFactions.Any())
{
parms.faction = suitableFactions.RandomElementByWeight(f => 1.0f / (f.def.techLevel - playerTech + 1));
}
}
}
return true; // Continue with the original method execution
}
}

Update: 1 Dec, 2023 @ 12:47pm

[Auto-generated text]: Initial upload.