From adfce0babcdee5a53b2330c31bd7c59debb2aba5 Mon Sep 17 00:00:00 2001 From: maarxx Date: Mon, 7 Dec 2020 23:28:54 -0500 Subject: [PATCH] Use Worst Available Medicine for Anesthesia --- ...DoBill_AddEveryMedicineToRelevantThings.cs | 41 +++++++++++++++++++ ...WorkGiver_DoBill_GetMedicalCareCategory.cs | 31 -------------- 2 files changed, 41 insertions(+), 31 deletions(-) create mode 100644 Source/Pharmacist/HarmonyPatches/WorkGiver_DoBill_AddEveryMedicineToRelevantThings.cs delete mode 100644 Source/Pharmacist/HarmonyPatches/WorkGiver_DoBill_GetMedicalCareCategory.cs diff --git a/Source/Pharmacist/HarmonyPatches/WorkGiver_DoBill_AddEveryMedicineToRelevantThings.cs b/Source/Pharmacist/HarmonyPatches/WorkGiver_DoBill_AddEveryMedicineToRelevantThings.cs new file mode 100644 index 0000000..0e6a122 --- /dev/null +++ b/Source/Pharmacist/HarmonyPatches/WorkGiver_DoBill_AddEveryMedicineToRelevantThings.cs @@ -0,0 +1,41 @@ +// WorkGiver_DoBill_GetMedicalCareCategory.cs +// Copyright Karel Kroeze, 2018-2018 + +using HarmonyLib; +using RimWorld; +using System; +using System.Collections.Generic; +using System.Reflection; +using Verse; +using Verse.AI; + +namespace Pharmacist.Properties +{ + [HarmonyPatch(typeof(WorkGiver_DoBill), "AddEveryMedicineToRelevantThings")] + public static class WorkGiver_DoBill_AddEveryMedicineToRelevantThings + { + public static bool Prefix(Pawn pawn, Thing billGiver, List relevantThings, Predicate baseValidator, Map map) + { + Pawn patient = billGiver as Pawn; + //MedicalCareCategory medicalCareCategory = GetMedicalCareCategory(billGiver); + MedicalCareCategory medicalCareCategory = PharmacistUtility.TendAdvice(patient, InjurySeverity.Operation); + List list = map.listerThings.ThingsInGroup(ThingRequestGroup.Medicine); + List tmpMedicine = (List)(typeof(WorkGiver_DoBill).GetField("tmpMedicine", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null)); + tmpMedicine.Clear(); + for (int i = 0; i < list.Count; i++) + { + Thing thing = list[i]; + if (medicalCareCategory.AllowsMedicine(thing.def) && baseValidator(thing) && pawn.CanReach(thing, PathEndMode.OnCell, Danger.Deadly)) + { + tmpMedicine.Add(thing); + } + } + float inverter = 1f; + if (patient.BillStack.FirstShouldDoNow.recipe.defName == "Anesthetize") { inverter = -1f; } + tmpMedicine.SortBy((Thing x) => 0f - (x.GetStatValue(StatDefOf.MedicalPotency) * inverter), (Thing x) => x.Position.DistanceToSquared(billGiver.Position)); + relevantThings.AddRange(tmpMedicine); + tmpMedicine.Clear(); + return false; + } + } +} diff --git a/Source/Pharmacist/HarmonyPatches/WorkGiver_DoBill_GetMedicalCareCategory.cs b/Source/Pharmacist/HarmonyPatches/WorkGiver_DoBill_GetMedicalCareCategory.cs deleted file mode 100644 index 1762ce2..0000000 --- a/Source/Pharmacist/HarmonyPatches/WorkGiver_DoBill_GetMedicalCareCategory.cs +++ /dev/null @@ -1,31 +0,0 @@ -// WorkGiver_DoBill_GetMedicalCareCategory.cs -// Copyright Karel Kroeze, 2018-2018 - -using HarmonyLib; -using RimWorld; -using Verse; - -namespace Pharmacist.Properties -{ - [HarmonyPatch(typeof(WorkGiver_DoBill), "GetMedicalCareCategory")] - public static class WorkGiver_DoBill_GetMedicalCareCategory - { - public static bool Prefix( Thing billGiver, ref MedicalCareCategory __result ) - { - Pawn pawn = billGiver as Pawn; - if ( pawn == null ) - { - // because this is the fallback vanilla uses... - __result = MedicalCareCategory.Best; - } - else - { - // assumption: bills on people === operations - __result = PharmacistUtility.TendAdvice( pawn, InjurySeverity.Operation ); - } - - // always cancel execution of vanilla method. - return false; - } - } -} \ No newline at end of file