Пример #1
0
        public static Toil GotoBed(TargetIndex bedIndex)
        {
            Toil gotoBed = new Toil();

            gotoBed.initAction = delegate
            {
                Pawn         actor2 = gotoBed.actor;
                Building_Bed bed    = (Building_Bed)actor2.CurJob.GetTarget(bedIndex).Thing;
                IntVec3      bedSleepingSlotPosFor = RestUtility.GetBedSleepingSlotPosFor(actor2, bed);
                if (actor2.Position == bedSleepingSlotPosFor)
                {
                    actor2.jobs.curDriver.ReadyForNextToil();
                }
                else
                {
                    actor2.pather.StartPath(RestUtility.GetBedSleepingSlotPosFor(actor2, bed), PathEndMode.OnCell);
                }
            };
            gotoBed.tickAction = delegate
            {
                Pawn         actor         = gotoBed.actor;
                Building_Bed building_Bed  = (Building_Bed)actor.CurJob.GetTarget(bedIndex).Thing;
                Pawn         curOccupantAt = building_Bed.GetCurOccupantAt(actor.pather.Destination.Cell);
                if (curOccupantAt != null && curOccupantAt != actor)
                {
                    actor.pather.StartPath(RestUtility.GetBedSleepingSlotPosFor(actor, building_Bed), PathEndMode.OnCell);
                }
            };
            gotoBed.defaultCompleteMode = ToilCompleteMode.PatherArrival;
            gotoBed.FailOnBedNoLongerUsable(bedIndex);
            return(gotoBed);
        }
Пример #2
0
            internal void <> m__1()
            {
                Pawn         actor         = this.gotoBed.actor;
                Building_Bed building_Bed  = (Building_Bed)actor.CurJob.GetTarget(this.bedIndex).Thing;
                Pawn         curOccupantAt = building_Bed.GetCurOccupantAt(actor.pather.Destination.Cell);

                if (curOccupantAt != null && curOccupantAt != actor)
                {
                    actor.pather.StartPath(RestUtility.GetBedSleepingSlotPosFor(actor, building_Bed), PathEndMode.OnCell);
                }
            }
Пример #3
0
 public static bool InBedOrRestSpotNow(Pawn pawn, LocalTargetInfo bedOrRestSpot)
 {
     if (!bedOrRestSpot.IsValid || !pawn.Spawned)
     {
         return(false);
     }
     if (bedOrRestSpot.HasThing)
     {
         return(bedOrRestSpot.Thing.Map == pawn.Map && RestUtility.GetBedSleepingSlotPosFor(pawn, (Building_Bed)bedOrRestSpot.Thing) == pawn.Position);
     }
     return(bedOrRestSpot.Cell == pawn.Position);
 }
Пример #4
0
            internal void <> m__0()
            {
                Pawn         actor = this.gotoBed.actor;
                Building_Bed bed   = (Building_Bed)actor.CurJob.GetTarget(this.bedIndex).Thing;
                IntVec3      bedSleepingSlotPosFor = RestUtility.GetBedSleepingSlotPosFor(actor, bed);

                if (actor.Position == bedSleepingSlotPosFor)
                {
                    actor.jobs.curDriver.ReadyForNextToil();
                }
                else
                {
                    actor.pather.StartPath(bedSleepingSlotPosFor, PathEndMode.OnCell);
                }
            }
Пример #5
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDestroyedOrNull(TargetIndex.A);
            this.FailOnDestroyedOrNull(TargetIndex.B);
            this.FailOnAggroMentalStateAndHostile(TargetIndex.A);
            this.FailOn(delegate
            {
                if (job.def.makeTargetPrisoner)
                {
                    if (!DropBed.ForPrisoners)
                    {
                        return(true);
                    }
                }
                else if (DropBed.ForPrisoners != Takee.IsPrisoner)
                {
                    return(true);
                }
                return(false);
            });
            yield return(Toils_Bed.ClaimBedIfNonMedical(TargetIndex.B, TargetIndex.A));

            AddFinishAction(delegate
            {
                if (job.def.makeTargetPrisoner && Takee.ownership.OwnedBed == DropBed && Takee.Position != RestUtility.GetBedSleepingSlotPosFor(Takee, DropBed))
                {
                    Takee.ownership.UnclaimBed();
                }
            });
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch).FailOnDespawnedNullOrForbidden(TargetIndex.A).FailOnDespawnedNullOrForbidden(TargetIndex.B)
                         .FailOn(() => job.def == JobDefOf.Arrest && !Takee.CanBeArrestedBy(pawn))
                         .FailOn(() => !pawn.CanReach(DropBed, PathEndMode.OnCell, Danger.Deadly))
                         .FailOn(() => (job.def == JobDefOf.Rescue || job.def == JobDefOf.Capture) && !Takee.Downed)
                         .FailOnSomeonePhysicallyInteracting(TargetIndex.A));

            Toil toil = new Toil();

            toil.initAction = delegate
            {
                if (job.def.makeTargetPrisoner)
                {
                    Pawn pawn = (Pawn)job.targetA.Thing;
                    pawn.GetLord()?.Notify_PawnAttemptArrested(pawn);
                    GenClamor.DoClamor(pawn, 10f, ClamorDefOf.Harm);
                    if (job.def == JobDefOf.Arrest && !pawn.CheckAcceptArrest(base.pawn))
                    {
                        base.pawn.jobs.EndCurrentJob(JobCondition.Incompletable);
                    }
                    if (!pawn.IsPrisoner)
                    {
                        QuestUtility.SendQuestTargetSignals(pawn.questTags, "Arrested", pawn.Named("SUBJECT"));
                    }
                }
            };
            yield return(toil);

            Toil toil2 = Toils_Haul.StartCarryThing(TargetIndex.A).FailOnNonMedicalBedNotOwned(TargetIndex.B, TargetIndex.A);

            toil2.AddPreInitAction(CheckMakeTakeeGuest);
            yield return(toil2);

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

            Toil toil3 = new Toil();

            toil3.initAction = delegate
            {
                CheckMakeTakeePrisoner();
                if (Takee.playerSettings == null)
                {
                    Takee.playerSettings = new Pawn_PlayerSettings(Takee);
                }
            };
            yield return(toil3);

            yield return(Toils_Reserve.Release(TargetIndex.B));

            Toil toil4 = new Toil();

            toil4.initAction = delegate
            {
                IntVec3 position = DropBed.Position;
                pawn.carryTracker.TryDropCarriedThing(position, ThingPlaceMode.Direct, out Thing _);
                if (!DropBed.Destroyed && (DropBed.OwnersForReading.Contains(Takee) || (DropBed.Medical && DropBed.AnyUnoccupiedSleepingSlot) || Takee.ownership == null))
                {
                    Takee.jobs.Notify_TuckedIntoBed(DropBed);
                    if (Takee.RaceProps.Humanlike && job.def != JobDefOf.Arrest && !Takee.IsPrisonerOfColony)
                    {
                        Takee.relations.Notify_RescuedBy(pawn);
                    }
                    Takee.mindState.Notify_TuckedIntoBed();
                }
                if (Takee.IsPrisonerOfColony)
                {
                    LessonAutoActivator.TeachOpportunity(ConceptDefOf.PrisonerTab, Takee, OpportunityType.GoodToKnow);
                }
            };
            toil4.defaultCompleteMode = ToilCompleteMode.Instant;
            yield return(toil4);
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDestroyedOrNull(TargetIndex.A);
            this.FailOnDestroyedOrNull(TargetIndex.B);
            this.FailOnAggroMentalStateAndHostile(TargetIndex.A);
            this.FailOn(delegate()
            {
                if (this.job.def.makeTargetPrisoner)
                {
                    if (!this.DropBed.ForPrisoners)
                    {
                        return(true);
                    }
                }
                else if (this.DropBed.ForPrisoners != this.Takee.IsPrisoner)
                {
                    return(true);
                }
                return(false);
            });
            yield return(Toils_Bed.ClaimBedIfNonMedical(TargetIndex.B, TargetIndex.A));

            base.AddFinishAction(delegate
            {
                if (this.job.def.makeTargetPrisoner && this.Takee.ownership.OwnedBed == this.DropBed && this.Takee.Position != RestUtility.GetBedSleepingSlotPosFor(this.Takee, this.DropBed))
                {
                    this.Takee.ownership.UnclaimBed();
                }
            });
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch).FailOnDespawnedNullOrForbidden(TargetIndex.A).FailOnDespawnedNullOrForbidden(TargetIndex.B).FailOn(() => this.job.def == JobDefOf.Arrest && !this.Takee.CanBeArrestedBy(this.pawn)).FailOn(() => !this.pawn.CanReach(this.DropBed, PathEndMode.OnCell, Danger.Deadly, false, TraverseMode.ByPawn)).FailOn(() => this.job.def == JobDefOf.Rescue && !this.Takee.Downed).FailOnSomeonePhysicallyInteracting(TargetIndex.A));

            yield return(new Toil
            {
                initAction = delegate()
                {
                    if (this.job.def.makeTargetPrisoner)
                    {
                        Pawn pawn = (Pawn)this.job.targetA.Thing;
                        Lord lord = pawn.GetLord();
                        if (lord != null)
                        {
                            lord.Notify_PawnAttemptArrested(pawn);
                        }
                        GenClamor.DoClamor(pawn, 10f, ClamorDefOf.Harm);
                        if (this.job.def == JobDefOf.Arrest && !pawn.CheckAcceptArrest(this.pawn))
                        {
                            this.pawn.jobs.EndCurrentJob(JobCondition.Incompletable, true);
                        }
                    }
                }
            });

            Toil startCarrying = Toils_Haul.StartCarryThing(TargetIndex.A, false, false, false).FailOnNonMedicalBedNotOwned(TargetIndex.B, TargetIndex.A);

            startCarrying.AddPreInitAction(new Action(this.CheckMakeTakeeGuest));
            yield return(startCarrying);

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

            yield return(new Toil
            {
                initAction = delegate()
                {
                    this.CheckMakeTakeePrisoner();
                    if (this.Takee.playerSettings == null)
                    {
                        this.Takee.playerSettings = new Pawn_PlayerSettings(this.Takee);
                    }
                }
            });

            yield return(Toils_Reserve.Release(TargetIndex.B));

            yield return(new Toil
            {
                initAction = delegate()
                {
                    IntVec3 position = this.DropBed.Position;
                    Thing thing;
                    this.pawn.carryTracker.TryDropCarriedThing(position, ThingPlaceMode.Direct, out thing, null);
                    if (!this.DropBed.Destroyed && (this.DropBed.owners.Contains(this.Takee) || (this.DropBed.Medical && this.DropBed.AnyUnoccupiedSleepingSlot) || this.Takee.ownership == null))
                    {
                        this.Takee.jobs.Notify_TuckedIntoBed(this.DropBed);
                        if (this.Takee.RaceProps.Humanlike && this.job.def != JobDefOf.Arrest && !this.Takee.IsPrisonerOfColony)
                        {
                            this.Takee.relations.Notify_RescuedBy(this.pawn);
                        }
                        this.Takee.mindState.Notify_TuckedIntoBed();
                    }
                    if (this.Takee.IsPrisonerOfColony)
                    {
                        LessonAutoActivator.TeachOpportunity(ConceptDefOf.PrisonerTab, this.Takee, OpportunityType.GoodToKnow);
                    }
                },
                defaultCompleteMode = ToilCompleteMode.Instant
            });

            yield break;
        }
            public bool MoveNext()
            {
                uint num = (uint)this.$PC;

                this.$PC = -1;
                switch (num)
                {
                case 0u:
                    this.FailOnDestroyedOrNull(TargetIndex.A);
                    this.FailOnDestroyedOrNull(TargetIndex.B);
                    this.FailOnAggroMentalStateAndHostile(TargetIndex.A);
                    this.FailOn(delegate()
                    {
                        if (this.job.def.makeTargetPrisoner)
                        {
                            if (!base.DropBed.ForPrisoners)
                            {
                                return(true);
                            }
                        }
                        else if (base.DropBed.ForPrisoners != base.Takee.IsPrisoner)
                        {
                            return(true);
                        }
                        return(false);
                    });
                    this.$current = Toils_Bed.ClaimBedIfNonMedical(TargetIndex.B, TargetIndex.A);
                    if (!this.$disposing)
                    {
                        this.$PC = 1;
                    }
                    return(true);

                case 1u:
                    base.AddFinishAction(delegate
                    {
                        if (this.job.def.makeTargetPrisoner && base.Takee.ownership.OwnedBed == base.DropBed && base.Takee.Position != RestUtility.GetBedSleepingSlotPosFor(base.Takee, base.DropBed))
                        {
                            base.Takee.ownership.UnclaimBed();
                        }
                    });
                    this.$current = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch).FailOnDespawnedNullOrForbidden(TargetIndex.A).FailOnDespawnedNullOrForbidden(TargetIndex.B).FailOn(() => this.job.def == JobDefOf.Arrest && !base.Takee.CanBeArrestedBy(this.pawn)).FailOn(() => !this.pawn.CanReach(base.DropBed, PathEndMode.OnCell, Danger.Deadly, false, TraverseMode.ByPawn)).FailOn(() => this.job.def == JobDefOf.Rescue && !base.Takee.Downed).FailOnSomeonePhysicallyInteracting(TargetIndex.A);
                    if (!this.$disposing)
                    {
                        this.$PC = 2;
                    }
                    return(true);

                case 2u:
                {
                    Toil checkArrestResistance = new Toil();
                    checkArrestResistance.initAction = delegate()
                    {
                        if (this.job.def.makeTargetPrisoner)
                        {
                            Pawn pawn = (Pawn)this.job.targetA.Thing;
                            Lord lord = pawn.GetLord();
                            if (lord != null)
                            {
                                lord.Notify_PawnAttemptArrested(pawn);
                            }
                            GenClamor.DoClamor(pawn, 10f, ClamorDefOf.Harm);
                            if (this.job.def == JobDefOf.Arrest && !pawn.CheckAcceptArrest(this.pawn))
                            {
                                this.pawn.jobs.EndCurrentJob(JobCondition.Incompletable, true);
                            }
                        }
                    };
                    this.$current = checkArrestResistance;
                    if (!this.$disposing)
                    {
                        this.$PC = 3;
                    }
                    return(true);
                }

                case 3u:
                    startCarrying = Toils_Haul.StartCarryThing(TargetIndex.A, false, false, false).FailOnNonMedicalBedNotOwned(TargetIndex.B, TargetIndex.A);
                    startCarrying.AddPreInitAction(new Action(base.CheckMakeTakeeGuest));
                    this.$current = startCarrying;
                    if (!this.$disposing)
                    {
                        this.$PC = 4;
                    }
                    return(true);

                case 4u:
                    this.$current = Toils_Goto.GotoThing(TargetIndex.B, PathEndMode.Touch);
                    if (!this.$disposing)
                    {
                        this.$PC = 5;
                    }
                    return(true);

                case 5u:
                {
                    Toil makePrisonerAndInit = new Toil();
                    makePrisonerAndInit.initAction = delegate()
                    {
                        base.CheckMakeTakeePrisoner();
                        if (base.Takee.playerSettings == null)
                        {
                            base.Takee.playerSettings = new Pawn_PlayerSettings(base.Takee);
                        }
                    };
                    this.$current = makePrisonerAndInit;
                    if (!this.$disposing)
                    {
                        this.$PC = 6;
                    }
                    return(true);
                }

                case 6u:
                    this.$current = Toils_Reserve.Release(TargetIndex.B);
                    if (!this.$disposing)
                    {
                        this.$PC = 7;
                    }
                    return(true);

                case 7u:
                {
                    Toil tuckIntoBed = new Toil();
                    tuckIntoBed.initAction = delegate()
                    {
                        IntVec3 position = base.DropBed.Position;
                        Thing   thing;
                        this.pawn.carryTracker.TryDropCarriedThing(position, ThingPlaceMode.Direct, out thing, null);
                        if (!base.DropBed.Destroyed && (base.DropBed.owners.Contains(base.Takee) || (base.DropBed.Medical && base.DropBed.AnyUnoccupiedSleepingSlot) || base.Takee.ownership == null))
                        {
                            base.Takee.jobs.Notify_TuckedIntoBed(base.DropBed);
                            if (base.Takee.RaceProps.Humanlike && this.job.def != JobDefOf.Arrest && !base.Takee.IsPrisonerOfColony)
                            {
                                base.Takee.relations.Notify_RescuedBy(this.pawn);
                            }
                            base.Takee.mindState.Notify_TuckedIntoBed();
                        }
                        if (base.Takee.IsPrisonerOfColony)
                        {
                            LessonAutoActivator.TeachOpportunity(ConceptDefOf.PrisonerTab, base.Takee, OpportunityType.GoodToKnow);
                        }
                    };
                    tuckIntoBed.defaultCompleteMode = ToilCompleteMode.Instant;
                    this.$current = tuckIntoBed;
                    if (!this.$disposing)
                    {
                        this.$PC = 8;
                    }
                    return(true);
                }

                case 8u:
                    this.$PC = -1;
                    break;
                }
                return(false);
            }