protected override IEnumerable <Toil> MakeNewToils()
        {
            CompEatWeirdFood comp = pawn.TryGetComp <CompEatWeirdFood>();

            if (comp == null)
            {
                yield break;
            }

            this.FailOn(() => this.IngestibleSource.Destroyed);

            Toil chew = ChewAnything(this.pawn, 1f, TargetIndex.A, TargetIndex.B).FailOn((Toil x) => !this.IngestibleSource.Spawned && (this.pawn.carryTracker == null || this.pawn.carryTracker.CarriedThing != this.IngestibleSource)).FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch);

            foreach (Toil toil in this.PrepareToIngestToils(chew))
            {
                yield return(toil);
            }
            IEnumerator <Toil> enumerator = null;

            yield return(chew);

            yield return(FinalizeIngestAnything(this.pawn, TargetIndex.A, comp));

            yield return(Toils_Jump.JumpIf(chew, () => this.job.GetTarget(TargetIndex.A).Thing is Corpse && this.pawn.needs.food.CurLevelPercentage < 0.9f));

            yield break;
            yield break;
        }
        public static bool StopEatingThings(Pawn pawn)

        {
            CompEatWeirdFood comp = pawn.TryGetComp <CompEatWeirdFood>();

            if (comp != null)
            {
                //Log.Message("Somehow I'm here");
                return(false);
            }
            else
            {
                return(true);
            }
        }
Пример #3
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            Need_Food food = pawn.needs.food;

            if (food == null || food.CurCategory < this.minCategory || food.CurLevelPercentage > this.maxLevelPercentage)
            {
                return(null);
            }

            //Log.Message("Eating");

            ThingDef thingDef = null;
            Thing    thing    = null;

            CompEatWeirdFood comp = pawn.TryGetComp <CompEatWeirdFood>();

            if (comp != null)
            {
                foreach (string customThingToEat in comp.Props.customThingToEat)
                {
                    thingDef = DefDatabase <ThingDef> .GetNamedSilentFail(customThingToEat);

                    if (thingDef != null)
                    {
                        thing = FindWeirdFoodInMap(thingDef, pawn);

                        if (thing != null)
                        {
                            break;
                        }
                    }
                }
            }
            else
            {
                return(null);
            }
            if (thing != null)
            {
                //float nutrition = 1f;
                Job job3 = JobMaker.MakeJob(DefDatabase <JobDef> .GetNamed("AA_IngestWeird", true), thing);
                job3.count = 1;// FoodUtility.WillIngestStackCountOf(pawn, thingDef, nutrition);
                return(job3);
            }
            else
            {
                if ((pawn.Map != null) && comp.Props.digThingIfMapEmpty && (pawn.needs.food.CurLevelPercentage < pawn.needs.food.PercentageThreshHungry) && (pawn.Awake()))
                {
                    ThingDef newThing  = ThingDef.Named(comp.Props.thingToDigIfMapEmpty);
                    Thing    newcorpse = null;
                    for (int i = 0; i < comp.Props.customAmountToDig; i++)
                    {
                        newcorpse = GenSpawn.Spawn(newThing, pawn.Position, pawn.Map, WipeMode.Vanish);
                    }

                    if (this.effecter == null)
                    {
                        this.effecter = EffecterDefOf.Mine.Spawn();
                    }
                    this.effecter.Trigger(pawn, newcorpse);
                }
            }
            return(null);
        }
        public static Toil FinalizeIngestAnything(Pawn ingester, TargetIndex ingestibleInd, CompEatWeirdFood comp)
        {
            Toil toil = new Toil();

            toil.initAction = delegate()
            {
                Pawn  actor  = toil.actor;
                Job   curJob = actor.jobs.curJob;
                Thing thing  = curJob.GetTarget(ingestibleInd).Thing;

                float num = ingester.needs.food.NutritionWanted;
                if (curJob.overeat)
                {
                    num = Mathf.Max(num, 0.75f);
                }
                float num2 = comp.Props.nutrition;// thing.Ingested(ingester, num);
                if (comp.Props.fullyDestroyThing)
                {
                    thing.Destroy(DestroyMode.Vanish);
                }
                else
                {
                    if (thing.def.useHitPoints)
                    {
                        thing.HitPoints -= (int)(thing.MaxHitPoints * comp.Props.percentageOfDestruction);
                        if (thing.HitPoints <= 0)
                        {
                            thing.Destroy(DestroyMode.Vanish);
                        }
                    }
                    else
                    {
                        int thingsToDestroy = (int)(comp.Props.percentageOfDestruction * thing.def.stackLimit);
                        //Log.Message(thingsToDestroy.ToString());

                        thing.stackCount = thing.stackCount - thingsToDestroy;
                        //Log.Message(thing.stackCount.ToString());
                        if (thing.stackCount < 10)
                        {
                            thing.Destroy(DestroyMode.Vanish);
                        }
                    }
                    if ((actor.def.defName == "AA_AngelMoth") && (actor.Faction == Faction.OfPlayer) && (thing.TryGetComp <CompQuality>() != null) && (thing.TryGetComp <CompQuality>().Quality == QualityCategory.Legendary))
                    {
                        actor.health.AddHediff(HediffDef.Named("AA_AteFinestClothes"));
                    }
                }

                if (comp.Props.hediffWhenEaten != "")
                {
                    actor.health.AddHediff(HediffDef.Named(comp.Props.hediffWhenEaten));
                }

                if (!ingester.Dead)
                {
                    ingester.needs.food.CurLevel += num2;
                }
                ingester.records.AddTo(RecordDefOf.NutritionEaten, num2);
            };
            toil.defaultCompleteMode = ToilCompleteMode.Instant;
            return(toil);
        }