Ejemplo n.º 1
0
        // Token: 0x0600012B RID: 299 RVA: 0x0000C0A4 File Offset: 0x0000A4A4
        protected override IEnumerable <Toil> MakeNewToils()
        {
            yield return(Toils_Reserve.Reserve((Verse.AI.TargetIndex) 1, 1, -1, null));

            yield return(Toils_Reserve.Reserve((Verse.AI.TargetIndex) 2, 1, -1, null));

            yield return(Toils_Goto.GotoThing((Verse.AI.TargetIndex) 1, (Verse.AI.PathEndMode) 3));

            yield return(Toils_Haul.StartCarryThing((Verse.AI.TargetIndex) 1, false, false));

            yield return(Toils_Haul.CarryHauledThingToCell((Verse.AI.TargetIndex) 2));

            Toil t2 = Toils_General.Wait(1000);

            t2.AddFailCondition(() => !this.Emitter.GetComp <CompPowerTrader>().PowerOn);
            t2 = ToilEffects.WithProgressBar(t2, (Verse.AI.TargetIndex) 1, () => (1000f - (float)this.ticksLeftThisToil) / 1000f, false, -0.5f);
            yield return(t2);

            yield return(new Toil
            {
                defaultCompleteMode = (Verse.AI.ToilCompleteMode) 1,
                initAction = delegate()
                {
                    this.Emitter.GetComp <CompHoloEmitter>().Scan(this.Corpse);
                }
            });

            yield return(Toils_Reserve.Release((Verse.AI.TargetIndex) 2));

            yield break;
        }
Ejemplo n.º 2
0
        // Token: 0x06000026 RID: 38 RVA: 0x000026A3 File Offset: 0x000008A3
        protected override IEnumerable <Toil> MakeNewToils()
        {
            base.AddEndCondition(delegate()
            {
                if (this.pawn.Faction == Faction.OfPlayer && HealthAIUtility.ShouldBeTendedNowByPlayer(this.pawn))
                {
                    return(JobCondition.Ongoing);
                }
                if (this.pawn.Faction != Faction.OfPlayer && this.pawn.health.HasHediffsNeedingTend(false))
                {
                    return(JobCondition.Ongoing);
                }
                return(JobCondition.Succeeded);
            });
            int ticks = (int)(1f / StatExtension.GetStatValue(this.pawn, StatDefOf.MedicalTendSpeed, true) * 600f);

            yield return(ToilEffects.PlaySustainerOrSound(ToilEffects.WithProgressBarToilDelay(Toils_General.Wait(ticks, 0), (TargetIndex)1, false, -0.5f), SoundDefOf.Interact_Tend));

            Toil toil = new Toil();

            toil.initAction = delegate()
            {
                Pawn     actor  = toil.actor;
                Cloakgen medkit = actor.apparel.WornApparel.OfType <Cloakgen>().FirstOrDefault <Cloakgen>();
                float    num    = (!actor.RaceProps.Animal) ? 500f : 175f;
                float    num2   = (medkit != null) ? medkit.kitComp.Props.medicine.MedicineTendXpGainFactor : 0.5f;
                actor.skills.Learn(SkillDefOf.Medicine, num * num2, false);
                HealthShardTendUtility.DoTend(actor, actor, medkit);
            };
            toil.defaultCompleteMode = (ToilCompleteMode)1;
            yield return(toil);

            yield break;
        }
Ejemplo n.º 3
0
        // Token: 0x06000002 RID: 2 RVA: 0x00002072 File Offset: 0x00000272
        protected override IEnumerable <Toil> MakeNewToils()
        {
            ToilFailConditions.FailOnDespawnedOrNull <JobDriver_RearmTrap>(this, TargetIndex.A);
            ToilFailConditions.FailOnThingMissingDesignation <JobDriver_RearmTrap>(this, TargetIndex.A, YautjaDefOf.RRY_RearmTrap);
            Toil toil = new Toil();

            toil.initAction = delegate()
            {
                this.pawn.pather.StartPath(base.TargetThingA, PathEndMode.Touch);
            };
            toil.defaultCompleteMode = ToilCompleteMode.PatherArrival;
            ToilFailConditions.FailOnDespawnedNullOrForbidden <Toil>(toil, TargetIndex.A);
            yield return(toil);

            yield return(ToilEffects.WithProgressBarToilDelay(Toils_General.Wait(1125, 0), TargetIndex.A, false, -0.5f));

            yield return(new Toil
            {
                initAction = delegate()
                {
                    Thing thing = this.job.targetA.Thing;
                    Designation designation = base.Map.designationManager.DesignationOn(thing, YautjaDefOf.RRY_RearmTrap);
                    if (designation != null)
                    {
                        designation.Delete();
                    }
                    (thing as Building_TrapRearmable).Rearm();
                    this.pawn.records.Increment(YautjaDefOf.RRY_TrapsRearmed);
                },
                defaultCompleteMode = ToilCompleteMode.Instant
            });

            yield break;
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.InteractionCell));

            Toil exitPocket = Toils_General.Wait(60, 0);

            ToilEffects.WithProgressBarToilDelay(exitPocket, TargetIndex.A, false, -0.5f);
            ToilFailConditions.FailOnDespawnedNullOrForbidden <Toil>(exitPocket, TargetIndex.A);
            ToilFailConditions.FailOnCannotTouch <Toil>(exitPocket, TargetIndex.A, PathEndMode.InteractionCell);
            yield return(exitPocket);

            yield return(new Toil
            {
                initAction = delegate()
                {
                    Pawn pawn = GetActor();
                    if (TargetA.Thing is Building_PocketDimensionExit pocketDimensionExit)
                    {
                        //PocketDimensionBox box = pocketDimensionExit.GetBox();

                        //if (box != null)
                        //{
                        //    pawn.DeSpawn(DestroyMode.Vanish);
                        //    GenSpawn.Spawn(pawn, box.Position, box.Map, WipeMode.Vanish);
                        //}
                    }
                }
            });
Ejemplo n.º 5
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.OnCell));

            Toil extractStack = Toils_General.Wait(120, 0);

            ToilEffects.WithProgressBarToilDelay(extractStack, TargetIndex.A, false, -0.5f);
            ToilFailConditions.FailOnDespawnedNullOrForbidden <Toil>(extractStack, TargetIndex.A);
            ToilFailConditions.FailOnCannotTouch <Toil>(extractStack, TargetIndex.A, PathEndMode.OnCell);
            yield return(extractStack);

            yield return(new Toil
            {
                initAction = delegate()
                {
                    Corpse corpse = (Corpse)TargetThingA;
                    Hediff_CorticalStack hediff = corpse.InnerPawn.health.hediffSet.hediffs.FirstOrDefault((Hediff x) =>
                                                                                                           x.def.defName == "AC_CorticalStack") as Hediff_CorticalStack;
                    if (hediff != null)
                    {
                        if (hediff.def.spawnThingOnRemoved != null)
                        {
                            var corticalStack = ThingMaker.MakeThing(hediff.def.spawnThingOnRemoved) as CorticalStack;
                            if (hediff.hasPawn)
                            {
                                corticalStack.SavePawnFromHediff(hediff);
                            }
                            else
                            {
                                corticalStack.SavePawnToCorticalStack(corpse.InnerPawn);
                            }
                            GenPlace.TryPlaceThing(corticalStack, TargetThingA.Position, GetActor().Map, ThingPlaceMode.Near);
                            ACUtils.ACTracker.RegisterStack(corticalStack);
                            ACUtils.ACTracker.RegisterSleeve(corpse.InnerPawn, corticalStack.stackGroupID);
                        }
                        var head = corpse.InnerPawn.health.hediffSet.GetNotMissingParts().FirstOrDefault((BodyPartRecord x) => x.def == BodyPartDefOf.Head);
                        if (head != null)
                        {
                            Hediff_MissingPart hediff_MissingPart = (Hediff_MissingPart)HediffMaker.MakeHediff(HediffDefOf.MissingBodyPart, corpse.InnerPawn, head);
                            hediff_MissingPart.lastInjury = HediffDefOf.SurgicalCut;
                            hediff_MissingPart.IsFresh = true;
                            corpse.InnerPawn.health.AddHediff(hediff_MissingPart);
                        }
                        corpse.InnerPawn.health.RemoveHediff(hediff);
                        if (pawn.Map.designationManager.DesignationOn(corpse).def == AlteredCarbonDefOf.AC_ExtractStackDesignation)
                        {
                            pawn.Map.designationManager.TryRemoveDesignationOn(corpse, AlteredCarbonDefOf.AC_ExtractStackDesignation);
                        }
                    }
                }
            });
        }
Ejemplo n.º 6
0
        /*
         * //maybe change?
         * protected abstract int GatherResourcesIntervalDays
         * {
         *      get;
         * }
         *
         * //add breastsize modifier?
         * protected abstract int ResourceAmount
         * {
         *      get;
         * }
         * //add more  milks?
         * protected abstract ThingDef ResourceDef
         * {
         *      get;
         * }
         */

        protected override IEnumerable <Toil> MakeNewToils()
        {
            ToilFailConditions.FailOnDespawnedNullOrForbidden <JobDriver_GatherHumanBodyResources>(this, TargetIndex.A);
            ToilFailConditions.FailOnNotCasualInterruptible <JobDriver_GatherHumanBodyResources>(this, TargetIndex.A);
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch));

            Toil wait = new Toil();

            wait.initAction = delegate
            {
                Pawn            milker  = base.pawn;
                LocalTargetInfo target  = base.job.GetTarget(TargetIndex.A);
                Pawn            target2 = (Pawn)target.Thing;
                milker.pather.StopDead();
                PawnUtility.ForceWait(target2, 15000, null, true);
            };
            wait.tickAction = delegate
            {
                Pawn milker = base.pawn;
                milker.skills.Learn(SkillDefOf.Animals, 0.13f, false);
                gatherProgress += StatExtension.GetStatValue(milker, StatDefOf.AnimalGatherSpeed, true);
                if (gatherProgress >= WorkTotal)
                {
                    GetComp((Pawn)base.job.GetTarget(TargetIndex.A)).Gathered(base.pawn);
                    milker.jobs.EndCurrentJob(JobCondition.Succeeded, true);
                }
            };
            wait.AddFinishAction((Action) delegate
            {
                Pawn milker            = base.pawn;
                LocalTargetInfo target = base.job.GetTarget(TargetIndex.A);
                Pawn target2           = (Pawn)target.Thing;
                if (target2 != null && target2.CurJobDef == JobDefOf.Wait_MaintainPosture)
                {
                    milker.jobs.EndCurrentJob(JobCondition.InterruptForced, true);
                }
            });
            ToilFailConditions.FailOnDespawnedOrNull <Toil>(wait, TargetIndex.A);
            ToilFailConditions.FailOnCannotTouch <Toil>(wait, TargetIndex.A, PathEndMode.Touch);
            wait.AddEndCondition((Func <JobCondition>) delegate
            {
                if (GetComp((Pawn)base.job.GetTarget(TargetIndex.A)).ActiveAndFull)
                {
                    return(JobCondition.Ongoing);
                }
                return(JobCondition.Incompletable);
            });
            wait.defaultCompleteMode = ToilCompleteMode.Never;
            ToilEffects.WithProgressBar(wait, TargetIndex.A, (Func <float>)(() => gatherProgress / WorkTotal), false, -0.5f);
            wait.activeSkill = (() => SkillDefOf.Animals);
            yield return(wait);
        }
Ejemplo n.º 7
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            ToilFailConditions.FailOnDespawnedNullOrForbidden(this, TargetIndex.A);
            ToilFailConditions.FailOnNotCasualInterruptible(this, TargetIndex.A);
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch));

            Toil wait = new Toil();

            wait.initAction = delegate()
            {
                Pawn actor = wait.actor;
                Pawn pawn  = (Pawn)job.GetTarget(TargetIndex.A).Thing;
                actor.pather.StopDead();
                PawnUtility.ForceWait(pawn, 15000, null, true);
            };
            wait.tickAction = delegate()
            {
                Pawn actor = wait.actor;
                actor.skills.Learn(SkillDefOf.Animals, 0.13f, false);
                gatherProgress += StatExtension.GetStatValue(actor, StatDefOf.AnimalGatherSpeed, true);
                if (gatherProgress >= WorkTotal)
                {
                    GetComp((Pawn)((Thing)job.GetTarget(TargetIndex.A))).Gathered(this.pawn);
                    actor.jobs.EndCurrentJob(JobCondition.Succeeded, true);
                }
            };
            wait.AddFinishAction(delegate()
            {
                Pawn pawn = (Pawn)job.GetTarget(TargetIndex.A).Thing;
                if (pawn != null && pawn.CurJobDef == JobDefOf.Wait_MaintainPosture)
                {
                    pawn.jobs.EndCurrentJob(JobCondition.InterruptForced, true);
                }
            });
            ToilFailConditions.FailOnDespawnedOrNull <Toil>(wait, TargetIndex.A);
            ToilFailConditions.FailOnCannotTouch <Toil>(wait, TargetIndex.A, PathEndMode.Touch);
            wait.AddEndCondition(delegate()
            {
                if (!GetComp((Pawn)((Thing)this.job.GetTarget(TargetIndex.A))).ActiveAndFull)
                {
                    return(JobCondition.Incompletable);
                }
                return(JobCondition.Ongoing);
            });
            wait.defaultCompleteMode = ToilCompleteMode.Never;
            ToilEffects.WithProgressBar(wait, TargetIndex.A, () => this.gatherProgress / this.WorkTotal, false, -0.5f);
            wait.activeSkill = (() => SkillDefOf.Animals);
            yield return(wait);

            yield break;
        }
Ejemplo n.º 8
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            ToilFailConditions.FailOnDestroyedOrNull <JobDriver_Segmentation>(this, TargetIndex.A);
            ToilFailConditions.FailOnDespawnedOrNull <JobDriver_Segmentation>(this, TargetIndex.A);
            ToilFailConditions.FailOn <JobDriver_Segmentation>(this, new Func <bool>(this.eaterIsKilled));
            Toil resCorpse = new Toil();

            resCorpse.initAction = delegate()
            {
                Pawn  actor = resCorpse.actor;
                Thing thing = resCorpse.actor.CurJob.GetTarget(TargetIndex.A).Thing;
                bool  flag  = !thing.Spawned || !this.Map.reservationManager.CanReserve(actor, thing, 1);
                bool  flag2 = flag;
                if (flag2)
                {
                    actor.jobs.EndCurrentJob(JobCondition.Incompletable, true);
                }
                else
                {
                    this.Map.reservationManager.Reserve(actor, actor.CurJob, thing, 1);
                }
            };
            resCorpse.defaultCompleteMode = ToilCompleteMode.Instant;
            yield return(resCorpse);

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

            yield return(Toils_General.Wait(400));

            Toil toil = new Toil
            {
                defaultCompleteMode = ToilCompleteMode.Instant
            };

            toil.initAction = new Action(this.doStripCorpse);
            yield return(toil);

            yield return(Toils_General.Wait(60));

            Toil toil2 = new Toil
            {
                defaultCompleteMode = ToilCompleteMode.Instant
            };

            toil2.initAction = new Action(this.doChewCorpse);
            ToilEffects.WithEffect(toil2, EffecterDefOf.EatMeat, TargetIndex.A);
            ToilFailConditions.EndOnDespawnedOrNull <Toil>(toil2, TargetIndex.A, JobCondition.Incompletable);
            yield return(toil2);

            yield break;
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDestroyedOrNull(TargetIndex.A);
            this.FailOnDestroyedOrNull(TargetIndex.B);
            this.FailOnAggroMentalState(TargetIndex.A);

            Toil approachPrisoner = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch);

            yield return(approachPrisoner);

            Toil collectPrisoner = Toils_Haul.StartCarryThing(TargetIndex.A, false, false, false);

            yield return(collectPrisoner);

            Toil escortPrisoner = Toils_Goto.GotoThing(TargetIndex.B, PathEndMode.InteractionCell);

            //Toil escortPrisoner = Toils_Haul.CarryHauledThingToContainer(.GotoThing(TargetIndex.B, PathEndMode.InteractionCell);
            yield return(escortPrisoner);

            Toil enterPocket = Toils_General.Wait(60, 0);

            ToilEffects.WithProgressBarToilDelay(enterPocket, TargetIndex.B, false, -0.5f);
            ToilFailConditions.FailOnCannotTouch <Toil>(enterPocket, TargetIndex.B, PathEndMode.InteractionCell);
            yield return(enterPocket);

            yield return(new Toil
            {
                initAction = delegate()
                {
                    Thing thing;
                    pawn.carryTracker.TryDropCarriedThing(TargetB.Thing.Position, ThingPlaceMode.Direct, out thing);

                    if (TargetA.Thing is Pawn prisoner && TargetB.Thing is Building_PocketDimensionEntranceBase pocketDimensionEntrance)
                    {
                        Building_PocketDimensionEntranceBase otherSide = PocketDimensionUtility.GetOtherSide(pocketDimensionEntrance);

                        if (otherSide != null && otherSide.Map != null)
                        {
                            IntVec3 position = otherSide.Position;
                            Map map = otherSide.Map;

                            if (position != null && map != null)
                            {
                                prisoner.DeSpawn(DestroyMode.Vanish);
                                GenSpawn.Spawn(prisoner, position, map, WipeMode.Vanish);
                            }
                        }
                    }
                }
            });
        // Token: 0x06000030 RID: 48 RVA: 0x00002C83 File Offset: 0x00000E83
        protected override IEnumerable <Toil> MakeNewToils()
        {
            CompUniversalFermenter comp = ThingCompUtility.TryGetComp <CompUniversalFermenter>(this.Fermenter);

            ToilFailConditions.FailOn <JobDriver_TakeProductOutOfUniversalFermenter>(this, () => !comp.Fermented);
            ToilFailConditions.FailOnDestroyedNullOrForbidden <JobDriver_TakeProductOutOfUniversalFermenter>(this, (TargetIndex)1);
            yield return(Toils_Reserve.Reserve((TargetIndex)1, 1, -1, null));

            yield return(Toils_Goto.GotoThing((TargetIndex)1, (PathEndMode)3));

            yield return(ToilEffects.WithProgressBarToilDelay(ToilFailConditions.FailOnDestroyedNullOrForbidden <Toil>(Toils_General.Wait(200, 0), (TargetIndex)1), (TargetIndex)1, false, -0.5f));

            yield return(new Toil
            {
                initAction = delegate()
                {
                    Thing thing = comp.TakeOutProduct();
                    GenPlace.TryPlaceThing(thing, this.pawn.Position, this.Map, (ThingPlaceMode)1, null, null);
                    StoragePriority storagePriority = StoreUtility.CurrentStoragePriorityOf(thing);
                    IntVec3 intVec;
                    if (StoreUtility.TryFindBestBetterStoreCellFor(thing, this.pawn, this.Map, storagePriority, this.pawn.Faction, out intVec, true))
                    {
                        this.job.SetTarget((TargetIndex)2, thing);
                        this.job.count = thing.stackCount;
                        this.job.SetTarget((TargetIndex)3, intVec);
                        return;
                    }
                    this.EndJobWith((JobCondition)3);
                },
                defaultCompleteMode = (ToilCompleteMode)1
            });

            yield return(Toils_Reserve.Reserve((TargetIndex)2, 1, -1, null));

            yield return(Toils_Reserve.Reserve((TargetIndex)3, 1, -1, null));

            yield return(Toils_Goto.GotoThing((TargetIndex)2, (PathEndMode)3));

            yield return(Toils_Haul.StartCarryThing((TargetIndex)2, false, false, false));

            Toil carry = Toils_Haul.CarryHauledThingToCell((TargetIndex)3);

            yield return(carry);

            yield return(Toils_Haul.PlaceHauledThingInCell((TargetIndex)3, carry, true));

            yield break;
        }
Ejemplo n.º 11
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.InteractionCell));

            Toil enterPocket = Toils_General.Wait(60, 0);

            ToilEffects.WithProgressBarToilDelay(enterPocket, TargetIndex.A, false, -0.5f);
            ToilFailConditions.FailOnDespawnedNullOrForbidden <Toil>(enterPocket, TargetIndex.A);
            ToilFailConditions.FailOnCannotTouch <Toil>(enterPocket, TargetIndex.A, PathEndMode.InteractionCell);
            yield return(enterPocket);

            yield return(new Toil
            {
                initAction = delegate()
                {
                    Pawn pawn = GetActor();
                    if (TargetA.Thing is Building_PocketDimensionEntranceBase pocketDimensionEntrance)
                    {
                        Building_PocketDimensionEntranceBase otherSide = PocketDimensionUtility.GetOtherSide(pocketDimensionEntrance);

                        if (otherSide != null && otherSide.Map != null)
                        {
                            IntVec3 position = otherSide.Position;
                            Map map = otherSide.Map;

                            // If otherSide is uninstalled...
                            if (otherSide.Map == null && otherSide.holdingOwner != null && otherSide.holdingOwner.Owner != null && (otherSide.holdingOwner.Owner as MinifiedThing) != null)
                            {
                                MinifiedThing miniThing = (otherSide.holdingOwner.Owner as MinifiedThing);
                                position = miniThing.Position;
                                map = miniThing.Map;
                            }

                            if (position != null && map != null)
                            {
                                pawn.ClearAllReservations();
                                pawn.DeSpawn(DestroyMode.Vanish);
                                GenSpawn.Spawn(pawn, position, map, WipeMode.Vanish);
                            }
                        }
                    }
                }
            });
        protected override IEnumerable <Toil> MakeNewToils()
        {
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.OnCell));

            Toil extractStack = Toils_General.Wait(120, 0);

            ToilEffects.WithProgressBarToilDelay(extractStack, TargetIndex.A, false, -0.5f);
            ToilFailConditions.FailOnDespawnedNullOrForbidden <Toil>(extractStack, TargetIndex.A);
            ToilFailConditions.FailOnCannotTouch <Toil>(extractStack, TargetIndex.A, PathEndMode.OnCell);
            yield return(extractStack);

            yield return(new Toil
            {
                initAction = delegate()
                {
                    Corpse corpse = (Corpse)TargetThingA;
                    Hediff_CorticalStack hediff = corpse.InnerPawn.health.hediffSet.hediffs.FirstOrDefault((Hediff x) =>
                                                                                                           x.def.defName == "AC_CorticalStack") as Hediff_CorticalStack;
                    if (hediff != null)
                    {
                        if (hediff.def.spawnThingOnRemoved != null)
                        {
                            var corticalStack = ThingMaker.MakeThing(hediff.def.spawnThingOnRemoved) as CorticalStack;
                            if (hediff.hasPawn)
                            {
                                corticalStack.SavePawnFromHediff(hediff);
                            }
                            else
                            {
                                corticalStack.SavePawnToCorticalStack(corpse.InnerPawn);
                            }
                            GenPlace.TryPlaceThing(corticalStack, TargetThingA.Position, GetActor().Map, ThingPlaceMode.Near);
                            ACUtils.ACTracker.RegisterStack(corticalStack);
                            ACUtils.ACTracker.RegisterSleeve(corpse.InnerPawn);
                        }
                        corpse.InnerPawn.health.RemoveHediff(hediff);
                    }
                }
            });
        }
        // Token: 0x0600002B RID: 43 RVA: 0x00002C03 File Offset: 0x00000E03
        protected override IEnumerable <Toil> MakeNewToils()
        {
            CompUniversalFermenter comp = ThingCompUtility.TryGetComp <CompUniversalFermenter>(this.Fermenter);

            ToilFailConditions.FailOn <JobDriver_FillUniversalFermenter>(this, () => comp.SpaceLeftForIngredient <= 0);
            ToilFailConditions.FailOnDestroyedNullOrForbidden <JobDriver_FillUniversalFermenter>(this, (TargetIndex)1);
            ToilFailConditions.FailOnDestroyedNullOrForbidden <JobDriver_FillUniversalFermenter>(this, (TargetIndex)2);
            Toil ingrToil = Toils_Reserve.Reserve((TargetIndex)2, 1, -1, null);

            yield return(ingrToil);

            yield return(Toils_Reserve.Reserve((TargetIndex)1, 1, -1, null));

            yield return(ToilFailConditions.FailOnDestroyedNullOrForbidden <Toil>(ToilFailConditions.FailOnSomeonePhysicallyInteracting <Toil>(Toils_Goto.GotoThing((TargetIndex)2, (PathEndMode)3), (TargetIndex)2), (TargetIndex)2));

            yield return(ToilFailConditions.FailOnDestroyedNullOrForbidden <Toil>(Toils_Haul.StartCarryThing((TargetIndex)2, false, true, false), (TargetIndex)2));

            yield return(Toils_Haul.CheckForGetOpportunityDuplicate(ingrToil, (TargetIndex)2, 0, true, null));

            yield return(Toils_Haul.CarryHauledThingToCell((TargetIndex)1));

            yield return(ToilEffects.WithProgressBarToilDelay(ToilFailConditions.FailOnDestroyedNullOrForbidden <Toil>(Toils_General.Wait(200, 0), (TargetIndex)1), (TargetIndex)1, false, -0.5f));

            yield return(new Toil
            {
                initAction = delegate()
                {
                    if (!comp.AddIngredient(this.Ingredient))
                    {
                        this.EndJobWith((JobCondition)3);
                        Log.Message("JobCondition.Incompletable", false);
                    }
                },
                defaultCompleteMode = (ToilCompleteMode)1
            });

            yield break;
        }
Ejemplo n.º 14
0
        // Token: 0x0600003C RID: 60 RVA: 0x000038A6 File Offset: 0x00001AA6
        protected override IEnumerable <Toil> MakeNewToils()
        {
            Pawn actor = base.GetActor();

            ToilFailConditions.FailOnDespawnedNullOrForbidden <JobDriver_JPRefuel>(this, TargetIndex.A);
            yield return(Toils_Reserve.Reserve(TargetIndex.A, 1, -1, null));

            yield return(ToilFailConditions.FailOnDespawnedNullOrForbidden <Toil>(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch), TargetIndex.A));

            Toil refuel = Toils_General.Wait(180, 0);

            ToilFailConditions.FailOnDespawnedNullOrForbidden <Toil>(refuel, TargetIndex.A);
            ToilFailConditions.FailOnCannotTouch <Toil>(refuel, TargetIndex.A, PathEndMode.Touch);
            ToilEffects.WithProgressBarToilDelay(refuel, TargetIndex.A, false, -0.5f);
            yield return(refuel);

            yield return(new Toil
            {
                initAction = delegate()
                {
                    int JPFuel = 0;
                    int JPMax = 0;
                    Pawn obj = actor;
                    if (obj != null && obj.apparel.WornApparelCount == 0)
                    {
                        //Log.Message("True: obj != null && obj.apparel.WornApparelCount == 0");
                        this.EndJobWith(JobCondition.Incompletable);
                        return;
                    }
                    Apparel JetPack = null;
                    List <Apparel> list = actor.apparel.WornApparel;
                    for (int i = 0; i < list.Count; i++)
                    {
                        if (list[i] is JetPackApparel)
                        {
                            JetPack = list[i];
                            break;
                        }
                    }
                    if (JetPack == null)
                    {
                        this.EndJobWith(JobCondition.Incompletable);
                        return;
                    }
                    if (JetPack is JetPackApparel)
                    {
                        //Log.Message("True: JetPack is JetPackApparel");
                        JPFuel = (JetPack as JetPackApparel).JPFuelAmount;
                        JPMax = (JetPack as JetPackApparel).JPFuelMax;
                    }
                    if (JPMax - JPFuel <= 0)
                    {
                        //Log.Message("True: JPMax - JPFuel <= 0");
                        this.EndJobWith(JobCondition.Incompletable);
                        return;
                    }
                    if (this.TargetThingA.stackCount > JPMax - JPFuel)
                    {
                        //Log.Message("True: this.TargetThingA.stackCount > JPMax - JPFuel");
                        (JetPack as JetPackApparel).JPFuelAmount = JPMax;
                        this.TargetThingA.stackCount -= JPMax - JPFuel;
                        Messages.Message(TranslatorFormattedStringExtensions.Translate("JetPack.FullyRefueled", actor.LabelShort), actor, MessageTypeDefOf.NeutralEvent, false);
                        this.EndJobWith(JobCondition.Succeeded);
                        return;
                    }
                    //Log.Message("False");
                    (JetPack as JetPackApparel).JPFuelAmount = JPFuel + this.TargetThingA.stackCount;
                    Messages.Message(TranslatorFormattedStringExtensions.Translate("JetPack.Refueled", GenText.CapitalizeFirst(actor.LabelShort), this.TargetThingA.stackCount.ToString(), (this.TargetThingA.stackCount > 1) ? "s" : ""), actor, MessageTypeDefOf.NeutralEvent, false);
                    this.TargetThingA.Destroy(0);
                    this.EndJobWith(JobCondition.Succeeded);
                }
            });

            yield break;
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            base.AddEndCondition(delegate()
            {
                var thing = base.GetActor().jobs.curJob.GetTarget(TargetIndex.A).Thing;
                if (thing is Building && !thing.Spawned)
                {
                    return(JobCondition.Incompletable);
                }
                return(JobCondition.Ongoing);
            });
            this.FailOnBurningImmobile <JobDriver_DoBill>(TargetIndex.A);
            this.FailOn <JobDriver_DoBill>(delegate()
            {
                if (!(this.job.GetTarget(TargetIndex.A).Thing is IBillGiver billGiver))
                {
                    return(false);
                }
                if (this.job.bill.DeletedOrDereferenced)
                {
                    return(true);
                }
                if (!billGiver.CurrentlyUsableForBills())
                {
                    return(true);
                }
                return(false);
            });
            yield return(Toils_Reserve.Reserve(TargetIndex.A, 1, -1, null));

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

            var            tableThing     = this.job.GetTarget(TargetIndex.A).Thing as Building_СontainmentBreach;
            CompRefuelable refuelableComp = tableThing.GetComp <CompRefuelable>();
            Toil           toil           = new Toil();

            toil.initAction = delegate()
            {
                this.job.bill.Notify_DoBillStarted(this.pawn);
                this.workCycleProgress = this.job.bill.recipe.workAmount;
            };
            toil.tickAction = delegate()
            {
                this.workCycleProgress -= StatExtension.GetStatValue(this.pawn, StatDefOf.WorkToMake, true);
                tableThing.UsedThisTick();
                if (!tableThing.CurrentlyUsableForBills() || (refuelableComp != null && !refuelableComp.HasFuel))
                {
                    this.pawn.jobs.EndCurrentJob(JobCondition.Incompletable, true, true);
                }
                if (this.workCycleProgress <= 0f)
                {
                    SkillDef workSkill = this.job.bill.recipe.workSkill;
                    if (workSkill != null)
                    {
                        SkillRecord skill = this.pawn.skills.GetSkill(workSkill);
                        if (skill != null)
                        {
                            skill.Learn(0.11f * this.job.bill.recipe.workSkillLearnFactor, false);
                        }
                    }
                    GenSpawn.Spawn(tableThing.GetKorsolianToxin(this.job.bill.recipe),
                                   tableThing.InteractionCell, tableThing.Map, 0);
                    Toils_Reserve.Release(TargetIndex.A);
                    PawnUtility.GainComfortFromCellIfPossible(this.pawn, false);
                    this.job.bill.Notify_IterationCompleted(this.pawn, null);
                    this.ReadyForNextToil();
                }
            };
            toil.defaultCompleteMode = ToilCompleteMode.Never;
            ToilEffects.WithEffect(toil, () => this.job.bill.recipe.effectWorking, TargetIndex.A);
            ToilEffects.PlaySustainerOrSound(toil, () => toil.actor.CurJob.bill.recipe.soundWorking);
            ToilEffects.WithProgressBar(toil, TargetIndex.A, delegate()
            {
                return(PurpleIvyUtils.GetPercentageFromPartWhole
                           (this.job.bill.recipe.workAmount - this.workCycleProgress,
                           (int)this.job.bill.recipe.workAmount) / 100f);
            }, false, 0.5f);
            ToilFailConditions.FailOn <Toil>(toil, delegate()
            {
                IBillGiver billGiver = this.job.GetTarget(TargetIndex.A).Thing as IBillGiver;
                return(this.job.bill.suspended || this.job.bill.DeletedOrDereferenced || (billGiver != null && !billGiver.CurrentlyUsableForBills()));
            });
            yield return(toil);

            yield break;
        }
Ejemplo n.º 16
0
        public static IEnumerable <Toil> GoToMap(Pawn pawn, Map dest, JobDriver instance)
        {
            Toil end = new Toil
            {
                initAction = delegate()
                {
                    ZLogger.Message("if (pawn.Map == dest): " + pawn.Map + " - " + dest);
                }
            };

            yield return(new Toil
            {
                initAction = delegate()
                {
                    if (pawn.Map == dest)
                    {
                        instance.JumpToToil(end);
                    }
                }
            });

            Toil setStairs = new Toil
            {
                initAction = delegate()
                {
                    var ZTracker = ZUtils.ZTracker;
                    ZLogger.Message("Pawn.map: " + pawn.Map);
                    ZLogger.Message("Dest Map: " + dest);
                    ZTracker.ReCheckStairs();
                    ZLogger.Message("1 Total count of stairs up: "
                                    + pawn.Map.listerThings.AllThings.Where(x => x is Building_StairsUp).Count());
                    ZLogger.Message("1 Total count of stairs down: "
                                    + pawn.Map.listerThings.AllThings.Where(x => x is Building_StairsDown).Count());

                    ZLogger.Message("2 Total count of stairs up: " + ZTracker.stairsUp[pawn.Map].Count);
                    ZLogger.Message("2 Total count of stairs down: " + ZTracker.stairsDown[pawn.Map].Count);
                    if (ZTracker.GetZIndexFor(pawn.Map) > ZTracker.GetZIndexFor(dest))
                    {
                        var stairs = ZTracker.stairsDown[pawn.Map];
                        if (stairs?.Count() > 0)
                        {
                            pawn.CurJob.targetC = new LocalTargetInfo(stairs.MinBy(x => IntVec3Utility.DistanceTo(pawn.Position, x.Position)));
                        }
                        else
                        {
                            ZLogger.Pause(pawn + " cant find stairs down");
                        }
                    }
                    else if (ZTracker.GetZIndexFor(pawn.Map) < ZTracker.GetZIndexFor(dest))
                    {
                        var stairs = ZTracker.stairsUp[pawn.Map];
                        if (stairs?.Count() > 0)
                        {
                            pawn.CurJob.targetC = new LocalTargetInfo(stairs.MinBy(y => IntVec3Utility.DistanceTo(pawn.Position, y.Position)));
                        }
                        else
                        {
                            ZLogger.Pause(pawn + " cant find stairs up");
                        }
                    }
                    else
                    {
                        pawn.CurJob.targetC = null;
                    }
                }
            };
            var  goToStairs = Toils_Goto.GotoThing(TargetIndex.C, PathEndMode.OnCell);
            Toil useStairs  = Toils_General.Wait(60, 0);

            ToilEffects.WithProgressBarToilDelay(useStairs, TargetIndex.C, false, -0.5f);
            //ToilFailConditions.FailOnDespawnedNullOrForbidden<Toil>(useStairs, TargetIndex.C);
            //ToilFailConditions.FailOnCannotTouch<Toil>(useStairs, TargetIndex.C, PathEndMode.OnCell);

            Toil teleport = new Toil
            {
                initAction = delegate()
                {
                    var ZTracker = ZUtils.ZTracker;
                    if (pawn.CurJob.targetC.Thing is Building_StairsUp stairsUp)
                    {
                        Map map = ZTracker.GetUpperLevel(pawn.Map.Tile, pawn.Map);
                        if (map == null)
                        {
                            map = ZTracker.CreateUpperLevel(pawn.Map, stairsUp.Position);
                            if (stairsUp.pathToPreset != null && stairsUp.pathToPreset.Length > 0)
                            {
                                var comp = map.GetComponent <MapComponentZLevel>();
                                comp.DoGeneration = true;
                                comp.path         = stairsUp.pathToPreset;
                            }
                            ZTracker.TeleportPawn(pawn, pawn.Position, map, true, false, true);
                        }
                        else
                        {
                            if (stairsUp.pathToPreset != null && stairsUp.pathToPreset.Length > 0)
                            {
                                var comp = map.GetComponent <MapComponentZLevel>();
                                comp.DoGeneration = true;
                                comp.path         = stairsUp.pathToPreset;
                            }
                            ZTracker.TeleportPawn(pawn, pawn.Position, map, false, false, stairsUp.shouldSpawnStairsUpper);
                            stairsUp.shouldSpawnStairsUpper = false;
                        }
                    }
                    else if (pawn.CurJob.targetC.Thing is Building_StairsDown stairsDown)
                    {
                        Map map = ZTracker.GetLowerLevel(pawn.Map.Tile, pawn.Map);
                        if (map == null)
                        {
                            map = ZTracker.CreateLowerLevel(pawn.Map, stairsDown.Position);
                            if (stairsDown.pathToPreset != null && stairsDown.pathToPreset.Length > 0)
                            {
                                var comp = map.GetComponent <MapComponentZLevel>();
                                comp.DoGeneration = true;
                                comp.path         = stairsDown.pathToPreset;
                            }
                            ZTracker.TeleportPawn(pawn, pawn.Position, map, true, true);
                        }
                        else
                        {
                            if (stairsDown.pathToPreset != null && stairsDown.pathToPreset.Length > 0)
                            {
                                var comp = map.GetComponent <MapComponentZLevel>();
                                comp.DoGeneration = true;
                                comp.path         = stairsDown.pathToPreset;
                            }
                            ZTracker.TeleportPawn(pawn, pawn.Position, map, false, stairsDown.shouldSpawnStairsBelow);
                            stairsDown.shouldSpawnStairsBelow = false;
                        }
                    }

                    if (pawn.Map != dest)
                    {
                        instance.JumpToToil(setStairs);
                    }
                }
            };

            yield return(setStairs);

            yield return(goToStairs);

            yield return(useStairs);

            yield return(teleport);

            yield return(end);
        }
    }
Ejemplo n.º 17
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            // Just on the off-chance the rock is on fire...
            this.FailOnBurningImmobile(TargetIndex.A);
            // Reserve the target
            yield return(Toils_Reserve.Reserve(TargetIndex.A));

            // Go to the target
            Toil toilGoto = Toils_Goto.GotoCell(TargetIndex.A, PathEndMode.Touch);

            // Fail going to the target if it becomes unreachable
            ToilFailConditions.FailOn <Toil>(toilGoto, (Func <bool>)(() =>
            {
                if (Reachability.CanReach(pawn, (TargetInfo)TargetLocA, PathEndMode.Touch, pawn.NormalMaxDanger()))
                {
                    return(false);
                }
                return(true);
            }));
            yield return(toilGoto);

            // Now the work toil itself
            Toil toilWork = new Toil
            {
                // Continue until done
                defaultCompleteMode = ToilCompleteMode.Never,
                // When the job starts...
                initAction = new Action(() =>
                {
                    smoothTicks = 0;
                }),
                // The work tick
                tickAction = new Action(() =>
                {
                    if (pawn.skills != null)
                    {
                        const float constructionXP = 0.11f / 5f;
                        const float miningXP       = 0.11f / 5f;
                        const float artisticXP     = 0.11f / 5f;
                        pawn.skills.Learn(SkillDefOf.Construction, constructionXP);
                        pawn.skills.Learn(SkillDefOf.Mining, miningXP);
                        pawn.skills.Learn(SkillDefOf.Artistic, artisticXP);
                    }
                    smoothTicks += 1;
                    if (smoothTicks < nextSmoothStrike)
                    {
                        return;
                    }
                    // Reset counter, damage rock
                    smoothTicks         = 0;
                    mineable.HitPoints -= DamagePerStrike;
                })
            };

            // When should we stop?
            toilWork.endConditions.Add((Func <JobCondition>)(() =>
            {
                // Go until the rock is fully damaged
                if (mineable.HitPoints > 0)
                {
                    return(JobCondition.Ongoing);
                }
                return(JobCondition.Succeeded);
            }));
            // Do something when done
            toilWork.AddFinishAction(new Action(() =>
            {
                // If the job failed, abort
                if (mineable.HitPoints > 0)
                {
                    return;
                }
                // Clear the designation at this cell
                Common.RemoveDesignationDefOfAt(SmoothWall.designationDef, TargetA.Cell);
                // Better have associated stone blocks...
                string blocksDef     = "Blocks" + mineable.def.defName;
                ThingDef stoneBlocks = DefDatabase <ThingDef> .GetNamed(blocksDef, true);
                // Replace the rock with a stone wall
                var wallThing = ThingMaker.MakeThing(SmoothWall.thingDef, stoneBlocks);
                if (wallThing != null)
                {
                    var wall = GenSpawn.Spawn(wallThing, TargetA.Cell);
                    if (wall != null)
                    {
                        wall.SetFaction(Faction.OfColony);
                    }
                }
            }));
            // Some fun sounds while working
            ToilEffects.WithSustainer(toilWork, (Func <SoundDef>)(() =>
            {
                return(SmoothWall.soundDef);
            }));
            // Some fun effects while working
            ToilEffects.WithEffect(toilWork, "Mine", TargetIndex.A);
            yield return(toilWork);

            // And we're done.
            yield break;
        }
Ejemplo n.º 18
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            base.AddEndCondition(delegate()
            {
                var thing = base.GetActor().jobs.curJob.GetTarget(TargetIndex.A).Thing;
                if (thing is Building && !thing.Spawned)
                {
                    return(JobCondition.Incompletable);
                }
                return(JobCondition.Ongoing);
            });
            this.FailOnBurningImmobile <JobDriver_DoBill>(TargetIndex.A);
            this.FailOn <JobDriver_DoBill>(delegate()
            {
                if (!(this.job.GetTarget(TargetIndex.A).Thing is IBillGiver billGiver))
                {
                    return(false);
                }
                if (this.job.bill.DeletedOrDereferenced)
                {
                    return(true);
                }
                if (!billGiver.CurrentlyUsableForBills())
                {
                    return(true);
                }
                return(false);
            });
            yield return(Toils_Reserve.Reserve(TargetIndex.A, 1, -1, null));

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

            var            tableThing     = this.job.GetTarget(TargetIndex.A).Thing as Building_СontainmentBreach;
            CompRefuelable refuelableComp = tableThing.GetComp <CompRefuelable>();
            Toil           toil           = new Toil();

            toil.initAction = delegate()
            {
                this.job.bill.Notify_DoBillStarted(this.pawn);
                this.workCycleProgress = this.job.bill.recipe.workAmount;
            };
            toil.tickAction = delegate()
            {
                this.workCycleProgress -= StatExtension.GetStatValue(this.pawn, StatDefOf.WorkToMake, true);
                tableThing.UsedThisTick();
                if (!tableThing.CurrentlyUsableForBills() || (refuelableComp != null && !refuelableComp.HasFuel))
                {
                    this.pawn.jobs.EndCurrentJob(JobCondition.Incompletable, true, true);
                }
                if (this.workCycleProgress <= 0f)
                {
                    SkillDef workSkill = this.job.bill.recipe.workSkill;
                    if (workSkill != null)
                    {
                        SkillRecord skill = this.pawn.skills.GetSkill(workSkill);
                        if (skill != null)
                        {
                            skill.Learn(0.11f * this.job.bill.recipe.workSkillLearnFactor, false);
                        }
                    }
                    var research = PurpleIvyData.AlienStudy.Where(x => x.TechprintsApplied == 0 &&
                                                                  GetActor().Map.listerThings.ThingsOfDef
                                                                      (ThingDef.Named("Techprint_" + x.defName)).Count == 0).RandomElement();
                    if (research != null)
                    {
                        GenSpawn.Spawn(ThingDef.Named("Techprint_" + research.defName),
                                       GetActor().Position, GetActor().Map);
                    }
                    job.bill.Notify_PawnDidWork(GetActor());
                    Bill_Production bill_Production = this.pawn.jobs.curJob.bill as Bill_Production;
                    if (bill_Production != null && bill_Production.repeatMode == BillRepeatModeDefOf.TargetCount)
                    {
                        this.Map.resourceCounter.UpdateResourceCounts();
                    }
                    Toils_Recipe.FinishRecipeAndStartStoringProduct();
                    job.bill.Notify_IterationCompleted(GetActor(), null);
                    Toils_Reserve.Release(TargetIndex.A);
                    PawnUtility.GainComfortFromCellIfPossible(this.pawn, false);
                    this.ReadyForNextToil();
                }
            };
            toil.defaultCompleteMode = ToilCompleteMode.Never;
            ToilEffects.WithEffect(toil, () => this.job.bill.recipe.effectWorking, TargetIndex.A);
            ToilEffects.PlaySustainerOrSound(toil, () => toil.actor.CurJob.bill.recipe.soundWorking);
            ToilEffects.WithProgressBar(toil, TargetIndex.A, delegate()
            {
                return(PurpleIvyUtils.GetPercentageFromPartWhole
                           (this.job.bill.recipe.workAmount - this.workCycleProgress,
                           (int)this.job.bill.recipe.workAmount) / 100f);
            }, false, 0.5f);
            ToilFailConditions.FailOn <Toil>(toil, delegate()
            {
                IBillGiver billGiver = this.job.GetTarget(TargetIndex.A).Thing as IBillGiver;
                return(this.job.bill.suspended || this.job.bill.DeletedOrDereferenced || (billGiver != null && !billGiver.CurrentlyUsableForBills()));
            });
            yield return(toil);

            yield break;
        }
Ejemplo n.º 19
0
        public override IEnumerable <Toil> MakeNewToils()
        {
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.OnCell));

            Toil useStairs = Toils_General.Wait(60, 0);

            ToilEffects.WithProgressBarToilDelay(useStairs, TargetIndex.A, false, -0.5f);
            ToilFailConditions.FailOnDespawnedNullOrForbidden <Toil>(useStairs, TargetIndex.A);
            ToilFailConditions.FailOnCannotTouch <Toil>(useStairs, TargetIndex.A, PathEndMode.OnCell);
            yield return(useStairs);

            yield return(new Toil
            {
                initAction = delegate()
                {
                    var ZTracker = ZUtils.ZTracker;
                    Pawn pawn = GetActor();
                    if (TargetA.Thing is Building_StairsUp stairsUp)
                    {
                        Map map = ZTracker.GetUpperLevel(this.pawn.Map.Tile, this.pawn.Map);
                        if (map == null)
                        {
                            map = ZTracker.CreateUpperLevel(this.pawn.Map, stairsUp.Position);
                            if (!string.IsNullOrEmpty(stairsUp.pathToPreset))
                            {
                                var comp = ZUtils.GetMapComponentZLevel(map);
                                comp.DoGeneration = true;
                                comp.path = stairsUp.pathToPreset;
                            }
                            ZTracker.TeleportPawn(pawn, pawn.Position, map, true, false, true);
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(stairsUp.pathToPreset))
                            {
                                var comp = ZUtils.GetMapComponentZLevel(map);
                                comp.DoGeneration = true;
                                comp.path = stairsUp.pathToPreset;
                            }
                            ZTracker.TeleportPawn(pawn, pawn.Position, map, false, false, stairsUp.shouldSpawnStairsUpper);
                            stairsUp.shouldSpawnStairsUpper = false;
                        }
                    }

                    else if (TargetA.Thing is Building_StairsDown stairsDown)
                    {
                        Map map = ZTracker.GetLowerLevel(this.pawn.Map.Tile, this.pawn.Map);
                        if (map == null)
                        {
                            //ZLogger.Message("CREATING LOWER LEVEL AGAIG", true);
                            map = ZTracker.CreateLowerLevel(this.pawn.Map, stairsDown.Position);
                            if (!string.IsNullOrEmpty(stairsDown.pathToPreset))
                            {
                                var comp = ZUtils.GetMapComponentZLevel(map);
                                comp.DoGeneration = true;
                                comp.path = stairsDown.pathToPreset;
                            }
                            ZTracker.TeleportPawn(pawn, pawn.Position, map, true, true);
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(stairsDown.pathToPreset))
                            {
                                var comp = ZUtils.GetMapComponentZLevel(map);
                                comp.DoGeneration = true;
                                comp.path = stairsDown.pathToPreset;
                            }
                            ZTracker.TeleportPawn(pawn, pawn.Position, map, false, stairsDown.shouldSpawnStairsBelow);
                            stairsDown.shouldSpawnStairsBelow = false;
                        }
                    }
                }
            });
Ejemplo n.º 20
0
        public static IEnumerable <Toil> Toils_GoToThingMap(Pawn pawn, Thing selectedStairs, Thing thing, JobDriver instance)
        {
            Toil setStairs = new Toil
            {
                initAction = delegate()
                {
                    var ZTracker = Current.Game.GetComponent <ZLevelsManager>();
                    ZLogger.Message("Pawn: " + pawn);
                    ZLogger.Message("Pawn.map: " + pawn.Map);
                    ZLogger.Message("thing: " + thing);
                    ZLogger.Message("thing.Map: " + thing.Map);
                    ZLogger.Message("pawn.CurJob: " + pawn.jobs.curJob);
                    if (ZTracker.GetZIndexFor(pawn.Map) > ZTracker.GetZIndexFor(thing.Map))
                    {
                        var stairs = ZTracker.stairsDown[pawn.Map];
                        if (stairs?.Count() > 0)
                        {
                            selectedStairs = stairs.MinBy(x => IntVec3Utility.DistanceTo(thing.Position, x.Position));
                        }
                    }
                    else if (ZTracker.GetZIndexFor(pawn.Map) < ZTracker.GetZIndexFor(thing.Map))
                    {
                        var stairs = ZTracker.stairsUp[pawn.Map];
                        if (stairs?.Count() > 0)
                        {
                            selectedStairs = stairs.MinBy(x => IntVec3Utility.DistanceTo(thing.Position, x.Position));
                        }
                    }
                    pawn.jobs.curJob.targetC = new LocalTargetInfo(selectedStairs);
                }
            };

            yield return(setStairs);

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

            Toil useStairs = Toils_General.Wait(60, 0);

            ToilEffects.WithProgressBarToilDelay(useStairs, TargetIndex.C, false, -0.5f);
            ToilFailConditions.FailOnDespawnedNullOrForbidden <Toil>(useStairs, TargetIndex.C);
            //ToilFailConditions.FailOnCannotTouch<Toil>(useStairs, TargetIndex.C, PathEndMode.OnCell);
            yield return(useStairs);

            yield return(new Toil
            {
                initAction = delegate()
                {
                    var ZTracker = Current.Game.GetComponent <ZLevelsManager>();
                    if (selectedStairs is Building_StairsUp stairsUp)
                    {
                        Map map = ZTracker.GetUpperLevel(pawn.Map.Tile, pawn.Map);
                        if (map == null)
                        {
                            map = ZTracker.CreateUpperLevel(pawn.Map, stairsUp.Position);
                            if (stairsUp.pathToPreset != null && stairsUp.pathToPreset.Length > 0)
                            {
                                var comp = map.GetComponent <MapComponentZLevel>();
                                comp.DoGeneration = true;
                                comp.path = stairsUp.pathToPreset;
                            }
                            ZTracker.TeleportPawn(pawn, pawn.Position, map, true, false, true);
                        }
                        else
                        {
                            if (stairsUp.pathToPreset != null && stairsUp.pathToPreset.Length > 0)
                            {
                                var comp = map.GetComponent <MapComponentZLevel>();
                                comp.DoGeneration = true;
                                comp.path = stairsUp.pathToPreset;
                            }
                            ZTracker.TeleportPawn(pawn, pawn.Position, map, false, false, stairsUp.shouldSpawnStairsUpper);
                            stairsUp.shouldSpawnStairsUpper = false;
                        }
                    }

                    else if (selectedStairs is Building_StairsDown stairsDown)
                    {
                        Map map = ZTracker.GetLowerLevel(pawn.Map.Tile, pawn.Map);
                        if (map == null)
                        {
                            map = ZTracker.CreateLowerLevel(pawn.Map, stairsDown.Position);
                            if (stairsDown.pathToPreset != null && stairsDown.pathToPreset.Length > 0)
                            {
                                var comp = map.GetComponent <MapComponentZLevel>();
                                comp.DoGeneration = true;
                                comp.path = stairsDown.pathToPreset;
                            }
                            ZTracker.TeleportPawn(pawn, pawn.Position, map, true, true);
                        }
                        else
                        {
                            if (stairsDown.pathToPreset != null && stairsDown.pathToPreset.Length > 0)
                            {
                                var comp = map.GetComponent <MapComponentZLevel>();
                                comp.DoGeneration = true;
                                comp.path = stairsDown.pathToPreset;
                            }
                            ZTracker.TeleportPawn(pawn, pawn.Position, map, false, stairsDown.shouldSpawnStairsBelow);
                            stairsDown.shouldSpawnStairsBelow = false;
                        }
                    }

                    if (pawn.Map != thing.Map)
                    {
                        instance.JumpToToil(setStairs);
                    }
                }
            });
Ejemplo n.º 21
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.OnCell));

            Toil useStairs = Toils_General.Wait(60, 0);

            ToilEffects.WithProgressBarToilDelay(useStairs, TargetIndex.A, false, -0.5f);
            ToilFailConditions.FailOnDespawnedNullOrForbidden <Toil>(useStairs, TargetIndex.A);
            ToilFailConditions.FailOnCannotTouch <Toil>(useStairs, TargetIndex.A, PathEndMode.OnCell);
            yield return(useStairs);

            yield return(new Toil
            {
                initAction = delegate()
                {
                    var ZTracker = Current.Game.GetComponent <ZLevelsManager>();
                    Pawn pawn = GetActor();
                    if (TargetA.Thing is Building_StairsUp stairsUp)
                    {
                        Map map = ZTracker.GetUpperLevel(this.pawn.Map.Tile, this.pawn.Map);
                        if (map == null)
                        {
                            map = ZTracker.CreateUpperLevel(this.pawn.Map, stairsUp.Position);
                            if (stairsUp.pathToPreset != null && stairsUp.pathToPreset.Length > 0)
                            {
                                var comp = map.GetComponent <MapComponentZLevel>();
                                comp.DoGeneration = true;
                                comp.path = stairsUp.pathToPreset;
                            }
                            ZTracker.TeleportPawn(pawn, pawn.Position, map, true, false, true);
                        }
                        else
                        {
                            if (stairsUp.pathToPreset != null && stairsUp.pathToPreset.Length > 0)
                            {
                                var comp = map.GetComponent <MapComponentZLevel>();
                                comp.DoGeneration = true;
                                comp.path = stairsUp.pathToPreset;
                            }
                            ZTracker.TeleportPawn(pawn, pawn.Position, map, false, false, stairsUp.shouldSpawnStairsUpper);
                            stairsUp.shouldSpawnStairsUpper = false;
                        }
                    }

                    else if (TargetA.Thing is Building_StairsDown stairsDown)
                    {
                        Map map = ZTracker.GetLowerLevel(this.pawn.Map.Tile, this.pawn.Map);
                        if (map == null)
                        {
                            map = ZTracker.CreateLowerLevel(this.pawn.Map, stairsDown.Position);
                            if (stairsDown.pathToPreset != null && stairsDown.pathToPreset.Length > 0)
                            {
                                var comp = map.GetComponent <MapComponentZLevel>();
                                comp.DoGeneration = true;
                                comp.path = stairsDown.pathToPreset;
                            }
                            ZTracker.TeleportPawn(pawn, pawn.Position, map, true, true);
                        }
                        else
                        {
                            if (stairsDown.pathToPreset != null && stairsDown.pathToPreset.Length > 0)
                            {
                                var comp = map.GetComponent <MapComponentZLevel>();
                                comp.DoGeneration = true;
                                comp.path = stairsDown.pathToPreset;
                            }
                            ZTracker.TeleportPawn(pawn, pawn.Position, map, false, stairsDown.shouldSpawnStairsBelow);
                            stairsDown.shouldSpawnStairsBelow = false;
                        }
                    }
                    try
                    {
                        ZLogger.Message("5 lastTick");

                        ZTracker.jobTracker[pawn].lastTickFood = Find.TickManager.TicksGame + 201;
                        ZTracker.jobTracker[pawn].lastTickJoy = Find.TickManager.TicksGame + 201;
                    }
                    catch { };
                }
            });
        protected override IEnumerable <Toil> MakeNewToils()
        {
            yield return(new Toil
            {
                initAction = delegate()
                {
                    var ZTracker = Current.Game.GetComponent <ZLevelsManager>();
                    if (ZTracker.jobTracker.ContainsKey(pawn))
                    {
                        this.savedThing = this.TargetB.Thing;
                    }
                }
            });

            this.FailOnDestroyedOrNull(TargetIndex.B);
            this.FailOnBurningImmobile(TargetIndex.B);
            this.FailOnForbidden(TargetIndex.B);
            Toil reserveTargetA = Toils_Reserve.Reserve(TargetIndex.B, 1, -1, null);

            yield return(reserveTargetA);

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

            yield return(new Toil
            {
                initAction = delegate()
                {
                    if (this.pawn.jobs.curJob.count == -1)
                    {
                        this.pawn.jobs.curJob.count = Mathf.Min(TargetB.Thing.stackCount, (int)(pawn.GetStatValue(StatDefOf.CarryingCapacity, true) / TargetB.Thing.def.VolumePerUnit));
                        if (this.pawn.jobs.curJob.count < 0)
                        {
                            this.pawn.jobs.curJob.count = TargetB.Thing.stackCount;
                        }
                    }
                    ZLogger.Message(this.pawn + " haul count: " + this.pawn.jobs.curJob.count);
                }
            });

            yield return(Toils_Haul.StartCarryThing(TargetIndex.B, false, true, false));

            yield return(Toils_Haul.CheckForGetOpportunityDuplicate(reserveTargetA, TargetIndex.B, TargetIndex.A,
                                                                    false, null));

            Toil carryToCell = Toils_Haul.CarryHauledThingToCell(TargetIndex.A);

            yield return(carryToCell);

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

            Toil useStairs = Toils_General.Wait(60, 0);

            ToilEffects.WithProgressBarToilDelay(useStairs, TargetIndex.A, false, -0.5f);
            ToilFailConditions.FailOnDespawnedNullOrForbidden <Toil>(useStairs, TargetIndex.A);
            ToilFailConditions.FailOnCannotTouch <Toil>(useStairs, TargetIndex.A, PathEndMode.OnCell);
            //yield return new Toil
            //{
            //    initAction = delegate () {
            //        ZLogger.Message("this.pawn.CanReachImmediate(TargetA.Thing, PathEndMode.OnCell): "
            //            + this.pawn.CanReachImmediate(TargetA.Thing, PathEndMode.OnCell), true);
            //    }
            //};
            yield return(useStairs);

            yield return(new Toil
            {
                initAction = delegate()
                {
                    try
                    {
                        var ZTracker = Current.Game.GetComponent <ZLevelsManager>();
                        if (ZTracker.jobTracker.ContainsKey(pawn))
                        {
                            if (ZTracker.jobTracker[pawn].mainJob.targetA.Thing != null &&
                                ZTracker.jobTracker[pawn].mainJob.targetA.Thing == this.savedThing &&
                                ZTracker.jobTracker[pawn].mainJob.targetA.Thing != TargetB.Thing)
                            {
                                ZLogger.Message("1 Pawns carried thing not the same: " + ZTracker.jobTracker[pawn].mainJob.targetA.Thing);
                                ZTracker.jobTracker[pawn].mainJob.targetA = new LocalTargetInfo(TargetB.Thing);
                            }
                            else if (ZTracker.jobTracker[pawn].mainJob.targetB.Thing != null &&
                                     ZTracker.jobTracker[pawn].mainJob.targetB.Thing == this.savedThing &&
                                     ZTracker.jobTracker[pawn].mainJob.targetB.Thing != TargetB.Thing)
                            {
                                ZLogger.Message("2 Pawns carried thing not the same: " + ZTracker.jobTracker[pawn].mainJob.targetB.Thing);
                                ZTracker.jobTracker[pawn].mainJob.targetB = new LocalTargetInfo(TargetB.Thing);
                            }

                            try
                            {
                                for (int i = ZTracker.jobTracker[pawn].mainJob.targetQueueA.Count - 1; i >= 0; i--)
                                {
                                    var target = ZTracker.jobTracker[pawn].mainJob.targetQueueA[i];
                                    if (target.Thing != null && target.Thing == this.savedThing && target.Thing != TargetB.Thing)
                                    {
                                        ZLogger.Message("3 Pawns carried thing not the same: " + target.Thing);
                                        ZTracker.jobTracker[pawn].mainJob.targetQueueA[i] = new LocalTargetInfo(TargetB.Thing);
                                    }
                                }
                            }
                            catch { }
                            try
                            {
                                try
                                {
                                    ZLogger.Message("--------------------------");
                                    for (int i = ZTracker.jobTracker[pawn].mainJob.targetQueueB.Count - 1; i >= 0; i--)
                                    {
                                        var target = ZTracker.jobTracker[pawn].mainJob.targetQueueB[i];
                                        ZLogger.Message("JobDriver_HaulThingToStairs BEFORE job.targetQueueB: " + target.Thing);
                                        ZLogger.Message("JobDriver_HaulThingToStairs BEFORE job.targetQueueB.Map: " + target.Thing.Map);
                                        ZLogger.Message("JobDriver_HaulThingToStairs BEFORE job.targetQueueB.stackCount: " + target.Thing.stackCount);
                                        ZLogger.Message("JobDriver_HaulThingToStairs BEFORE job.targetQueueB.countQueue: " + ZTracker.jobTracker[pawn].mainJob.countQueue[i]);
                                    }
                                }
                                catch { }

                                for (int i = ZTracker.jobTracker[pawn].mainJob.targetQueueB.Count - 1; i >= 0; i--)
                                {
                                    var target = ZTracker.jobTracker[pawn].mainJob.targetQueueB[i];
                                    if (target.Thing != null && target.Thing == this.savedThing && target.Thing != TargetB.Thing)
                                    {
                                        ZLogger.Message("4 Pawns carried thing not the same");
                                        ZLogger.Message("4 Pawns target.Thing: " + target.Thing);
                                        ZLogger.Message("4 Pawns target.Thing.Map: " + target.Thing.Map);
                                        ZLogger.Message("4 Pawns this.savedThing: " + this.savedThing);
                                        ZLogger.Message("4 Pawns this.savedThing.Map: " + this.savedThing.Map);
                                        ZLogger.Message("4 Pawns TargetB.Thing: " + TargetB.Thing);
                                        ZLogger.Message("4 Pawns TargetB.Thing.Map: " + TargetB.Thing.Map);

                                        //ZLogger.Message("Replacing " + ZTracker.jobTracker[this.pawn].mainJob.targetQueueB[i] + " by " + TargetB);
                                        //
                                        //ZTracker.jobTracker[pawn].mainJob.targetQueueB[i] = new LocalTargetInfo(TargetB.Thing);
                                        //ZTracker.jobTracker[pawn].mainJob.countQueue[i] = TargetB.Thing.stackCount;
                                        //

                                        if (ZTracker.jobTracker[pawn].mainJob.targetQueueB[i].Thing.stackCount == 0)
                                        {
                                            ZTracker.jobTracker[pawn].mainJob.targetQueueB[i] = new LocalTargetInfo(TargetB.Thing);
                                            ZTracker.jobTracker[pawn].mainJob.countQueue[i] = TargetB.Thing.stackCount;
                                            ZLogger.Message("Altering " + ZTracker.jobTracker[this.pawn].mainJob);
                                            break;
                                        }
                                        else
                                        {
                                            if (ZTracker.jobTracker[pawn].mainJob.targetQueueB
                                                .Where(x => x.Thing == TargetB.Thing).Count() == 0)
                                            {
                                                var newTarget = new LocalTargetInfo(TargetB.Thing);
                                                ZTracker.jobTracker[this.pawn].mainJob.targetQueueB.Add(newTarget);
                                                ZTracker.jobTracker[this.pawn].mainJob.countQueue.Add(newTarget.Thing.stackCount);
                                                ZLogger.Message("2 Adding " + newTarget + " to " + ZTracker.jobTracker[this.pawn].mainJob);
                                                int ind = ZTracker.jobTracker[this.pawn].mainJob.targetQueueB.FirstIndexOf(x => x.Thing == this.savedThing);
                                                ZLogger.Message("2 Removing " + ZTracker.jobTracker[this.pawn].mainJob.targetQueueB[ind] + " from " + ZTracker.jobTracker[this.pawn].mainJob);

                                                ZTracker.jobTracker[this.pawn].mainJob.targetQueueB.RemoveAt(ind);
                                                ZTracker.jobTracker[this.pawn].mainJob.countQueue.RemoveAt(ind);
                                                break;
                                            }
                                            else
                                            {
                                                ZLogger.Message("Cant add  " + TargetB.Thing + " to " + ZTracker.jobTracker[this.pawn].mainJob);
                                            }
                                        }
                                    }
                                }

                                try
                                {
                                    ZLogger.Message("--------------------------");
                                    for (int i = ZTracker.jobTracker[pawn].mainJob.targetQueueB.Count - 1; i >= 0; i--)
                                    {
                                        var target = ZTracker.jobTracker[pawn].mainJob.targetQueueB[i];

                                        ZLogger.Message("JobDriver_HaulThingToStairs AFTER job.targetQueueB: " + target.Thing);
                                        ZLogger.Message("JobDriver_HaulThingToStairs AFTER job.targetQueueB.Map: " + target.Thing.Map);
                                        ZLogger.Message("JobDriver_HaulThingToStairs AFTER job.targetQueueB.stackCount: " + target.Thing.stackCount);
                                        ZLogger.Message("JobDriver_HaulThingToStairs AFTER job.targetQueueB.countQueue: " + ZTracker.jobTracker[pawn].mainJob.countQueue[i]);
                                    }
                                }
                                catch { }
                            }
                            catch { }
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error("Z-Tracker produced an error in JobDriver_HaulThingToStairs class. Report about it to devs. Error: " + ex);
                    }
                }
            });

            yield return(new Toil()
            {
                initAction = () =>
                {
                    var ZTracker = Current.Game.GetComponent <ZLevelsManager>();
                    Pawn pawn = GetActor();
                    if (TargetA.Thing is Building_StairsUp stairsUp)
                    {
                        Map map = ZTracker.GetUpperLevel(this.pawn.Map.Tile, this.pawn.Map);
                        if (map == null)
                        {
                            map = ZTracker.CreateUpperLevel(this.pawn.Map, stairsUp.Position);
                            if (stairsUp.pathToPreset != null && stairsUp.pathToPreset.Length > 0)
                            {
                                var comp = map.GetComponent <MapComponentZLevel>();
                                comp.DoGeneration = true;
                                comp.path = stairsUp.pathToPreset;
                            }
                            ZTracker.TeleportPawn(pawn, pawn.Position, map, true, false, stairsUp.shouldSpawnStairsUpper);
                            stairsUp.shouldSpawnStairsUpper = false;
                        }
                        else
                        {
                            if (stairsUp.pathToPreset != null && stairsUp.pathToPreset.Length > 0)
                            {
                                var comp = map.GetComponent <MapComponentZLevel>();
                                comp.DoGeneration = true;
                                comp.path = stairsUp.pathToPreset;
                            }
                            ZTracker.TeleportPawn(pawn, pawn.Position, map, false, false, stairsUp.shouldSpawnStairsUpper);
                            stairsUp.shouldSpawnStairsUpper = false;
                        }
                    }
                    if (TargetA.Thing is Building_StairsDown stairsDown)
                    {
                        Map map = ZTracker.GetLowerLevel(this.pawn.Map.Tile, this.pawn.Map);
                        if (map == null)
                        {
                            map = ZTracker.CreateLowerLevel(this.pawn.Map, stairsDown.Position);
                            if (stairsDown.pathToPreset != null && stairsDown.pathToPreset.Length > 0)
                            {
                                var comp = map.GetComponent <MapComponentZLevel>();
                                comp.DoGeneration = true;
                                comp.path = stairsDown.pathToPreset;
                            }
                            ZTracker.TeleportPawn(pawn, pawn.Position, map);
                        }
                        else
                        {
                            if (stairsDown.pathToPreset != null && stairsDown.pathToPreset.Length > 0)
                            {
                                var comp = map.GetComponent <MapComponentZLevel>();
                                comp.DoGeneration = true;
                                comp.path = stairsDown.pathToPreset;
                            }
                            ZTracker.TeleportPawn(pawn, pawn.Position, map);
                        }
                    }

                    try
                    {
                        for (int i = ZTracker.jobTracker[pawn].mainJob.targetQueueB.Count - 1; i >= 0; i--)
                        {
                            var target = ZTracker.jobTracker[pawn].mainJob.targetQueueB[i];
                            ZLogger.Message("JobDriver_HaulThingToStairs job.targetQueueB: " + target.Thing);
                            ZLogger.Message("JobDriver_HaulThingToStairs job.targetQueueB.Map: " + target.Thing.Map);
                            ZLogger.Message("JobDriver_HaulThingToStairs job.targetQueueB.stackCount: " + target.Thing.stackCount);
                            ZLogger.Message("JobDriver_HaulThingToStairs job.targetQueueB.countQueue: " + ZTracker.jobTracker[pawn].mainJob.countQueue[i]);
                        }
                    }
                    catch { }
                }
            });
Ejemplo n.º 23
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDestroyedOrNull(TargetIndex.B);
            yield return(Toils_Reserve.Reserve(TargetIndex.B));

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

            pawn.CurJob.count = 1;
            yield return(Toils_Haul.StartCarryThing(TargetIndex.B));

            yield return(FindSeatsForReading(pawn).FailOnForbidden(TargetIndex.C));

            var toil = new Toil();

            toil.AddPreInitAction(() =>
            {
                pawn.CurJob.targetA = pawn;
                if (pawn.carryTracker.CarriedThing is Book carriedBook)
                {
                    book.stopDraw = true;
                }
                pawn.GainComfortFromCellIfPossible();
                if (book.Props.saveReadingProgress)
                {
                    curReadingTicks = book.curReadingTicks;
                }
            });

            toil.tickAction = () =>
            {
                Pawn actor = pawn;
                if (TargetC.HasThing)
                {
                    actor.Rotation = TargetC.Thing.Rotation;
                }
                if (book is SkillBook skillBook)
                {
                    if (skillBook.CanLearnFromBook(pawn))
                    {
                        var compBook = skillBook.TryGetComp <CompBook>();
                        if (compBook != null && compBook.Props.skillData.skillToTeach != null)
                        {
                            var learnValue = skillBook.GetLearnAmount();
                            //Log.Message(pawn + " learn " + compBook.Props.skillData.skillToTeach + " ("
                            //    + learnValue + ") from " + book + " - " + book.TryGetComp<CompQuality>().Quality, true);
                            actor.skills.Learn(compBook.Props.skillData.skillToTeach, learnValue);
                        }
                    }
                    else
                    {
                        if (pawn.carryTracker.CarriedThing is Book carriedBook)
                        {
                            book.stopDraw = false;
                        }
                        ReadyForNextToil();
                    }
                }
                if (book.Props.joyAmountPerTick > 0)
                {
                    pawn.needs.joy.GainJoy(book.Props.joyAmountPerTick, VBE_DefOf.VBE_Reading);
                }
                curReadingTicks++;
                book.curReadingTicks = curReadingTicks;
                if (curReadingTicks > totalReadingTicks)
                {
                    if (pawn.carryTracker.CarriedThing is Book carriedBook)
                    {
                        book.stopDraw = false;
                    }
                    ReadyForNextToil();
                }
            };
            toil.handlingFacing = true;
            toil.WithEffect(() => book.Props.readingEffecter, () => TargetA);
            toil.defaultCompleteMode = ToilCompleteMode.Never;
            ToilEffects.WithProgressBar(toil, TargetIndex.B, () => (float)this.curReadingTicks / (float)this.totalReadingTicks, false, -0.5f);
            yield return(toil);

            yield return(new Toil
            {
                initAction = delegate()
                {
                    if (pawn.carryTracker.CarriedThing is Book carriedBook)
                    {
                        book.stopDraw = false;
                    }

                    if (book is TechBlueprint techBlueprint)
                    {
                        techBlueprint.UnlockResearch(pawn);
                    }
                    else if (book is MapItem mapItem)
                    {
                        mapItem.UnlockQuest(pawn);
                    }
                    if (pawn.GetRoom()?.Role == VBE_DefOf.VBE_Library)
                    {
                        TryGainLibraryRoomThought(pawn);
                    }
                    else
                    {
                        JoyUtility.TryGainRecRoomThought(pawn);
                    }

                    if (book.Props.destroyAfterReading)
                    {
                        book.Destroy(DestroyMode.Vanish);
                    }
                    else
                    {
                        Thing thing = book;
                        StoragePriority storagePriority = StoreUtility.CurrentStoragePriorityOf(thing);
                        IntVec3 intVec;
                        if (StoreUtility.TryFindBestBetterStoreCellFor(thing, this.pawn, base.Map, storagePriority, this.pawn.Faction, out intVec, true))
                        {
                            this.job.SetTarget(TargetIndex.C, intVec);
                            this.job.SetTarget(TargetIndex.B, thing);
                            this.job.count = thing.stackCount;
                            return;
                        }
                    }
                    base.EndJobWith(JobCondition.Succeeded);
                },
                defaultCompleteMode = ToilCompleteMode.Instant
            });