Skip to content

Commit 4d8ee08

Browse files
committed
Made Medicine Options Modular
1 parent 955b191 commit 4d8ee08

8 files changed

Lines changed: 63 additions & 1 deletion

File tree

Assemblies/O21Toolbox.dll

1.5 KB
Binary file not shown.
-10.5 KB
Binary file not shown.
0 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.

Source/O21Toolbox/O21Toolbox/Harmony/HarmonyPatches.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using O21Toolbox;
1717
using O21Toolbox.Alliances;
1818
using O21Toolbox.ApparelRestrict;
19+
using O21Toolbox.ArtificialPawn;
1920
using O21Toolbox.Bunker;
2021
//using O21Toolbox.Laser;
2122
using 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;

Source/O21Toolbox/O21Toolbox/Needs/ArtificialPawnProperties.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,13 @@ public class ArtificialPawnProperties : DefModExtension
2525
public bool canSocialize = false;
2626

2727
/// <summary>
28-
/// Do the colony care if they die?
28+
/// Does the colony care if they die?
2929
/// </summary>
3030
public bool colonyCaresIfDead = false;
31+
32+
/// <summary>
33+
/// Def for applicable repair parts (medicine)
34+
/// </summary>
35+
public List<ThingDef> repairParts = null;
3136
}
3237
}
1.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)