public static void GetOptimalHediffsToTendWithSingleTreatment(Pawn patient, bool usingMedicine, List <Hediff> outHediffsToTend, List <Hediff> tendableHediffsInTendPriorityOrder = null) { outHediffsToTend.Clear(); TendUtility.tmpHediffs.Clear(); if (tendableHediffsInTendPriorityOrder != null) { TendUtility.tmpHediffs.AddRange(tendableHediffsInTendPriorityOrder); } else { List <Hediff> hediffs = patient.health.hediffSet.hediffs; for (int i = 0; i < hediffs.Count; i++) { if (hediffs[i].TendableNow) { TendUtility.tmpHediffs.Add(hediffs[i]); } } TendUtility.SortByTendPriority(TendUtility.tmpHediffs); } if (TendUtility.tmpHediffs.Any()) { Hediff hediff = TendUtility.tmpHediffs[0]; outHediffsToTend.Add(hediff); HediffCompProperties_TendDuration hediffCompProperties_TendDuration = hediff.def.CompProps <HediffCompProperties_TendDuration>(); if (hediffCompProperties_TendDuration != null && hediffCompProperties_TendDuration.tendAllAtOnce) { for (int j = 0; j < TendUtility.tmpHediffs.Count; j++) { if (TendUtility.tmpHediffs[j] != hediff && TendUtility.tmpHediffs[j].def == hediff.def) { outHediffsToTend.Add(TendUtility.tmpHediffs[j]); } } } else if (hediff is Hediff_Injury && usingMedicine) { float num = hediff.Severity; for (int k = 0; k < TendUtility.tmpHediffs.Count; k++) { if (TendUtility.tmpHediffs[k] != hediff) { Hediff_Injury hediff_Injury = TendUtility.tmpHediffs[k] as Hediff_Injury; if (hediff_Injury != null) { float severity = hediff_Injury.Severity; if (num + severity <= 20.0) { num += severity; outHediffsToTend.Add(hediff_Injury); } } } } } TendUtility.tmpHediffs.Clear(); } }
// Token: 0x06000032 RID: 50 RVA: 0x00002BD8 File Offset: 0x00000DD8 public static void GetOptimalHediffsToTendWithSingleTreatment(Pawn patient, bool usingMedicine, List <Hediff> outHediffsToTend, List <Hediff> tendableHediffsInTendPriorityOrder = null) { outHediffsToTend.Clear(); HealthShardTendUtility.tmpHediffs.Clear(); bool flag = tendableHediffsInTendPriorityOrder != null; if (flag) { HealthShardTendUtility.tmpHediffs.AddRange(tendableHediffsInTendPriorityOrder); } else { List <Hediff> hediffs = patient.health.hediffSet.hediffs; for (int i = 0; i < hediffs.Count; i++) { bool flag2 = hediffs[i].TendableNow(false); if (flag2) { HealthShardTendUtility.tmpHediffs.Add(hediffs[i]); } } HealthShardTendUtility.SortByTendPriority(HealthShardTendUtility.tmpHediffs); } bool flag3 = GenCollection.Any <Hediff>(HealthShardTendUtility.tmpHediffs); if (flag3) { Hediff hediff = HealthShardTendUtility.tmpHediffs[0]; outHediffsToTend.Add(hediff); HediffCompProperties_TendDuration hediffCompProperties_TendDuration = hediff.def.CompProps <HediffCompProperties_TendDuration>(); bool flag4 = hediffCompProperties_TendDuration != null && hediffCompProperties_TendDuration.tendAllAtOnce; if (flag4) { for (int j = 0; j < HealthShardTendUtility.tmpHediffs.Count; j++) { bool flag5 = HealthShardTendUtility.tmpHediffs[j] != hediff && HealthShardTendUtility.tmpHediffs[j].def == hediff.def; if (flag5) { outHediffsToTend.Add(HealthShardTendUtility.tmpHediffs[j]); } } } else { bool flag6 = hediff is Hediff_Injury && usingMedicine; if (flag6) { float num = hediff.Severity; for (int k = 0; k < HealthShardTendUtility.tmpHediffs.Count; k++) { bool flag7 = HealthShardTendUtility.tmpHediffs[k] != hediff; if (flag7) { Hediff_Injury hediff_Injury = HealthShardTendUtility.tmpHediffs[k] as Hediff_Injury; bool flag8 = hediff_Injury != null; if (flag8) { float severity = hediff_Injury.Severity; bool flag9 = num + severity <= 20f; if (flag9) { num += severity; outHediffsToTend.Add(hediff_Injury); } } } } } } HealthShardTendUtility.tmpHediffs.Clear(); } }
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); } } }
public static bool GetOptimalHediffsToTendWithSingleTreatment( Pawn patient, bool usingMedicine, List <Hediff> outHediffsToTend, List <Hediff> tendableHediffsInTendPriorityOrder = null) { outHediffsToTend.Clear(); //TendUtility.tmpHediffs.Clear(); List <Hediff> tmpHediffs = new List <Hediff>(); if (tendableHediffsInTendPriorityOrder != null) { tmpHediffs.AddRange(tendableHediffsInTendPriorityOrder); } else { List <Hediff> hediffs = patient.health.hediffSet.hediffs; for (int index = 0; index < hediffs.Count; ++index) { if (hediffs[index].TendableNow(false)) { tmpHediffs.Add(hediffs[index]); } } TendUtility.SortByTendPriority(tmpHediffs); } if (!tmpHediffs.Any()) { return(false); } Hediff tmpHediff1 = tmpHediffs[0]; outHediffsToTend.Add(tmpHediff1); HediffCompProperties_TendDuration propertiesTendDuration = tmpHediff1.def.CompProps <HediffCompProperties_TendDuration>(); if (propertiesTendDuration != null && propertiesTendDuration.tendAllAtOnce) { for (int index = 0; index < tmpHediffs.Count; ++index) { if (tmpHediffs[index] != tmpHediff1 && tmpHediffs[index].def == tmpHediff1.def) { outHediffsToTend.Add(tmpHediffs[index]); } } } else if (tmpHediff1 is Hediff_Injury & usingMedicine) { float severity1 = tmpHediff1.Severity; for (int index = 0; index < tmpHediffs.Count; ++index) { if (tmpHediffs[index] != tmpHediff1 && tmpHediffs[index] is Hediff_Injury tmpHediff2) { float severity2 = tmpHediff2.Severity; if (severity1 + (double)severity2 <= 20.0) { severity1 += severity2; outHediffsToTend.Add(tmpHediff2); } } } } //TendUtility.tmpHediffs.Clear(); return(false); }
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); } } }