public Thing FindNextIngredientInHopper(List <IntVec3> cachedCells, Building_NutrientPasteDispenser instance, float[] nutrition) { foreach (IntVec3 c in cachedCells) { Thing thing = null; Thing thing2 = null; List <Thing> thingList = c.GetThingList(instance.Map); foreach (Thing t in thingList) { if (Building_NutrientPasteDispenser.IsAcceptableFeedstock(t.def) && this.ingredientList.Any(x => x.thingDef == t.def) && nutrition[ingredientList.FindIndex(x => x.thingDef == t.def)] > 0f) { thing = t; } if (t.def == ThingDefOf.Hopper || t.def.thingClass == typeof(NPDHopper_Storage)) { thing2 = t; } } if (!(thing is null) && !(thing2 is null)) { return(thing); } } return(null); }
protected override Thing FindFeedInAnyHopper() { // Check for generic hoppers if (compHopperUser != null) { var hoppers = compHopperUser.FindHoppers(); if (!hoppers.NullOrEmpty()) { foreach (var hopper in hoppers) { var resources = hopper.GetAllResources(compHopperUser.Resources); if (!resources.NullOrEmpty()) { foreach (var resource in resources) { // This check shouldn't be needed, but we'll do it as a fail-safe if (Building_NutrientPasteDispenser.IsAcceptableFeedstock(resource.def)) { return(resource); } } } } } } // Check for vanilla hoppers return(base.FindFeedInAnyHopper()); }
public static bool FindFeedInAnyCustomHopper(Building_NutrientPasteDispenser __instance, ref Thing __result, ref List <IntVec3> ___cachedAdjCellsCardinal) { if (___cachedAdjCellsCardinal is null) { ___cachedAdjCellsCardinal = (from c in GenAdj.CellsAdjacentCardinal(__instance) where c.InBounds(__instance.Map) select c).ToList <IntVec3>(); } foreach (IntVec3 c in ___cachedAdjCellsCardinal) { Thing thing = null; Thing thing2 = null; List <Thing> thingList = c.GetThingList(__instance.Map); foreach (Thing t in thingList) { if (Building_NutrientPasteDispenser.IsAcceptableFeedstock(t.def)) { thing = t; } if (t.def == ThingDefOf.Hopper || t.def.thingClass == typeof(NPDHopper_Storage)) { thing2 = t; } } if (thing != null && thing2 != null) { __result = thing; return(false); } } __result = null; return(true); }
static bool Prefix(Building_NutrientPasteDispenser __instance, ref Thing __result) { var fc = FridgeCache.GetFridgeCache(__instance.Map); foreach (IntVec3 cell in __instance.AdjCellsCardinalInBounds) { Thing thing = null; Thing holder = null; foreach (Thing t in cell.GetThingList(__instance.Map)) { if (Building_NutrientPasteDispenser.IsAcceptableFeedstock(t.def)) { thing = t; } if (t.def == ThingDefOf.Hopper || fc?.HasFridgeAt(cell) == true) { holder = t; } } if (thing != null && holder != null) { __result = thing; return(false); } } return(false); }
static bool Prefix(Building_NutrientPasteDispenser __instance, ref bool __result) { var fc = FridgeCache.GetFridgeCache(__instance.Map); float num = 0f; foreach (IntVec3 cell in __instance.AdjCellsCardinalInBounds) { Thing thing = null; Thing holder = null; foreach (Thing t in cell.GetThingList(__instance.Map)) { if (Building_NutrientPasteDispenser.IsAcceptableFeedstock(t.def)) { thing = t; } if (t.def == ThingDefOf.Hopper || fc?.HasFridgeAt(cell) == true) { holder = t; } if (thing != null && holder != null) { num += (float)thing.stackCount * thing.GetStatValue(StatDefOf.Nutrition, true); if (num >= __instance.def.building.nutritionCostPerDispense) { __result = true; return(false); } break; } } } return(false); }
public static bool Prefix(ref Job __result, Pawn pawn, Thing thing) { __result = null; if (!(thing is ISlotGroupParent hopperSgp)) { return(false); } var setting = hopperSgp.GetStoreSettings(); var limit = setting.GetStacklimit(); if (setting.IsRefillingDisabled() || limit == 0) { return(false); } foreach (var thing2 in pawn.Map.thingGrid.ThingsListAt(thing.Position)) { if (Building_NutrientPasteDispenser.IsAcceptableFeedstock(thing2.def)) { if ((thing2.stackCount * 100) >= ((limit < 0 ? thing2.def.stackLimit : limit) * setting.GetRefillPercent())) { return(false); } } } return(true); }
internal static Thing _FindFeedInAnyHopper(this Building_NutrientPasteDispenser obj) { // Check for generic hoppers var CompHopperUser = obj.TryGetComp <CompHopperUser>(); if (CompHopperUser != null) { var hoppers = CompHopperUser.FindHoppers(); if (!hoppers.NullOrEmpty()) { foreach (var hopper in hoppers) { var resources = hopper.GetAllResources(CompHopperUser.Resources); if (!resources.NullOrEmpty()) { foreach (var resource in resources) { // This check shouldn't be needed, but we'll do it as a fail-safe if (Building_NutrientPasteDispenser.IsAcceptableFeedstock(resource.def)) { return(resource); } } } } } } // Check for vanilla hoppers var adjCells = _AdjCellsCardinalInBounds(obj); for (int cellIndex = 0; cellIndex < adjCells.Count; ++cellIndex) { IntVec3 c = adjCells[cellIndex]; Thing resource = (Thing)null; Thing hopper = (Thing)null; List <Thing> thingList = c.GetThingList(); for (int thingIndex = 0; thingIndex < thingList.Count; ++thingIndex) { Thing thisThing = thingList[thingIndex]; if (Building_NutrientPasteDispenser.IsAcceptableFeedstock(thisThing.def)) { resource = thisThing; } if (thisThing.def == ThingDefOf.Hopper) { hopper = thisThing; } } if ( (resource != null) && (hopper != null) ) { return(resource); } } return((Thing)null); }
internal static bool _HasEnoughFeedstockInHoppers(this Building_NutrientPasteDispenser obj) { int costPerDispense = obj.def.building.foodCostPerDispense; /* Research Project cut from A13 * if( ResearchProjectDef.Named( "NutrientResynthesis" ).IsFinished ) * { * costPerDispense--; * } */ // Check for generic hoppers var CompHopperUser = obj.TryGetComp <CompHopperUser>(); if (CompHopperUser != null) { if (CompHopperUser.EnoughResourcesInHoppers(costPerDispense)) { return(true); } } // Check for vanilla hoppers var adjCells = _AdjCellsCardinalInBounds(obj); int resourceCount = 0; for (int cellIndex = 0; cellIndex < adjCells.Count; ++cellIndex) { IntVec3 c = adjCells[cellIndex]; Thing resource = (Thing)null; Thing hopper = (Thing)null; List <Thing> thingList = GridsUtility.GetThingList(c); for (int thingIndex = 0; thingIndex < thingList.Count; ++thingIndex) { Thing thisThing = thingList[thingIndex]; if (Building_NutrientPasteDispenser.IsAcceptableFeedstock(thisThing.def)) { resource = thisThing; } if (thisThing.def == ThingDefOf.Hopper) { hopper = thisThing; } } if ( (resource != null) && (hopper != null) ) { resourceCount += resource.stackCount; } if (resourceCount >= costPerDispense) { return(true); } } return(false); }
static List <Thing> GetAllHoppersThings(this RimWorld.Building_NutrientPasteDispenser self) { var list = new List <Thing>(); for (int i = 0; i < self.AdjCellsCardinalInBounds().Count; i++) { IntVec3 c = self.AdjCellsCardinalInBounds()[i]; Building edifice = c.GetEdifice(self.Map); if (edifice != null && edifice.def == ThingDefOf.Hopper // && eater.CanReach(edifice, PathEndMode.Touch, Danger.Deadly, false, TraverseMode.ByPawn) ) { List <Thing> thingList = self.AdjCellsCardinalInBounds()[i].GetThingList(self.Map).ToList(); list.AddRange(thingList.Where((Thing arg) => Building_NutrientPasteDispenser.IsAcceptableFeedstock(arg.def))); } } return(list); }
static void Postfix(Building_NutrientPasteDispenser __instance, ref Thing __result) { if (__result == null) { //loop over Inputs for (int i = 0; i < __instance.AdjCellsCardinalInBounds.Count; i++) { //Get list of Items INutrientPasteDispenserInput input = (INutrientPasteDispenserInput)__instance.AdjCellsCardinalInBounds[i].GetThingList(__instance.Map).Where(thing => thing is INutrientPasteDispenserInput).FirstOrDefault(); if (input == null || input.NPDI_Item == null) { continue; } if (Building_NutrientPasteDispenser.IsAcceptableFeedstock(input.NPDI_Item.def)) { __result = input.NPDI_Item; } if (__result != null) { break; } } } }
public static bool HasEnoughFeedstockInCustomHoppers(ref bool __result, Building_NutrientPasteDispenser __instance, ref List <IntVec3> ___cachedAdjCellsCardinal) { if (!(__instance.def.GetModExtension <NutrientPasteCustom>() is null)) { if (___cachedAdjCellsCardinal is null) { ___cachedAdjCellsCardinal = (from c in GenAdj.CellsAdjacentCardinal(__instance) where c.InBounds(__instance.Map) select c).ToList <IntVec3>(); } float num = 0f; bool empty = __instance.def.GetModExtension <NutrientPasteCustom>().ingredientList is null || !__instance.def.GetModExtension <NutrientPasteCustom>().ingredientList.Any(); if (!empty) { __result = false; List <IngredientAndCostClass> ingredientList = __instance.def.GetModExtension <NutrientPasteCustom>().ingredientList; bool[] ingredientFulfilled = new bool[ingredientList.Count]; float[] nutritionCost = new float[ingredientList.Count]; foreach (IntVec3 c in ___cachedAdjCellsCardinal) { Thing thing = null; Thing thing2 = null; List <Thing> thingList = c.GetThingList(__instance.Map); foreach (Thing t in thingList) { if (Building_NutrientPasteDispenser.IsAcceptableFeedstock(t.def) && ingredientList.Any(x => x.thingDef == t.def) && nutritionCost[ingredientList.FindIndex(x => x.thingDef == t.def)] <= 0f) { thing = t; } if (t.def == ThingDefOf.Hopper || t.def.thingClass == typeof(NPDHopper_Storage)) { thing2 = t; } } if (!(thing is null) && !(thing2 is null)) { nutritionCost[ingredientList.FindIndex(x => x.thingDef == thing.def)] += (float)thing.stackCount * thing.GetStatValue(StatDefOf.Nutrition, true); if (nutritionCost[ingredientList.FindIndex(x => x.thingDef == thing.def)] >= ingredientList.Find(x => x.thingDef == thing.def).nutritionCost) { ingredientFulfilled[ingredientList.FindIndex(x => x.thingDef == thing.def)] = true; } } if (ingredientFulfilled.All(x => x)) { __result = true; return(false); } } return(false); } foreach (IntVec3 c in ___cachedAdjCellsCardinal) { Thing thing = null; Thing thing2 = null; List <Thing> thingList = c.GetThingList(__instance.Map); foreach (Thing t in thingList) { if (Building_NutrientPasteDispenser.IsAcceptableFeedstock(t.def)) { thing = t; } if (t.def == ThingDefOf.Hopper || t.def.thingClass == typeof(NPDHopper_Storage)) { thing2 = t; } } if (thing != null && thing2 != null) { num += (float)thing.stackCount * thing.GetStatValue(StatDefOf.Nutrition, true); } if (num >= __instance.def.building.nutritionCostPerDispense) { __result = true; return(false); } } __result = false; return(false); } return(true); }
internal static Job HopperFillFoodJob(Pawn pawn, Building hopper, Thing parent) { var hopperSgp = hopper as ISlotGroupParent; if ( (!pawn.CanReserveAndReach( hopper.Position, PathEndMode.Touch, pawn.NormalMaxDanger(), 1) ) ) { return(null); } ThingDef resourceDef = null; var firstItem = hopper.Position.GetFirstItem(); if (firstItem != null) { if ( ( (parent is Building_NutrientPasteDispenser) && (Building_NutrientPasteDispenser.IsAcceptableFeedstock(firstItem.def)) ) || ( (parent is Building_AutomatedFactory) && (((Building_AutomatedFactory)parent).CompHopperUser.ResourceSettings.AllowedToAccept(firstItem)) ) ) { resourceDef = firstItem.def; } else { if (firstItem.IsForbidden(pawn)) { return(( Job )null); } return(HaulAIUtility.HaulAsideJobFor(pawn, firstItem)); } } List <Thing> list = resourceDef != null ? Find.Map.listerThings.ThingsOfDef(resourceDef) : Find.Map.listerThings.ThingsInGroup(ThingRequestGroup.FoodSourceNotPlantOrTree); for (int index = 0; index < list.Count; ++index) { Thing t = list[index]; if ( (t.def.IsNutritionGivingIngestible) && ( (t.def.ingestible.preferability == FoodPreferability.RawBad) || (t.def.ingestible.preferability == FoodPreferability.RawTasty) ) && (HaulAIUtility.PawnCanAutomaticallyHaul(pawn, t)) && ( (Find.SlotGroupManager.SlotGroupAt(hopper.Position).Settings.AllowedToAccept(t)) && (HaulAIUtility.StoragePriorityAtFor(t.Position, t) < hopperSgp.GetSlotGroup().Settings.Priority) ) ) { Job job = HaulAIUtility.HaulMaxNumToCellJob(pawn, t, hopper.Position, true); if (job != null) { return(job); } } } return(null); }
static void Postfix(Building_NutrientPasteDispenser __instance, ref bool __result) { //Sadly witth the current valilla implementation adding support between mods is difficult. //Each mod needs to patch this but cant build on the progress of the other one. // //If for example Rimfrige supplies 50% of the nutriants then we will never know about it //If we want to support the input of other mods we need a patch for them. if (__result == false) { //Support for Rimfrige object rimFridgeCache = null; if (ProjectRimFactory_ModComponent.ModSupport_RrimFrige_Dispenser) { rimFridgeCache = ProjectRimFactory_ModComponent.ModSupport_RrimFridge_GetFridgeCache.Invoke(null, new object[] { (object)__instance.Map }); } float num = 0f; for (int i = 0; i < __instance.AdjCellsCardinalInBounds.Count; i++) { IntVec3 c = __instance.AdjCellsCardinalInBounds[i]; INutrientPasteDispenserInput input = (INutrientPasteDispenserInput)c.GetThingList(__instance.Map).Where(thing => thing is INutrientPasteDispenserInput).FirstOrDefault(); if (input != null && input.NPDI_Item != null && Building_NutrientPasteDispenser.IsAcceptableFeedstock(input.NPDI_Item.def)) { num += (float)input.NPDI_Item.stackCount * input.NPDI_Item.GetStatValue(StatDefOf.Nutrition); } else { Thing thing = null; Thing thing2 = null; List <Thing> thingList = c.GetThingList(__instance.Map); for (int j = 0; j < thingList.Count; j++) { Thing thing3 = thingList[j]; if (Building_NutrientPasteDispenser.IsAcceptableFeedstock(thing3.def)) { thing = thing3; } //Support for Rimfrige if (rimFridgeCache != null) { bool isfc = (bool)ProjectRimFactory_ModComponent.ModSupport_RrimFridge_HasFridgeAt.Invoke(rimFridgeCache, new object[] { (object)c }); if (isfc) { thing2 = thing3; } } if (thing3.def == ThingDefOf.Hopper) { thing2 = thing3; } } if (thing != null && thing2 != null) { num += (float)thing.stackCount * thing.GetStatValue(StatDefOf.Nutrition); } } if (num >= __instance.def.building.nutritionCostPerDispense) { __result = true; break; } } } }