private 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); }
internal static bool HasFoodToInteractAnimal(Pawn pawn, Pawn tamee) { if (Policies.Taming == null) { throw new Exception("Everything is broken !"); } ThingOwner 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) && Policies.Taming.PolicyAllows(tamee, thing)) { for (int j = 0; j < thing.stackCount; j++) { num3 += thing.def.ingestible.nutrition; if (num3 >= num2) { num++; num3 = 0f; } if (num >= 2) { return(true); } } } } return(false); }
internal static Job TakeFoodForAnimalInteractJob(this WorkGiver_InteractAnimal _this, Pawn pawn, Pawn tamee) { float reqNutrition = JobDriver_InteractAnimal.RequiredNutritionPerFeed(tamee) * 2f * 4f; Thing thing = FoodUtility.BestFoodSourceOnMap(pawn, tamee, false, FoodPreferability.RawTasty, false, false, false, false, false, false); if (thing == null) { return(null); } // Check for inventory space int numToCarry = Mathf.CeilToInt(reqNutrition / thing.def.ingestible.nutrition); CompInventory inventory = pawn.TryGetComp <CompInventory>(); if (inventory != null) { int maxCount; if (inventory.CanFitInInventory(thing, out maxCount)) { numToCarry = Mathf.Min(numToCarry, maxCount); } else { Messages.Message("CR_TamerInventoryFull".Translate(), pawn, MessageSound.RejectInput); return(null); } } return(new Job(JobDefOf.TakeInventory, thing) { count = numToCarry }); }
public static void Postfix(WorkGiver_InteractAnimal __instance, ref Job __result, Pawn pawn, Pawn tamee) { if (__result != null) { // Check for inventory space int numToCarry = __result.count; CompInventory inventory = pawn.TryGetComp <CompInventory>(); float minNutrition = JobDriver_InteractAnimal.RequiredNutritionPerFeed(tamee); int requiredThingCount = Mathf.CeilToInt(minNutrition / FoodUtility.GetNutrition(__result.targetA.Thing, FoodUtility.GetFinalIngestibleDef(__result.targetA.Thing))); if (inventory != null) { if (inventory.CanFitInInventory(__result.targetA.Thing, out int maxCount) && requiredThingCount <= maxCount) { __result.count = Mathf.Min(numToCarry, maxCount); pawn.Notify_HoldTrackerItem(__result.targetA.Thing, __result.count); } else { rejectedInventoryMass = true; __result = null; } } } }
// RimWorld.WorkGiver_InteractAnimal protected Job TakeFoodForAnimalInteractJob(Pawn pawn, Pawn tamee) { float num = JobDriver_InteractAnimal.RequiredNutritionPerFeed(tamee) * 2f * 4f; Thing thing; ThingDef def; if (!FoodUtility.TryFindBestFoodSourceFor_Internal(pawn, tamee, false, out thing, out def, false, false, false, Config.useCorpsesForTaming, Policies.Taming)) { return(null); } return(new Job(JobDefOf.TakeInventory, thing) { count = Mathf.CeilToInt(num / thing.GetNutritionAmount()) }); }
internal static Job TakeFoodForAnimalInteractJob(Pawn pawn, Pawn tamee) { float num = JobDriver_InteractAnimal.RequiredNutritionPerFeed(tamee) * 2f * 4f; Thing thing; ThingDef thingdef; // -------- MOD -------- bool result = Detours.FoodUtility.TryFindBestFoodSourceFor.Internal(pawn, tamee, false, out thing, out thingdef, true, false, false, Config.useCorpsesForTaming, Policies.Taming); // -------- -------- if (!result) { return(null); } return(new Job(JobDefOf.TakeInventory, thing) { count = Mathf.CeilToInt(num / thing.GetNutritionAmount()) }); }
private Job TakeFoodForAnimalInteractJob(Pawn pawn, Pawn tamee) { FoodUtility.bestFoodSourceOnMap_minNutrition_NewTemp = JobDriver_InteractAnimal.RequiredNutritionPerFeed(tamee) * 2f * 4f; ThingDef foodDef; Thing thing = FoodUtility.BestFoodSourceOnMap(pawn, tamee, false, out foodDef, FoodPreferability.RawTasty, allowPlant: false, allowDrug: false, allowCorpse: false, allowDispenserFull: false, allowDispenserEmpty: false); FoodUtility.bestFoodSourceOnMap_minNutrition_NewTemp = null; if (thing == null) { return(null); } float num = JobDriver_InteractAnimal.RequiredNutritionPerFeed(tamee) * 2f * 4f; float nutrition = FoodUtility.GetNutrition(thing, foodDef); int count = Mathf.CeilToInt(num / nutrition); Job job = JobMaker.MakeJob(JobDefOf.TakeInventory, thing); job.count = count; return(job); }