Skip to content

Commit

Permalink
Tweak lasso generation to not generate on pawns without required skill.
Browse files Browse the repository at this point in the history
  • Loading branch information
Epicguru committed Feb 16, 2024
1 parent ad79da5 commit f074f28
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions Source/ThingGenerator/Patches/Patch_PawnGenerator_GeneratePawn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,23 @@ public static void Postfix(Pawn pawn)
if (pawn == null)
return;

switch (Core.Settings.LassoSpawnChance)
{
case <= 0f:
case < 1f when !Rand.Chance(Core.Settings.LassoSpawnChance):
return;
}
// Spawn chance from settings:
if (!Rand.Chance(Core.Settings.LassoSpawnChance))
return;

// Basic pawn checks.
if (!pawn.def.race.Humanlike || !pawn.def.race.ToolUser || pawn.apparel == null)
return;

// Only give to pawns with melee weapons.
var weapon = pawn.GetFirstMeleeWeapon();
if (weapon == null)
return;

// Don't bother giving to pawns that do not have the required melee skill.
if (Core.Settings.MinMeleeSkillToLasso > 0 && !HasSkillToUseLasso(pawn))
return;

GiveLasso(pawn, GetRandomLasso());
}
catch (Exception e)
Expand All @@ -44,6 +47,12 @@ public static void Postfix(Pawn pawn)
}
}

private static bool HasSkillToUseLasso(Pawn pawn)
{
int skill = pawn.skills?.GetSkill(SkillDefOf.Melee)?.Level ?? -1;
return skill >= Core.Settings.MinMeleeSkillToLasso;
}

private static void GiveLasso(Pawn pawn, ThingDef lasso)
{
if (pawn == null || lasso == null)
Expand All @@ -62,6 +71,7 @@ private static void GiveLasso(Pawn pawn, ThingDef lasso)

private static ThingDef GetRandomLasso()
{
return Content.LassoDefs.RandomElementByWeightWithFallback(l => 1f / Mathf.Pow(l.BaseMarketValue, 4));
// Random lasso with a heavy weight on cheaper ones.
return Content.LassoDefs.RandomElementByWeightWithFallback(l => 1f / Mathf.Pow(l.BaseMarketValue, 3));
}
}

0 comments on commit f074f28

Please sign in to comment.