Esempio n. 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
            });
        }
Esempio n. 3
0
 public void ReplaceVanillaBarrels()
 {
     if (Current.ProgramState != ProgramState.Playing)
     {
         return;
     }
     foreach (Map map in Find.Maps)
     {
         foreach (Thing thing in map.listerThings.ThingsOfDef(ThingDefOf.FermentingBarrel).ToList())
         {
             bool     inUse     = false;
             float    progress  = 0;
             int      fillCount = 0;
             IntVec3  position  = thing.Position;
             ThingDef stuff;
             if (thing.Stuff != null)
             {
                 stuff = thing.Stuff;
             }
             else
             {
                 stuff = ThingDefOf.WoodLog;
             }
             if (thing is Building_FermentingBarrel oldBarrel)
             {
                 inUse = oldBarrel.SpaceLeftForWort < 25;
                 if (inUse)
                 {
                     progress  = oldBarrel.Progress;
                     fillCount = 25 - oldBarrel.SpaceLeftForWort;
                 }
             }
             Thing newBarrel = ThingMaker.MakeThing(UF_DefOf.UniversalFermenter, stuff);
             GenSpawn.Spawn(newBarrel, position, map);
             if (inUse)
             {
                 CompUniversalFermenter compUF = newBarrel.TryGetComp <CompUniversalFermenter>();
                 compUF.CurrentProcess = compUF.Props.processes.First(p => p.thingDef == ThingDefOf.Beer);
                 Thing wort = ThingMaker.MakeThing(ThingDefOf.Wort, null);
                 wort.stackCount = fillCount;
                 compUF.AddIngredient(wort);
                 compUF.ProgressTicks = (int)(360000 * progress);
             }
         }
         foreach (Thing thing in map.listerThings.ThingsOfDef(ThingDefOf.MinifiedThing).Where(t => t.GetInnerIfMinified().def == ThingDefOf.FermentingBarrel))
         {
             MinifiedThing minifiedThing = thing as MinifiedThing;
             ThingDef      stuff;
             if (minifiedThing.InnerThing.Stuff != null)
             {
                 stuff = minifiedThing.InnerThing.Stuff;
             }
             else
             {
                 stuff = ThingDefOf.WoodLog;
             }
             minifiedThing.InnerThing = null;
             Thing newBarrel = ThingMaker.MakeThing(UF_DefOf.UniversalFermenter, stuff);
             minifiedThing.InnerThing = newBarrel;
             cachedGraphic.SetValue(minifiedThing, null);
         }
     }
 }