public override ThinkResult TryIssueJobPackage(Pawn pawn, JobIssueParams jobParams)
        {
            ThinkResult result;

            if (!HealthAIUtility.ShouldSeekMedicalRest(pawn))
            {
                result = ThinkResult.NoJob;
            }
            else if (this.respectTimetable && RestUtility.TimetablePreventsLayDown(pawn) && !HealthAIUtility.ShouldHaveSurgeryDoneNow(pawn) && !HealthAIUtility.ShouldBeTendedNowByPlayer(pawn))
            {
                result = ThinkResult.NoJob;
            }
            else if (RestUtility.DisturbancePreventsLyingDown(pawn))
            {
                result = ThinkResult.NoJob;
            }
            else
            {
                Thing thing = RestUtility.FindPatientBedFor(pawn);
                if (thing == null)
                {
                    result = ThinkResult.NoJob;
                }
                else
                {
                    Job job = new Job(JobDefOf.LayDown, thing);
                    result = new ThinkResult(job, this, null, false);
                }
            }
            return(result);
        }
示例#2
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            this.FailOn(delegate()
            {
                if (!WorkGiver_Tend.GoodLayingStatusForTend(this.Deliveree, this.pawn))
                {
                    return(true);
                }
                if (this.MedicineUsed != null && this.pawn.Faction == Faction.OfPlayer)
                {
                    if (this.Deliveree.playerSettings == null)
                    {
                        return(true);
                    }
                    if (!this.Deliveree.playerSettings.medCare.AllowsMedicine(this.MedicineUsed.def))
                    {
                        return(true);
                    }
                }
                return(this.pawn == this.Deliveree && this.pawn.Faction == Faction.OfPlayer && !this.pawn.playerSettings.selfTend);
            });
            base.AddEndCondition(delegate
            {
                if (this.pawn.Faction == Faction.OfPlayer && HealthAIUtility.ShouldBeTendedNowByPlayer(this.Deliveree))
                {
                    return(JobCondition.Ongoing);
                }
                if (this.pawn.Faction != Faction.OfPlayer && this.Deliveree.health.HasHediffsNeedingTend(false))
                {
                    return(JobCondition.Ongoing);
                }
                return(JobCondition.Succeeded);
            });
            this.FailOnAggroMentalState(TargetIndex.A);
            Toil reserveMedicine = null;

            if (this.usesMedicine)
            {
                reserveMedicine = Toils_Tend.ReserveMedicine(TargetIndex.B, this.Deliveree).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, TargetIndex.None).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.MedicineUsed.DestroyedOrNull())
                        {
                            Thing thing = HealthAIUtility.FindBestMedicine(this.pawn, this.Deliveree);
                            if (thing != null)
                            {
                                this.job.targetB = thing;
                                this.JumpToToil(reserveMedicine);
                            }
                        }
                    }
                });
            }
            yield return(Toils_Jump.Jump(gotoToil));

            yield break;
        }
示例#3
0
        public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            Pawn pawn2 = t as Pawn;

            if (pawn2 != null && (!def.tendToHumanlikesOnly || pawn2.RaceProps.Humanlike) && (!def.tendToAnimalsOnly || pawn2.RaceProps.Animal) && GoodLayingStatusForTend(pawn2, pawn) && HealthAIUtility.ShouldBeTendedNowByPlayer(pawn2))
            {
                LocalTargetInfo target = pawn2;
                bool            ignoreOtherReservations = forced;
                if (pawn.CanReserve(target, 1, -1, null, ignoreOtherReservations))
                {
                    return(true);
                }
            }
            return(false);
        }
示例#4
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            _003CMakeNewToils_003Ec__Iterator0 _003CMakeNewToils_003Ec__Iterator = (_003CMakeNewToils_003Ec__Iterator0) /*Error near IL_0052: stateMachine*/;

            this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            this.FailOn(delegate
            {
                if (!WorkGiver_Tend.GoodLayingStatusForTend(_003CMakeNewToils_003Ec__Iterator._0024this.Deliveree, _003CMakeNewToils_003Ec__Iterator._0024this.pawn))
                {
                    return(true);
                }
                if (_003CMakeNewToils_003Ec__Iterator._0024this.MedicineUsed != null && _003CMakeNewToils_003Ec__Iterator._0024this.pawn.Faction == Faction.OfPlayer)
                {
                    if (_003CMakeNewToils_003Ec__Iterator._0024this.Deliveree.playerSettings == null)
                    {
                        return(true);
                    }
                    if (!_003CMakeNewToils_003Ec__Iterator._0024this.Deliveree.playerSettings.medCare.AllowsMedicine(_003CMakeNewToils_003Ec__Iterator._0024this.MedicineUsed.def))
                    {
                        return(true);
                    }
                }
                if (_003CMakeNewToils_003Ec__Iterator._0024this.pawn == _003CMakeNewToils_003Ec__Iterator._0024this.Deliveree && _003CMakeNewToils_003Ec__Iterator._0024this.pawn.Faction == Faction.OfPlayer && !_003CMakeNewToils_003Ec__Iterator._0024this.pawn.playerSettings.selfTend)
                {
                    return(true);
                }
                return(false);
            });
            AddEndCondition(delegate
            {
                if (_003CMakeNewToils_003Ec__Iterator._0024this.pawn.Faction == Faction.OfPlayer && HealthAIUtility.ShouldBeTendedNowByPlayer(_003CMakeNewToils_003Ec__Iterator._0024this.Deliveree))
                {
                    return(JobCondition.Ongoing);
                }
                if (_003CMakeNewToils_003Ec__Iterator._0024this.pawn.Faction != Faction.OfPlayer && _003CMakeNewToils_003Ec__Iterator._0024this.Deliveree.health.HasHediffsNeedingTend())
                {
                    return(JobCondition.Ongoing);
                }
                return(JobCondition.Succeeded);
            });
            this.FailOnAggroMentalState(TargetIndex.A);
            Toil reserveMedicine = null;

            if (!usesMedicine)
            {
                PathEndMode interactionCell = (Deliveree == pawn) ? PathEndMode.OnCell : PathEndMode.InteractionCell;
                Toil        gotoToil        = Toils_Goto.GotoThing(TargetIndex.A, interactionCell);
                yield return(gotoToil);

                /*Error: Unable to find new state assignment for yield return*/;
            }
            reserveMedicine = Toils_Tend.ReserveMedicine(TargetIndex.B, Deliveree).FailOnDespawnedNullOrForbidden(TargetIndex.B);
            yield return(reserveMedicine);

            /*Error: Unable to find new state assignment for yield return*/;
        }
示例#5
0
 public static bool ShouldBeTendedNowByPlayerUrgent(Pawn pawn)
 {
     return(HealthAIUtility.ShouldBeTendedNowByPlayer(pawn) && HealthUtility.TicksUntilDeathDueToBloodLoss(pawn) < 45000);
 }
示例#6
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            this.FailOn(delegate
            {
                if (!WorkGiver_Tend.GoodLayingStatusForTend(Deliveree, pawn))
                {
                    return(true);
                }
                if (MedicineUsed != null && pawn.Faction == Faction.OfPlayer)
                {
                    if (Deliveree.playerSettings == null)
                    {
                        return(true);
                    }
                    if (!Deliveree.playerSettings.medCare.AllowsMedicine(MedicineUsed.def))
                    {
                        return(true);
                    }
                }
                return((pawn == Deliveree && pawn.Faction == Faction.OfPlayer && !pawn.playerSettings.selfTend) ? true : false);
            });
            AddEndCondition(delegate
            {
                if (pawn.Faction == Faction.OfPlayer && HealthAIUtility.ShouldBeTendedNowByPlayer(Deliveree))
                {
                    return(JobCondition.Ongoing);
                }
                return((pawn.Faction != Faction.OfPlayer && Deliveree.health.HasHediffsNeedingTend()) ? JobCondition.Ongoing : JobCondition.Succeeded);
            });
            this.FailOnAggroMentalState(TargetIndex.A);
            Toil reserveMedicine = null;

            if (usesMedicine)
            {
                reserveMedicine = Toils_Tend.ReserveMedicine(TargetIndex.B, Deliveree).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, Deliveree).FailOnDestroyedOrNull(TargetIndex.B));

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

            yield return(gotoToil);

            Toil toil = Toils_General.Wait((int)(1f / pawn.GetStatValue(StatDefOf.MedicalTendSpeed) * 600f)).FailOnCannotTouch(TargetIndex.A, interactionCell).WithProgressBarToilDelay(TargetIndex.A)
                        .PlaySustainerOrSound(SoundDefOf.Interact_Tend);

            toil.activeSkill = () => SkillDefOf.Medicine;
            if (pawn == Deliveree && pawn.Faction != Faction.OfPlayer)
            {
                toil.tickAction = delegate
                {
                    if (pawn.IsHashIntervalTick(100) && !pawn.Position.Fogged(pawn.Map))
                    {
                        MoteMaker.ThrowMetaIcon(pawn.Position, pawn.Map, ThingDefOf.Mote_HealingCross);
                    }
                };
            }
            yield return(toil);

            yield return(Toils_Tend.FinalizeTend(Deliveree));

            if (usesMedicine)
            {
                Toil toil2 = new Toil();
                toil2.initAction = delegate
                {
                    if (MedicineUsed.DestroyedOrNull())
                    {
                        Thing thing = HealthAIUtility.FindBestMedicine(pawn, Deliveree);
                        if (thing != null)
                        {
                            job.targetB = thing;
                            JumpToToil(reserveMedicine);
                        }
                    }
                };
                yield return(toil2);
            }
            yield return(Toils_Jump.Jump(gotoToil));
        }
示例#7
0
        public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            Pawn pawn2 = t as Pawn;

            if (pawn2 == null || pawn.WorkTypeIsDisabled(WorkTypeDefOf.Doctor) || (def.tendToHumanlikesOnly && !pawn2.RaceProps.Humanlike) || (def.tendToAnimalsOnly && !pawn2.RaceProps.Animal) || !GoodLayingStatusForTend(pawn2, pawn) || !HealthAIUtility.ShouldBeTendedNowByPlayer(pawn2) || !pawn.CanReserve(pawn2, 1, -1, null, forced))
            {
                return(false);
            }
            return(true);
        }
示例#8
0
        public override ThinkResult TryIssueJobPackage(Pawn pawn, JobIssueParams jobParams)
        {
            if (!HealthAIUtility.ShouldSeekMedicalRest(pawn))
            {
                return(ThinkResult.NoJob);
            }
            if (respectTimetable && RestUtility.TimetablePreventsLayDown(pawn) && !HealthAIUtility.ShouldHaveSurgeryDoneNow(pawn) && !HealthAIUtility.ShouldBeTendedNowByPlayer(pawn))
            {
                return(ThinkResult.NoJob);
            }
            if (RestUtility.DisturbancePreventsLyingDown(pawn))
            {
                return(ThinkResult.NoJob);
            }
            Thing thing = RestUtility.FindPatientBedFor(pawn);

            if (thing == null)
            {
                return(ThinkResult.NoJob);
            }
            return(new ThinkResult(JobMaker.MakeJob(JobDefOf.LayDown, thing), this));
        }
        // Token: 0x060000BD RID: 189 RVA: 0x000060F4 File Offset: 0x000042F4
        public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            Pawn pawn2 = t as Pawn;
            bool flag  = pawn2 != null && (!this.def.tendToHumanlikesOnly || pawn2.RaceProps.Humanlike) && (!this.def.tendToAnimalsOnly || pawn2.RaceProps.Animal) && WorkGiver_Tend.GoodLayingStatusForTend(pawn2, pawn) && HealthAIUtility.ShouldBeTendedNowByPlayer(pawn2);

            if (flag)
            {
                LocalTargetInfo target = pawn2;
                bool            flag2  = pawn.CanReserve(target, 1, -1, null, forced);
                if (flag2)
                {
                    return(true);
                }
            }
            return(false);
        }
示例#10
0
        // Token: 0x0600006A RID: 106 RVA: 0x000045B4 File Offset: 0x000027B4
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            this.FailOn(delegate()
            {
                bool flag4 = !WorkGiver_WPTend.GoodLayingStatusForTend(this.Deliveree, this.pawn);
                bool result;
                if (flag4)
                {
                    result = true;
                }
                else
                {
                    bool flag5 = this.MedicineUsed != null;
                    if (flag5)
                    {
                        bool flag6 = this.Deliveree.playerSettings == null;
                        if (flag6)
                        {
                            return(true);
                        }
                        bool flag7 = !this.Deliveree.playerSettings.medCare.AllowsMedicine(this.MedicineUsed.def);
                        if (flag7)
                        {
                            return(true);
                        }
                    }
                    result = (this.pawn == this.Deliveree && (this.pawn.playerSettings == null || !this.pawn.playerSettings.selfTend));
                }
                return(result);
            });
            base.AddEndCondition(delegate
            {
                bool flag4 = HealthAIUtility.ShouldBeTendedNowByPlayer(this.Deliveree);
                JobCondition result;
                if (flag4)
                {
                    result = JobCondition.Ongoing;
                }
                else
                {
                    result = JobCondition.Succeeded;
                }
                return(result);
            });
            this.FailOnAggroMentalState(TargetIndex.A);
            Toil reserveMedicine = null;
            bool flag            = this.usesMedicine;

            if (flag)
            {
                reserveMedicine = Toils_Tend.ReserveMedicine(TargetIndex.B, this.Deliveree).FailOnDespawnedNullOrForbidden(TargetIndex.B);
                yield return(reserveMedicine);

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

                yield return(Toils_WPTend.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.OnCell : PathEndMode.InteractionCell;
            Toil        gotoToil        = Toils_Goto.GotoThing(TargetIndex.A, interactionCell);

            yield return(gotoToil);

            Toil toil  = Toils_General.Wait((int)(1f / this.pawn.GetStatValue(StatDefOf.MedicalTendSpeed, true) * 600f), TargetIndex.None).FailOnCannotTouch(TargetIndex.A, interactionCell).WithProgressBarToilDelay(TargetIndex.A, false, -0.5f).PlaySustainerOrSound(SoundDefOf.Interact_Tend);
            bool flag2 = this.pawn == this.Deliveree && this.pawn.Faction != Faction.OfPlayer;

            if (flag2)
            {
                toil.tickAction = delegate()
                {
                    bool flag4 = this.pawn.IsHashIntervalTick(100) && !this.pawn.Position.Fogged(this.pawn.Map);
                    if (flag4)
                    {
                        MoteMaker.ThrowMetaIcon(this.pawn.Position, this.pawn.Map, ThingDefOf.Mote_HealingCross);
                    }
                };
            }
            yield return(toil);

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

            bool flag3 = this.usesMedicine;

            if (flag3)
            {
                yield return(new Toil
                {
                    initAction = delegate()
                    {
                        bool flag4 = this.MedicineUsed.DestroyedOrNull();
                        if (flag4)
                        {
                            Thing thing = HealthAIUtility.FindBestMedicine(this.pawn, this.Deliveree);
                            bool flag5 = thing != null;
                            if (flag5)
                            {
                                this.job.targetB = thing;
                                this.JumpToToil(reserveMedicine);
                            }
                        }
                    }
                });
            }
            yield return(Toils_Jump.Jump(gotoToil));

            yield break;
        }