// Token: 0x0600002D RID: 45 RVA: 0x0000384C File Offset: 0x00001A4C
        public static Toil MakeUnfinishedThingIfNeeded()
        {
            Toil toil = new Toil();

            toil.initAction = delegate()
            {
                Pawn actor  = toil.actor;
                Job  curJob = actor.jobs.curJob;
                bool flag   = !curJob.RecipeDef.UsesUnfinishedThing;
                if (!flag)
                {
                    bool flag2 = curJob.GetTarget(TargetIndex.B).Thing is UnfinishedThing;
                    if (!flag2)
                    {
                        List <Thing> list  = Toils_WPRecipe.CalculateIngredients(curJob, actor);
                        string       str   = "ingredient list in toil_wprecipe";
                        List <Thing> list2 = list;
                        Log.Message(str + ((list2 != null) ? list2.ToString() : null), false);
                        Thing thing = Toils_WPRecipe.CalculateDominantIngredient(curJob, list);
                        for (int i = 0; i < list.Count; i++)
                        {
                            Thing  thing2 = list[i];
                            string str2   = "ingredient in toil_wprecipe";
                            Thing  thing3 = list[i];
                            Log.Message(str2 + ((thing3 != null) ? thing3.ToString() : null), false);
                            actor.Map.designationManager.RemoveAllDesignationsOn(thing2, false);
                            bool spawned = thing2.Spawned;
                            if (spawned)
                            {
                                thing2.DeSpawn(DestroyMode.Vanish);
                            }
                        }
                        ThingDef        stuff           = (!curJob.RecipeDef.unfinishedThingDef.MadeFromStuff) ? null : thing.def;
                        UnfinishedThing unfinishedThing = (UnfinishedThing)ThingMaker.MakeThing(curJob.RecipeDef.unfinishedThingDef, stuff);
                        unfinishedThing.Creator     = actor;
                        unfinishedThing.BoundBill   = (Bill_ProductionWithUft)curJob.bill;
                        unfinishedThing.ingredients = list;
                        CompColorable compColorable = unfinishedThing.TryGetComp <CompColorable>();
                        bool          flag3         = compColorable != null;
                        if (flag3)
                        {
                            compColorable.Color = thing.DrawColor;
                        }
                        GenSpawn.Spawn(unfinishedThing, curJob.GetTarget(TargetIndex.A).Cell, actor.Map, WipeMode.Vanish);
                        curJob.SetTarget(TargetIndex.B, unfinishedThing);
                        actor.Reserve(unfinishedThing, curJob, 1, -1, null, true);
                    }
                }
            };
            return(toil);
        }
        // Token: 0x0600001D RID: 29 RVA: 0x0000351E File Offset: 0x0000171E
        protected override IEnumerable <Toil> MakeNewToils()
        {
            base.AddEndCondition(delegate
            {
                Thing thing = base.GetActor().jobs.curJob.GetTarget(TargetIndex.A).Thing;
                bool flag2  = thing is Building && !thing.Spawned;
                JobCondition result;
                if (flag2)
                {
                    result = JobCondition.Incompletable;
                }
                else
                {
                    result = JobCondition.Ongoing;
                }
                return(result);
            });
            this.FailOnBurningImmobile(TargetIndex.A);
            this.FailOn(delegate()
            {
                IBillGiver billGiver = this.job.GetTarget(TargetIndex.A).Thing as IBillGiver;
                bool flag2           = billGiver != null;
                if (flag2)
                {
                    bool deletedOrDereferenced = this.job.bill.DeletedOrDereferenced;
                    if (deletedOrDereferenced)
                    {
                        return(true);
                    }
                    bool flag3 = !billGiver.CurrentlyUsableForBills();
                    if (flag3)
                    {
                        return(true);
                    }
                }
                return(false);
            });
            Toil gotoBillGiver = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.InteractionCell);

            yield return(new Toil
            {
                initAction = delegate()
                {
                    bool flag2 = this.job.targetQueueB != null && this.job.targetQueueB.Count == 1;
                    if (flag2)
                    {
                        UnfinishedThing unfinishedThing = this.job.targetQueueB[0].Thing as UnfinishedThing;
                        bool flag3 = unfinishedThing != null;
                        if (flag3)
                        {
                            unfinishedThing.BoundBill = (this.job.bill as Bill_ProductionWithUft);
                        }
                    }
                }
            });

            yield return(Toils_Jump.JumpIf(gotoBillGiver, () => this.job.GetTargetQueue(TargetIndex.B).NullOrEmpty <LocalTargetInfo>()));

            Toil extract = Toils_JobTransforms.ExtractNextTargetFromQueue(TargetIndex.B, true);

            yield return(extract);

            Toil getToHaulTarget = Toils_Goto.GotoThing(TargetIndex.B, PathEndMode.ClosestTouch).FailOnDespawnedNullOrForbidden(TargetIndex.B).FailOnSomeonePhysicallyInteracting(TargetIndex.B);

            yield return(getToHaulTarget);

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

            yield return(JobDriver_WPDoBill.JumpToCollectNextIntoHandsForBill(getToHaulTarget, TargetIndex.B));

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

            Toil findPlaceTarget = Toils_JobTransforms.SetTargetToIngredientPlaceCell(TargetIndex.A, TargetIndex.B, TargetIndex.C);

            yield return(findPlaceTarget);

            yield return(Toils_Haul.PlaceHauledThingInCell(TargetIndex.C, findPlaceTarget, false, false));

            yield return(Toils_Jump.JumpIfHaveTargetInQueue(TargetIndex.B, extract));

            yield return(gotoBillGiver);

            yield return(Toils_WPRecipe.MakeUnfinishedThingIfNeeded());

            yield return(Toils_WPRecipe.DoRecipeWork().FailOnDespawnedNullOrForbiddenPlacedThings().FailOnCannotTouch(TargetIndex.A, PathEndMode.InteractionCell));

            yield return(Toils_WPRecipe.FinishRecipeAndStartStoringProduct());

            bool flag = !this.job.RecipeDef.products.NullOrEmpty <ThingDefCountClass>() || !this.job.RecipeDef.specialProducts.NullOrEmpty <SpecialProductType>();

            if (flag)
            {
                yield return(Toils_Reserve.Reserve((TargetIndex)2, 1, -1, (ReservationLayerDef)null));

                Toil carryToCell = Toils_Haul.CarryHauledThingToCell((TargetIndex)2);
                yield return(carryToCell);

                yield return(Toils_Haul.PlaceHauledThingInCell((TargetIndex)2, carryToCell, true, false));

                Toil recount = (Toil)(object)new Toil();
                recount.initAction = delegate
                {
                    Bill_Production val2 = recount.actor.jobs.curJob.bill as Bill_Production;
                    if (val2 != null && val2.repeatMode == BillRepeatModeDefOf.TargetCount)
                    {
                        this.Map.resourceCounter.UpdateResourceCounts();
                    }
                };
                yield return(recount);
            }
            yield break;
        }
        // Token: 0x0600002F RID: 47 RVA: 0x00003958 File Offset: 0x00001B58
        public static Toil FinishRecipeAndStartStoringProduct()
        {
            Log.Message("start finish recipe, store product.", false);
            Toil toil = new Toil();

            toil.initAction = delegate()
            {
                Log.Message("in finishing", false);
                Pawn   actor  = toil.actor;
                Job    curJob = actor.jobs.curJob;
                string str    = "curJob";
                Job    job    = curJob;
                string str2   = (job != null) ? job.ToString() : null;
                string str3   = " actor ";
                Pawn   pawn   = actor;
                Log.Message(str + str2 + str3 + ((pawn != null) ? pawn.ToString() : null), false);
                JobDriver_WPDoBill jobDriver_WPDoBill = (JobDriver_WPDoBill)actor.jobs.curDriver;
                List <Thing>       list = Toils_WPRecipe.CalculateIngredients(curJob, actor);
                for (int i = 0; i < list.Count; i++)
                {
                    string str4  = "toils_wprecipe: ingredient[i] ";
                    Thing  thing = list[i];
                    Log.Message(str4 + ((thing != null) ? thing.ToString() : null), false);
                }
                Thing    thing2 = Toils_WPRecipe.CalculateDominantIngredient(curJob, list);
                string[] array  = new string[8];
                array[0] = "finishing: curJob.RecipeDef ";
                int       num       = 1;
                RecipeDef recipeDef = curJob.RecipeDef;
                array[num] = ((recipeDef != null) ? recipeDef.ToString() : null);
                array[2]   = " actor ";
                int  num2  = 3;
                Pawn pawn2 = actor;
                array[num2] = ((pawn2 != null) ? pawn2.ToString() : null);
                array[4]    = " ingredients ";
                int          num3  = 5;
                List <Thing> list2 = list;
                array[num3] = ((list2 != null) ? list2.ToString() : null);
                array[6]    = " dominantIngredient ";
                int   num4   = 7;
                Thing thing3 = thing2;
                array[num4] = ((thing3 != null) ? thing3.ToString() : null);
                Log.Message(string.Concat(array), false);
                List <Thing> list3 = WPGenRecipe.MakeRecipeProducts(curJob.RecipeDef, actor, list, thing2).ToList <Thing>();
                Toils_WPRecipe.ConsumeIngredients(list, curJob.RecipeDef, actor.Map);
                curJob.bill.Notify_IterationCompleted(actor, list);
                RecordsUtility.Notify_BillDone(actor, list3);
                UnfinishedThing unfinishedThing = curJob.GetTarget(TargetIndex.B).Thing as UnfinishedThing;
                bool            flag            = list3.Count == 0;
                if (flag)
                {
                    actor.jobs.EndCurrentJob(JobCondition.Succeeded, true, true);
                }
                else
                {
                    bool flag2 = curJob.bill.GetStoreMode() == BillStoreModeDefOf.DropOnFloor;
                    if (flag2)
                    {
                        for (int j = 0; j < list3.Count; j++)
                        {
                            bool flag3 = !GenPlace.TryPlaceThing(list3[j], actor.Position, actor.Map, ThingPlaceMode.Near, null, null, default(Rot4));
                            if (flag3)
                            {
                                Log.Error(string.Concat(new object[]
                                {
                                    actor,
                                    " could not drop recipe product ",
                                    list3[j],
                                    " near ",
                                    actor.Position
                                }), false);
                            }
                        }
                        actor.jobs.EndCurrentJob(JobCondition.Succeeded, true, true);
                    }
                    else
                    {
                        bool flag4 = list3.Count > 1;
                        if (flag4)
                        {
                            for (int k = 1; k < list3.Count; k++)
                            {
                                bool flag5 = !GenPlace.TryPlaceThing(list3[k], actor.Position, actor.Map, ThingPlaceMode.Near, null, null, default(Rot4));
                                if (flag5)
                                {
                                    Log.Error(string.Concat(new object[]
                                    {
                                        actor,
                                        " could not drop recipe product ",
                                        list3[k],
                                        " near ",
                                        actor.Position
                                    }), false);
                                }
                            }
                        }
                        list3[0].SetPositionDirect(actor.Position);
                        IntVec3 c;
                        bool    flag6 = StoreUtility.TryFindBestBetterStoreCellFor(list3[0], actor, actor.Map, StoragePriority.Unstored, actor.Faction, out c, true);
                        if (flag6)
                        {
                            actor.carryTracker.TryStartCarry(list3[0]);
                            curJob.targetB = c;
                            curJob.targetA = list3[0];
                            curJob.count   = 99999;
                        }
                        else
                        {
                            bool flag7 = !GenPlace.TryPlaceThing(list3[0], actor.Position, actor.Map, ThingPlaceMode.Near, null, null, default(Rot4));
                            if (flag7)
                            {
                                Log.Error(string.Concat(new object[]
                                {
                                    "Bill doer could not drop product ",
                                    list3[0],
                                    " near ",
                                    actor.Position
                                }), false);
                            }
                            actor.jobs.EndCurrentJob(JobCondition.Succeeded, true, true);
                        }
                    }
                }
            };
            return(toil);
        }