// Token: 0x0600002E RID: 46 RVA: 0x0000388C File Offset: 0x00001A8C
        public static Toil DoRecipeWork()
        {
            Toil toil = new Toil();

            toil.initAction = delegate()
            {
                Pawn actor  = toil.actor;
                Job  curJob = actor.jobs.curJob;
                JobDriver_WPDoBill jobDriver_WPDoBill = (JobDriver_WPDoBill)actor.jobs.curDriver;
                UnfinishedThing    unfinishedThing    = curJob.GetTarget(TargetIndex.B).Thing as UnfinishedThing;
                bool flag = unfinishedThing != null && unfinishedThing.Initialized;
                if (flag)
                {
                    jobDriver_WPDoBill.workLeft = unfinishedThing.workLeft;
                }
                else
                {
                    jobDriver_WPDoBill.workLeft = curJob.bill.recipe.WorkAmountTotal((unfinishedThing == null) ? null : unfinishedThing.Stuff);
                    bool flag2 = unfinishedThing != null;
                    if (flag2)
                    {
                        unfinishedThing.workLeft = jobDriver_WPDoBill.workLeft;
                    }
                }
                jobDriver_WPDoBill.billStartTick             = Find.TickManager.TicksGame;
                jobDriver_WPDoBill.ticksSpentDoingRecipeWork = 0;
                curJob.bill.Notify_DoBillStarted(actor);
            };
            toil.tickAction = delegate()
            {
                Pawn actor  = toil.actor;
                Job  curJob = actor.jobs.curJob;
                JobDriver_WPDoBill jobDriver_WPDoBill = (JobDriver_WPDoBill)actor.jobs.curDriver;
                UnfinishedThing    unfinishedThing    = curJob.GetTarget(TargetIndex.B).Thing as UnfinishedThing;
                bool flag = unfinishedThing != null && unfinishedThing.Destroyed;
                if (flag)
                {
                    actor.jobs.EndCurrentJob(JobCondition.Incompletable, true, true);
                }
                else
                {
                    jobDriver_WPDoBill.ticksSpentDoingRecipeWork++;
                    curJob.bill.Notify_PawnDidWork(actor);
                    IBillGiverWithTickAction billGiverWithTickAction = toil.actor.CurJob.GetTarget(TargetIndex.A).Thing as IBillGiverWithTickAction;
                    bool flag2 = billGiverWithTickAction != null;
                    if (flag2)
                    {
                        billGiverWithTickAction.UsedThisTick();
                    }
                    float num = (curJob.RecipeDef.workSpeedStat != null) ? actor.GetStatValue(curJob.RecipeDef.workSpeedStat, true) : 1f;
                    Building_WorkTable building_WorkTable = jobDriver_WPDoBill.BillGiver as Building_WorkTable;
                    bool flag3 = building_WorkTable != null;
                    if (flag3)
                    {
                        num *= building_WorkTable.GetStatValue(StatDefOf.WorkTableWorkSpeedFactor, true);
                    }
                    bool fastCrafting = DebugSettings.fastCrafting;
                    if (fastCrafting)
                    {
                        num *= 30f;
                    }
                    jobDriver_WPDoBill.workLeft -= num;
                    bool flag4 = unfinishedThing != null;
                    if (flag4)
                    {
                        unfinishedThing.workLeft = jobDriver_WPDoBill.workLeft;
                    }
                    actor.GainComfortFromCellIfPossible(false);
                    bool flag5 = jobDriver_WPDoBill.workLeft <= 0f;
                    if (flag5)
                    {
                        jobDriver_WPDoBill.ReadyForNextToil();
                    }
                    bool usesUnfinishedThing = curJob.bill.recipe.UsesUnfinishedThing;
                    if (usesUnfinishedThing)
                    {
                        int  num2  = Find.TickManager.TicksGame - jobDriver_WPDoBill.billStartTick;
                        bool flag6 = num2 >= 3000 && num2 % 1000 == 0;
                        if (flag6)
                        {
                            actor.jobs.CheckForJobOverride();
                        }
                    }
                }
            };
            toil.defaultCompleteMode = ToilCompleteMode.Never;
            toil.WithEffect(() => toil.actor.CurJob.bill.recipe.effectWorking, TargetIndex.A);
            toil.PlaySustainerOrSound(() => toil.actor.CurJob.bill.recipe.soundWorking);
            toil.WithProgressBar(TargetIndex.A, delegate
            {
                Pawn actor = toil.actor;
                Job curJob = actor.CurJob;
                UnfinishedThing unfinishedThing = curJob.GetTarget(TargetIndex.B).Thing as UnfinishedThing;
                return(1f - ((JobDriver_WPDoBill)actor.jobs.curDriver).workLeft / curJob.bill.recipe.WorkAmountTotal((unfinishedThing == null) ? null : unfinishedThing.Stuff));
            }, false, -0.5f);
            toil.FailOn(() => toil.actor.CurJob.bill.suspended);
            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);
        }