// Token: 0x060000BF RID: 191 RVA: 0x000061C0 File Offset: 0x000043C0
        public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            Pawn  pawn2 = t as Pawn;
            Thing thing = null;
            bool  flag  = Medicine.GetMedicineCountToFullyHeal(pawn2) > 0;

            if (flag)
            {
                thing = HealthAIUtility.FindBestMedicine(pawn, pawn2);
            }
            bool flag2 = thing != null;
            Job  result;

            if (flag2)
            {
                result = new Job(WPJobDefOf.WPTendPatient, pawn2, thing);
            }
            else
            {
                result = new Job(WPJobDefOf.WPTendPatient, pawn2);
            }
            return(result);
        }
Пример #2
0
        private float GetAverageMedicalPotency(List <Thing> ingredients, Bill bill)
        {
            Bill_Medical bill_Medical = bill as Bill_Medical;
            ThingDef     thingDef;

            if (bill_Medical != null)
            {
                thingDef = bill_Medical.consumedInitialMedicineDef;
            }
            else
            {
                thingDef = null;
            }
            int   num  = 0;
            float num2 = 0f;

            if (thingDef != null)
            {
                num++;
                num2 += thingDef.GetStatValueAbstract(StatDefOf.MedicalPotency, null);
            }
            for (int i = 0; i < ingredients.Count; i++)
            {
                Medicine medicine = ingredients[i] as Medicine;
                if (medicine != null)
                {
                    num  += medicine.stackCount;
                    num2 += medicine.GetStatValue(StatDefOf.MedicalPotency, true) * (float)medicine.stackCount;
                }
            }
            if (num == 0)
            {
                return(1f);
            }
            return(num2 / (float)num);
        }
Пример #3
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);
        }
Пример #4
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            this.FailOn(delegate
            {
                if (!WorkGiver_Tend.GoodLayingStatusForTend(this.$this.Deliveree, this.$this.pawn))
                {
                    return(true);
                }
                if (this.$this.MedicineUsed != null)
                {
                    if (this.$this.Deliveree.playerSettings == null)
                    {
                        return(true);
                    }
                    if (!this.$this.Deliveree.playerSettings.medCare.AllowsMedicine(this.$this.MedicineUsed.def))
                    {
                        return(true);
                    }
                }
                return(this.$this.pawn == this.$this.Deliveree && (this.$this.pawn.playerSettings == null || !this.$this.pawn.playerSettings.selfTend));
            });
            base.AddEndCondition(delegate
            {
                if (HealthAIUtility.ShouldBeTendedNow(this.$this.Deliveree))
                {
                    return(JobCondition.Ongoing);
                }
                return(JobCondition.Succeeded);
            });
            this.FailOnAggroMentalState(TargetIndex.A);
            Toil reserveMedicine = null;

            if (this.usesMedicine)
            {
                reserveMedicine = Toils_Reserve.Reserve(TargetIndex.B, 1, -1, null).FailOnDespawnedNullOrForbidden(TargetIndex.B);
                yield return(reserveMedicine);

                yield return(Toils_Goto.GotoThing(TargetIndex.B, PathEndMode.ClosestTouch).FailOnDespawnedNullOrForbidden(TargetIndex.B));

                yield return(Toils_Tend.PickupMedicine(TargetIndex.B, this.Deliveree).FailOnDestroyedOrNull(TargetIndex.B));

                yield return(Toils_Haul.CheckForGetOpportunityDuplicate(reserveMedicine, TargetIndex.B, TargetIndex.None, true, null));
            }
            PathEndMode interactionCell = (this.Deliveree != this.pawn) ? PathEndMode.InteractionCell : PathEndMode.OnCell;
            Toil        gotoToil        = Toils_Goto.GotoThing(TargetIndex.A, interactionCell);

            yield return(gotoToil);

            int duration = (int)(1f / this.pawn.GetStatValue(StatDefOf.MedicalTendSpeed, true) * 600f);

            yield return(Toils_General.Wait(duration).FailOnCannotTouch(TargetIndex.A, interactionCell).WithProgressBarToilDelay(TargetIndex.A, false, -0.5f).PlaySustainerOrSound(SoundDefOf.Interact_Tend));

            yield return(Toils_Tend.FinalizeTend(this.Deliveree));

            if (this.usesMedicine)
            {
                yield return(new Toil
                {
                    initAction = delegate
                    {
                        if (this.$this.MedicineUsed.DestroyedOrNull() && Medicine.GetMedicineCountToFullyHeal(this.$this.Deliveree) > 0)
                        {
                            Thing thing = HealthAIUtility.FindBestMedicine(this.$this.pawn, this.$this.Deliveree);
                            if (thing != null)
                            {
                                this.$this.job.targetB = thing;
                                this.$this.JumpToToil(reserveMedicine);
                            }
                        }
                    }
                });
            }
            yield return(Toils_Jump.Jump(gotoToil));
        }
Пример #5
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);
             }
         }
     }
 }
Пример #6
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.", 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)
         {
             if (RelationsUtility.TryDevelopBondRelation(doctor, patient, 0.004f))
             {
                 if (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))
             {
                 if (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 override bool TryMakePreToilReservations()
        {
            bool result;

            if (!this.pawn.Reserve(this.Deliveree, this.job, 1, -1, null))
            {
                result = false;
            }
            else
            {
                if (this.usesMedicine)
                {
                    int num = this.pawn.Map.reservationManager.CanReserveStack(this.pawn, this.MedicineUsed, 10, null, false);
                    if (num <= 0 || !this.pawn.Reserve(this.MedicineUsed, this.job, 10, Mathf.Min(num, Medicine.GetMedicineCountToFullyHeal(this.Deliveree)), null))
                    {
                        return(false);
                    }
                }
                result = true;
            }
            return(result);
        }
Пример #8
0
        // Token: 0x06000069 RID: 105 RVA: 0x000044E4 File Offset: 0x000026E4
        public override bool TryMakePreToilReservations(bool errorOnFailed)
        {
            bool flag = this.Deliveree != this.pawn && !this.pawn.Reserve(this.Deliveree, this.job, 1, -1, null, errorOnFailed);
            bool result;

            if (flag)
            {
                result = false;
            }
            else
            {
                bool flag2 = this.usesMedicine;
                if (flag2)
                {
                    int  num   = this.pawn.Map.reservationManager.CanReserveStack(this.pawn, this.MedicineUsed, 10, null, false);
                    bool flag3 = num <= 0 || !this.pawn.Reserve(this.MedicineUsed, this.job, 10, Mathf.Min(num, Medicine.GetMedicineCountToFullyHeal(this.Deliveree)), null, errorOnFailed);
                    if (flag3)
                    {
                        return(false);
                    }
                }
                result = true;
            }
            return(result);
        }