private IEnumerable <Toil> FeedToils()
        {
            yield return(new Toil
            {
                initAction = delegate
                {
                    this.$this.feedNutritionLeft = JobDriver_InteractAnimal.RequiredNutritionPerFeed(this.$this.Animal);
                },
                defaultCompleteMode = ToilCompleteMode.Instant
            });

            Toil gotoAnimal = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch);

            yield return(gotoAnimal);

            yield return(this.StartFeedAnimal(TargetIndex.A));

            yield return(Toils_Ingest.FinalizeIngest(this.Animal, TargetIndex.B));

            yield return(Toils_General.PutCarriedThingInInventory());

            yield return(Toils_General.ClearTarget(TargetIndex.B));

            yield return(Toils_Jump.JumpIf(gotoAnimal, () => this.$this.feedNutritionLeft > 0f));
        }
Beispiel #2
0
        protected bool HasFoodToInteractAnimal(Pawn pawn, Pawn tamee)
        {
            ThingOwner <Thing> innerContainer = pawn.inventory.innerContainer;
            int   num  = 0;
            float num2 = JobDriver_InteractAnimal.RequiredNutritionPerFeed(tamee);
            float num3 = 0f;

            for (int i = 0; i < innerContainer.Count; i++)
            {
                Thing thing = innerContainer[i];
                if (!tamee.WillEat(thing, pawn) || (int)thing.def.ingestible.preferability > 5 || thing.def.IsDrug)
                {
                    continue;
                }
                for (int j = 0; j < thing.stackCount; j++)
                {
                    num3 += thing.GetStatValue(StatDefOf.Nutrition);
                    if (num3 >= num2)
                    {
                        num++;
                        num3 = 0f;
                    }
                    if (num >= 2)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Beispiel #3
0
        protected bool HasFoodToInteractAnimal(Pawn pawn, Pawn tamee)
        {
            ThingOwner <Thing> innerContainer = pawn.inventory.innerContainer;
            int   num  = 0;
            float num2 = JobDriver_InteractAnimal.RequiredNutritionPerFeed(tamee);
            float num3 = 0f;

            for (int i = 0; i < innerContainer.Count; i++)
            {
                Thing thing = innerContainer[i];
                if (tamee.RaceProps.CanEverEat(thing) && thing.def.ingestible.preferability <= FoodPreferability.RawTasty && !thing.def.IsDrug)
                {
                    for (int j = 0; j < thing.stackCount; j++)
                    {
                        num3 += thing.GetStatValue(StatDefOf.Nutrition, true);
                        if (num3 >= num2)
                        {
                            num++;
                            num3 = 0f;
                        }
                        if (num >= 2)
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Beispiel #4
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            this.FailOnDowned(TargetIndex.A);
            this.FailOnNotCasualInterruptible(TargetIndex.A);
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch));

            yield return(Toils_Interpersonal.WaitToBeAbleToInteract(this.pawn));

            yield return(Toils_Interpersonal.GotoInteractablePosition(TargetIndex.A));

            yield return(JobDriver_InteractAnimal.TalkToAnimal(TargetIndex.A));

            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch));

            yield return(Toils_Interpersonal.WaitToBeAbleToInteract(this.pawn));

            yield return(Toils_Interpersonal.GotoInteractablePosition(TargetIndex.A));

            yield return(JobDriver_InteractAnimal.TalkToAnimal(TargetIndex.A));

            foreach (Toil t in this.FeedToils())
            {
                yield return(t);
            }
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch));

            yield return(Toils_Interpersonal.WaitToBeAbleToInteract(this.pawn));

            yield return(Toils_Interpersonal.GotoInteractablePosition(TargetIndex.A));

            yield return(JobDriver_InteractAnimal.TalkToAnimal(TargetIndex.A));

            foreach (Toil t2 in this.FeedToils())
            {
                yield return(t2);
            }
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch));

            yield return(Toils_Interpersonal.SetLastInteractTime(TargetIndex.A));

            yield return(Toils_Interpersonal.WaitToBeAbleToInteract(this.pawn));

            yield return(Toils_Interpersonal.GotoInteractablePosition(TargetIndex.A));

            yield return(this.FinalInteractToil());

            yield break;
        }
Beispiel #5
0
        protected Job TakeFoodForAnimalInteractJob(Pawn pawn, Pawn tamee)
        {
            float    num = JobDriver_InteractAnimal.RequiredNutritionPerFeed(tamee) * 2f * 4f;
            ThingDef thingDef;
            Thing    thing = FoodUtility.BestFoodSourceOnMap(pawn, tamee, false, out thingDef, FoodPreferability.RawTasty, false, false, false, false, false, false, false, false);

            if (thing == null)
            {
                return(null);
            }
            return(new Job(JobDefOf.TakeInventory, thing)
            {
                count = Mathf.CeilToInt(num / thingDef.ingestible.nutrition)
            });
        }
Beispiel #6
0
        protected Job TakeFoodForAnimalInteractJob(Pawn pawn, Pawn tamee)
        {
            float    num = JobDriver_InteractAnimal.RequiredNutritionPerFeed(tamee) * 2f * 4f;
            ThingDef foodDef;
            Thing    thing = FoodUtility.BestFoodSourceOnMap(pawn, tamee, desperate: false, out foodDef, FoodPreferability.RawTasty, allowPlant: false, allowDrug: false, allowCorpse: false, allowDispenserFull: false, allowDispenserEmpty: false);

            if (thing == null)
            {
                return(null);
            }
            float nutrition = FoodUtility.GetNutrition(thing, foodDef);
            Job   job       = new Job(JobDefOf.TakeInventory, thing);

            job.count = Mathf.CeilToInt(num / nutrition);
            return(job);
        }
        private Toil StartFeedAnimal(TargetIndex tameeInd)
        {
            Toil toil = new Toil();

            toil.initAction = delegate
            {
                Pawn actor = toil.GetActor();
                Pawn pawn  = (Pawn)(Thing)actor.CurJob.GetTarget(tameeInd);
                PawnUtility.ForceWait(pawn, 270, actor, false);
                Thing thing = FoodUtility.BestFoodInInventory(actor, pawn, FoodPreferability.NeverForNutrition, FoodPreferability.RawTasty, 0f, false);
                if (thing == null)
                {
                    actor.jobs.EndCurrentJob(JobCondition.Incompletable, true);
                }
                else
                {
                    actor.mindState.lastInventoryRawFoodUseTick = Find.TickManager.TicksGame;
                    int   num        = FoodUtility.StackCountForNutrition(thing.def, this.feedNutritionLeft);
                    int   stackCount = thing.stackCount;
                    Thing thing2     = actor.inventory.innerContainer.Take(thing, Mathf.Min(num, stackCount));
                    actor.carryTracker.TryStartCarry(thing2);
                    actor.CurJob.SetTarget(TargetIndex.B, thing2);
                    float num2 = (float)thing2.stackCount * thing2.def.ingestible.nutrition;
                    base.ticksLeftThisToil = Mathf.CeilToInt((float)(270.0 * (num2 / JobDriver_InteractAnimal.RequiredNutritionPerFeed(pawn))));
                    if (num <= stackCount)
                    {
                        this.feedNutritionLeft = 0f;
                    }
                    else
                    {
                        this.feedNutritionLeft -= num2;
                        if (this.feedNutritionLeft < 0.0010000000474974513)
                        {
                            this.feedNutritionLeft = 0f;
                        }
                    }
                }
            };
            toil.defaultCompleteMode = ToilCompleteMode.Delay;
            return(toil);
        }
Beispiel #8
0
        protected Job TakeFoodForAnimalInteractJob(Pawn pawn, Pawn tamee)
        {
            float    num = JobDriver_InteractAnimal.RequiredNutritionPerFeed(tamee) * 2f * 4f;
            ThingDef foodDef;
            Thing    thing = FoodUtility.BestFoodSourceOnMap(pawn, tamee, false, out foodDef, FoodPreferability.RawTasty, false, false, false, false, false, false, false, false, false);
            Job      result;

            if (thing == null)
            {
                result = null;
            }
            else
            {
                float nutrition = FoodUtility.GetNutrition(thing, foodDef);
                result = new Job(JobDefOf.TakeInventory, thing)
                {
                    count = Mathf.CeilToInt(num / nutrition)
                };
            }
            return(result);
        }
        private IEnumerable <Toil> FeedToils()
        {
            yield return(new Toil
            {
                initAction = delegate
                {
                    ((_003CFeedToils_003Ec__Iterator1) /*Error near IL_004a: stateMachine*/)._0024this.feedNutritionLeft = JobDriver_InteractAnimal.RequiredNutritionPerFeed(((_003CFeedToils_003Ec__Iterator1) /*Error near IL_004a: stateMachine*/)._0024this.Animal);
                },
                defaultCompleteMode = ToilCompleteMode.Instant
            });

            /*Error: Unable to find new state assignment for yield return*/;
        }
Beispiel #10
0
            public bool MoveNext()
            {
                uint num = (uint)this.$PC;

                this.$PC = -1;
                bool flag = false;

                switch (num)
                {
                case 0u:
                    this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
                    this.FailOnDowned(TargetIndex.A);
                    this.FailOnNotCasualInterruptible(TargetIndex.A);
                    this.$current = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch);
                    if (!this.$disposing)
                    {
                        this.$PC = 1;
                    }
                    return(true);

                case 1u:
                    this.$current = Toils_Interpersonal.WaitToBeAbleToInteract(this.pawn);
                    if (!this.$disposing)
                    {
                        this.$PC = 2;
                    }
                    return(true);

                case 2u:
                    this.$current = Toils_Interpersonal.GotoInteractablePosition(TargetIndex.A);
                    if (!this.$disposing)
                    {
                        this.$PC = 3;
                    }
                    return(true);

                case 3u:
                    this.$current = JobDriver_InteractAnimal.TalkToAnimal(TargetIndex.A);
                    if (!this.$disposing)
                    {
                        this.$PC = 4;
                    }
                    return(true);

                case 4u:
                    this.$current = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch);
                    if (!this.$disposing)
                    {
                        this.$PC = 5;
                    }
                    return(true);

                case 5u:
                    this.$current = Toils_Interpersonal.WaitToBeAbleToInteract(this.pawn);
                    if (!this.$disposing)
                    {
                        this.$PC = 6;
                    }
                    return(true);

                case 6u:
                    this.$current = Toils_Interpersonal.GotoInteractablePosition(TargetIndex.A);
                    if (!this.$disposing)
                    {
                        this.$PC = 7;
                    }
                    return(true);

                case 7u:
                    this.$current = JobDriver_InteractAnimal.TalkToAnimal(TargetIndex.A);
                    if (!this.$disposing)
                    {
                        this.$PC = 8;
                    }
                    return(true);

                case 8u:
                    enumerator = base.FeedToils().GetEnumerator();
                    num        = 4294967293u;
                    break;

                case 9u:
                    break;

                case 10u:
                    this.$current = Toils_Interpersonal.WaitToBeAbleToInteract(this.pawn);
                    if (!this.$disposing)
                    {
                        this.$PC = 11;
                    }
                    return(true);

                case 11u:
                    this.$current = Toils_Interpersonal.GotoInteractablePosition(TargetIndex.A);
                    if (!this.$disposing)
                    {
                        this.$PC = 12;
                    }
                    return(true);

                case 12u:
                    this.$current = JobDriver_InteractAnimal.TalkToAnimal(TargetIndex.A);
                    if (!this.$disposing)
                    {
                        this.$PC = 13;
                    }
                    return(true);

                case 13u:
                    enumerator2 = base.FeedToils().GetEnumerator();
                    num         = 4294967293u;
                    goto Block_15;

                case 14u:
                    goto IL_2E4;

                case 15u:
                    this.$current = Toils_Interpersonal.SetLastInteractTime(TargetIndex.A);
                    if (!this.$disposing)
                    {
                        this.$PC = 16;
                    }
                    return(true);

                case 16u:
                    this.$current = Toils_Interpersonal.WaitToBeAbleToInteract(this.pawn);
                    if (!this.$disposing)
                    {
                        this.$PC = 17;
                    }
                    return(true);

                case 17u:
                    this.$current = Toils_Interpersonal.GotoInteractablePosition(TargetIndex.A);
                    if (!this.$disposing)
                    {
                        this.$PC = 18;
                    }
                    return(true);

                case 18u:
                    this.$current = this.FinalInteractToil();
                    if (!this.$disposing)
                    {
                        this.$PC = 19;
                    }
                    return(true);

                case 19u:
                    this.$PC = -1;
                    return(false);

                default:
                    return(false);
                }
                try
                {
                    switch (num)
                    {
                    }
                    if (enumerator.MoveNext())
                    {
                        t             = enumerator.Current;
                        this.$current = t;
                        if (!this.$disposing)
                        {
                            this.$PC = 9;
                        }
                        flag = true;
                        return(true);
                    }
                }
                finally
                {
                    if (!flag)
                    {
                        if (enumerator != null)
                        {
                            enumerator.Dispose();
                        }
                    }
                }
                this.$current = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch);
                if (!this.$disposing)
                {
                    this.$PC = 10;
                }
                return(true);

Block_15:
                try
                {
IL_2E4:
                    switch (num)
                    {
                    }
                    if (enumerator2.MoveNext())
                    {
                        t2            = enumerator2.Current;
                        this.$current = t2;
                        if (!this.$disposing)
                        {
                            this.$PC = 14;
                        }
                        flag = true;
                        return(true);
                    }
                }
                finally
                {
                    if (!flag)
                    {
                        if (enumerator2 != null)
                        {
                            enumerator2.Dispose();
                        }
                    }
                }
                this.$current = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch);
                if (!this.$disposing)
                {
                    this.$PC = 15;
                }
                return(true);
            }