Exemple #1
0
        public override bool TryMakePreToilReservations(bool errorOnFailed)
        {
            Pawn            pawn   = this.pawn;
            LocalTargetInfo target = this.Deliveree;
            Job             job    = this.job;

            if (!pawn.Reserve(target, job, 1, -1, null, errorOnFailed))
            {
                return(false);
            }
            if (this.usesMedicine)
            {
                int num = this.pawn.Map.reservationManager.CanReserveStack(this.pawn, this.MedicineUsed, 10, null, false);
                if (num > 0)
                {
                    pawn   = this.pawn;
                    target = this.MedicineUsed;
                    job    = this.job;
                    int maxPawns   = 10;
                    int stackCount = Mathf.Min(num, Medicine.GetMedicineCountToFullyHeal(this.Deliveree));
                    if (pawn.Reserve(target, job, maxPawns, stackCount, null, errorOnFailed))
                    {
                        return(true);
                    }
                }
                return(false);
            }
            return(true);
        }
Exemple #2
0
        public static Thing FindBestMedicine(Pawn healer, Pawn patient)
        {
            if (patient.playerSettings == null || (int)patient.playerSettings.medCare <= 1)
            {
                return(null);
            }
            if (Medicine.GetMedicineCountToFullyHeal(patient) <= 0)
            {
                return(null);
            }
            Predicate <Thing> predicate = delegate(Thing m)
            {
                if (m.IsForbidden(healer) || !patient.playerSettings.medCare.AllowsMedicine(m.def) || !healer.CanReserve(m, 10, 1))
                {
                    return(false);
                }
                return(true);
            };
            Func <Thing, float> priorityGetter = (Thing t) => t.def.GetStatValueAbstract(StatDefOf.MedicalPotency);
            IntVec3             position       = patient.Position;
            Map               map            = patient.Map;
            List <Thing>      searchSet      = patient.Map.listerThings.ThingsInGroup(ThingRequestGroup.Medicine);
            PathEndMode       peMode         = PathEndMode.ClosestTouch;
            TraverseParms     traverseParams = TraverseParms.For(healer);
            Predicate <Thing> validator      = predicate;

            return(GenClosest.ClosestThing_Global_Reachable(position, map, searchSet, peMode, traverseParams, 9999f, validator, priorityGetter));
        }
Exemple #3
0
        public static Toil PickupMedicine(TargetIndex ind, Pawn injured)
        {
            Toil toil = new Toil();

            toil.initAction = delegate
            {
                Pawn  actor  = toil.actor;
                Job   curJob = actor.jobs.curJob;
                Thing thing  = curJob.GetTarget(ind).Thing;
                int   num    = Medicine.GetMedicineCountToFullyHeal(injured);
                if (actor.carryTracker.CarriedThing != null)
                {
                    num -= actor.carryTracker.CarriedThing.stackCount;
                }
                int num2 = Mathf.Min(actor.Map.reservationManager.CanReserveStack(actor, thing, 10), num);
                if (num2 > 0)
                {
                    actor.carryTracker.TryStartCarry(thing, num2);
                }
                curJob.count = num - num2;
                if (thing.Spawned)
                {
                    toil.actor.Map.reservationManager.Release(thing, actor, curJob);
                }
                curJob.SetTarget(ind, actor.carryTracker.CarriedThing);
            };
            toil.defaultCompleteMode = ToilCompleteMode.Instant;
            return(toil);
        }
        public override bool TryMakePreToilReservations(bool errorOnFailed)
        {
            Pawn            pawn           = base.pawn;
            LocalTargetInfo target         = Deliveree;
            Job             job            = base.job;
            bool            errorOnFailed2 = errorOnFailed;

            if (!pawn.Reserve(target, job, 1, -1, null, errorOnFailed2))
            {
                return(false);
            }
            if (usesMedicine)
            {
                int num = base.pawn.Map.reservationManager.CanReserveStack(base.pawn, MedicineUsed, 10);
                if (num > 0)
                {
                    pawn   = base.pawn;
                    target = MedicineUsed;
                    job    = base.job;
                    int maxPawns   = 10;
                    int stackCount = Mathf.Min(num, Medicine.GetMedicineCountToFullyHeal(Deliveree));
                    errorOnFailed2 = errorOnFailed;
                    if (pawn.Reserve(target, job, maxPawns, stackCount, null, errorOnFailed2))
                    {
                        goto IL_00b7;
                    }
                }
                return(false);
            }
            goto IL_00b7;
IL_00b7:
            return(true);
        }
Exemple #5
0
        public static Thing FindBestMedicine(Pawn healer, Pawn patient)
        {
            Thing result;

            if (patient.playerSettings == null || patient.playerSettings.medCare <= MedicalCareCategory.NoMeds)
            {
                result = null;
            }
            else if (Medicine.GetMedicineCountToFullyHeal(patient) <= 0)
            {
                result = null;
            }
            else
            {
                Predicate <Thing>   predicate      = (Thing m) => !m.IsForbidden(healer) && patient.playerSettings.medCare.AllowsMedicine(m.def) && healer.CanReserve(m, 10, 1, null, false);
                Func <Thing, float> priorityGetter = (Thing t) => t.def.GetStatValueAbstract(StatDefOf.MedicalPotency, null);
                IntVec3             position       = patient.Position;
                Map               map            = patient.Map;
                List <Thing>      searchSet      = patient.Map.listerThings.ThingsInGroup(ThingRequestGroup.Medicine);
                PathEndMode       peMode         = PathEndMode.ClosestTouch;
                TraverseParms     traverseParams = TraverseParms.For(healer, Danger.Deadly, TraverseMode.ByPawn, false);
                Predicate <Thing> validator      = predicate;
                result = GenClosest.ClosestThing_Global_Reachable(position, map, searchSet, peMode, traverseParams, 9999f, validator, priorityGetter);
            }
            return(result);
        }
            internal void <> m__0()
            {
                Pawn  actor  = this.toil.actor;
                Job   curJob = actor.jobs.curJob;
                Thing thing  = curJob.GetTarget(this.ind).Thing;
                int   num    = actor.Map.reservationManager.CanReserveStack(actor, thing, 10, null, false);

                if (num <= 0 || !actor.Reserve(thing, curJob, 10, Mathf.Min(num, Medicine.GetMedicineCountToFullyHeal(this.injured)), null))
                {
                    this.toil.actor.jobs.EndCurrentJob(JobCondition.Incompletable, true);
                }
            }
        public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            Pawn  pawn2 = t as Pawn;
            Thing thing = null;

            if (Medicine.GetMedicineCountToFullyHeal(pawn2) > 0)
            {
                thing = HealthAIUtility.FindBestMedicine(pawn, pawn2);
            }
            if (thing != null)
            {
                return(new Job(JobDefOf.TendPatient, pawn2, thing));
            }
            return(new Job(JobDefOf.TendPatient, pawn2));
        }
Exemple #8
0
        public static Thing FindBestMedicine(Pawn healer, Pawn patient)
        {
            if (patient.playerSettings == null || (int)patient.playerSettings.medCare <= 1)
            {
                return(null);
            }
            if (Medicine.GetMedicineCountToFullyHeal(patient) <= 0)
            {
                return(null);
            }
            Predicate <Thing>   validator      = (Thing m) => (!m.IsForbidden(healer) && patient.playerSettings.medCare.AllowsMedicine(m.def) && healer.CanReserve(m, 10, 1)) ? true : false;
            Func <Thing, float> priorityGetter = (Thing t) => t.def.GetStatValueAbstract(StatDefOf.MedicalPotency);

            return(GenClosest.ClosestThing_Global_Reachable(patient.Position, patient.Map, patient.Map.listerThings.ThingsInGroup(ThingRequestGroup.Medicine), PathEndMode.ClosestTouch, TraverseParms.For(healer), 9999f, validator, priorityGetter));
        }
Exemple #9
0
 public override bool TryMakePreToilReservations(bool errorOnFailed)
 {
     if (Deliveree != pawn && !pawn.Reserve(Deliveree, job, 1, -1, null, errorOnFailed))
     {
         return(false);
     }
     if (usesMedicine)
     {
         int num = pawn.Map.reservationManager.CanReserveStack(pawn, MedicineUsed, 10);
         if (num <= 0 || !pawn.Reserve(MedicineUsed, job, 10, Mathf.Min(num, Medicine.GetMedicineCountToFullyHeal(Deliveree)), null, errorOnFailed))
         {
             return(false);
         }
     }
     return(true);
 }
Exemple #10
0
        public static Toil ReserveMedicine(TargetIndex ind, Pawn injured)
        {
            Toil toil = new Toil();

            toil.initAction = delegate
            {
                Pawn  actor  = toil.actor;
                Job   curJob = actor.jobs.curJob;
                Thing thing  = curJob.GetTarget(ind).Thing;
                int   num    = actor.Map.reservationManager.CanReserveStack(actor, thing, 10);
                if (num <= 0 || !actor.Reserve(thing, curJob, 10, Mathf.Min(num, Medicine.GetMedicineCountToFullyHeal(injured))))
                {
                    toil.actor.jobs.EndCurrentJob(JobCondition.Incompletable);
                }
            };
            toil.defaultCompleteMode = ToilCompleteMode.Instant;
            toil.atomicWithPrevious  = true;
            return(toil);
        }
        // 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);
        }
Exemple #12
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));
        }
        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);
        }
Exemple #14
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);
        }