public static bool GetCarriedCount(RecipeWorkerCounter __instance, ref int __result, Bill_Production bill, ThingDef prodDef) { int num = 0; //foreach (Pawn item in bill.Map.mapPawns.FreeColonistsSpawned) if (!RimThreaded.billFreeColonistsSpawned.TryGetValue(bill, out List <Pawn> freeColonistsSpawned)) { freeColonistsSpawned = bill.Map.mapPawns.FreeColonistsSpawned; RimThreaded.billFreeColonistsSpawned[bill] = freeColonistsSpawned; } for (int i = 0; i < freeColonistsSpawned.Count; i++) { Thing carriedThing = freeColonistsSpawned[i]?.carryTracker?.CarriedThing; if (carriedThing == null) { continue; } int stackCount = carriedThing.stackCount; carriedThing = carriedThing.GetInnerIfMinified(); if (__instance.CountValidThing(carriedThing, bill, prodDef)) { num += stackCount; } } __result = num; return(false); }
public static bool GetCarriedCount(RecipeWorkerCounter __instance, ref int __result, Bill_Production bill, ThingDef prodDef) { int num = 0; //foreach (Pawn item in bill.Map.mapPawns.FreeColonistsSpawned) for (int i = 0; i < bill.Map.mapPawns.FreeColonistsSpawned.Count; i++) { Pawn item; try { item = bill.Map.mapPawns.FreeColonistsSpawned[i]; } catch (ArgumentOutOfRangeException) { break; } Thing carriedThing = item.carryTracker.CarriedThing; if (carriedThing != null) { int stackCount = carriedThing.stackCount; carriedThing = carriedThing.GetInnerIfMinified(); if (__instance.CountValidThing(carriedThing, bill, prodDef)) { num += stackCount; } } } __result = num; return(false); }
// Helper function to count matching items in inventory lists private static int CountMatchingThingsIn(IEnumerable <Thing> things, RecipeWorkerCounter counterClass, Bill_Production bill, ThingDef productThingDef) { var count = 0; foreach (var thing in things) { Thing item = thing.GetInnerIfMinified(); if (counterClass.CountValidThing(thing, bill, productThingDef)) { count += item.stackCount; } } return(count); }
// Count other things on map for ProductAdditionalFilter // This is sadly most of CountProducts re-written with a for loop for the additional defs public static int CountAdditionalProducts(RecipeWorkerCounter counter, Bill_Production bill, ExtendedBillData extendedBillData) { ThingFilter filter = extendedBillData.ProductAdditionalFilter; bool countAway = extendedBillData.CountAway; Map map = bill.Map; ThingDef defaultProductDef = counter.recipe.products[0].thingDef; int count = 0; foreach (ThingDef def in filter.AllowedThingDefs) { //Obviously skip the default product, it was already counted if (def == defaultProductDef) { continue; } //Same as CountProducts but now with other products if (def.CountAsResource && !bill.includeEquipped && (bill.includeTainted || !def.IsApparel || !def.apparel.careIfWornByCorpse) && bill.includeFromZone == null && bill.hpRange.min == 0f && bill.hpRange.max == 1f && bill.qualityRange.min == QualityCategory.Awful && bill.qualityRange.max == QualityCategory.Legendary && !bill.limitToAllowedStuff) { count += map.resourceCounter.GetCount(def); foreach (Pawn pawn in map.mapPawns.FreeColonistsSpawned) { count += CountPawnThings(pawn, counter, bill, def, true); } } else if (bill.includeFromZone == null) { count += counter.CountValidThings(map.listerThings.ThingsOfDef(def), bill, def); if (def.Minifiable) { List <Thing> list = map.listerThings.ThingsInGroup(ThingRequestGroup.MinifiedThing); for (int i = 0; i < list.Count; i++) { MinifiedThing minifiedThing = (MinifiedThing)list[i]; if (counter.CountValidThing(minifiedThing.InnerThing, bill, def)) { count += minifiedThing.stackCount * minifiedThing.InnerThing.stackCount; } } } if (!bill.includeEquipped) { //Still count Carried Things foreach (Pawn pawn in map.mapPawns.FreeColonistsSpawned) { count += CountPawnThings(pawn, counter, bill, def, true); } } } else { foreach (Thing current in bill.includeFromZone.AllContainedThings) { Thing innerIfMinified = current.GetInnerIfMinified(); if (counter.CountValidThing(innerIfMinified, bill, def)) { count += innerIfMinified.stackCount; } } } if (bill.includeEquipped) { foreach (Pawn pawn in map.mapPawns.FreeColonistsSpawned) { count += CountPawnThings(pawn, counter, bill, def); } } if (countAway) { count += CountAway(map, counter, bill, def); } } return(count); }
//public int CountValidThings(List<Thing> things, Bill_Production bill, ThingDef def) public static bool Prefix(ref int __result, RecipeWorkerCounter __instance, List <Thing> things, Bill_Production bill, ThingDef def) { //Vital fix being stackCount, not just # of things. __result = things.Where(t => __instance.CountValidThing(t, bill, def)).Sum(t => t.stackCount); return(false); }