public static void DoTend(Pawn doctor, Pawn patient, Medicine medicine) { if (!patient.health.HasHediffsNeedingTend(false)) { return; } if (medicine != null && medicine.Destroyed) { Log.Warning("Tried to use destroyed medicine.", false); medicine = null; } float quality = TendUtility.CalculateBaseTendQuality(doctor, patient, (medicine == null) ? null : medicine.def); TendUtility.GetOptimalHediffsToTendWithSingleTreatment(patient, medicine != null, TendUtility.tmpHediffsToTend, null); for (int i = 0; i < TendUtility.tmpHediffsToTend.Count; i++) { TendUtility.tmpHediffsToTend[i].Tended(quality, i); } if (doctor != null && doctor.Faction == Faction.OfPlayer && patient.Faction != doctor.Faction && !patient.IsPrisoner && patient.Faction != null) { patient.mindState.timesGuestTendedToByPlayer++; } if (doctor != null && doctor.IsColonistPlayerControlled) { patient.records.AccumulateStoryEvent(StoryEventDefOf.TendedByPlayer); } if (doctor != null && doctor.RaceProps.Humanlike && patient.RaceProps.Animal && RelationsUtility.TryDevelopBondRelation(doctor, patient, 0.004f) && doctor.Faction != null && doctor.Faction != patient.Faction) { InteractionWorker_RecruitAttempt.DoRecruit(doctor, patient, 1f, false); } patient.records.Increment(RecordDefOf.TimesTendedTo); if (doctor != null) { doctor.records.Increment(RecordDefOf.TimesTendedOther); } if (doctor == patient && !doctor.Dead) { doctor.mindState.Notify_SelfTended(); } if (medicine != null) { if ((patient.Spawned || (doctor != null && doctor.Spawned)) && medicine != null && medicine.GetStatValue(StatDefOf.MedicalPotency, true) > ThingDefOf.MedicineIndustrial.GetStatValueAbstract(StatDefOf.MedicalPotency, null)) { SoundDefOf.TechMedicineUsed.PlayOneShot(new TargetInfo(patient.Position, patient.Map, false)); } if (medicine.stackCount > 1) { medicine.stackCount--; } else if (!medicine.Destroyed) { medicine.Destroy(DestroyMode.Vanish); } } }
public static int GetMedicineCountToFullyHeal(Pawn pawn) { int num = 0; int num2 = pawn.health.hediffSet.hediffs.Count + 1; Medicine.tendableHediffsInTendPriorityOrder.Clear(); List <Hediff> hediffs = pawn.health.hediffSet.hediffs; for (int i = 0; i < hediffs.Count; i++) { if (hediffs[i].TendableNow(false)) { Medicine.tendableHediffsInTendPriorityOrder.Add(hediffs[i]); } } TendUtility.SortByTendPriority(Medicine.tendableHediffsInTendPriorityOrder); int num3 = 0; while (true) { num++; if (num > num2) { break; } TendUtility.GetOptimalHediffsToTendWithSingleTreatment(pawn, true, Medicine.tmpHediffs, Medicine.tendableHediffsInTendPriorityOrder); if (!Medicine.tmpHediffs.Any <Hediff>()) { goto IL_F8; } num3++; for (int j = 0; j < Medicine.tmpHediffs.Count; j++) { Medicine.tendableHediffsInTendPriorityOrder.Remove(Medicine.tmpHediffs[j]); } } Log.Error("Too many iterations.", false); IL_F8: Medicine.tmpHediffs.Clear(); Medicine.tendableHediffsInTendPriorityOrder.Clear(); return(num3); }
public static int GetMedicineCountToFullyHeal(Pawn pawn) { int num = 0; int num2 = pawn.health.hediffSet.hediffs.Count + 1; tendableHediffsInTendPriorityOrder.Clear(); List <Hediff> hediffs = pawn.health.hediffSet.hediffs; for (int i = 0; i < hediffs.Count; i++) { if (hediffs[i].TendableNow()) { tendableHediffsInTendPriorityOrder.Add(hediffs[i]); } } TendUtility.SortByTendPriority(tendableHediffsInTendPriorityOrder); int num3 = 0; while (true) { num++; if (num > num2) { Log.Error("Too many iterations."); break; } TendUtility.GetOptimalHediffsToTendWithSingleTreatment(pawn, usingMedicine: true, tmpHediffs, tendableHediffsInTendPriorityOrder); if (!tmpHediffs.Any()) { break; } num3++; for (int j = 0; j < tmpHediffs.Count; j++) { tendableHediffsInTendPriorityOrder.Remove(tmpHediffs[j]); } } tmpHediffs.Clear(); tendableHediffsInTendPriorityOrder.Clear(); return(num3); }
public static void DoTend(Pawn doctor, Pawn patient, Medicine medicine) { if (patient.health.HasHediffsNeedingTend(false)) { if (medicine != null && medicine.Destroyed) { Log.Warning("Tried to use destroyed medicine."); medicine = null; } float num = (float)((medicine == null) ? 0.30000001192092896 : medicine.def.GetStatValueAbstract(StatDefOf.MedicalPotency, null)); float num2 = (float)((doctor == null) ? 0.75 : doctor.GetStatValue(StatDefOf.MedicalTendQuality, true)); num2 *= num; Building_Bed building_Bed = patient.CurrentBed(); if (building_Bed != null) { num2 += building_Bed.GetStatValue(StatDefOf.MedicalTendQualityOffset, true); } if (doctor == patient) { num2 = (float)(num2 * 0.699999988079071); } num2 = Mathf.Clamp01(num2); TendUtility.GetOptimalHediffsToTendWithSingleTreatment(patient, medicine != null, TendUtility.tmpHediffsToTend, null); for (int i = 0; i < TendUtility.tmpHediffsToTend.Count; i++) { TendUtility.tmpHediffsToTend[i].Tended(num2, i); } if (doctor != null && doctor.Faction != null && patient.HostFaction == null && patient.Faction != null && patient.Faction != doctor.Faction) { patient.Faction.AffectGoodwillWith(doctor.Faction, 0.3f); } if (doctor != null && doctor.IsColonistPlayerControlled) { patient.records.AccumulateStoryEvent(StoryEventDefOf.TendedByPlayer); } if (doctor != null && doctor.RaceProps.Humanlike && patient.RaceProps.Animal && RelationsUtility.TryDevelopBondRelation(doctor, patient, 0.004f) && doctor.Faction != null && doctor.Faction != patient.Faction) { InteractionWorker_RecruitAttempt.DoRecruit(doctor, patient, 1f, false); } patient.records.Increment(RecordDefOf.TimesTendedTo); if (doctor != null) { doctor.records.Increment(RecordDefOf.TimesTendedOther); } if (medicine != null) { if ((patient.Spawned || (doctor != null && doctor.Spawned)) && num > ThingDefOf.Medicine.GetStatValueAbstract(StatDefOf.MedicalPotency, null)) { SoundDefOf.TechMedicineUsed.PlayOneShot(new TargetInfo(patient.Position, patient.Map, false)); } if (medicine.stackCount > 1) { medicine.stackCount--; } else if (!medicine.Destroyed) { medicine.Destroy(DestroyMode.Vanish); } } } }