Skip to content

Commit

Permalink
Create Harmony_StartingPawnUtility.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
CMDR-Bill-Doors committed Sep 17, 2024
1 parent 1c4a264 commit a405cd8
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions Source/CombatExtended/Harmony/Harmony_StartingPawnUtility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using HarmonyLib;
using Verse;
using System.Linq;
using System.Collections.Generic;

namespace CombatExtended.HarmonyCE
{
[HarmonyPatch(typeof(StartingPawnUtility), nameof(StartingPawnUtility.GeneratePossessions))]
internal static class StartingPawnUtility_GenerateAmmo
{
static IntRange magRange = new IntRange(3, 5);

internal static void Postfix(Pawn pawn)
{
var startingPossessions = Find.GameInitData.startingPossessions;
if (startingPossessions.ContainsKey(pawn))
{
List<ThingDefCount> ammoList = new List<ThingDefCount>();
foreach (var possession in startingPossessions[pawn])
{
if (possession.thingDef.GetCompProperties<CompProperties_AmmoUser>() is CompProperties_AmmoUser ammoUser && ammoUser.ammoSet != null)
{
int count = ammoUser.AmmoGenPerMagOverride;
if (count <= 0)
{
count = ammoUser.magazineSize;
}
count *= magRange.RandomInRange;

ammoList.Add(new ThingDefCount(ammoUser.ammoSet.ammoTypes.First().ammo, count));
}
}
foreach (var ammo in ammoList)
{
startingPossessions[pawn].Add(ammo);
}
}
}
}
}

0 comments on commit a405cd8

Please sign in to comment.