internal 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."); medicine = null; } float num = (medicine == null) ? 0.2f : medicine.def.GetStatValueAbstract(StatDefOf.MedicalPotency, null); float num2 = num; Building_Bed building_Bed = patient.CurrentBed(); if (building_Bed != null) { num2 += building_Bed.GetStatValue(StatDefOf.MedicalTendQualityOffset, true); } if (doctor != null) { num2 *= doctor.GetStatValue(StatDefOf.HealingQuality, true); } num2 = Mathf.Clamp01(num2); if (patient.health.hediffSet.GetInjuriesTendable().Any <Hediff_Injury>()) { float num3 = 0f; int num4 = 0; foreach (Hediff_Injury current in from x in patient.health.hediffSet.GetInjuriesTendable() orderby x.Severity descending select x) { float num5 = Mathf.Min(current.Severity, 20f); if (num3 + num5 > 20f) { break; } num3 += num5; current.Tended(num2, num4); if (medicine == null) { break; } num4++; } } else { bleedingStumps.Clear(); List <Hediff_MissingPart> missingPartsCommonAncestors = patient.health.hediffSet.GetMissingPartsCommonAncestors(); for (int i = 0; i < missingPartsCommonAncestors.Count; i++) { if (missingPartsCommonAncestors[i].IsFresh) { bleedingStumps.Add(missingPartsCommonAncestors[i]); } } if (bleedingStumps.Count > 0) { bleedingStumps.RandomElement <Hediff_MissingPart>().IsFresh = false; bleedingStumps.Clear(); } else { otherHediffs.Clear(); otherHediffs.AddRange(patient.health.hediffSet.GetTendableNonInjuryNonMissingPartHediffs()); Hediff hediff; if (otherHediffs.TryRandomElement(out hediff)) { HediffCompProperties_TendDuration hediffCompProperties_TendDuration = hediff.def.CompProps <HediffCompProperties_TendDuration>(); if (hediffCompProperties_TendDuration != null && hediffCompProperties_TendDuration.tendAllAtOnce) { int num6 = 0; for (int j = 0; j < otherHediffs.Count; j++) { if (otherHediffs[j].def == hediff.def) { otherHediffs[j].Tended(num2, num6); num6++; } } } else { hediff.Tended(num2, 0); } } otherHediffs.Clear(); } } if (doctor != null && patient.HostFaction == null && patient.Faction != null && patient.Faction != doctor.Faction) { patient.Faction.AffectGoodwillWith(doctor.Faction, 0.3f); } 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); doctor.needs.mood.thoughts.memories.TryGainMemoryThought(ThoughtDefOfPsychology.DoctorBleedingHeart, patient); } if (medicine != null) { if ((patient.Spawned || (doctor != null && doctor.Spawned)) && num > 1f) { SoundDef.Named("TechMedicineUsed").PlayOneShot(new TargetInfo(patient.Position, patient.Map, false)); } if (medicine.stackCount > 1) { medicine.stackCount--; } else if (!medicine.Destroyed) { medicine.Destroy(DestroyMode.Vanish); } } }
internal 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."); medicine = (Medicine)null; } float num1 = medicine == null ? 0.0f : medicine.def.GetStatValueAbstract(StatDefOf.MedicalPotency, (ThingDef)null); float quality = medicine == null ? 0.5f : num1; if (doctor != null) { quality *= doctor.GetStatValue(StatDefOf.BaseHealingQuality, true); } if (patient.InBed()) { quality *= patient.CurrentBed().GetStatValue(StatDefOf.MedicalTreatmentQualityFactor, true); } if (patient.health.hediffSet.GetInjuriesTendable().Any <Hediff_Injury>()) { float num2 = 0.0f; int batchPosition = 0; foreach (Hediff_Injury hediffInjury in (IEnumerable <Hediff_Injury>)patient.health.hediffSet.GetInjuriesTendable().OrderByDescending <Hediff_Injury, float>((Func <Hediff_Injury, float>)(x => x.Severity))) { float num3 = Mathf.Min(hediffInjury.Severity, 20f); if ((double)num2 + (double)num3 <= 20.0) { num2 += num3; hediffInjury.Tended(quality, batchPosition); if (medicine != null) { ++batchPosition; } else { break; } } else { break; } } } else { bleedingStumps.Clear(); List <Hediff_MissingPart> partsCommonAncestors = patient.health.hediffSet.GetMissingPartsCommonAncestors(); for (int index = 0; index < partsCommonAncestors.Count; ++index) { if (partsCommonAncestors[index].IsFresh) { bleedingStumps.Add(partsCommonAncestors[index]); } } if (bleedingStumps.Count > 0) { bleedingStumps.RandomElement <Hediff_MissingPart>().IsFresh = false; bleedingStumps.Clear(); } else { otherHediffs.Clear(); otherHediffs.AddRange(patient.health.hediffSet.GetTendableNonInjuryNonMissingPartHediffs()); Hediff result; if (otherHediffs.TryRandomElement <Hediff>(out result)) { HediffCompProperties hediffCompProperties = result.def.CompPropsFor(typeof(HediffComp_Tendable)); if (hediffCompProperties != null && hediffCompProperties.tendAllAtOnce) { int batchPosition = 0; for (int index = 0; index < otherHediffs.Count; ++index) { if (otherHediffs[index].def == result.def) { otherHediffs[index].Tended(quality, batchPosition); ++batchPosition; } } } else { result.Tended(quality, 0); } } otherHediffs.Clear(); } } if (doctor != null && patient.HostFaction == null && (patient.Faction != null && patient.Faction != doctor.Faction)) { patient.Faction.AffectGoodwillWith(doctor.Faction, 0.3f); } if (doctor != null && doctor.RaceProps.Humanlike && (patient.RaceProps.Animal && RelationsUtility.TryDevelopBondRelation(doctor, patient, 0.01f)) && (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); doctor.needs.mood.thoughts.memories.TryGainMemoryThought(ThoughtDefOfPsychology.DoctorBleedingHeart, patient); } if (medicine == null) { return; } if ((patient.Spawned || doctor != null && doctor.Spawned) && (double)num1 > 0.899999976158142) { SoundDef.Named("TechMedicineUsed").PlayOneShot((SoundInfo)patient.Position); } if (medicine.stackCount > 1) { --medicine.stackCount; } else { if (medicine.Destroyed) { return; } medicine.Destroy(DestroyMode.Vanish); } }
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."); medicine = null; } float num = (medicine == null) ? 0.2f : medicine.def.GetStatValueAbstract(StatDefOf.MedicalPotency, null); float quality = num; Building_Bed building_Bed = patient.CurrentBed(); if (building_Bed != null) { quality += building_Bed.GetStatValue(StatDefOf.MedicalTendQualityOffset, true); } if (doctor != null) { quality *= doctor.GetStatValue(StatDefOf.HealingQuality, true); } quality = Mathf.Clamp01(quality); if (patient.health.hediffSet.GetInjuriesTendable().Any <Hediff_Injury>()) { float maxSeverity = 0f; int batchPosition = 0; // added prio by bleeding, everything else vanilla foreach (Hediff_Injury current in from x in patient.health.hediffSet.GetInjuriesTendable().Where(x => x.BleedRate > 0) orderby x.BleedRate descending select x) { float severity = Mathf.Min(current.Severity, 20f); if (maxSeverity + severity > 20f) { break; } maxSeverity += severity; current.Tended(quality, batchPosition); if (medicine == null) { break; } batchPosition++; } foreach (Hediff_Injury current in from x in patient.health.hediffSet.GetInjuriesTendable() orderby x.Severity descending select x) { float severity = Mathf.Min(current.Severity, 20f); if (maxSeverity + severity > 20f) { break; } maxSeverity += severity; current.Tended(quality, batchPosition); if (medicine == null) { break; } batchPosition++; } } else { _TendUtility.bleedingStumps.Clear(); List <Hediff_MissingPart> missingPartsCommonAncestors = patient.health.hediffSet.GetMissingPartsCommonAncestors(); for (int i = 0; i < missingPartsCommonAncestors.Count; i++) { if (missingPartsCommonAncestors[i].IsFresh) { _TendUtility.bleedingStumps.Add(missingPartsCommonAncestors[i]); } } if (_TendUtility.bleedingStumps.Count > 0) { _TendUtility.bleedingStumps.RandomElement <Hediff_MissingPart>().IsFresh = false; _TendUtility.bleedingStumps.Clear(); } else { _TendUtility.otherHediffs.Clear(); _TendUtility.otherHediffs.AddRange(patient.health.hediffSet.GetTendableNonInjuryNonMissingPartHediffs()); Hediff hediff; if (_TendUtility.otherHediffs.TryRandomElement(out hediff)) { HediffCompProperties_TendDuration hediffCompProperties_TendDuration = hediff.def.CompProps <HediffCompProperties_TendDuration>(); if (hediffCompProperties_TendDuration != null && hediffCompProperties_TendDuration.tendAllAtOnce) { int num6 = 0; for (int j = 0; j < _TendUtility.otherHediffs.Count; j++) { if (_TendUtility.otherHediffs[j].def == hediff.def) { _TendUtility.otherHediffs[j].Tended(quality, num6); num6++; } } } else { hediff.Tended(quality, 0); } } _TendUtility.otherHediffs.Clear(); } } if (doctor != null && patient.HostFaction == null && patient.Faction != null && patient.Faction != doctor.Faction) { patient.Faction.AffectGoodwillWith(doctor.Faction, 0.3f); } if (doctor != null && doctor.RaceProps.Humanlike && patient.RaceProps.Animal && RelationsUtility.TryDevelopBondRelation(doctor, patient, ChanceToDevelopBondRelationOnTended) && 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 > 1f) { SoundDef.Named("TechMedicineUsed").PlayOneShot(new TargetInfo(patient.Position, patient.Map, false)); } if (medicine.stackCount > 1) { medicine.stackCount--; } else if (!medicine.Destroyed) { medicine.Destroy(DestroyMode.Vanish); } } }