static bool Prefix(Pawn pawn, ref Job __result) { if (pawn == null || pawn.Faction == null || !pawn.Faction.IsPlayer) { return(true); } Comp_PawnMenu comp = pawn.GetComp <Comp_PawnMenu>(); if (comp == null && !comp.activated()) { return(true); } if (pawn.inventory == null) { return(false); } ThingOwner <Thing> innerContainer = pawn.inventory.innerContainer; for (int i = 0; i < innerContainer.Count; i++) { Thing thing = innerContainer[i]; if (thing.def.ingestible != null && thing.def.ingestible.nutrition > 0.3f && thing.def.ingestible.preferability >= FoodPreferability.MealAwful && pawn.RaceProps.CanEverEat(thing)) { return(false); } } if (pawn.Map.resourceCounter.TotalHumanEdibleNutrition < (float)pawn.Map.mapPawns.ColonistsSpawnedCount * 1.5f) { return(false); } Thing thing2 = GenClosest.ClosestThing_Regionwise_ReachablePrioritized(pawn.Position, pawn.Map, ThingRequest.ForGroup(ThingRequestGroup.FoodSourceNotPlantOrTree), PathEndMode.ClosestTouch, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), 20f, delegate(Thing t) { if (!comp.contains(t.def)) { return(false); } if (t.def.category != ThingCategory.Item || t.def.ingestible == null || t.def.ingestible.nutrition < 0.3f || t.IsForbidden(pawn) || t is Corpse || !pawn.CanReserve(t, 1, -1, null, false) || !t.IsSociallyProper(pawn) || !pawn.RaceProps.CanEverEat(t)) { return(false); } List <ThoughtDef> list = FoodUtility.ThoughtsFromIngesting(pawn, t, FoodUtility.GetFinalIngestibleDef(t, false)); for (int j = 0; j < list.Count; j++) { if (list[j].stages[0].baseMoodEffect < 0f) { return(false); } } return(true); }, (Thing x) => FoodUtility.FoodOptimality(pawn, x, FoodUtility.GetFinalIngestibleDef(x, false), 0f, false), 24, 30); if (thing2 == null) { return(false); } __result = new Job(JobDefOf.TakeInventory, thing2) { count = 1 }; return(false); }
static bool Prefix(ThingDef food, Pawn pawn, ref float __result) { if (pawn == null || pawn.Faction == null || !pawn.Faction.IsPlayer) { return(true); } Comp_PawnMenu comp = pawn.GetComp <Comp_PawnMenu>(); if (comp != null && comp.activated() && comp.contains(food)) { __result += 10000; return(false); } return(true); }
static bool Prefix(Pawn pawn, IntVec3 partySpot, ref Thing __result) { if (pawn == null || pawn.Faction == null || !pawn.Faction.IsPlayer) { return(true); } Comp_PawnMenu comp = pawn.GetComp <Comp_PawnMenu>(); if (comp != null && comp.activated()) { Predicate <Thing> validator = (Thing x) => x.IngestibleNow && x.def.IsNutritionGivingIngestible && PartyUtility.InPartyArea(x.Position, partySpot, pawn.Map) && !x.def.IsDrug && x.def.ingestible.preferability > FoodPreferability.RawBad && pawn.RaceProps.WillAutomaticallyEat(x) && !x.IsForbidden(pawn) && x.IsSociallyProper(pawn) && pawn.CanReserve(x, 1, -1, null, false) && comp.contains(x.def); __result = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForGroup(ThingRequestGroup.FoodSourceNotPlantOrTree), PathEndMode.ClosestTouch, TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Deadly, false), 14f, validator, null, 0, 12, false, RegionType.Set_Passable, false); return(__result == null); } return(true); }
static bool Prefix(Pawn pawn, ref Job __result) { if (pawn == null || pawn.Faction == null || !pawn.Faction.IsPlayer) { return(true); } Comp_PawnMenu comp = pawn.GetComp <Comp_PawnMenu>(); if (comp != null && comp.activated()) { Predicate <Thing> validator = (Thing t) => t.def.category == ThingCategory.Item && t.IngestibleNow && pawn.RaceProps.CanEverEat(t) && pawn.CanReserve(t, 1, -1, null, false) && comp.contains(t.def); Thing food = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForGroup(ThingRequestGroup.HaulableAlways), PathEndMode.OnCell, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), 10f, validator, null, 0, -1, false, RegionType.Set_Passable, false); if (food != null) { __result = new Job(JobDefOf.Ingest, food); return(false); } } return(true); }
static bool Prefix(ref Thing __result, Pawn holder, Pawn eater = null, FoodPreferability minFoodPref = FoodPreferability.NeverForNutrition, FoodPreferability maxFoodPref = FoodPreferability.MealLavish, float minStackNutrition = 0f, bool allowDrug = false) { if (holder == null || holder.inventory == null) { return(false); } if (eater == null) { eater = holder; } if (eater == null || eater.Faction == null || !eater.Faction.IsPlayer) { return(true); } Comp_PawnMenu comp = eater.GetComp <Comp_PawnMenu>(); if (comp == null) { return(true); } if (!comp.activated()) { return(true); } ThingOwner <Thing> innerContainer = holder.inventory.innerContainer; for (int i = 0; i < innerContainer.Count; i++) { Thing thing = innerContainer[i]; if (thing.def.IsNutritionGivingIngestible && thing.IngestibleNow && eater.RaceProps.CanEverEat(thing) && thing.def.ingestible.preferability >= minFoodPref && thing.def.ingestible.preferability <= maxFoodPref && (allowDrug || !thing.def.IsDrug) && comp.contains(thing.def)) { float num = thing.def.ingestible.nutrition * (float)thing.stackCount; if (num >= minStackNutrition) { __result = thing; return(false); } } } return(true); }
static void Postfix(Pawn eater, ThingDef foodDef, ref float __result) { if (eater == null || foodDef == null || eater.Faction == null || !eater.Faction.IsPlayer) { return; } Comp_PawnMenu comp = eater.GetComp <Comp_PawnMenu>(); if (comp == null) { return; } if (!comp.activated()) { return; } if (comp.contains(foodDef)) { __result += 100000; } }
static bool Prefix(Pawn eater, Pawn getter, bool allowPlant, bool allowForbidden, bool desperate, FoodPreferability maxPref, bool allowCorpse, bool allowDrug, out ThingDef foodDef, ref Thing __result) { foodDef = null; if (eater == null || eater.Faction == null || !eater.Faction.IsPlayer || eater.def.race.Humanlike) { return(true); } Comp_PawnMenu comp = eater.GetComp <Comp_PawnMenu>(); if (comp == null) { return(true); } if (!comp.activated()) { return(true); } FoodPreferability minPref = FoodPreferability.NeverForNutrition; Predicate <Thing> foodValidator = delegate(Thing t) { if (!allowForbidden && t.IsForbidden(getter)) { return(false); } if (t.def.ingestible.preferability < minPref) { return(false); } if (t.def.ingestible.preferability > maxPref) { return(false); } if (!t.IngestibleNow || !t.def.IsNutritionGivingIngestible || (!allowCorpse && t is Corpse) || (!allowDrug && t.def.IsDrug) || (!desperate && t.IsNotFresh()) || t.IsDessicated() || !eater.RaceProps.WillAutomaticallyEat(t) || !getter.AnimalAwareOf(t) || !getter.CanReserve(t, 1, -1, null, false)) { return(false); } return(comp.contains(t.def)); }; ThingRequest thingRequest; if ((eater.RaceProps.foodType & (FoodTypeFlags.Plant | FoodTypeFlags.Tree)) != FoodTypeFlags.None && allowPlant) { thingRequest = ThingRequest.ForGroup(ThingRequestGroup.FoodSource); } else { thingRequest = ThingRequest.ForGroup(ThingRequestGroup.FoodSourceNotPlantOrTree); } int searchRegionsMax = 100; HashSet <Thing> ___filtered = new HashSet <Thing>(); foreach (Thing thing2 in GenRadial.RadialDistinctThingsAround(getter.Position, getter.Map, 2f, true)) { Pawn pawn = thing2 as Pawn; if (pawn != null && pawn != getter && pawn.RaceProps.Animal && pawn.CurJob != null && pawn.CurJob.def == JobDefOf.Ingest && pawn.CurJob.GetTarget(TargetIndex.A).HasThing) { ___filtered.Add(pawn.CurJob.GetTarget(TargetIndex.A).Thing); } } bool ignoreEntirelyForbiddenRegions = !allowForbidden && ForbidUtility.CaresAboutForbidden(getter, true) && getter.playerSettings != null && getter.playerSettings.EffectiveAreaRestrictionInPawnCurrentMap != null; Predicate <Thing> predicate = (Thing t) => foodValidator(t) && !___filtered.Contains(t) && !t.IsNotFresh(); IntVec3 position = getter.Position; Map map = getter.Map; PathEndMode peMode = PathEndMode.ClosestTouch; TraverseParms traverseParams = TraverseParms.For(getter, Danger.Deadly, TraverseMode.ByPawn, false); Thing bestThing = GenClosest.ClosestThingReachable(position, map, thingRequest, peMode, traverseParams, 9999f, predicate, null, 0, searchRegionsMax, false, RegionType.Set_Passable, ignoreEntirelyForbiddenRegions); if (bestThing != null) { if (bestThing != null) { foodDef = FoodUtility.GetFinalIngestibleDef(bestThing, false); } __result = bestThing; return(false); } return(true); }
protected override void FillTab() { IStoreSettingsParent selStoreSettingsParent = this.SelStoreSettingsParent; Comp_PawnMenu comp = selStoreSettingsParent as Comp_PawnMenu; comp.syncForAndWhen(comp.kind, comp.supper); Rect rect = new Rect(8f, 0f, 300f, 30f); rect = rect.ContractedBy(2f); GUI.BeginGroup(rect); Text.Font = GameFont.Small; Text.Anchor = TextAnchor.LowerLeft; string labelKind = "Kind"; string labelSelf = "Self"; string labelNormal = "Breakfast"; string labelSupper = "Supper"; string buttonLabel; if (comp.kind) { buttonLabel = labelKind; } else { buttonLabel = labelSelf; } rect = new Rect(0f, 0f, 30f, 30f); Widgets.Label(rect, "For:"); rect = new Rect(30f, 0f, 60f, 30f); if (Widgets.ButtonText(rect, buttonLabel, true, false, true)) { List <FloatMenuOption> list = new List <FloatMenuOption>(); list.Add(new FloatMenuOption(labelKind, delegate { comp.kind = true; comp.syncForAndWhen(comp.kind, comp.supper); })); list.Add(new FloatMenuOption(labelSelf, delegate { comp.kind = false; comp.syncForAndWhen(comp.kind, comp.supper); })); Find.WindowStack.Add(new FloatMenu(list)); } UIHighlighter.HighlightOpportunity(rect, buttonLabel); rect = new Rect(100f, 0f, 45f, 30f); Widgets.Label(rect, "When:"); rect = new Rect(145f, 0f, 100f, 30f); if (comp.supper) { buttonLabel = labelSupper; } else { buttonLabel = labelNormal; } if (Widgets.ButtonText(rect, buttonLabel, true, false, true)) { List <FloatMenuOption> list = new List <FloatMenuOption>(); list.Add(new FloatMenuOption(labelSupper, delegate { comp.supper = true; comp.syncForAndWhen(comp.kind, comp.supper); })); list.Add(new FloatMenuOption(labelNormal, delegate { comp.supper = false; comp.syncForAndWhen(comp.kind, comp.supper); })); Find.WindowStack.Add(new FloatMenu(list)); } UIHighlighter.HighlightOpportunity(rect, buttonLabel); GUI.EndGroup(); base.FillTab(); }