예제 #1
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDestroyedOrNull(TargetIndex.A);

            Toil gotoThing = new Toil();

            gotoThing.initAction = delegate
            {
                this.pawn.pather.StartPath(this.TargetThingA, PathEndMode.ClosestTouch);
            };
            gotoThing.defaultCompleteMode = ToilCompleteMode.PatherArrival;
            gotoThing.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            yield return(gotoThing);

            yield return(Toils_ItemBelt.TakeToItemBelt(TargetIndex.A, this.job.count));
        }
예제 #2
0
        public static Toil TakeToItemBelt(TargetIndex ind, Func <int> countGetter)
        {
            Toil takeThing = new Toil();

            takeThing.initAction = delegate
            {
                Pawn  actor = takeThing.actor;
                Thing thing = actor.CurJob.GetTarget(ind).Thing;
                Toils_ItemBelt.ErrorCheck(actor, thing);
                int num = Mathf.Min(countGetter(), thing.stackCount);
                if (num <= 0)
                {
                    actor.jobs.curDriver.ReadyForNextToil();
                }
                else
                {
                    CompItemBelt comp = actor.GetComp <CompItemBelt>();
                    if (comp.innerContainer == null)
                    {
                        comp.Initialize(comp.props);
                    }
                    if (comp != null)
                    {
                        if (comp.innerContainer.Count > 0)
                        {
                            if (comp.innerContainer[0].def != thing.def)
                            {
                                comp.innerContainer.TryDropAll(actor.Position, actor.Map, ThingPlaceMode.Near);
                            }
                        }
                        comp.innerContainer.TryAdd(thing.SplitOff(num), true);
                        if (thing.def.ingestible != null && thing.def.ingestible.preferability <= FoodPreferability.RawTasty)
                        {
                            actor.mindState.lastInventoryRawFoodUseTick = Find.TickManager.TicksGame;
                        }
                        thing.def.soundPickup.PlayOneShot(new TargetInfo(actor.Position, actor.Map, false));
                    }
                    else
                    {
                        Log.Message("comp was null");
                    }
                }
            };
            return(takeThing);
        }
예제 #3
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDestroyedOrNull(TargetIndex.A);
            Toil gotoThing = new Toil();

            gotoThing.initAction = delegate
            {
                this.pawn.pather.StartPath(this.TargetThingA, PathEndMode.ClosestTouch);
            };
            gotoThing.defaultCompleteMode = ToilCompleteMode.PatherArrival;
            gotoThing.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            yield return(gotoThing);

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

            yield return(Toils_ItemBelt.ChewIngestible(pawn, .8f, TargetIndex.A, TargetIndex.None));

            yield return(Toils_ItemBelt.FinalizeIngest(pawn, TargetIndex.A));
        }
예제 #4
0
 public static Toil TakeToItemBelt(TargetIndex ind, int count)
 {
     return(Toils_ItemBelt.TakeToItemBelt(ind, () => count));
 }
예제 #5
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);
                    return;
                }
                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;
                if (thing == null)
                {
                    return(1f);
                }
                return(1f - (float)toil.actor.jobs.curDriver.ticksLeftThisToil / Mathf.Round((float)thing.def.ingestible.baseIngestTicks * durationMultiplier));
            }, false, -0.5f);
            toil.defaultCompleteMode = ToilCompleteMode.Delay;
            toil.FailOnDestroyedOrNull(ingestibleInd);
            toil.AddFinishAction(delegate
            {
                if (chewer == null)
                {
                    return;
                }
                if (chewer.CurJob == null)
                {
                    return;
                }
                Thing thing = chewer.CurJob.GetTarget(ingestibleInd).Thing;
                if (thing == null)
                {
                    return;
                }
                if (chewer.Map.physicalInteractionReservationManager.IsReservedBy(chewer, thing))
                {
                    chewer.Map.physicalInteractionReservationManager.Release(chewer, toil.actor.CurJob, thing);
                }
            });
            toil.handlingFacing = true;
            Toils_ItemBelt.AddIngestionEffects(toil, chewer, ingestibleInd, eatSurfaceInd);
            return(toil);
        }