1616using O21Toolbox ;
1717using O21Toolbox . Alliances ;
1818using O21Toolbox . ApparelRestrict ;
19+ using O21Toolbox . ArtificialPawn ;
1920using O21Toolbox . Bunker ;
2021//using O21Toolbox.Laser;
2122using O21Toolbox . Needs ;
@@ -246,6 +247,17 @@ static HarmonyPatches()
246247 new HarmonyMethod ( typeof ( HarmonyPatches ) . GetMethod ( nameof ( Patch_Toils_Tend_FinalizeTend ) ) ) ,
247248 null ) ;
248249 }
250+
251+ {
252+ //HealthAIUtility
253+ Type type = typeof ( HealthAIUtility ) ;
254+
255+ //Patch: HealthAIUtility.FindBestMedicine as Prefix
256+ O21ToolboxHarmony . Patch (
257+ type . GetMethod ( "FindBestMedicine" ) ,
258+ new HarmonyMethod ( typeof ( HarmonyPatches ) . GetMethod ( nameof ( Patch_HealthAIUtility_FindBestMedicine ) ) ) ,
259+ null ) ;
260+ }
249261 #endregion EnergyNeed
250262
251263 #region Restrict
@@ -340,6 +352,46 @@ static void CanBeResearchedAtPostFix(bool __result, Building_ResearchBench bench
340352
341353 #region EnergyNeedPatches
342354
355+ public static bool Patch_HealthAIUtility_FindBestMedicine ( ref Thing __result , Pawn healer , Pawn patient )
356+ {
357+ if ( patient . def . HasModExtension < ArtificialPawnProperties > ( ) )
358+ {
359+ Thing result ;
360+ if ( patient . playerSettings == null || patient . playerSettings . medCare <= MedicalCareCategory . NoMeds )
361+ {
362+ result = null ;
363+ }
364+ else if ( Medicine . GetMedicineCountToFullyHeal ( patient ) <= 0 )
365+ {
366+ result = null ;
367+ }
368+ else
369+ {
370+ Predicate < Thing > predicate = ( Thing m ) => ! m . IsForbidden ( healer ) && patient . playerSettings . medCare . AllowsMedicine ( m . def ) && healer . CanReserve ( m , 10 , 1 , null , false ) && m . def . GetModExtension < DefModExtension_RepairPartsProps > ( ) != null ;
371+ Func < Thing , float > priorityGetter = delegate ( Thing t )
372+ {
373+ DefModExtension_RepairPartsProps repairParts = t . def . GetModExtension < DefModExtension_RepairPartsProps > ( ) ;
374+ if ( repairParts == null )
375+ return 0f ;
376+
377+ return repairParts . repairPotency ;
378+ } ;
379+ IntVec3 position = patient . Position ;
380+ Map map = patient . Map ;
381+ List < Thing > searchSet = patient . Map . listerThings . ThingsInGroup ( ThingRequestGroup . HaulableEver ) ;
382+ PathEndMode peMode = PathEndMode . ClosestTouch ;
383+ TraverseParms traverseParams = TraverseParms . For ( healer , Danger . Deadly , TraverseMode . ByPawn , false ) ;
384+ Predicate < Thing > validator = predicate ;
385+ result = GenClosest . ClosestThing_Global_Reachable ( position , map , searchSet , peMode , traverseParams , 9999f , validator , priorityGetter ) ;
386+ }
387+
388+ __result = result ;
389+ return false ;
390+ }
391+
392+ return true ;
393+ }
394+
343395 public static bool Patch_Toils_Tend_FinalizeTend ( ref Toil __result , Pawn patient )
344396 {
345397 if ( patient . def . HasModExtension < ArtificialPawnProperties > ( ) )
@@ -351,6 +403,11 @@ public static bool Patch_Toils_Tend_FinalizeTend(ref Toil __result, Pawn patient
351403
352404 Thing repairParts = ( Thing ) actor . CurJob . targetB . Thing ;
353405
406+ if ( patient . def . GetModExtension < ArtificialPawnProperties > ( ) . repairParts != null && ! patient . def . GetModExtension < ArtificialPawnProperties > ( ) . repairParts . Contains ( actor . CurJob . targetB . Thing . def ) )
407+ {
408+ repairParts = null ;
409+ }
410+
354411 //Experience
355412 float num = ( ! patient . RaceProps . Animal ) ? 500f : 175f ;
356413 float num2 = RimWorld . ThingDefOf . MedicineIndustrial . MedicineTendXpGainFactor ;
0 commit comments