-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create Harmony_StartingPawnUtility.cs
- Loading branch information
1 parent
1c4a264
commit a405cd8
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
Source/CombatExtended/Harmony/Harmony_StartingPawnUtility.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} | ||
} |