protected override IEnumerable<Toil> MakeNewToils()
        {
            //Set what will cause the job to fail:
            this.FailOnDestroyedOrForbidden(CorpseIndex);
            this.FailOnBurningImmobile(CorpseIndex);
            this.FailOn(() => !(pawn is Droid));

            //Reserve the corpse
            yield return Toils_Reserve.Reserve(CorpseIndex);
            //Go to the corpse
            yield return Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch);
            Toil toil = new Toil();
            toil.initAction = () =>
                {
                    //Check if the pawn is set to strip bodies, if yes then strip it, otherwise skip this step
                    Droid droid = (Droid)pawn;
                    CremationWorker worker = droid.work.specialist.GetWorker<CremationWorker>();
                    if (worker.StripBodies)
                    {
                        Corpse corpse = (Corpse)TargetThingA;
                        if (corpse.AnythingToStrip())
                            corpse.Strip();
                    }
                };
            toil.defaultCompleteMode = ToilCompleteMode.Delay;
            toil.defaultDuration = 300;
            toil.WithEffect(() => DefDatabase<EffecterDef>.GetNamed("Cremate"), CorpseIndex);
            toil.WithSustainer(() => DefDatabase<SoundDef>.GetNamed("Recipe_Cremate"));
            toil.AddFinishAction(() => TargetA.Thing.Destroy());
            toil.FailOnBurningImmobile(CorpseIndex);
            toil.FailOnDestroyedOrForbidden(CorpseIndex);
            toil.AddEndCondition(() => this.ticksLeftThisToil <= 0 ? JobCondition.Succeeded : JobCondition.Ongoing);
            yield return toil;
        }
        protected override IEnumerable<Toil> MakeNewToils()
        {
            this.FailOnDestroyedOrForbidden<JobDriver_PlantHarvestWithSeeds>(TargetIndex.A);
            yield return Toils_Reserve.Reserve(TargetIndex.A, 1);
            yield return Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch);

            var toil = new Toil();
            toil.tickAction = () =>
            {
                Pawn actor = toil.actor;
                if (actor.skills != null)
                    actor.skills.Learn(SkillDefOf.Growing, 0.154f);
                float num = actor.GetStatValue(StatDefOf.PlantWorkSpeed, true);
                Plant plant = (Plant)actor.jobs.curJob.GetTarget(TargetIndex.A).Thing;
                harvestWorkDone += num;
                if (harvestWorkDone >= plant.def.plant.harvestWork)
                {
                    if (plant.def.plant.harvestedThingDef != null)
                    {
                        int num2 = plant.YieldNow();
                        if (plant is PlantWithSeeds)
                            num2 = ((PlantWithSeeds)plant).YieldNow();
                        if (num2 > 0)
                        {
                            Thing t = ThingMaker.MakeThing(plant.def.plant.harvestedThingDef, null);
                            t.stackCount = num2;
                            if (actor.Faction != Faction.OfColony)
                                t.SetForbidden(true, true);
                            GenPlace.TryPlaceThing(t, actor.Position, ThingPlaceMode.Near);
                        }
                        if (plant is PlantWithSeeds)
                        {
                            PlantWithSeeds seeds = plant as PlantWithSeeds;
                            float num3 = Mathf.Max(Mathf.InverseLerp(seeds.def.plant.harvestMinGrowth, 1.2f, seeds.growth), 1f);
                            if (seeds.m_CustomPlantDef != null && seeds.m_CustomPlantDef.SeedDef != null && Rand.Value < (seeds.genome.baseSeedChance * num3))
                            {
                                Thing thing = ThingMaker.MakeThing(seeds.m_CustomPlantDef.SeedDef, null);
                                if (Rand.Value < (seeds.genome.addSeedChance * num3))
                                    thing.stackCount = 2;
                                else
                                    thing.stackCount = 1;
                                GenPlace.TryPlaceThing(thing, actor.Position, ThingPlaceMode.Near);
                            }
                        }
                    }
                    plant.PlantCollected();
                    plant.def.plant.soundHarvestFinish.PlayOneShot(actor);
                    harvestWorkDone = 0f;
                    ReadyForNextToil();
                }
            };
            toil.FailOnDestroyedOrForbidden<Toil>(TargetIndex.A);
            toil.defaultCompleteMode = ToilCompleteMode.Never;
            toil.WithEffect("Harvest", TargetIndex.A);
            toil.WithSustainer(() => toil.actor.jobs.curJob.GetTarget(TargetIndex.A).Thing.def.plant.soundHarvesting);
            yield return toil;
            yield return Toils_General.RemoveDesignationsOnThing(TargetIndex.A, DesignationDefOf.HarvestPlant);
        }
        protected override IEnumerable<Toil> MakeNewToils()
        {
            this.FailOnDestroyedOrForbidden(TargetIndex.A);
            yield return Toils_Reserve.Reserve(TargetIndex.A);
            yield return Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch);

            var toil = new Toil();
            toil.tickAction = () =>
            {
                Pawn actor = toil.actor;
                if (actor.skills != null)
                {
                    actor.skills.Learn(SkillDefOf.Growing, 0.154f);
                }
                float statValue = actor.GetStatValue(StatDefOf.PlantWorkSpeed, true);
                Plant plant = (Plant)actor.jobs.curJob.GetTarget(TargetIndex.A).Thing;
                harvestWorkDone += statValue;
                if (harvestWorkDone >= plant.def.plant.harvestWork)
                {
                    if (plant.def.plant.harvestedThingDef != null)
                    {
                        int num3 = plant.YieldNow();
                        if (plant is PlantWithSeeds)
                        {
                            Log.Message("We harvest a PlantWithSeeds");
                            num3 = ((PlantWithSeeds)plant).YieldNow();
                        }
                        if (num3 > 0)
                        {

                            Thing thing = ThingMaker.MakeThing(plant.def.plant.harvestedThingDef, null);
                            thing.stackCount = num3;
                            if (actor.Faction != Faction.OfColony)
                            {
                                thing.SetForbidden(true, true);
                            }
                            GenPlace.TryPlaceThing(thing, actor.Position, ThingPlaceMode.Near);
                        }
                    }
                    plant.PlantCollected();
                    plant.def.plant.soundHarvestFinish.PlayOneShot(actor);
                    harvestWorkDone = 0;
                    ReadyForNextToil();
                }
            };
            toil.FailOnDestroyedOrForbidden(TargetIndex.A);
            toil.defaultCompleteMode = ToilCompleteMode.Never;
            toil.WithEffect("Harvest", TargetIndex.A);
            toil.WithSustainer(() => toil.actor.jobs.curJob.GetTarget(TargetIndex.A).Thing.def.plant.soundHarvesting);
            yield return toil;
            yield return Toils_General.RemoveDesignationsOnThing(TargetIndex.A, DesignationDefOf.HarvestPlant);
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            //Set what will cause the job to fail
            this.FailOnBurningImmobile(RepairStationIndex);
            this.FailOnDestroyedOrForbidden(RepairStationIndex);
            this.FailOn(delegate
            {
                return(Repairee == null || !Repairee.ShouldGetRepairs);
            });

            //Reserve the repair station
            yield return(Toils_Reserve.Reserve(RepairStationIndex));

            //Go to the repair station interaction cell
            yield return(Toils_Goto.GotoThing(RepairStationIndex, PathEndMode.InteractionCell));

            //Make a new toil that sets the droid to repair mode, then wait until fully repaired
            Toil toil = new Toil();

            toil.FailOnDestroyedOrForbidden(RepairStationIndex);
            toil.FailOn(() =>
            {
                return(Repairee == null || RPS == null || Repairee.Pawn.Position != TargetThingA.InteractionCell || !RPS.IsAvailable(Repairee));
            });

            toil.initAction = () =>
            {
                //Log.Message("initAction");
                Repairee.BeingRepaired = true;
                RPS.RegisterRepairee(Repairee);
            };
            toil.defaultCompleteMode = ToilCompleteMode.Never;
            toil.AddFinishAction(delegate
            {
                //Log.Message("Finish action");
                RPS.DeregisterRepairee(Repairee);
                Repairee.BeingRepaired = false;
            });
            toil.AddEndCondition(() =>
            {
                if (Repairee.ShouldGetRepairs)
                {
                    return(JobCondition.Ongoing);
                }
                return(JobCondition.Succeeded);
            });
            toil.WithEffect(DefDatabase <EffecterDef> .GetNamed("Repair"), TargetIndex.A);
            toil.WithSustainer(() => { return(DefDatabase <SoundDef> .GetNamed("Interact_Repair")); });
            yield return(toil);
        }
        protected override IEnumerable<Toil> MakeNewToils()
        {
            //Set what will cause the job to fail
            this.FailOnBurningImmobile(RepairStationIndex);
            this.FailOnDestroyedOrForbidden(RepairStationIndex);
            this.FailOn(delegate
            {
                return Repairee == null || !Repairee.ShouldGetRepairs;
            });

            //Reserve the repair station
            yield return Toils_Reserve.Reserve(RepairStationIndex);
            //Go to the repair station interaction cell
            yield return Toils_Goto.GotoThing(RepairStationIndex, PathEndMode.InteractionCell);
            //Make a new toil that sets the droid to repair mode, then wait until fully repaired
            Toil toil = new Toil();
            toil.FailOnDestroyedOrForbidden(RepairStationIndex);
            toil.FailOn(() =>
                {
                    return Repairee == null || RPS == null || Repairee.Pawn.Position != TargetThingA.InteractionCell || !RPS.IsAvailable(Repairee);
                });

            toil.initAction = () =>
                {
                    //Log.Message("initAction");
                    Repairee.BeingRepaired = true;
                    RPS.RegisterRepairee(Repairee);
                };
            toil.defaultCompleteMode = ToilCompleteMode.Never;
            toil.AddFinishAction(delegate
            {
                //Log.Message("Finish action");
                RPS.DeregisterRepairee(Repairee);
                Repairee.BeingRepaired = false;
            });
            toil.AddEndCondition(() =>
            {
                if (Repairee.ShouldGetRepairs)
                    return JobCondition.Ongoing;
                return JobCondition.Succeeded;
            });
            toil.WithEffect(DefDatabase<EffecterDef>.GetNamed("Repair"), TargetIndex.A);
            toil.WithSustainer(() => { return DefDatabase<SoundDef>.GetNamed("Interact_Repair"); });
            yield return toil;
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            //Set what will cause the job to fail:
            this.FailOnDestroyedOrForbidden(CorpseIndex);
            this.FailOnBurningImmobile(CorpseIndex);
            this.FailOn(() => !(pawn is Droid));

            //Reserve the corpse
            yield return(Toils_Reserve.Reserve(CorpseIndex));

            //Go to the corpse
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch));

            Toil toil = new Toil();

            toil.initAction = () =>
            {
                //Check if the pawn is set to strip bodies, if yes then strip it, otherwise skip this step
                Droid           droid  = (Droid)pawn;
                CremationWorker worker = droid.work.specialist.GetWorker <CremationWorker>();
                if (worker.StripBodies)
                {
                    Corpse corpse = (Corpse)TargetThingA;
                    if (corpse.AnythingToStrip())
                    {
                        corpse.Strip();
                    }
                }
            };
            toil.defaultCompleteMode = ToilCompleteMode.Delay;
            toil.defaultDuration     = 300;
            toil.WithEffect(() => DefDatabase <EffecterDef> .GetNamed("Cremate"), CorpseIndex);
            toil.WithSustainer(() => DefDatabase <SoundDef> .GetNamed("Recipe_Cremate"));
            toil.AddFinishAction(() => TargetA.Thing.Destroy());
            toil.FailOnBurningImmobile(CorpseIndex);
            toil.FailOnDestroyedOrForbidden(CorpseIndex);
            toil.AddEndCondition(() => this.ticksLeftThisToil <= 0 ? JobCondition.Succeeded : JobCondition.Ongoing);
            yield return(toil);
        }
        protected override IEnumerable<Toil> MakeNewToils()
        {
            //Set what will cause the job to fail
            this.FailOnBurningImmobile(RepairStationIndex);
            this.FailOnDestroyedOrForbidden(RepairStationIndex);
            this.FailOn(delegate
            {
                return Droid != null && !Droid.ShouldGetRepairs;
            });

            //Reserve the repair station
            yield return Toils_Reserve.Reserve(RepairStationIndex);
            //Go to the repair station interaction cell
            yield return Toils_Goto.GotoThing(RepairStationIndex, PathEndMode.InteractionCell);
            //Make a new toil that sets the droid to repair mode, then wait until fully repaired
            IRepairable droid = pawn as IRepairable;
            Building_RepairStation rps = TargetThingA as Building_RepairStation;
            Toil toil = new Toil();
            toil.FailOnDestroyedOrForbidden(RepairStationIndex);
            toil.FailOn(() =>
                {
                    Pawn p = toil.GetActor();
                    Building_RepairStation rps2 = TargetThingA as Building_RepairStation;
                    if (!(p is IRepairable))
                        return true;
                    if (p.Position != TargetThingA.InteractionCell)
                        return true;
                    if (rps2 == null || !rps2.IsAvailable(p))
                        return true;
                    return false;
                });

            toil.initAction = () =>
                {
                    //Log.Message("initAction");
                    droid.BeingRepaired = true;
                    rps.RegisterRepairee(droid);
                };
            toil.defaultCompleteMode = ToilCompleteMode.Delay;
            toil.defaultDuration = rps.Def.ticksPerRepairCycle * droid.RepairsNeededCount + 1;
            toil.tickAction = () =>
            {
                //Log.Message("Toil tick");
                if ( droid.RepairStation != null && Find.TickManager.TicksGame % droid.RepairStation.Def.ticksPerRepairCycle == 0)
                {
                    if (droid.RepairStation.Power != null && !droid.RepairStation.Power.PowerOn)
                    {
                        return;
                    }
                    //Log.Message("Repaired");
                    droid.RepairTick();
                }
            };
            toil.AddFinishAction(delegate
            {
                //Log.Message("Finish action");
                rps.DeregisterRepairee(droid);
                droid.BeingRepaired = false;
            });
            toil.WithEffect(DefDatabase<EffecterDef>.GetNamed("Repair"), TargetIndex.A);
            toil.WithSustainer(() => { return DefDatabase<SoundDef>.GetNamed("Interact_Repair"); });
            yield return toil;
        }