Esempio n. 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);
        }
        public static bool CanBeStrippedByColony(Thing th)
        {
            IStrippable strippable = th as IStrippable;

            if (strippable == null)
            {
                return(false);
            }
            if (!strippable.AnythingToStrip())
            {
                return(false);
            }
            Pawn pawn = th as Pawn;

            if (pawn == null)
            {
                return(true);
            }
            if (pawn.IsQuestLodger())
            {
                return(false);
            }
            if (pawn.Downed)
            {
                return(true);
            }
            if (pawn.IsPrisonerOfColony && pawn.guest.PrisonerIsSecure)
            {
                return(true);
            }
            return(false);
        }
Esempio n. 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);
        }
        public static bool CanBeStrippedByColony(Thing th)
        {
            IStrippable strippable = th as IStrippable;
            bool        result;

            if (strippable == null)
            {
                result = false;
            }
            else if (!strippable.AnythingToStrip())
            {
                result = false;
            }
            else
            {
                Pawn pawn = th as Pawn;
                result = (pawn == null || pawn.Downed || (pawn.IsPrisonerOfColony && pawn.guest.PrisonerIsSecure));
            }
            return(result);
        }
        // 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);
            }