public static void Postfix(WorkGiver_CookFillHopper __instance, Pawn pawn, Thing thing, bool forced, Job __result) { if (__result != null && forced) { CompMeeseeksMemory memory = pawn.GetComp <CompMeeseeksMemory>(); if (memory != null) { memory.AddToPotentialTargetCache(__instance, thing); } } }
protected override Job TryGiveJob(Pawn pawn) { var food = pawn.needs.food; if (food == null || food.CurCategory < minCategory) { return(null); } if (!pawn.RaceProps.Animal) { return(null); } var localCocoons = Utility.CocoonsFor(pawn.Map, pawn); if (localCocoons != null && localCocoons.Count > 0) { Building_Cocoon closestCocoon = null; var shortestDistance = 9999f; foreach (var thing1 in localCocoons) { var cocoon = (Building_Cocoon)thing1; //Log.Message("1"); if (cocoon?.isConsumableBy(pawn) != true || cocoon.CurrentDrinker != null) { continue; } //Log.Message("2"); if (closestCocoon == null) { closestCocoon = cocoon; continue; } var thisDistance = (float)(cocoon.Position - pawn.Position).LengthHorizontalSquared; if (!(thisDistance < shortestDistance)) { continue; } shortestDistance = thisDistance; closestCocoon = cocoon; } if (closestCocoon != null) { //Log.Message("3"); closestCocoon.CurrentDrinker = pawn as PawnWebSpinner; var newJob = new Job(ROMADefOf.ROMA_ConsumeCocoon, closestCocoon); //pawn.Reserve(closestCocoon, newJob); return(newJob); } } var desperate = pawn.needs.food.CurCategory == HungerCategory.Starving; if (!FoodUtility.TryFindBestFoodSourceFor(pawn, pawn, desperate, out var thing, out var def)) { return(null); } if (thing is Pawn pawn2) { var jobToDo = new Job(ROMADefOf.ROMA_SpinPrey, pawn2) { count = 1 }; return(jobToDo); } if (thing is Building_NutrientPasteDispenser building_NutrientPasteDispenser && !building_NutrientPasteDispenser.HasEnoughFeedstockInHoppers()) { var building = building_NutrientPasteDispenser.AdjacentReachableHopper(pawn); if (building != null) { var hopperSgp = building as ISlotGroupParent; var job = WorkGiver_CookFillHopper.HopperFillFoodJob(pawn, hopperSgp); if (job != null) { return(job); } } thing = FoodUtility.BestFoodSourceOnMap(pawn, pawn, desperate, out var thingDef, FoodPreferability.MealLavish, false, !pawn.IsTeetotaler(), false, false, false); if (thing == null) { return(null); } def = thingDef; } var nutrition = FoodUtility.GetNutrition(thing, def); return(new Job(JobDefOf.Ingest, thing) { count = FoodUtility.WillIngestStackCountOf(pawn, def, nutrition) }); }
protected override Job TryGiveJob(Pawn pawn) { var food = pawn.needs.food; if (food == null || food.CurCategory < minCategory) { return(null); } var need = pawn.needs.TryGetNeed <Need_Motivation>(); if (need != null) { need.Enabled = false; } bool flag; if (pawn.RaceProps.Animal) { flag = true; } else { var firstHediffOfDef = pawn.health.hediffSet.GetFirstHediffOfDef(HediffDefOf.Malnutrition, false); flag = firstHediffOfDef != null && firstHediffOfDef.Severity > 0.4f; } var desperate = pawn.needs.food.CurCategory == HungerCategory.Starving; var allowCorpse = flag; Thing thing; ThingDef def; if (!FoodUtility_Tweak.TryFindBestFoodSourceFor(pawn, pawn, desperate, out thing, out def, true, true, true, allowCorpse, false)) { return(null); } var pawn2 = thing as Pawn; if (pawn2 != null) { return new Job(JobDefOf.PredatorHunt, pawn2) { killIncappedTarget = true } } ; var building_NutrientPasteDispenser = thing as Building_NutrientPasteDispenser; if (building_NutrientPasteDispenser != null && !building_NutrientPasteDispenser.HasEnoughFeedstockInHoppers()) { var building = building_NutrientPasteDispenser.AdjacentReachableHopper(pawn); if (building != null) { var hopperSgp = building as ISlotGroupParent; var job = WorkGiver_CookFillHopper.HopperFillFoodJob(pawn, hopperSgp); if (job != null) { return(job); } } thing = FoodUtility_Tweak.BestFoodSourceOnMap(pawn, pawn, desperate, FoodPreferability.MealLavish, false, !pawn.IsTeetotaler(), false, false, false, false, false); if (thing == null) { return(null); } def = thing.def; } return(new Job(JobDefOf.Ingest, thing) { count = FoodUtility_Tweak.WillIngestStackCountOf(pawn, def) }); } }