2021-07-27 00:44:17 +00:00
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
{
2021-07-29 01:45:25 +00:00
public static void Prefix ( HumanCompHasGatherableBodyResource __instance )
{
if ( ! __instance . parent . IsHashIntervalTick ( 100 ) )
{
return ;
}
if ( ! ( __instance . parent is Pawn ) ) return ;
Pawn p = __instance . parent as Pawn ;
if ( p ? . health ? . hediffSet = = null ) return ;
if ( p . Ideo ? . GetRole ( p ) ! = null & & p . Ideo . GetRole ( p ) . def = = PreceptDefOf_Lactation . IdeoRole_Hucow )
{
if ( p . health . hediffSet . HasHediff ( HediffDef . Named ( "Lactating_Natural" ) , false ) )
{
p . health . RemoveHediff ( p . health . hediffSet . GetFirstHediffOfDef ( HediffDef . Named ( "Lactating_Natural" ) , false ) ) ;
}
if ( p . health . hediffSet . HasHediff ( HediffDef . Named ( "Lactating_Drug" ) , false ) )
{
p . health . RemoveHediff ( p . health . hediffSet . GetFirstHediffOfDef ( HediffDef . Named ( "Lactating_Drug" ) , false ) ) ;
}
if ( ! ( p . health . hediffSet . HasHediff ( HediffDef . Named ( "Lactating_Permanent" ) , false ) | |
p . health . hediffSet . HasHediff ( HediffDef . Named ( "Heavy_Lactating_Permanent" ) , false ) ) )
{
p . health . AddHediff ( HediffDef . Named ( "Lactating_Permanent" ) ) ;
}
}
}
2021-07-27 00:44:17 +00:00
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 ) )
{
2021-07-29 01:45:25 +00:00
return resourcesIntervalDays * 0.666f * ( ( pawn ? . Ideo ? . GetRole ( pawn ) ! = null & & pawn . Ideo . GetRole ( pawn ) . def = = PreceptDefOf_Lactation . IdeoRole_Hucow ) ? 0.5f : 1f ) ; //1.5x normal rate
2021-07-27 00:44:17 +00:00
}
return resourcesIntervalDays ;
}
}
2021-07-29 01:45:25 +00:00
[HarmonyPatch(typeof(CompHyperMilkableHuman), "ResourceAmount", MethodType.Getter)]
public static class HarmonyPatch_IncreaseYieldForHucowHyperMilkable
{
public static void Postfix ( CompHyperMilkableHuman __instance , ref float __result )
{
Pawn p = __instance . parent as Pawn ;
if ( p . Ideo . GetRole ( p ) . def = = PreceptDefOf_Lactation . IdeoRole_Hucow )
{
2021-07-29 15:51:28 +00:00
__result = 45 ;
2021-07-29 01:45:25 +00:00
}
}
}
[HarmonyPatch(typeof(CompMilkableHuman), "ResourceAmount", MethodType.Getter)]
public static class HarmonyPatch_IncreaseYieldForHucowMilkable
{
public static void Postfix ( CompHyperMilkableHuman __instance , ref float __result )
{
Pawn p = __instance . parent as Pawn ;
if ( p ? . Ideo ? . GetRole ( p ) ! = null & & p . Ideo . GetRole ( p ) . def = = PreceptDefOf_Lactation . IdeoRole_Hucow )
{
__result = 45 ;
}
}
}
2021-07-27 00:44:17 +00:00
}