public static bool TryFindBestFoodSourceFor(Pawn getter, Pawn eater, bool desperate, out Thing foodSource, out ThingDef foodDef, bool canRefillDispenser = true, bool canUseInventory = true, bool allowForbidden = false, bool allowCorpse = true, bool allowSociallyImproper = false, bool allowHarvest = false, bool forceScanWholeMap = false) { bool flag = getter.RaceProps.ToolUser && getter.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation); bool allowDrug = !eater.IsTeetotaler(); Thing thing = null; if (canUseInventory) { if (flag) { thing = FoodUtility.BestFoodInInventory(getter, null, FoodPreferability.MealAwful, FoodPreferability.MealLavish, 0f, false); } if (thing != null) { if (getter.Faction != Faction.OfPlayer) { foodSource = thing; foodDef = FoodUtility.GetFinalIngestibleDef(foodSource, false); return(true); } CompRottable compRottable = thing.TryGetComp <CompRottable>(); if (compRottable != null && compRottable.Stage == RotStage.Fresh && compRottable.TicksUntilRotAtCurrentTemp < 30000) { foodSource = thing; foodDef = FoodUtility.GetFinalIngestibleDef(foodSource, false); return(true); } } } ThingDef thingDef; ref ThingDef foodDef2 = ref thingDef;
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); Thing thing = FoodUtility.BestFoodInInventory(actor, pawn, FoodPreferability.NeverForNutrition, FoodPreferability.RawTasty); if (thing == null) { actor.jobs.EndCurrentJob(JobCondition.Incompletable); } else { actor.mindState.lastInventoryRawFoodUseTick = Find.TickManager.TicksGame; int num = FoodUtility.StackCountForNutrition(feedNutritionLeft, thing.GetStatValue(StatDefOf.Nutrition)); 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.GetStatValue(StatDefOf.Nutrition); ticksLeftThisToil = Mathf.CeilToInt(270f * (num2 / RequiredNutritionPerFeed(pawn))); if (num <= stackCount) { feedNutritionLeft = 0f; } else { feedNutritionLeft -= num2; if (feedNutritionLeft < 0.001f) { feedNutritionLeft = 0f; } } } }; toil.defaultCompleteMode = ToilCompleteMode.Delay; toil.activeSkill = () => SkillDefOf.Animals; return(toil); }
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); }
public static bool TryFindBestFoodSourceFor(Pawn getter, Pawn eater, bool desperate, out Thing foodSource, out ThingDef foodDef, bool canRefillDispenser = true, bool canUseInventory = true, bool allowForbidden = false, bool allowCorpse = true, bool allowSociallyImproper = false, bool allowHarvest = false) { bool flag = getter.RaceProps.ToolUser && getter.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation); bool allowDrug = !eater.IsTeetotaler(); Thing thing = null; if (canUseInventory) { if (flag) { thing = FoodUtility.BestFoodInInventory(getter, null, FoodPreferability.MealAwful, FoodPreferability.MealLavish, 0f, false); } if (thing != null) { if (getter.Faction != Faction.OfPlayer) { foodSource = thing; foodDef = FoodUtility.GetFinalIngestibleDef(foodSource, false); return(true); } CompRottable compRottable = thing.TryGetComp <CompRottable>(); if (compRottable != null && compRottable.Stage == RotStage.Fresh && compRottable.TicksUntilRotAtCurrentTemp < 30000) { foodSource = thing; foodDef = FoodUtility.GetFinalIngestibleDef(foodSource, false); return(true); } } } bool allowPlant = getter == eater; ThingDef thingDef = default(ThingDef); Thing thing2 = FoodUtility.BestFoodSourceOnMap(getter, eater, desperate, out thingDef, FoodPreferability.MealLavish, allowPlant, allowDrug, allowCorpse, true, canRefillDispenser, allowForbidden, allowSociallyImproper, allowHarvest); if (thing == null && thing2 == null) { if (canUseInventory && flag) { thing = FoodUtility.BestFoodInInventory(getter, null, FoodPreferability.DesperateOnly, FoodPreferability.MealLavish, 0f, allowDrug); if (thing != null) { foodSource = thing; foodDef = FoodUtility.GetFinalIngestibleDef(foodSource, false); return(true); } } if (thing2 == null && getter == eater && (getter.RaceProps.predator || getter.IsWildMan())) { Pawn pawn = FoodUtility.BestPawnToHuntForPredator(getter); if (pawn != null) { foodSource = pawn; foodDef = FoodUtility.GetFinalIngestibleDef(foodSource, false); return(true); } } foodSource = null; foodDef = null; return(false); } if (thing == null && thing2 != null) { foodSource = thing2; foodDef = thingDef; return(true); } ThingDef finalIngestibleDef = FoodUtility.GetFinalIngestibleDef(thing, false); if (thing2 == null) { foodSource = thing; foodDef = finalIngestibleDef; return(true); } float num = FoodUtility.FoodOptimality(eater, thing2, thingDef, (float)(getter.Position - thing2.Position).LengthManhattan, false); float num2 = FoodUtility.FoodOptimality(eater, thing, finalIngestibleDef, 0f, false); num2 = (float)(num2 - 32.0); if (num > num2) { foodSource = thing2; foodDef = thingDef; return(true); } foodSource = thing; foodDef = FoodUtility.GetFinalIngestibleDef(foodSource, false); return(true); }