示例#1
0
        public static float CalculateBaseTendQuality(Pawn doctor, Pawn patient, ThingDef medicine)
        {
            float medicinePotency    = (medicine == null) ? 0.3f : medicine.GetStatValueAbstract(StatDefOf.MedicalPotency, null);
            float medicineQualityMax = (medicine == null) ? 0.7f : medicine.GetStatValueAbstract(StatDefOf.MedicalQualityMax, null);

            return(TendUtility.CalculateBaseTendQuality(doctor, patient, medicinePotency, medicineQualityMax));
        }
示例#2
0
 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();
     }
 }
示例#3
0
        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);
                }
            }
        }
        // Token: 0x06000071 RID: 113 RVA: 0x000046F8 File Offset: 0x000028F8
        public static Toil FinalizeTend(Pawn patient)
        {
            Toil toil = new Toil();

            toil.initAction = delegate()
            {
                Pawn     actor    = toil.actor;
                Medicine medicine = (Medicine)actor.jobs.curJob.targetB.Thing;
                float    num      = (!patient.RaceProps.Animal) ? 500f : 175f;
                TendUtility.DoTend(actor, patient, medicine);
                bool flag = medicine != null && medicine.Destroyed;
                if (flag)
                {
                    actor.CurJob.SetTarget(TargetIndex.B, LocalTargetInfo.Invalid);
                }
            };
            toil.defaultCompleteMode = ToilCompleteMode.Instant;
            return(toil);
        }
示例#5
0
        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 Toil FinalizeTend(Pawn patient)
        {
            Toil toil = new Toil();

            toil.initAction = delegate
            {
                Pawn     actor    = toil.actor;
                Medicine medicine = (Medicine)actor.jobs.curJob.targetB.Thing;
                float    num      = (float)((!patient.RaceProps.Animal) ? 500.0 : 175.0);
                float    num2     = (float)((medicine != null) ? medicine.def.MedicineTendXpGainFactor : 0.5);
                actor.skills.Learn(SkillDefOf.Medicine, num * num2, false);
                TendUtility.DoTend(actor, patient, medicine);
                if (medicine != null && medicine.Destroyed)
                {
                    actor.CurJob.SetTarget(TargetIndex.B, LocalTargetInfo.Invalid);
                }
            };
            toil.defaultCompleteMode = ToilCompleteMode.Instant;
            return(toil);
        }
示例#7
0
        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);
        }
示例#8
0
        public static Toil FinalizeTend(Pawn patient)
        {
            Toil toil = new Toil();

            toil.initAction = delegate
            {
                Pawn     actor    = toil.actor;
                Medicine medicine = (Medicine)actor.CurJob.targetB.Thing;
                float    num      = patient.RaceProps.Animal ? 175f : 500f;
                float    num2     = medicine?.def.MedicineTendXpGainFactor ?? 0.5f;
                actor.skills.Learn(SkillDefOf.Medicine, num * num2);
                TendUtility.DoTend(actor, patient, medicine);
                if (medicine != null && medicine.Destroyed)
                {
                    actor.CurJob.SetTarget(TargetIndex.B, LocalTargetInfo.Invalid);
                }
                if (toil.actor.CurJob.endAfterTendedOnce)
                {
                    actor.jobs.EndCurrentJob(JobCondition.Succeeded);
                }
            };
            toil.defaultCompleteMode = ToilCompleteMode.Instant;
            return(toil);
        }
示例#9
0
 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);
             }
         }
     }
 }