protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedNullOrForbidden(CabinetIndex);

            Building_ExperimentFilingCabinet cabinet = this.job.GetTarget(TargetIndex.A).Thing as Building_ExperimentFilingCabinet;

            var thing = LoreComputerHarmonyPatches.TempRequestedExp;

            var curExp = thing as Thing_FinishedExperiment;

            _currentFinishedExperiment = curExp;

            yield return(Toils_Goto.GotoThing(CabinetIndex, PathEndMode.Touch));

            this.pawn.CurJob.count    = 1;
            this.pawn.CurJob.haulMode = HaulMode.ToCellStorage;

            // perform work toil
            var TakeExperiment = new Toil();

            TakeExperiment.initAction = delegate
            {
                var newThing = cabinet.TakeExperimentFromCabinet(curExp.TryGetComp <ResearchThingComp>().researchDefName);

                var finalThing = GenSpawn.Spawn(newThing.def, _cabinet.Position, _cabinet.Map);
                finalThing.TryGetComp <ResearchThingComp>().pawnExperimentAuthorName = newThing.TryGetComp <ResearchThingComp>().pawnExperimentAuthorName;
                finalThing.TryGetComp <ResearchThingComp>().researchDefName          = newThing.TryGetComp <ResearchThingComp>().researchDefName;
            };

            yield return(TakeExperiment);

            yield break;
        }
Example #2
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedNullOrForbidden(CabinetIndex);

            Building_ExperimentFilingCabinet cabinet = this.job.GetTarget(TargetIndex.A).Thing as Building_ExperimentFilingCabinet;

            var thingList = LoreComputerHarmonyPatches.GetAllOfThingsOnMap("FinishedExperiment");

            if (thingList.Count == 0)
            {
                yield break;
            }

            var curExp = thingList[thingList.Count - 1] as Thing_FinishedExperiment;

            if (thingList.Count > 0)
            {// this appears to be only way to enqueue new custom jobs without using work/jobgiver
                for (int i = 0; i < thingList.Count; i++)
                {
                    if (thingList[i] == curExp)
                    {
                        break;
                    }
                    var newJob = JobMaker.MakeJob(AddExperimentJobDefOf.CabinetAddExperiment, cabinet);
                    newJob.count = 1;
                    pawn.jobs.jobQueue.EnqueueFirst(newJob);
                }
            }


            _currentFinishedExperiment = curExp;
            this.job.SetTarget(ExperimentIndex, _currentFinishedExperiment);

            yield return(Toils_Goto.GotoThing(ExperimentIndex, PathEndMode.Touch));

            this.pawn.CurJob.haulMode = HaulMode.ToCellStorage;

            yield return(Toils_Haul.StartCarryThing(ExperimentIndex, false, false));

            var GetHeldThing = new Toil();

            GetHeldThing.initAction = delegate
            {
                this.job.SetTarget(HeldExperimentIndex, this.pawn.carryTracker.CarriedThing);
                _heldThing = this.job.GetTarget(HeldExperimentIndex).Thing;
            };
            yield return(GetHeldThing);

            yield return(Toils_Goto.GotoThing(CabinetIndex, PathEndMode.Touch));

            yield return(Toils_Haul.PlaceHauledThingInCell(CabinetIndex, Toils_Goto.GotoThing(CabinetIndex, PathEndMode.Touch), false));

            // perform work toil
            var AddExperiment = new Toil();

            AddExperiment.initAction = delegate
            {
                cabinet.AddExperimentToCabinet(_heldThing);
                _heldThing.Destroy();
            };

            yield return(AddExperiment);
        }