示例#1
0
        private static List <Thing> CalculateIngredients(Job job, Pawn actor)
        {
            UnfinishedThing unfinishedThing = job.GetTarget(TargetIndex.B).Thing as UnfinishedThing;

            if (unfinishedThing != null)
            {
                List <Thing> ingredients = unfinishedThing.ingredients;
                job.RecipeDef.Worker.ConsumeIngredient(unfinishedThing, job.RecipeDef, actor.Map);
                job.placedThings = null;
                return(ingredients);
            }
            List <Thing> list = new List <Thing>();

            if (job.placedThings != null)
            {
                for (int i = 0; i < job.placedThings.Count; i++)
                {
                    if (job.placedThings[i].Count <= 0)
                    {
                        Log.Error(string.Concat(new object[]
                        {
                            "PlacedThing ",
                            job.placedThings[i],
                            " with count ",
                            job.placedThings[i].Count,
                            " for job ",
                            job
                        }));
                    }
                    else
                    {
                        Thing thing;
                        if (job.placedThings[i].Count < job.placedThings[i].thing.stackCount)
                        {
                            thing = job.placedThings[i].thing.SplitOff(job.placedThings[i].Count);
                        }
                        else
                        {
                            thing = job.placedThings[i].thing;
                        }
                        job.placedThings[i].Count = 0;
                        if (list.Contains(thing))
                        {
                            Log.Error("Tried to add ingredient from job placed targets twice: " + thing);
                        }
                        else
                        {
                            list.Add(thing);
                            IStrippable strippable = thing as IStrippable;
                            if (strippable != null)
                            {
                                strippable.Strip();
                            }
                        }
                    }
                }
            }
            job.placedThings = null;
            return(list);
        }
            static void Postfix(JobDriver_StripA __instance, ref IEnumerable <Toil> __result)
            {
                Toil t = new Toil
                {
                    initAction = delegate()
                    {
                        Thing       thing      = __instance.job.targetA.Thing;
                        IStrippable strippable = thing as IStrippable;
                        if (strippable != null)
                        {
                            strippable.Strip();
                        }
                        Designation designation = __instance.MapA.designationManager.DesignationOn(thing, DesignationDefOf.Strip);
                        if (designation != null)
                        {
                            designation.Delete();
                        }
                        __instance.pawn.records.Increment(RecordDefOf.BodiesStripped);
                    },
                    defaultCompleteMode = ToilCompleteMode.Instant
                };

                //naive patch
                __result = __result.Select((x, i) => i == 2 ? t : x);
            }
示例#3
0
		protected override IEnumerable<Toil> MakeNewToils()
		{
			this.FailOnDespawnedOrNull(TargetIndex.A);
			this.FailOnAggroMentalState(TargetIndex.A);
			this.FailOn(() => !StrippableUtility.CanBeStrippedByColony(this.$this.TargetThingA));
			Toil gotoThing = new Toil();
			gotoThing.initAction = delegate
			{
				this.$this.pawn.pather.StartPath(this.$this.TargetThingA, PathEndMode.ClosestTouch);
			};
			gotoThing.defaultCompleteMode = ToilCompleteMode.PatherArrival;
			gotoThing.FailOnDespawnedNullOrForbidden(TargetIndex.A);
			yield return gotoThing;
			yield return Toils_General.Wait(60, TargetIndex.None).WithProgressBarToilDelay(TargetIndex.A, false, -0.5f);
			yield return new Toil
			{
				initAction = delegate
				{
					Thing thing = this.$this.job.targetA.Thing;
					Designation designation = this.$this.Map.designationManager.DesignationOn(thing, DesignationDefOf.Strip);
					if (designation != null)
					{
						designation.Delete();
					}
					IStrippable strippable = thing as IStrippable;
					if (strippable != null)
					{
						strippable.Strip();
					}
					this.$this.pawn.records.Increment(RecordDefOf.BodiesStripped);
				},
				defaultCompleteMode = ToilCompleteMode.Instant
			};
		}
        // prefix
        // - wants instance, result and count
        // - wants to change count
        // - returns a boolean that controls if original is executed (true) or not (false)
        public static Boolean CalculateIngredientsPrefix(Job job, Pawn actor, ref List <Thing> __result)
        {
            UnfinishedThing unfinishedThing = job.GetTarget(TargetIndex.B).Thing as UnfinishedThing;

            if (unfinishedThing != null)
            {
                List <Thing> ingredients = unfinishedThing.ingredients;
                job.RecipeDef.Worker.ConsumeIngredient(unfinishedThing, job.RecipeDef, actor.Map);
                job.placedThings = null;
                //return ingredients;
                __result = ingredients;
                return(false);
            }
            List <Thing> list = new List <Thing>();

            if (job.placedThings != null)
            {
                for (int i = 0; i < job.placedThings.Count; i++)
                {
                    if (job.placedThings[i].Count <= 0)
                    {
                        Log.Error("PlacedThing " + job.placedThings[i] + " with count " + job.placedThings[i].Count + " for job " + job);
                    }
                    else
                    {
                        Thing thing = (job.placedThings[i].Count >= job.placedThings[i].thing.stackCount) ? job.placedThings[i].thing : job.placedThings[i].thing.SplitOff(job.placedThings[i].Count);
                        job.placedThings[i].Count = 0;
                        if (list.Contains(thing))
                        {
                            Log.Error("Tried to add ingredient from job placed targets twice: " + thing);
                        }
                        else
                        {
                            list.Add(thing);

                            //Check if the Name of the Recipe is "CremateCorpse", if so do not strip.
                            if (!string.Equals(job.RecipeDef.defName, "CremateCorpse"))
                            {
                                IStrippable strippable = thing as IStrippable;
                                if (strippable != null)
                                {
                                    strippable.Strip();
                                }
                            }
                        }
                    }
                }
            }
            job.placedThings = null;

            // return list;
            __result = list;
            return(false);
        }
示例#5
0
        //============================================================================================
        //================================= Products creation helpers ================================
        //============================================================================================

        /// <summary>
        /// Gathers a list of ingredients used by a job, whether they are on the table or inside an UnfinishedThing.
        /// Clears the placedTargets so we don't retain useless references to destroyed things.
        /// </summary>
        private static List <Thing> CalculateIngredients(Job job, Pawn actor)
        {
            //Pull the ingredients from the unfinished thing and destroy it
            UnfinishedThing uft = job.GetTarget(JobDriver_DoBill.IngredientInd).Thing as UnfinishedThing;

            if (uft != null)
            {
                var ufIngs = uft.ingredients;
                job.RecipeDef.Worker.ConsumeIngredient(uft, job.RecipeDef, actor.Map);          //Todo remove? Really hacky to have this here
                job.placedThings = null;
                return(ufIngs);
            }

            //Pull the ingredients from what is currently on the work table
            List <Thing> ingredients = new List <Thing>();

            if (job.placedThings != null)
            {
                for (int i = 0; i < job.placedThings.Count; i++)
                {
                    if (job.placedThings[i].Count <= 0)
                    {
                        Log.Error("PlacedThing " + job.placedThings[i] + " with count " + job.placedThings[i].Count + " for job " + job);
                        continue;
                    }

                    //We split off the part of the stack we actually want to consume
                    //Note that we avoid splitting for cases where we want the whole stack. This is because we don't
                    //want to split off Corpses because then they lose their MapHeld and can't spawn stripped apparel or butcher products.
                    Thing ingredient;
                    if (job.placedThings[i].Count < job.placedThings[i].thing.stackCount)
                    {
                        ingredient = job.placedThings[i].thing.SplitOff(job.placedThings[i].Count);
                    }
                    else
                    {
                        ingredient = job.placedThings[i].thing;
                    }

                    job.placedThings[i].Count = 0;

                    //Error catch
                    //Maybe related to double-destroy below
                    if (ingredients.Contains(ingredient))
                    {
                        Log.Error("Tried to add ingredient from job placed targets twice: " + ingredient);
                        continue;
                    }

                    ingredients.Add(ingredient);

                    //Auto-strip anything
                    //Note: This happens even if the strippable is unspawned, and thus only works
                    //		because the strippable should still have a last good position.
                    if (job.RecipeDef.autoStripCorpses)
                    {
                        IStrippable stripIng = ingredient as IStrippable;
                        if (stripIng != null)
                        {
                            stripIng.Strip();
                        }
                    }
                }
            }

            job.placedThings = null;

            return(ingredients);
        }
        // Token: 0x06000030 RID: 48 RVA: 0x000039A4 File Offset: 0x00001BA4
        private static List <Thing> CalculateIngredients(Job job, Pawn actor)
        {
            UnfinishedThing unfinishedThing = job.GetTarget(TargetIndex.B).Thing as UnfinishedThing;
            bool            flag            = unfinishedThing != null;
            List <Thing>    result;

            if (flag)
            {
                List <Thing> ingredients = unfinishedThing.ingredients;
                job.RecipeDef.Worker.ConsumeIngredient(unfinishedThing, job.RecipeDef, actor.Map);
                job.placedThings = null;
                result           = ingredients;
            }
            else
            {
                List <Thing> list  = new List <Thing>();
                bool         flag2 = job.placedThings != null;
                if (flag2)
                {
                    for (int i = 0; i < job.placedThings.Count; i++)
                    {
                        bool flag3 = job.placedThings[i].Count <= 0;
                        if (flag3)
                        {
                            Log.Error(string.Concat(new object[]
                            {
                                "PlacedThing ",
                                job.placedThings[i],
                                " with count ",
                                job.placedThings[i].Count,
                                " for job ",
                                job
                            }), false);
                        }
                        else
                        {
                            bool  flag4 = job.placedThings[i].Count < job.placedThings[i].thing.stackCount;
                            Thing thing;
                            if (flag4)
                            {
                                thing = job.placedThings[i].thing.SplitOff(job.placedThings[i].Count);
                            }
                            else
                            {
                                thing = job.placedThings[i].thing;
                            }
                            job.placedThings[i].Count = 0;
                            bool flag5 = list.Contains(thing);
                            if (flag5)
                            {
                                string str    = "Tried to add ingredient from job placed targets twice: ";
                                Thing  thing2 = thing;
                                Log.Error(str + ((thing2 != null) ? thing2.ToString() : null), false);
                            }
                            else
                            {
                                list.Add(thing);
                                IStrippable strippable = thing as IStrippable;
                                bool        flag6      = strippable != null;
                                if (flag6)
                                {
                                    strippable.Strip();
                                }
                            }
                        }
                    }
                }
                job.placedThings = null;
                result           = list;
            }
            return(result);
        }
            public bool MoveNext()
            {
                uint num = (uint)this.$PC;

                this.$PC = -1;
                switch (num)
                {
                case 0u:
                    this.FailOnDespawnedOrNull(TargetIndex.A);
                    this.FailOnAggroMentalState(TargetIndex.A);
                    this.FailOn(() => !StrippableUtility.CanBeStrippedByColony(base.TargetThingA));
                    gotoThing            = new Toil();
                    gotoThing.initAction = delegate()
                    {
                        this.pawn.pather.StartPath(base.TargetThingA, PathEndMode.ClosestTouch);
                    };
                    gotoThing.defaultCompleteMode = ToilCompleteMode.PatherArrival;
                    gotoThing.FailOnDespawnedNullOrForbidden(TargetIndex.A);
                    this.$current = gotoThing;
                    if (!this.$disposing)
                    {
                        this.$PC = 1;
                    }
                    return(true);

                case 1u:
                    this.$current = Toils_General.Wait(60, TargetIndex.None).WithProgressBarToilDelay(TargetIndex.A, false, -0.5f);
                    if (!this.$disposing)
                    {
                        this.$PC = 2;
                    }
                    return(true);

                case 2u:
                {
                    Toil strip = new Toil();
                    strip.initAction = delegate()
                    {
                        Thing       thing       = this.job.targetA.Thing;
                        Designation designation = base.Map.designationManager.DesignationOn(thing, DesignationDefOf.Strip);
                        if (designation != null)
                        {
                            designation.Delete();
                        }
                        IStrippable strippable = thing as IStrippable;
                        if (strippable != null)
                        {
                            strippable.Strip();
                        }
                        this.pawn.records.Increment(RecordDefOf.BodiesStripped);
                    };
                    strip.defaultCompleteMode = ToilCompleteMode.Instant;
                    this.$current             = strip;
                    if (!this.$disposing)
                    {
                        this.$PC = 3;
                    }
                    return(true);
                }

                case 3u:
                    this.$PC = -1;
                    break;
                }
                return(false);
            }