// Token: 0x0600003F RID: 63 RVA: 0x00004036 File Offset: 0x00002236
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedNullOrForbidden(TargetIndex.B);
            this.FailOn(() => !FoodUtility.ShouldBeFedBySomeone(this.Deliveree));
            bool flag = base.TargetThingA is Building_NutrientPasteDispenser;

            if (flag)
            {
                yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.InteractionCell).FailOnForbidden(TargetIndex.A));

                yield return(Toils_Ingest.TakeMealFromDispenser(TargetIndex.A, this.pawn));
            }
            else
            {
                yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch).FailOnForbidden(TargetIndex.A));

                yield return(Toils_Ingest.PickupIngestible(TargetIndex.A, this.Deliveree));
            }
            yield return(Toils_Goto.GotoThing(TargetIndex.B, PathEndMode.Touch));

            yield return(Toils_Ingest.ChewIngestible(this.Deliveree, 1.5f, TargetIndex.A, TargetIndex.None).FailOnCannotTouch(TargetIndex.B, PathEndMode.Touch));

            yield return(Toils_Ingest.FinalizeIngest(this.Deliveree, TargetIndex.A));

            yield break;
        }
コード例 #2
0
        private IEnumerable <Toil> FeedToils()
        {
            yield return(new Toil
            {
                initAction = delegate
                {
                    this.$this.feedNutritionLeft = JobDriver_InteractAnimal.RequiredNutritionPerFeed(this.$this.Animal);
                },
                defaultCompleteMode = ToilCompleteMode.Instant
            });

            Toil gotoAnimal = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch);

            yield return(gotoAnimal);

            yield return(this.StartFeedAnimal(TargetIndex.A));

            yield return(Toils_Ingest.FinalizeIngest(this.Animal, TargetIndex.B));

            yield return(Toils_General.PutCarriedThingInInventory());

            yield return(Toils_General.ClearTarget(TargetIndex.B));

            yield return(Toils_Jump.JumpIf(gotoAnimal, () => this.$this.feedNutritionLeft > 0f));
        }
コード例 #3
0
        private IEnumerable <Toil> FeedToils()
        {
            Toil toil = new Toil();

            toil.initAction = delegate
            {
                feedNutritionLeft = RequiredNutritionPerFeed(Animal);
            };
            toil.defaultCompleteMode = ToilCompleteMode.Instant;
            yield return(toil);

            Toil gotoAnimal = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch);

            yield return(gotoAnimal);

            yield return(StartFeedAnimal(TargetIndex.A));

            yield return(Toils_Ingest.FinalizeIngest(Animal, TargetIndex.B));

            yield return(Toils_General.PutCarriedThingInInventory());

            yield return(Toils_General.ClearTarget(TargetIndex.B));

            yield return(Toils_Jump.JumpIf(gotoAnimal, () => feedNutritionLeft > 0f));
        }
コード例 #4
0
        private IEnumerable <Toil> TakeExtraIngestibles()
        {
            if (!pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation))
            {
                yield break;
            }
            Toil reserveExtraFoodToCollect = Toils_Ingest.ReserveFoodFromStackForIngesting(TargetIndex.C);
            Toil findExtraFoodToCollect    = new Toil
            {
                initAction = delegate
                {
                    if (pawn.inventory.innerContainer.TotalStackCountOfDef(IngestibleSource.def) < job.takeExtraIngestibles)
                    {
                        Thing thing = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForDef(IngestibleSource.def), PathEndMode.Touch, TraverseParms.For(pawn), 30f, (Thing x) => pawn.CanReserve(x, 10, 1) && !x.IsForbidden(pawn) && x.IsSociallyProper(pawn));
                        if (thing != null)
                        {
                            job.SetTarget(TargetIndex.C, thing);
                            JumpToToil(reserveExtraFoodToCollect);
                        }
                    }
                },
                defaultCompleteMode = ToilCompleteMode.Instant
            };

            yield return(Toils_Jump.Jump(findExtraFoodToCollect));

            yield return(reserveExtraFoodToCollect);

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

            yield return(Toils_Haul.TakeToInventory(TargetIndex.C, () => job.takeExtraIngestibles - pawn.inventory.innerContainer.TotalStackCountOfDef(IngestibleSource.def)));

            yield return(findExtraFoodToCollect);
        }
コード例 #5
0
        private IEnumerable <Toil> PrepareToIngestToils_ToolUser(Toil chewToil)
        {
            if (eatingFromInventory)
            {
                yield return(Toils_Misc.TakeItemFromInventoryToCarrier(pawn, TargetIndex.A));
            }
            else
            {
                yield return(ReserveFood());

                Toil gotoToPickup = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch).FailOnDespawnedNullOrForbidden(TargetIndex.A);
                yield return(Toils_Jump.JumpIf(gotoToPickup, () => pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation)));

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

                yield return(Toils_Jump.Jump(chewToil));

                yield return(gotoToPickup);

                yield return(Toils_Ingest.PickupIngestible(TargetIndex.A, pawn));
            }
            if (job.takeExtraIngestibles > 0)
            {
                foreach (Toil item in TakeExtraIngestibles())
                {
                    yield return(item);
                }
            }
            if (!pawn.Drafted)
            {
                yield return(Toils_Ingest.CarryIngestibleToChewSpot(pawn, TargetIndex.A).FailOnDestroyedOrNull(TargetIndex.A));
            }
            yield return(Toils_Ingest.FindAdjacentEatSurface(TargetIndex.B, TargetIndex.A));
        }
コード例 #6
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedNullOrForbidden(TargetIndex.B);
            this.FailOn(() => !FoodUtility.ShouldBeFedBySomeone(Deliveree));
            if (pawn.inventory != null && pawn.inventory.Contains(base.TargetThingA))
            {
                yield return(Toils_Misc.TakeItemFromInventoryToCarrier(pawn, TargetIndex.A));
            }
            else if (base.TargetThingA is Building_NutrientPasteDispenser)
            {
                yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.InteractionCell).FailOnForbidden(TargetIndex.A));

                yield return(Toils_Ingest.TakeMealFromDispenser(TargetIndex.A, pawn));
            }
            else
            {
                yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch).FailOnForbidden(TargetIndex.A));

                yield return(Toils_Ingest.PickupIngestible(TargetIndex.A, Deliveree));
            }
            yield return(Toils_Goto.GotoThing(TargetIndex.B, PathEndMode.Touch));

            yield return(Toils_Ingest.ChewIngestible(Deliveree, 1.5f, TargetIndex.A).FailOnCannotTouch(TargetIndex.B, PathEndMode.Touch));

            yield return(Toils_Ingest.FinalizeIngest(Deliveree, TargetIndex.A));
        }
コード例 #7
0
        private IEnumerable <Toil> PrepareToIngestToils_Dispenser()
        {
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.InteractionCell).FailOnDespawnedNullOrForbidden(TargetIndex.A));

            yield return(Toils_Ingest.TakeMealFromDispenser(TargetIndex.A, this.pawn));

            yield return(Toils_Ingest.CarryIngestibleToChewSpot(this.pawn, TargetIndex.A).FailOnDestroyedNullOrForbidden(TargetIndex.A));

            yield return(Toils_Ingest.FindAdjacentEatSurface(TargetIndex.B, TargetIndex.A));
        }
コード例 #8
0
        private IEnumerable <Toil> PrepareToIngestToils_ToolUser(Toil chewToil)
        {
            if (eatingFromInventory)
            {
                yield return(Toils_Misc.TakeItemFromInventoryToCarrier(pawn, TargetIndex.A));
            }
            else
            {
                yield return(ReserveFood());

                Toil gotoToPickup = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch).FailOnDespawnedNullOrForbidden(TargetIndex.A);
                yield return(Toils_Jump.JumpIf(gotoToPickup, () => pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation)));

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

                yield return(Toils_Jump.Jump(chewToil));

                yield return(gotoToPickup);

                yield return(Toils_Ingest.PickupIngestible(TargetIndex.A, pawn));

                Toil reserveExtraFoodToCollect = Toils_Ingest.ReserveFoodFromStackForIngesting(TargetIndex.C);
                Toil findExtraFoodToCollect    = new Toil
                {
                    initAction = delegate
                    {
                        if (pawn.inventory.innerContainer.TotalStackCountOfDef(IngestibleSource.def) < job.takeExtraIngestibles)
                        {
                            Thing thing = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForDef(IngestibleSource.def), PathEndMode.Touch, TraverseParms.For(pawn), 12f, (Thing x) => pawn.CanReserve(x, 10, 1) && !x.IsForbidden(pawn) && x.IsSociallyProper(pawn));
                            if (thing != null)
                            {
                                job.SetTarget(TargetIndex.C, thing);
                                JumpToToil(reserveExtraFoodToCollect);
                            }
                        }
                    },
                    defaultCompleteMode = ToilCompleteMode.Instant
                };
                yield return(Toils_Jump.Jump(findExtraFoodToCollect));

                yield return(reserveExtraFoodToCollect);

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

                yield return(Toils_Haul.TakeToInventory(TargetIndex.C, () => job.takeExtraIngestibles - pawn.inventory.innerContainer.TotalStackCountOfDef(IngestibleSource.def)));

                yield return(findExtraFoodToCollect);
            }
            if (!IngestibleSource.def.IsDrug)
            {
                yield return(Toils_Ingest.CarryIngestibleToChewSpot(pawn, TargetIndex.A).FailOnDestroyedOrNull(TargetIndex.A));
            }
            yield return(Toils_Ingest.FindAdjacentEatSurface(TargetIndex.B, TargetIndex.A));
        }
コード例 #9
0
        private IEnumerable <Toil> PrepareToIngestToils_ToolUser(Toil chewToil)
        {
            if (this.eatingFromInventory)
            {
                yield return(Toils_Misc.TakeItemFromInventoryToCarrier(this.pawn, TargetIndex.A));
            }
            else
            {
                yield return(this.ReserveFoodIfWillIngestWholeStack());

                Toil gotoToPickup = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch).FailOnDespawnedNullOrForbidden(TargetIndex.A);
                yield return(Toils_Jump.JumpIf(gotoToPickup, () => this.pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation)));

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

                yield return(Toils_Jump.Jump(chewToil));

                yield return(gotoToPickup);

                yield return(Toils_Ingest.PickupIngestible(TargetIndex.A, this.pawn));

                Toil reserveExtraFoodToCollect = Toils_Reserve.Reserve(TargetIndex.C, 1, -1, null);
                Toil findExtraFoodToCollect    = new Toil();
                findExtraFoodToCollect.initAction = delegate()
                {
                    if (this.pawn.inventory.innerContainer.TotalStackCountOfDef(this.IngestibleSource.def) < this.job.takeExtraIngestibles)
                    {
                        Thing thing = GenClosest.ClosestThingReachable(this.pawn.Position, this.pawn.Map, ThingRequest.ForDef(this.IngestibleSource.def), PathEndMode.Touch, TraverseParms.For(this.pawn, Danger.Deadly, TraverseMode.ByPawn, false), 12f, (Thing x) => this.pawn.CanReserve(x, 1, -1, null, false) && !x.IsForbidden(this.pawn) && x.IsSociallyProper(this.pawn), null, 0, -1, false, RegionType.Set_Passable, false);
                        if (thing != null)
                        {
                            this.job.SetTarget(TargetIndex.C, thing);
                            this.JumpToToil(reserveExtraFoodToCollect);
                        }
                    }
                };
                findExtraFoodToCollect.defaultCompleteMode = ToilCompleteMode.Instant;
                yield return(Toils_Jump.Jump(findExtraFoodToCollect));

                yield return(reserveExtraFoodToCollect);

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

                yield return(Toils_Haul.TakeToInventory(TargetIndex.C, () => this.job.takeExtraIngestibles - this.pawn.inventory.innerContainer.TotalStackCountOfDef(this.IngestibleSource.def)));

                yield return(findExtraFoodToCollect);
            }
            yield return(Toils_Ingest.CarryIngestibleToChewSpot(this.pawn, TargetIndex.A).FailOnDestroyedOrNull(TargetIndex.A));

            yield return(Toils_Ingest.FindAdjacentEatSurface(TargetIndex.B, TargetIndex.A));

            yield break;
        }
コード例 #10
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedOrNull(TargetIndex.B);
            if (eatingFromInventory)
            {
                yield return(Toils_Misc.TakeItemFromInventoryToCarrier(pawn, TargetIndex.A));
            }
            else if (usingNutrientPasteDispenser)
            {
                yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.InteractionCell).FailOnForbidden(TargetIndex.A));

                yield return(Toils_Ingest.TakeMealFromDispenser(TargetIndex.A, pawn));
            }
            else
            {
                yield return(Toils_Ingest.ReserveFoodFromStackForIngesting(TargetIndex.A, Deliveree));

                yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch).FailOnForbidden(TargetIndex.A));

                yield return(Toils_Ingest.PickupIngestible(TargetIndex.A, Deliveree));
            }
            Toil toil = new Toil();

            toil.initAction = delegate
            {
                Pawn actor  = toil.actor;
                Job  curJob = actor.jobs.curJob;
                actor.pather.StartPath(curJob.targetC, PathEndMode.OnCell);
            };
            toil.defaultCompleteMode = ToilCompleteMode.PatherArrival;
            toil.FailOnDestroyedNullOrForbidden(TargetIndex.B);
            toil.AddFailCondition(delegate
            {
                Pawn pawn = (Pawn)toil.actor.jobs.curJob.targetB.Thing;
                if (!pawn.IsPrisonerOfColony)
                {
                    return(true);
                }
                return((!pawn.guest.CanBeBroughtFood) ? true : false);
            });
            yield return(toil);

            Toil toil2 = new Toil();

            toil2.initAction = delegate
            {
                pawn.carryTracker.TryDropCarriedThing(toil2.actor.jobs.curJob.targetC.Cell, ThingPlaceMode.Direct, out Thing _);
            };
            toil2.defaultCompleteMode = ToilCompleteMode.Instant;
            yield return(toil2);
        }
コード例 #11
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            if (!this.usingNutrientPasteDispenser)
            {
                this.FailOn(() => !this.$this.IngestibleSource.Destroyed && !this.$this.IngestibleSource.IngestibleNow);
            }
            Toil chew = Toils_Ingest.ChewIngestible(this.pawn, this.ChewDurationMultiplier, TargetIndex.A, TargetIndex.B).FailOn((Toil x) => !this.$this.IngestibleSource.Spawned && (this.$this.pawn.carryTracker == null || this.$this.pawn.carryTracker.CarriedThing != this.$this.IngestibleSource)).FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch);

            foreach (Toil toil in this.PrepareToIngestToils(chew))
            {
                yield return(toil);
            }
            yield return(chew);

            yield return(Toils_Ingest.FinalizeIngest(this.pawn, TargetIndex.A));

            yield return(Toils_Jump.JumpIf(chew, () => this.$this.job.GetTarget(TargetIndex.A).Thing is Corpse && this.$this.pawn.needs.food.CurLevelPercentage < 0.9f));
        }
コード例 #12
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.EndOnDespawnedOrNull(TargetIndex.A, JobCondition.Incompletable);
            if (this.HasChair)
            {
                this.EndOnDespawnedOrNull(TargetIndex.B, JobCondition.Incompletable);
            }
            if (this.HasDrink)
            {
                this.FailOnDestroyedNullOrForbidden(TargetIndex.C);
                yield return(Toils_Goto.GotoThing(TargetIndex.C, PathEndMode.OnCell).FailOnSomeonePhysicallyInteracting(TargetIndex.C));

                yield return(Toils_Haul.StartCarryThing(TargetIndex.C, false, false, false));
            }
            yield return(Toils_Goto.GotoCell(TargetIndex.B, PathEndMode.OnCell));

            Toil chew = new Toil();

            chew.tickAction = delegate()
            {
                this.pawn.rotationTracker.FaceCell(this.ClosestGatherSpotParentCell);
                this.pawn.GainComfortFromCellIfPossible();
                JoyUtility.JoyTickCheckEnd(this.pawn, JoyTickFullJoyAction.GoToNextToil, 1f, null);
            };
            chew.handlingFacing      = true;
            chew.defaultCompleteMode = ToilCompleteMode.Delay;
            chew.defaultDuration     = this.job.def.joyDuration;
            chew.AddFinishAction(delegate
            {
                JoyUtility.TryGainRecRoomThought(this.pawn);
            });
            chew.socialMode = RandomSocialMode.SuperActive;
            Toils_Ingest.AddIngestionEffects(chew, this.pawn, TargetIndex.C, TargetIndex.None);
            yield return(chew);

            if (this.HasDrink)
            {
                yield return(Toils_Ingest.FinalizeIngest(this.pawn, TargetIndex.C));
            }
            yield break;
        }
コード例 #13
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            if (!usingNutrientPasteDispenser)
            {
                this.FailOn(() => !((_003CMakeNewToils_003Ec__Iterator0) /*Error near IL_0045: stateMachine*/)._0024this.IngestibleSource.Destroyed && !((_003CMakeNewToils_003Ec__Iterator0) /*Error near IL_0045: stateMachine*/)._0024this.IngestibleSource.IngestibleNow);
            }
            Toil chew = Toils_Ingest.ChewIngestible(pawn, ChewDurationMultiplier, TargetIndex.A, TargetIndex.B).FailOn((Toil x) => !((_003CMakeNewToils_003Ec__Iterator0) /*Error near IL_0075: stateMachine*/)._0024this.IngestibleSource.Spawned && (((_003CMakeNewToils_003Ec__Iterator0) /*Error near IL_0075: stateMachine*/)._0024this.pawn.carryTracker == null || ((_003CMakeNewToils_003Ec__Iterator0) /*Error near IL_0075: stateMachine*/)._0024this.pawn.carryTracker.CarriedThing != ((_003CMakeNewToils_003Ec__Iterator0) /*Error near IL_0075: stateMachine*/)._0024this.IngestibleSource)).FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch);

            using (IEnumerator <Toil> enumerator = PrepareToIngestToils(chew).GetEnumerator())
            {
                if (enumerator.MoveNext())
                {
                    Toil toil = enumerator.Current;
                    yield return(toil);

                    /*Error: Unable to find new state assignment for yield return*/;
                }
            }
            yield return(chew);

            /*Error: Unable to find new state assignment for yield return*/;
IL_01aa:
            /*Error near IL_01ab: Unexpected return in MoveNext()*/;
        }
コード例 #14
0
            public bool MoveNext()
            {
                uint num = (uint)this.$PC;

                this.$PC = -1;
                bool flag = false;

                switch (num)
                {
                case 0u:
                    if (!this.usingNutrientPasteDispenser)
                    {
                        this.FailOn(() => !base.IngestibleSource.Destroyed && !base.IngestibleSource.IngestibleNow);
                    }
                    chew       = Toils_Ingest.ChewIngestible(this.pawn, base.ChewDurationMultiplier, TargetIndex.A, TargetIndex.B).FailOn((Toil x) => !base.IngestibleSource.Spawned && (this.pawn.carryTracker == null || this.pawn.carryTracker.CarriedThing != base.IngestibleSource)).FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch);
                    enumerator = base.PrepareToIngestToils(chew).GetEnumerator();
                    num        = 4294967293u;
                    break;

                case 1u:
                    break;

                case 2u:
                    this.$current = Toils_Ingest.FinalizeIngest(this.pawn, TargetIndex.A);
                    if (!this.$disposing)
                    {
                        this.$PC = 3;
                    }
                    return(true);

                case 3u:
                    this.$current = Toils_Jump.JumpIf(chew, () => this.job.GetTarget(TargetIndex.A).Thing is Corpse && this.pawn.needs.food.CurLevelPercentage < 0.9f);
                    if (!this.$disposing)
                    {
                        this.$PC = 4;
                    }
                    return(true);

                case 4u:
                    this.$PC = -1;
                    return(false);

                default:
                    return(false);
                }
                try
                {
                    switch (num)
                    {
                    }
                    if (enumerator.MoveNext())
                    {
                        toil          = enumerator.Current;
                        this.$current = toil;
                        if (!this.$disposing)
                        {
                            this.$PC = 1;
                        }
                        flag = true;
                        return(true);
                    }
                }
                finally
                {
                    if (!flag)
                    {
                        if (enumerator != null)
                        {
                            enumerator.Dispose();
                        }
                    }
                }
                this.$current = chew;
                if (!this.$disposing)
                {
                    this.$PC = 2;
                }
                return(true);
            }
コード例 #15
0
ファイル: RCellFinder.cs プロジェクト: wensincai/RW-Decompile
        public static IntVec3 SpotToChewStandingNear(Pawn pawn, Thing ingestible)
        {
            IntVec3             root         = pawn.Position;
            Room                rootRoom     = pawn.GetRoom(RegionType.Set_Passable);
            bool                desperate    = false;
            bool                ignoreDanger = false;
            float               maxDist      = 4f;
            Predicate <IntVec3> validator    = delegate(IntVec3 c)
            {
                if ((float)(root - c).LengthHorizontalSquared > maxDist * maxDist)
                {
                    return(false);
                }
                if (pawn.HostFaction != null && c.GetRoom(pawn.Map, RegionType.Set_Passable) != rootRoom)
                {
                    return(false);
                }
                if (!desperate)
                {
                    if (!c.Standable(pawn.Map))
                    {
                        return(false);
                    }
                    if (GenPlace.HaulPlaceBlockerIn(null, c, pawn.Map, false) != null)
                    {
                        return(false);
                    }
                    if (c.GetRegion(pawn.Map, RegionType.Set_Passable).type == RegionType.Portal)
                    {
                        return(false);
                    }
                }
                IntVec3 intVec2;
                return((ignoreDanger || c.GetDangerFor(pawn, pawn.Map) == Danger.None) && !c.ContainsStaticFire(pawn.Map) && !c.ContainsTrap(pawn.Map) && pawn.Map.pawnDestinationReservationManager.CanReserve(c, pawn, false) && Toils_Ingest.TryFindAdjacentIngestionPlaceSpot(c, ingestible.def, pawn, out intVec2));
            };
            int    maxRegions = 1;
            Region region     = pawn.GetRegion(RegionType.Set_Passable);

            for (int i = 0; i < 30; i++)
            {
                if (i == 1)
                {
                    desperate = true;
                }
                else if (i == 2)
                {
                    desperate  = false;
                    maxRegions = 4;
                }
                else if (i == 6)
                {
                    desperate = true;
                }
                else if (i == 10)
                {
                    desperate  = false;
                    maxDist    = 8f;
                    maxRegions = 12;
                }
                else if (i == 15)
                {
                    desperate = true;
                }
                else if (i == 20)
                {
                    maxDist    = 15f;
                    maxRegions = 16;
                }
                else if (i == 26)
                {
                    maxDist      = 5f;
                    maxRegions   = 4;
                    ignoreDanger = true;
                }
                else if (i == 29)
                {
                    maxDist    = 15f;
                    maxRegions = 16;
                }
                Region  reg = CellFinder.RandomRegionNear(region, maxRegions, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), null, null, RegionType.Set_Passable);
                IntVec3 intVec;
                if (reg.TryFindRandomCellInRegionUnforbidden(pawn, validator, out intVec))
                {
                    if (DebugViewSettings.drawDestSearch)
                    {
                        pawn.Map.debugDrawer.FlashCell(intVec, 0.5f, "go!", 50);
                    }
                    return(intVec);
                }
                if (DebugViewSettings.drawDestSearch)
                {
                    pawn.Map.debugDrawer.FlashCell(intVec, 0f, i.ToString(), 50);
                }
            }
            return(region.RandomCell);
        }
コード例 #16
0
ファイル: RCellFinder.cs プロジェクト: KraigXu/GameProject
        public static IntVec3 SpotToChewStandingNear(Pawn pawn, Thing ingestible)
        {
            IntVec3             root         = pawn.Position;
            Room                rootRoom     = pawn.GetRoom();
            bool                desperate    = false;
            bool                ignoreDanger = false;
            float               maxDist      = 4f;
            Predicate <IntVec3> validator    = delegate(IntVec3 c)
            {
                IntVec3 placeSpot = root - c;
                if ((float)placeSpot.LengthHorizontalSquared > maxDist * maxDist)
                {
                    return(false);
                }
                if (pawn.HostFaction != null && c.GetRoom(pawn.Map) != rootRoom)
                {
                    return(false);
                }
                if (!desperate)
                {
                    if (!c.Standable(pawn.Map))
                    {
                        return(false);
                    }
                    if (GenPlace.HaulPlaceBlockerIn(null, c, pawn.Map, checkBlueprintsAndFrames: false) != null)
                    {
                        return(false);
                    }
                    if (c.GetRegion(pawn.Map).type == RegionType.Portal)
                    {
                        return(false);
                    }
                }
                if (!ignoreDanger && c.GetDangerFor(pawn, pawn.Map) != Danger.None)
                {
                    return(false);
                }
                if (c.ContainsStaticFire(pawn.Map) || c.ContainsTrap(pawn.Map))
                {
                    return(false);
                }
                if (!pawn.Map.pawnDestinationReservationManager.CanReserve(c, pawn))
                {
                    return(false);
                }
                return(Toils_Ingest.TryFindAdjacentIngestionPlaceSpot(c, ingestible.def, pawn, out placeSpot) ? true : false);
            };
            int    maxRegions = 1;
            Region region     = pawn.GetRegion();

            for (int i = 0; i < 30; i++)
            {
                switch (i)
                {
                case 1:
                    desperate = true;
                    break;

                case 2:
                    desperate  = false;
                    maxRegions = 4;
                    break;

                case 6:
                    desperate = true;
                    break;

                case 10:
                    desperate  = false;
                    maxDist    = 8f;
                    maxRegions = 12;
                    break;

                case 15:
                    desperate = true;
                    break;

                case 20:
                    maxDist    = 15f;
                    maxRegions = 16;
                    break;

                case 26:
                    maxDist      = 5f;
                    maxRegions   = 4;
                    ignoreDanger = true;
                    break;

                case 29:
                    maxDist    = 15f;
                    maxRegions = 16;
                    break;
                }
                if (CellFinder.RandomRegionNear(region, maxRegions, TraverseParms.For(pawn)).TryFindRandomCellInRegionUnforbidden(pawn, validator, out IntVec3 result))
                {
                    if (DebugViewSettings.drawDestSearch)
                    {
                        pawn.Map.debugDrawer.FlashCell(result, 0.5f, "go!");
                    }
                    return(result);
                }
                if (DebugViewSettings.drawDestSearch)
                {
                    pawn.Map.debugDrawer.FlashCell(result, 0f, i.ToString());
                }
            }
            return(region.RandomCell);
        }
コード例 #17
0
            public bool MoveNext()
            {
                uint num = (uint)this.$PC;

                this.$PC = -1;
                Toil toil;

                switch (num)
                {
                case 0u:
                    this.FailOnDespawnedOrNull(TargetIndex.B);
                    if (this.eatingFromInventory)
                    {
                        this.$current = Toils_Misc.TakeItemFromInventoryToCarrier(this.pawn, TargetIndex.A);
                        if (!this.$disposing)
                        {
                            this.$PC = 1;
                        }
                        return(true);
                    }
                    if (this.usingNutrientPasteDispenser)
                    {
                        this.$current = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.InteractionCell).FailOnForbidden(TargetIndex.A);
                        if (!this.$disposing)
                        {
                            this.$PC = 2;
                        }
                        return(true);
                    }
                    this.$current = Toils_Reserve.Reserve(TargetIndex.A, 1, -1, null);
                    if (!this.$disposing)
                    {
                        this.$PC = 4;
                    }
                    return(true);

                case 1u:
                    break;

                case 2u:
                    this.$current = Toils_Ingest.TakeMealFromDispenser(TargetIndex.A, this.pawn);
                    if (!this.$disposing)
                    {
                        this.$PC = 3;
                    }
                    return(true);

                case 3u:
                    break;

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

                case 5u:
                    this.$current = Toils_Ingest.PickupIngestible(TargetIndex.A, base.Deliveree);
                    if (!this.$disposing)
                    {
                        this.$PC = 6;
                    }
                    return(true);

                case 6u:
                    break;

                case 7u:
                {
                    Toil toil = new Toil();
                    toil.initAction = delegate()
                    {
                        Thing thing;
                        this.pawn.carryTracker.TryDropCarriedThing(toil.actor.jobs.curJob.targetC.Cell, ThingPlaceMode.Direct, out thing, null);
                    };
                    toil.defaultCompleteMode = ToilCompleteMode.Instant;
                    this.$current            = toil;
                    if (!this.$disposing)
                    {
                        this.$PC = 8;
                    }
                    return(true);
                }

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

                default:
                    return(false);
                }
                toil            = new Toil();
                toil.initAction = delegate()
                {
                    Pawn actor  = toil.actor;
                    Job  curJob = actor.jobs.curJob;
                    actor.pather.StartPath(curJob.targetC, PathEndMode.OnCell);
                };
                toil.defaultCompleteMode = ToilCompleteMode.PatherArrival;
                toil.FailOnDestroyedNullOrForbidden(TargetIndex.B);
                toil.AddFailCondition(delegate
                {
                    Pawn pawn = (Pawn)toil.actor.jobs.curJob.targetB.Thing;
                    return(!pawn.IsPrisonerOfColony || !pawn.guest.CanBeBroughtFood);
                });
                this.$current = toil;
                if (!this.$disposing)
                {
                    this.$PC = 7;
                }
                return(true);
            }
コード例 #18
0
            public bool MoveNext()
            {
                uint num = (uint)this.$PC;

                this.$PC = -1;
                switch (num)
                {
                case 0u:
                    this.FailOnDespawnedNullOrForbidden(TargetIndex.B);
                    this.FailOn(() => !FoodUtility.ShouldBeFedBySomeone(base.Deliveree));
                    if (this.pawn.inventory != null && this.pawn.inventory.Contains(base.TargetThingA))
                    {
                        this.$current = Toils_Misc.TakeItemFromInventoryToCarrier(this.pawn, TargetIndex.A);
                        if (!this.$disposing)
                        {
                            this.$PC = 1;
                        }
                        return(true);
                    }
                    if (base.TargetThingA is Building_NutrientPasteDispenser)
                    {
                        this.$current = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.InteractionCell).FailOnForbidden(TargetIndex.A);
                        if (!this.$disposing)
                        {
                            this.$PC = 2;
                        }
                        return(true);
                    }
                    this.$current = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch).FailOnForbidden(TargetIndex.A);
                    if (!this.$disposing)
                    {
                        this.$PC = 4;
                    }
                    return(true);

                case 1u:
                    break;

                case 2u:
                    this.$current = Toils_Ingest.TakeMealFromDispenser(TargetIndex.A, this.pawn);
                    if (!this.$disposing)
                    {
                        this.$PC = 3;
                    }
                    return(true);

                case 3u:
                    break;

                case 4u:
                    this.$current = Toils_Ingest.PickupIngestible(TargetIndex.A, base.Deliveree);
                    if (!this.$disposing)
                    {
                        this.$PC = 5;
                    }
                    return(true);

                case 5u:
                    break;

                case 6u:
                    this.$current = Toils_Ingest.ChewIngestible(base.Deliveree, 1.5f, TargetIndex.A, TargetIndex.None).FailOnCannotTouch(TargetIndex.B, PathEndMode.Touch);
                    if (!this.$disposing)
                    {
                        this.$PC = 7;
                    }
                    return(true);

                case 7u:
                    this.$current = Toils_Ingest.FinalizeIngest(base.Deliveree, TargetIndex.A);
                    if (!this.$disposing)
                    {
                        this.$PC = 8;
                    }
                    return(true);

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

                default:
                    return(false);
                }
                this.$current = Toils_Goto.GotoThing(TargetIndex.B, PathEndMode.Touch);
                if (!this.$disposing)
                {
                    this.$PC = 6;
                }
                return(true);
            }
コード例 #19
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            base.AddFinishAction(delegate
            {
                this.$this.Map.attackTargetsCache.UpdateTarget(this.$this.pawn);
            });
            Toil prepareToEatCorpse = new Toil();

            prepareToEatCorpse.initAction = delegate
            {
                Pawn   actor  = prepareToEatCorpse.actor;
                Corpse corpse = this.$this.Corpse;
                if (corpse == null)
                {
                    Pawn prey = this.$this.Prey;
                    if (prey == null)
                    {
                        actor.jobs.EndCurrentJob(JobCondition.Incompletable, true);
                        return;
                    }
                    corpse = prey.Corpse;
                    if (corpse == null || !corpse.Spawned)
                    {
                        actor.jobs.EndCurrentJob(JobCondition.Incompletable, true);
                        return;
                    }
                }
                if (actor.Faction == Faction.OfPlayer)
                {
                    corpse.SetForbidden(false, false);
                }
                else
                {
                    corpse.SetForbidden(true, false);
                }
                actor.CurJob.SetTarget(TargetIndex.A, corpse);
            };
            yield return(Toils_General.DoAtomic(delegate
            {
                this.$this.Map.attackTargetsCache.UpdateTarget(this.$this.pawn);
            }));

            Action onHitAction = delegate
            {
                Pawn prey           = this.$this.Prey;
                bool surpriseAttack = this.$this.firstHit && !prey.IsColonist;
                if (this.$this.pawn.meleeVerbs.TryMeleeAttack(prey, this.$this.job.verbToUse, surpriseAttack))
                {
                    if (!this.$this.notifiedPlayerAttacked && PawnUtility.ShouldSendNotificationAbout(prey))
                    {
                        this.$this.notifiedPlayerAttacked = true;
                        Messages.Message("MessageAttackedByPredator".Translate(prey.LabelShort, this.$this.pawn.LabelIndefinite(), prey.Named("PREY"), this.$this.pawn.Named("PREDATOR")).CapitalizeFirst(), prey, MessageTypeDefOf.ThreatSmall, true);
                    }
                    this.$this.Map.attackTargetsCache.UpdateTarget(this.$this.pawn);
                    this.$this.firstHit = false;
                }
            };
            Toil followAndAttack = Toils_Combat.FollowAndMeleeAttack(TargetIndex.A, onHitAction).JumpIfDespawnedOrNull(TargetIndex.A, prepareToEatCorpse).JumpIf(() => this.$this.Corpse != null, prepareToEatCorpse).FailOn(() => Find.TickManager.TicksGame > this.$this.startTick + 5000 && (float)(this.$this.job.GetTarget(TargetIndex.A).Cell - this.$this.pawn.Position).LengthHorizontalSquared > 4f);

            followAndAttack.AddPreTickAction(new Action(this.CheckWarnPlayer));
            yield return(followAndAttack);

            yield return(prepareToEatCorpse);

            Toil gotoCorpse = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch);

            yield return(gotoCorpse);

            float durationMultiplier = 1f / this.pawn.GetStatValue(StatDefOf.EatingSpeed, true);

            yield return(Toils_Ingest.ChewIngestible(this.pawn, durationMultiplier, TargetIndex.A, TargetIndex.None).FailOnDespawnedOrNull(TargetIndex.A).FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch));

            yield return(Toils_Ingest.FinalizeIngest(this.pawn, TargetIndex.A));

            yield return(Toils_Jump.JumpIf(gotoCorpse, () => this.$this.pawn.needs.food.CurLevelPercentage < 0.9f));
        }
コード例 #20
0
        public static Toil ChewIngestible(Pawn chewer, float durationMultiplier, TargetIndex ingestibleInd, TargetIndex eatSurfaceInd = TargetIndex.None)
        {
            Toil toil = new Toil();

            toil.initAction = delegate()
            {
                Pawn  actor = toil.actor;
                Thing thing = actor.CurJob.GetTarget(ingestibleInd).Thing;
                if (!thing.IngestibleNow)
                {
                    chewer.jobs.EndCurrentJob(JobCondition.Incompletable, true);
                }
                else
                {
                    actor.jobs.curDriver.ticksLeftThisToil = Mathf.RoundToInt((float)thing.def.ingestible.baseIngestTicks * durationMultiplier);
                    if (thing.Spawned)
                    {
                        thing.Map.physicalInteractionReservationManager.Reserve(chewer, actor.CurJob, thing);
                    }
                }
            };
            toil.tickAction = delegate()
            {
                if (chewer != toil.actor)
                {
                    toil.actor.rotationTracker.FaceCell(chewer.Position);
                }
                else
                {
                    Thing thing = toil.actor.CurJob.GetTarget(ingestibleInd).Thing;
                    if (thing != null && thing.Spawned)
                    {
                        toil.actor.rotationTracker.FaceCell(thing.Position);
                    }
                    else if (eatSurfaceInd != TargetIndex.None && toil.actor.CurJob.GetTarget(eatSurfaceInd).IsValid)
                    {
                        toil.actor.rotationTracker.FaceCell(toil.actor.CurJob.GetTarget(eatSurfaceInd).Cell);
                    }
                }
                toil.actor.GainComfortFromCellIfPossible();
            };
            toil.WithProgressBar(ingestibleInd, delegate
            {
                Pawn actor  = toil.actor;
                Thing thing = actor.CurJob.GetTarget(ingestibleInd).Thing;
                float result;
                if (thing == null)
                {
                    result = 1f;
                }
                else
                {
                    result = 1f - (float)toil.actor.jobs.curDriver.ticksLeftThisToil / Mathf.Round((float)thing.def.ingestible.baseIngestTicks * durationMultiplier);
                }
                return(result);
            }, false, -0.5f);
            toil.defaultCompleteMode = ToilCompleteMode.Delay;
            toil.FailOnDestroyedOrNull(ingestibleInd);
            toil.AddFinishAction(delegate
            {
                if (chewer != null)
                {
                    if (chewer.CurJob != null)
                    {
                        Thing thing = chewer.CurJob.GetTarget(ingestibleInd).Thing;
                        if (thing != null)
                        {
                            if (chewer.Map.physicalInteractionReservationManager.IsReservedBy(chewer, thing))
                            {
                                chewer.Map.physicalInteractionReservationManager.Release(chewer, toil.actor.CurJob, thing);
                            }
                        }
                    }
                }
            });
            toil.handlingFacing = true;
            Toils_Ingest.AddIngestionEffects(toil, chewer, ingestibleInd, eatSurfaceInd);
            return(toil);
        }
コード例 #21
0
            public bool MoveNext()
            {
                uint num = (uint)this.$PC;

                this.$PC = -1;
                switch (num)
                {
                case 0u:
                    this.EndOnDespawnedOrNull(TargetIndex.A, JobCondition.Incompletable);
                    if (base.HasChair)
                    {
                        this.EndOnDespawnedOrNull(TargetIndex.B, JobCondition.Incompletable);
                    }
                    if (base.HasDrink)
                    {
                        this.FailOnDestroyedNullOrForbidden(TargetIndex.C);
                        this.$current = Toils_Goto.GotoThing(TargetIndex.C, PathEndMode.OnCell).FailOnSomeonePhysicallyInteracting(TargetIndex.C);
                        if (!this.$disposing)
                        {
                            this.$PC = 1;
                        }
                        return(true);
                    }
                    break;

                case 1u:
                    this.$current = Toils_Haul.StartCarryThing(TargetIndex.C, false, false, false);
                    if (!this.$disposing)
                    {
                        this.$PC = 2;
                    }
                    return(true);

                case 2u:
                    break;

                case 3u:
                    chew            = new Toil();
                    chew.tickAction = delegate()
                    {
                        this.pawn.rotationTracker.FaceCell(base.ClosestGatherSpotParentCell);
                        this.pawn.GainComfortFromCellIfPossible();
                        JoyUtility.JoyTickCheckEnd(this.pawn, JoyTickFullJoyAction.GoToNextToil, 1f, null);
                    };
                    chew.handlingFacing      = true;
                    chew.defaultCompleteMode = ToilCompleteMode.Delay;
                    chew.defaultDuration     = this.job.def.joyDuration;
                    chew.AddFinishAction(delegate
                    {
                        JoyUtility.TryGainRecRoomThought(this.pawn);
                    });
                    chew.socialMode = RandomSocialMode.SuperActive;
                    Toils_Ingest.AddIngestionEffects(chew, this.pawn, TargetIndex.C, TargetIndex.None);
                    this.$current = chew;
                    if (!this.$disposing)
                    {
                        this.$PC = 4;
                    }
                    return(true);

                case 4u:
                    if (base.HasDrink)
                    {
                        this.$current = Toils_Ingest.FinalizeIngest(this.pawn, TargetIndex.C);
                        if (!this.$disposing)
                        {
                            this.$PC = 5;
                        }
                        return(true);
                    }
                    goto IL_1D6;

                case 5u:
                    goto IL_1D6;

                default:
                    return(false);
                }
                this.$current = Toils_Goto.GotoCell(TargetIndex.B, PathEndMode.OnCell);
                if (!this.$disposing)
                {
                    this.$PC = 3;
                }
                return(true);

IL_1D6:
                this.$PC = -1;
                return(false);
            }