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); } 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; }
public static bool StopEatingThings(Pawn pawn) { CompEatWeirdFood comp = pawn.TryGetComp <CompEatWeirdFood>(); if (comp != null) { return(false); } else { return(true); } }
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) { if (comp.Props.drainBattery) { Building_Battery battery = thing as Building_Battery; if (battery != null) { CompPowerBattery compPower = battery.TryGetComp <CompPowerBattery>(); compPower.SetStoredEnergyPct(compPower.StoredEnergyPct - comp.Props.percentageDrain); } else { thing.Destroy(DestroyMode.Vanish); } } else { 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 (comp.Props.advanceLifeStage && actor.Map != null) { comp.currentFeedings++; if (comp.currentFeedings >= comp.Props.advanceAfterXFeedings) { if (comp.Props.fissionAfterXFeedings) { if (!comp.Props.fissionOnlyIfTamed || actor.Faction.IsPlayer) { for (int i = 0; i < comp.Props.numberOfOffspring; i++) { PawnGenerationRequest request = new PawnGenerationRequest(PawnKindDef.Named(comp.Props.defToFissionTo), actor.Faction, PawnGenerationContext.NonPlayer, -1, true, true, false, false, true, false, 1f, false, true, true, false, false); Pawn newPawn = PawnGenerator.GeneratePawn(request); newPawn.playerSettings.AreaRestriction = actor.playerSettings.AreaRestriction; newPawn.relations.AddDirectRelation(PawnRelationDefOf.Parent, actor); GenSpawn.Spawn(newPawn, actor.Position, actor.Map, WipeMode.Vanish); } actor.Destroy(); } } else { PawnGenerationRequest request = new PawnGenerationRequest(PawnKindDef.Named(comp.Props.defToAdvanceTo), actor.Faction, PawnGenerationContext.NonPlayer, -1, true, true, false, false, true, false, 1f, false, true, true, false, false); Pawn newPawn = PawnGenerator.GeneratePawn(request); if (!actor.Name.ToString().UncapitalizeFirst().Contains(actor.def.label)) { newPawn.Name = actor.Name; } newPawn.training = actor.training; newPawn.health = actor.health; newPawn.foodRestriction = actor.foodRestriction; newPawn.playerSettings.AreaRestriction = actor.playerSettings.AreaRestriction; GenSpawn.Spawn(newPawn, actor.Position, actor.Map, WipeMode.Vanish); actor.Destroy(); } } } if (!ingester.Dead) { ingester.needs.food.CurLevel += num2; } ingester.records.AddTo(RecordDefOf.NutritionEaten, num2); }; toil.defaultCompleteMode = ToilCompleteMode.Instant; return(toil); }
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 && pawn.Map.reservationManager.CanReserve(pawn, thing, 1)) { //float nutrition = 1f; Job job3 = JobMaker.MakeJob(DefDatabase <JobDef> .GetNamed("VEF_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); }