2022-10-24 01:02:02 +00:00
using HarmonyLib ;
using RimWorld ;
2023-09-30 04:11:22 +00:00
using rjw ;
2022-12-25 14:36:56 +00:00
using System ;
2022-10-24 01:02:02 +00:00
using System.Collections.Generic ;
2022-12-25 14:36:56 +00:00
using System.Linq ;
2022-10-24 01:02:02 +00:00
using UnityEngine ;
using Verse ;
namespace RJW_Menstruation
{
[HarmonyPatch(typeof(Pawn), nameof(Pawn.SpawnSetup))]
public class Pawn_Patch
{
public static void Postfix ( Pawn __instance )
{
//Log.Message("Initialize on spawnsetup");
foreach ( HediffComp_Menstruation comp in __instance . GetMenstruationComps ( ) )
{
comp . Initialize ( ) ;
}
2022-12-25 14:38:58 +00:00
__instance . GetBreastComp ( ) ? . Initialize ( ) ;
2022-10-24 01:02:02 +00:00
}
}
[HarmonyPatch(typeof(FloatMenuMakerMap), "AddHumanlikeOrders")]
public class HumanlikeOrder_Patch
{
public static void Postfix ( Vector3 clickPos , Pawn pawn , List < FloatMenuOption > opts )
{
IEnumerable < LocalTargetInfo > selftargets = GenUI . TargetsAt ( clickPos , TargetingParameters . ForSelf ( pawn ) ) ;
foreach ( LocalTargetInfo t in selftargets )
{
if ( t . Pawn = = pawn & & pawn . HasMenstruationComp ( ) ) opts . AddDistinct ( MakeSelfMenu ( pawn , t ) ) ;
break ;
}
}
public static FloatMenuOption MakeSelfMenu ( Pawn pawn , LocalTargetInfo target )
{
FloatMenuOption option = FloatMenuUtility . DecoratePrioritizedTask ( new FloatMenuOption ( Translations . FloatMenu_CleanSelf , delegate ( )
{
pawn . jobs . TryTakeOrderedJob ( new Verse . AI . Job ( VariousDefOf . VaginaWashing , null , null , target . Cell ) ) ;
} , MenuOptionPriority . Low ) , pawn , target ) ;
return option ;
}
}
2023-12-02 03:39:20 +00:00
[HarmonyPatch(typeof(HealthCardUtility), "DrawOverviewTab")]
public class DrawOverviewTab_Patch
2022-10-24 01:02:02 +00:00
{
public const float buttonWidth = 50f ;
public const float buttonHeight = 20f ;
2023-12-02 03:39:20 +00:00
public static void Prefix ( Rect leftRect , Pawn pawn , float curY )
2022-10-24 01:02:02 +00:00
{
2023-12-02 03:39:20 +00:00
if ( Configurations . EnableButtonInHT & & pawn . ShowStatus ( ) & & pawn . ShouldCycle ( ) )
2022-10-24 01:02:02 +00:00
{
2023-12-02 03:39:20 +00:00
HediffComp_Menstruation comp = pawn . GetFirstMenstruationComp ( ) ;
2022-10-24 01:02:02 +00:00
if ( comp ! = null )
{
2023-12-02 03:39:20 +00:00
Text . Font = GameFont . Tiny ;
Rect buttonRect = new Rect ( leftRect . xMax - buttonWidth - 8f , curY + 4f , buttonWidth , buttonHeight ) ;
if ( Widgets . ButtonText ( buttonRect , Translations . Button_HealthTab ) )
2022-10-24 01:02:02 +00:00
{
Dialog_WombStatus . ToggleWindow ( pawn , comp ) ;
}
}
}
}
}
2022-12-25 14:36:56 +00:00
[HarmonyPatch(typeof(CompBiosculpterPod), nameof(CompBiosculpterPod.CannotUseNowPawnCycleReason), new Type[] { typeof ( Pawn ) , typeof ( Pawn ) , typeof ( CompBiosculpterPod_Cycle ) , typeof ( bool ) } ) ]
public class CannotUseNowPawnCycleReason_Patch
{
private const string eggRestorationKey = "eggRestoration" ;
public static void Postfix ( ref string __result , Pawn biosculptee , CompBiosculpterPod_Cycle cycle )
{
if ( __result ! = null ) return ;
if ( cycle . Props . key = = eggRestorationKey & & ! biosculptee . GetMenstruationComps ( ) . Any ( ) )
__result = Translations . CannotNoWomb ;
}
}
2024-01-01 15:28:30 +00:00
// Doesn't cover everything, but at least it'll get the auto equip
[HarmonyPatch(typeof(Apparel), nameof(Apparel.PawnCanWear))]
public class PawnCanWear_Patch
{
public static void Postfix ( ref bool __result , Apparel __instance , Pawn pawn )
{
if ( __result & & __instance is Absorber )
{
__result = pawn . ShouldCycle ( ) & & pawn . GetMenstruationComps ( ) . Any ( ) ;
}
}
}
// Might cause issues when it comes to caravans
//[HarmonyPatch(typeof(JobGiver_OptimizeApparel), nameof(JobGiver_OptimizeApparel.ApparelScoreRaw))]
//public class ApparelScoreRaw_Patch
//{
// public static void Postfix(ref float __result, Pawn pawn, Apparel ap)
// {
// if (__result > 0f && ap is Absorber && !pawn.GetMenstruationComps().Any(comp => comp.TotalCum > 0))
// __result = -10f;
// }
//}
2022-10-24 01:02:02 +00:00
}