示例#1
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            CompUniversalFermenter comp = Fermenter.TryGetComp <CompUniversalFermenter>();

            // Verify fermenter and ingredient validity
            this.FailOn(() => comp.SpaceLeftForIngredient <= 0);
            this.FailOnDespawnedNullOrForbidden(FermenterInd);
            this.FailOnBurningImmobile(FermenterInd);
            this.FailOnDestroyedNullOrForbidden(IngredientInd);

            // Reserve resources
            // Creating the toil before yielding allows for CheckForGetOpportunityDuplicate
            Toil ingrToil = Toils_Reserve.Reserve(IngredientInd);

            yield return(ingrToil);

            // Reserve fermenter
            yield return(Toils_Reserve.Reserve(FermenterInd));

            // Go to the ingredient
            yield return(Toils_Goto.GotoThing(IngredientInd, PathEndMode.ClosestTouch)
                         .FailOnSomeonePhysicallyInteracting(IngredientInd)
                         .FailOnDestroyedNullOrForbidden(IngredientInd));

            // Haul the ingredients
            yield return(Toils_Haul.StartCarryThing(IngredientInd, false, true).FailOnDestroyedNullOrForbidden(IngredientInd));

            yield return(Toils_Haul.CheckForGetOpportunityDuplicate(ingrToil, IngredientInd, TargetIndex.None, true));

            // Carry ingredients to the fermenter
            yield return(Toils_Haul.CarryHauledThingToCell(FermenterInd));

            // Add delay for adding ingredients to the fermenter
            yield return(Toils_General.Wait(Duration).FailOnDestroyedNullOrForbidden(FermenterInd).WithProgressBarToilDelay(FermenterInd));

            // Use ingredients
            // The UniversalFermenter automatically destroys held ingredients
            Toil add = new Toil();

            add.initAction = () =>
            {
                if (!comp.AddIngredient(Ingredient))
                {
                    // The ingredient is not allowed, end the job
                    EndJobWith(JobCondition.Incompletable);
                    Log.Message("JobCondition.Incompletable");
                }
            };
            add.defaultCompleteMode = ToilCompleteMode.Instant;
            yield return(add);

            // End the current job
            yield break;
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            CompUniversalFermenter comp = Fermenter.TryGetComp <CompUniversalFermenter>();

            // Verify fermenter and ingredient validity
            this.FailOnDespawnedNullOrForbidden(FermenterInd);
            this.FailOnBurningImmobile(FermenterInd);
            base.AddEndCondition(delegate
            {
                if (comp.SpaceLeftForIngredient > 0)
                {
                    return(JobCondition.Ongoing);
                }
                return(JobCondition.Succeeded);
            });
            yield return(Toils_General.DoAtomic(delegate
            {
                job.count = comp.SpaceLeftForIngredient;
            }));

            // Creating the toil before yielding allows for CheckForGetOpportunityDuplicate
            Toil reserveIngredient = Toils_Reserve.Reserve(IngredientInd);

            yield return(reserveIngredient);

            yield return(Toils_Goto.GotoThing(IngredientInd, PathEndMode.ClosestTouch).FailOnDespawnedNullOrForbidden(IngredientInd).FailOnSomeonePhysicallyInteracting(IngredientInd));

            yield return(Toils_Haul.StartCarryThing(IngredientInd, false, true, false).FailOnDestroyedNullOrForbidden(IngredientInd));

            yield return(Toils_Haul.CheckForGetOpportunityDuplicate(reserveIngredient, IngredientInd, TargetIndex.None, true));

            // Carry ingredients to the fermenter
            yield return(Toils_Goto.GotoThing(FermenterInd, PathEndMode.Touch));

            // Add delay for adding ingredients to the fermenter
            yield return(Toils_General.Wait(Duration, FermenterInd).FailOnDestroyedNullOrForbidden(IngredientInd).FailOnDestroyedNullOrForbidden(FermenterInd)
                         .FailOnCannotTouch(FermenterInd, PathEndMode.Touch).WithProgressBarToilDelay(FermenterInd, false, -0.5f));

            // Use ingredients
            // The UniversalFermenter automatically destroys held ingredients
            yield return(new Toil
            {
                initAction = delegate()
                {
                    comp.AddIngredient(Ingredient);
                },
                defaultCompleteMode = ToilCompleteMode.Instant
            });
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            CompUniversalFermenter comp = Fermenter.TryGetComp <CompUniversalFermenter>();

            // Verify fermenter validity
            this.FailOn(() => !comp.Fermented);
            this.FailOnDestroyedNullOrForbidden(FermenterInd);

            // Reserve fermenter
            yield return(Toils_Reserve.Reserve(FermenterInd));

            // Go to the fermenter
            yield return(Toils_Goto.GotoThing(FermenterInd, PathEndMode.ClosestTouch));

            // Add delay for collecting product from fermenter, if it is ready
            yield return(Toils_General.Wait(Duration).FailOnDestroyedNullOrForbidden(FermenterInd).WithProgressBarToilDelay(FermenterInd));

            // Collect product
            Toil collect = new Toil();

            collect.initAction = () =>
            {
                Thing product = comp.TakeOutProduct();
                GenPlace.TryPlaceThing(product, pawn.Position, Map, ThingPlaceMode.Near);
                StoragePriority storagePriority = StoreUtility.CurrentStoragePriorityOf(product);
                IntVec3         c;

                // Try to find a suitable storage spot for the product
                if (StoreUtility.TryFindBestBetterStoreCellFor(product, pawn, Map, storagePriority, pawn.Faction, out c))
                {
                    this.job.SetTarget(TargetIndex.B, product);
                    this.job.count = product.stackCount;
                    this.job.SetTarget(TargetIndex.C, c);
                }
                // If there is no spot to store the product, end this job
                else
                {
                    EndJobWith(JobCondition.Incompletable);
                }
            };
            collect.defaultCompleteMode = ToilCompleteMode.Instant;
            yield return(collect);

            // Reserve the product
            yield return(Toils_Reserve.Reserve(ProductToHaulInd));

            // Reserve the storage cell
            yield return(Toils_Reserve.Reserve(StorageCellInd));

            // Go to the product
            yield return(Toils_Goto.GotoThing(ProductToHaulInd, PathEndMode.ClosestTouch));

            // Pick up the product
            yield return(Toils_Haul.StartCarryThing(ProductToHaulInd));

            // Carry the product to the storage cell, then place it down
            Toil carry = Toils_Haul.CarryHauledThingToCell(StorageCellInd);

            yield return(carry);

            yield return(Toils_Haul.PlaceHauledThingInCell(StorageCellInd, carry, true));

            // End the current job
            yield break;
        }