coffees-rjw-ideology-addons/CRIALactation/Source/HarmonyPatches/RJW/HarmonyPatch_Milk_HumanCompHasGatherableBodyResource.cs
2021-07-26 19:23:46 -07:00

64 lines
1.7 KiB
C#

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;
using RimWorld;
using rjw;
using Milk;
using UnityEngine;
using HarmonyLib;
using System.Reflection.Emit;
namespace CRIALactation
{
[HarmonyPatch(typeof(HumanCompHasGatherableBodyResource), "CompTick")]
public static class HarmonyPatch_Milk_HumanCompHasGatherableBodyResource
{
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> codeInstructions)
{
var ins = codeInstructions.ToList();
for(int i = 0; i < ins.Count; i++)
{
if (ins[i].opcode == OpCodes.Callvirt && ins.Count > i + 1 && ins[i + 1].OperandIs(60000))
{
yield return ins[i];
yield return new CodeInstruction(OpCodes.Ldarg_0);
yield return new CodeInstruction(OpCodes.Call, AccessTools.DeclaredMethod(typeof(HarmonyPatch_Milk_HumanCompHasGatherableBodyResource), "AdjustGatherResourceDaysForPrecept"));
}
else
{
yield return ins[i];
}
}
}
public static float AdjustGatherResourceDaysForPrecept(float resourcesIntervalDays, HumanCompHasGatherableBodyResource __instance)
{
Pawn pawn = __instance.parent as Pawn;
if(pawn.Ideo.HasPrecept(PreceptDefOf_Lactation.Lactating_Essential))
{
return resourcesIntervalDays * 0.666f; //1.5x normal rate
}
return resourcesIntervalDays;
}
}
}