Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Operations That Cannot Fail Should Use Lowest Quality Medicine #36

Open
wants to merge 1 commit into
base: 1.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<Thing> relevantThings, Predicate<Thing> baseValidator, Map map)
{
Pawn patient = billGiver as Pawn;
//MedicalCareCategory medicalCareCategory = GetMedicalCareCategory(billGiver);
MedicalCareCategory medicalCareCategory = PharmacistUtility.TendAdvice(patient, InjurySeverity.Operation);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we're here, this line obsoletes the other patch.

List<Thing> list = map.listerThings.ThingsInGroup(ThingRequestGroup.Medicine);
List<Thing> tmpMedicine = (List<Thing>)(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));
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The inverter variable in the above 3 lines is the only place we intend to affect any change here.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heya, I know it's been ages since you made this PR, but did you check if this affects op chances? Don't more advanced meds increase success chances? Because pawns will pick up stacks of meds at once, if this affects operations in that they pick up crappy meds for anestesis and whatever affects the op itself, that might be an issue.

relevantThings.AddRange(tmpMedicine);
tmpMedicine.Clear();
return false;
}
}
}

This file was deleted.