static void Postfix(Thing __result, ThingDef def, ThingDef stuff) { if (Settings.CommonSenseMod == null || __result == null || __result.def == null || !__result.def.IsIngestible) { return; } CompIngredients ings = __result.TryGetComp <CompIngredients>(); if (ings == null || ings.ingredients.Count == 0) { return; } // if (def == PackedMeat.MysteriousPackDef) { ings.ingredients.Clear(); if (humanlikes == null) { humanlikes = DefDatabase <ThingDef> .AllDefsListForReading.Where(x => x.IsIngestible && x.ingestible.foodType == FoodTypeFlags.Meat && x.ingestible.sourceDef != null && x.ingestible.sourceDef.race != null && x.ingestible.sourceDef.race.Humanlike); } ThingDef td = humanlikes.RandomElement(); if (td != null) { ings.RegisterIngredient(td); } } else if (def == PackedMeat.OddPackDef) { ings.ingredients.Clear(); if (disgusting == null) { disgusting = DefDatabase <ThingDef> .AllDefsListForReading.Where(x => x.IsIngestible && x.ingestible.foodType == FoodTypeFlags.Meat && x.ingestible.sourceDef != null && x.ingestible.sourceDef.race != null && x.ingestible.sourceDef.race.Insect); } ThingDef td = disgusting.RandomElement(); if (td != null) { ings.RegisterIngredient(td); } } else if (def == PackedMeat.RegularPackDef) { ings.ingredients.Clear(); if (regular == null) { regular = DefDatabase <ThingDef> .AllDefsListForReading.Where(x => x.IsIngestible && x.ingestible.foodType == FoodTypeFlags.Meat && x.ingestible.sourceDef != null && x.ingestible.sourceDef.race != null && !x.ingestible.sourceDef.race.Humanlike && !x.ingestible.sourceDef.race.Insect && (x.ingredient == null || x.ingredient.mergeCompatibilityTags.NullOrEmpty())); } ThingDef td = regular.RandomElement(); if (td != null) { ings.RegisterIngredient(td); } } }
public static List <ThoughtDef> GetBestMealThoughtsFor(this RimWorld.Building_NutrientPasteDispenser self, Pawn eater) { List <ThoughtDef> thoughts; if (!self.HasEnoughFeedstockInHoppers() || !eater.RaceProps.Humanlike) { return(new List <ThoughtDef>()); } var list = IngredientsFor(self, eater.IsCannibal() ? DispenseMode.Cannibal : DispenseMode.Standard); // make dummy meal for thoughts simulation Thing dummyMeal = ThingMaker.MakeThing(ThingDefOf.MealNutrientPaste, null); CompIngredients compIngredients = dummyMeal.TryGetComp <CompIngredients>(); float num = 0; for (int i = 0; num < NutritionCostPerDispense; i++) { float num2 = Mathf.Min(list[i].stackCount * list[i].GetStatValue(StatDefOf.Nutrition), NutritionCostPerDispense); num += num2; compIngredients.RegisterIngredient(list[i].def); } thoughts = RimWorld.FoodUtility.ThoughtsFromIngesting(eater, dummyMeal, dummyMeal.def); dummyMeal.Destroy(); return(thoughts); }
//[DetourMethod(typeof(RimWorld.Building_NutrientPasteDispenser),"TryDispenseFood")] // RimWorld.Building_NutrientPasteDispenser public static Thing TryDispenseFood(this RimWorld.Building_NutrientPasteDispenser self, DispenseMode mode = DispenseMode.Standard, bool silent = false) { if (!self.CanDispenseNow) { return(null); } // ----- begin mod code ------ List <Thing> ingredients; ingredients = IngredientsFor(self, mode); if (ingredients.Sum((arg) => arg.stackCount) < NutritionCostPerDispense) { if (!silent) { Log.Error("Did not find enough food in hoppers while trying to dispense. (" + ingredients.Count + "/" + NutritionCostPerDispense + ")"); } return(null); } #if DEBUG //foreach (var e in query) //{ // Log.Message("dispenser has " + e.def + " rank: #" + rankForPawn(eater, e.def) + " total count: " + e.stackCount); //} //Log.Message("dispense"); #endif self.def.building.soundDispense.PlayOneShot(new TargetInfo(self.Position, self.Map, false)); Thing thing2 = ThingMaker.MakeThing(ThingDefOf.MealNutrientPaste, null); CompIngredients compIngredients = thing2.TryGetComp <CompIngredients>(); float num = 0; for (int i = 0; num < NutritionCostPerDispense; i++) { var nutrition = ingredients[i].GetStatValue(StatDefOf.Nutrition); float num2 = Mathf.Min(ingredients[i].stackCount * nutrition, NutritionCostPerDispense); num += num2; ingredients[i].SplitOff(Convert.ToInt32(num2 / nutrition)); compIngredients.RegisterIngredient(ingredients[i].def); } if (Config.SeparatedNutrientPaste && compIngredients.ingredients.Any((arg) => arg.DetermineFoodCategory() == FoodCategory.RawHuman)) { thing2.def = ThingDef.Named("MealNutrientPasteCannibal"); } // ----- end mod code ------ return(thing2); }
static void StackIn(Thing thing, CompIngredients ingredients, Thing with) { ingredients.RegisterIngredient(with.def); CompRottable r = thing.TryGetComp <CompRottable>(); CompRottable rr = with.TryGetComp <CompRottable>(); if (r != null && rr != null) { r.RotProgress = (r.RotProgress * thing.stackCount + rr.RotProgress * with.stackCount) / (thing.stackCount + with.stackCount); } thing.stackCount += with.stackCount; }
static void Postfix(ref IEnumerable <Thing> __result, ref Pawn __instance) { if (!Settings.pack_on_butchering || __result == null || !__result.Any()) { return; } var things = __result.ToList(); Thing meat = things.Find(x => x.def.IsIngestible && x.def.ingestible.foodType == FoodTypeFlags.Meat); if (meat == null) { return; } ThingDef d; if (FoodUtility.IsHumanlikeMeat(meat.def)) { d = PackedMeat.MysteriousPackDef; } else if (!Settings.unusual_is_generic && meat.def.ingestible.specialThoughtDirect != null && meat.def.ingestible.specialThoughtDirect.stages[0].baseMoodEffect < 0) { d = PackedMeat.OddPackDef; } else { d = PackedMeat.RegularPackDef; } ThingWithComps t = (ThingWithComps)ThingMaker.MakeThing(d, null); t.stackCount = meat.stackCount; CompIngredients ingredientsComp = t.TryGetComp <CompIngredients>(); if (ingredientsComp != null) { ingredientsComp.ingredients.Clear(); ingredientsComp.RegisterIngredient(meat.def); } things.Remove(meat); things.Insert(0, t); __result = things; }
static void Postfix(ref IEnumerable <Thing> __result, ref Pawn __instance) { if (!Settings.pack_on_butchering || __result == null || !__result.Any()) { return; } var things = __result.ToList(); Thing meat = things.Find(x => x.def.IsIngestible && x.def.ingestible.foodType == FoodTypeFlags.Meat); if (meat == null || meat.def.ingestible.ateEvent != null) { return; } ThingDef d; if (FoodUtility.GetMeatSourceCategory(meat.def) == MeatSourceCategory.Humanlike) { d = PackedMeat.MysteriousPackDef; } else if (FoodUtility.GetMeatSourceCategory(meat.def) == MeatSourceCategory.Insect) { d = PackedMeat.OddPackDef; } else { d = PackedMeat.RegularPackDef; } ThingWithComps t = (ThingWithComps)ThingMaker.MakeThing(d, null); t.stackCount = meat.stackCount; CompIngredients ingredientsComp = t.TryGetComp <CompIngredients>(); if (ingredientsComp != null) { ingredientsComp.ingredients.Clear(); ingredientsComp.RegisterIngredient(meat.def); } things.Remove(meat); things.Insert(0, t); __result = things; }
static void Postfix(Thing __result, ThingDef def, ThingDef stuff) { if (!Settings.add_meal_ingredients || __result == null || !__result.def.IsIngestible) { return; } CompIngredients ings = __result.TryGetComp <CompIngredients>(); if (ings == null || ings.ingredients.Count > 0) { return; } RecipeDef d = hTable.TryGetValue(def); if (d == null) { d = DefDatabase <RecipeDef> .AllDefsListForReading.Where(x => !x.ingredients.NullOrEmpty() && x.products.Any(y => y.thingDef == def)).RandomElement(); if (d == null) { return; } hTable.Add(def, d); } foreach (IngredientCount c in d.ingredients) { ThingDef td = c.filter.AllowedThingDefs.Where( x => x.IsIngestible && !x.comps.Any(y => y.compClass == typeof(CompIngredients)) && !FoodUtility.IsHumanlikeMeat(x) && (x.ingestible.specialThoughtAsIngredient == null || x.ingestible.specialThoughtAsIngredient.stages[0].baseMoodEffect >= 0) ).RandomElement(); if (td != null) { ings.RegisterIngredient(td); } } }
public static IEnumerable <Thing> MakeRecipeProductsInt(RecipeDef recipeDef, IRecipeProductWorker worker, List <Thing> ingredients, Thing dominantIngredient, IBillGiver billGiver) { float efficiency; if (recipeDef.efficiencyStat == null) { efficiency = 1f; } else { efficiency = worker.GetStatValue(recipeDef.efficiencyStat, true); } if (recipeDef.workTableEfficiencyStat != null) { Building_WorkTable building_WorkTable = billGiver as Building_WorkTable; if (building_WorkTable != null) { efficiency *= building_WorkTable.GetStatValue(recipeDef.workTableEfficiencyStat, true); } } if (recipeDef.products != null) { for (int i = 0; i < recipeDef.products.Count; i++) { ThingDefCountClass prod = recipeDef.products[i]; ThingDef stuffDef; if (prod.thingDef.MadeFromStuff) { stuffDef = dominantIngredient.def; } else { stuffDef = null; } Thing product = ThingMaker.MakeThing(prod.thingDef, stuffDef); product.stackCount = Mathf.CeilToInt((float)prod.count * efficiency); if (dominantIngredient != null) { product.SetColor(dominantIngredient.DrawColor, false); } CompIngredients ingredientsComp = product.TryGetComp <CompIngredients>(); if (ingredientsComp != null) { for (int l = 0; l < ingredients.Count; l++) { ingredientsComp.RegisterIngredient(ingredients[l].def); } } CompFoodPoisonable foodPoisonable = product.TryGetComp <CompFoodPoisonable>(); if (foodPoisonable != null) { Room room = worker.GetRoom(RegionType.Set_Passable); float chance = (room == null) ? RoomStatDefOf.FoodPoisonChance.roomlessScore : room.GetStat(RoomStatDefOf.FoodPoisonChance); if (Rand.Chance(chance)) { foodPoisonable.SetPoisoned(FoodPoisonCause.FilthyKitchen); } else { float statValue = worker.GetStatValue(StatDefOf.FoodPoisonChance, true); if (Rand.Chance(statValue)) { foodPoisonable.SetPoisoned(FoodPoisonCause.IncompetentCook); } } } yield return(GenRecipe2.PostProcessProduct(product, recipeDef, worker)); } } if (recipeDef.specialProducts != null) { for (int j = 0; j < recipeDef.specialProducts.Count; j++) { for (int k = 0; k < ingredients.Count; k++) { Thing ing = ingredients[k]; SpecialProductType specialProductType = recipeDef.specialProducts[j]; if (specialProductType != SpecialProductType.Butchery) { if (specialProductType == SpecialProductType.Smelted) { foreach (Thing product2 in ing.SmeltProducts(efficiency)) { yield return(GenRecipe2.PostProcessProduct(product2, recipeDef, worker)); } } } else { foreach (Thing product3 in ButcherProducts(ing, efficiency, worker)) { yield return(GenRecipe2.PostProcessProduct(product3, recipeDef, worker)); } } } } } }
public static bool TryDispenseCustomFood(ref Thing __result, Building_NutrientPasteDispenser __instance, ref List <IntVec3> ___cachedAdjCellsCardinal) { if (__instance.def.HasModExtension <NutrientPasteCustom>()) { if (!__instance.CanDispenseNow) { __result = null; return(false); } List <ThingDef> list = new List <ThingDef>(); List <IngredientAndCostClass> ingredientList = __instance.def.GetModExtension <NutrientPasteCustom>().ingredientList; bool empty = !__instance.def.GetModExtension <NutrientPasteCustom>().ingredientList.Any(); Log.Message("-" + empty); if (!empty) { float[] nutritionLeft = new float[ingredientList.Count]; for (int i = 0; i < nutritionLeft.Length; i++) { nutritionLeft[i] = ingredientList[i].nutritionCost; } for (; ;) { Thing thing = __instance.def.GetModExtension <NutrientPasteCustom>().FindNextIngredientInHopper(___cachedAdjCellsCardinal, __instance, nutritionLeft); if (thing is null) { break; } int index = ingredientList.FindIndex(x => x.thingDef == thing.def); int num2 = Mathf.Min(thing.stackCount, Mathf.CeilToInt(nutritionLeft[index] / thing.GetStatValue(StatDefOf.Nutrition, true))); nutritionLeft[index] -= (float)num2 * thing.GetStatValue(StatDefOf.Nutrition, true); list.Add(thing.def); thing.SplitOff(num2); if (!nutritionLeft.Any(x => x > 0f)) { goto Block_3; } } } else { Log.Message("2"); float num = __instance.def.building.nutritionCostPerDispense - 0.0001f; for (; ;) { Thing thing = __instance.FindFeedInAnyHopper(); if (thing is null) { break; } int num2 = Mathf.Min(thing.stackCount, Mathf.CeilToInt(num / thing.GetStatValue(StatDefOf.Nutrition, true))); num -= (float)num2 * thing.GetStatValue(StatDefOf.Nutrition, true); list.Add(thing.def); thing.SplitOff(num2); if (num <= 0f) { goto Block_3; } } } Log.Error("Did not find enough food in hoppers while trying to dispense.", false); __result = null; return(false); Block_3: __instance.def.building.soundDispense.PlayOneShot(new TargetInfo(__instance.Position, __instance.Map, false)); Thing thing2 = ThingMaker.MakeThing(__instance.def.GetModExtension <NutrientPasteCustom>().customMeal, null); CompIngredients compIngredients = thing2.TryGetComp <CompIngredients>(); foreach (ThingDef ingredient in list) { if (!__instance.def.GetModExtension <NutrientPasteCustom>().mysteryIngredients) { compIngredients.RegisterIngredient(ingredient); } } __result = thing2; return(false); } return(true); }
public static IEnumerable <Thing> MakeRecipeProducts(RecipeDef recipeDef, Pawn worker, List <Thing> ingredients, Thing dominantIngredient) { float efficiency; if (recipeDef.efficiencyStat == null) { efficiency = 1f; } else { efficiency = worker.GetStatValue(recipeDef.efficiencyStat, true); } if (recipeDef.products != null) { for (int i = 0; i < recipeDef.products.Count; i++) { ThingCountClass prod = recipeDef.products[i]; ThingDef stuffDef; if (prod.thingDef.MadeFromStuff) { stuffDef = dominantIngredient.def; } else { stuffDef = null; } Thing product = ThingMaker.MakeThing(prod.thingDef, stuffDef); product.stackCount = Mathf.CeilToInt((float)prod.count * efficiency); if (dominantIngredient != null) { product.SetColor(dominantIngredient.DrawColor, false); } CompIngredients ingredientsComp = product.TryGetComp <CompIngredients>(); if (ingredientsComp != null) { for (int l = 0; l < ingredients.Count; l++) { ingredientsComp.RegisterIngredient(ingredients[l].def); } } CompFoodPoisonable foodPoisonable = product.TryGetComp <CompFoodPoisonable>(); if (foodPoisonable != null) { float num = worker.GetStatValue(StatDefOf.FoodPoisonChance, true); Room room = worker.GetRoom(RegionType.Set_Passable); if (room != null) { num *= room.GetStat(RoomStatDefOf.FoodPoisonChanceFactor); } if (Rand.Value < num) { foodPoisonable.PoisonPercent = 1f; } } yield return(GenRecipe.PostProcessProduct(product, recipeDef, worker)); } } if (recipeDef.specialProducts != null) { for (int j = 0; j < recipeDef.specialProducts.Count; j++) { for (int k = 0; k < ingredients.Count; k++) { Thing ing = ingredients[k]; SpecialProductType specialProductType = recipeDef.specialProducts[j]; if (specialProductType != SpecialProductType.Butchery) { if (specialProductType == SpecialProductType.Smelted) { foreach (Thing product2 in ing.SmeltProducts(efficiency)) { yield return(GenRecipe.PostProcessProduct(product2, recipeDef, worker)); } } } else { foreach (Thing product3 in ing.ButcherProducts(worker, efficiency)) { yield return(GenRecipe.PostProcessProduct(product3, recipeDef, worker)); } } } } } }
public static IEnumerable <Thing> MakeRecipeProducts(RecipeDef recipeDef, Pawn worker, List <Thing> ingredients, Thing dominantIngredient, IBillGiver billGiver) { float efficiency = (recipeDef.efficiencyStat != null) ? worker.GetStatValue(recipeDef.efficiencyStat) : 1f; if (recipeDef.workTableEfficiencyStat != null) { Building_WorkTable building_WorkTable = billGiver as Building_WorkTable; if (building_WorkTable != null) { efficiency *= building_WorkTable.GetStatValue(recipeDef.workTableEfficiencyStat); } } if (recipeDef.products != null) { for (int k = 0; k < recipeDef.products.Count; k++) { ThingDefCountClass thingDefCountClass = recipeDef.products[k]; Thing thing = ThingMaker.MakeThing(stuff: (!thingDefCountClass.thingDef.MadeFromStuff) ? null : dominantIngredient.def, def: thingDefCountClass.thingDef); thing.stackCount = Mathf.CeilToInt((float)thingDefCountClass.count * efficiency); if (dominantIngredient != null) { thing.SetColor(dominantIngredient.DrawColor, reportFailure: false); } CompIngredients compIngredients = thing.TryGetComp <CompIngredients>(); if (compIngredients != null) { for (int l = 0; l < ingredients.Count; l++) { compIngredients.RegisterIngredient(ingredients[l].def); } } CompFoodPoisonable compFoodPoisonable = thing.TryGetComp <CompFoodPoisonable>(); if (compFoodPoisonable != null) { if (Rand.Chance(worker.GetRoom()?.GetStat(RoomStatDefOf.FoodPoisonChance) ?? RoomStatDefOf.FoodPoisonChance.roomlessScore)) { compFoodPoisonable.SetPoisoned(FoodPoisonCause.FilthyKitchen); } else if (Rand.Chance(worker.GetStatValue(StatDefOf.FoodPoisonChance))) { compFoodPoisonable.SetPoisoned(FoodPoisonCause.IncompetentCook); } } yield return(PostProcessProduct(thing, recipeDef, worker)); } } if (recipeDef.specialProducts == null) { yield break; } for (int k = 0; k < recipeDef.specialProducts.Count; k++) { for (int i = 0; i < ingredients.Count; i++) { Thing thing2 = ingredients[i]; switch (recipeDef.specialProducts[k]) { case SpecialProductType.Butchery: foreach (Thing item in thing2.ButcherProducts(worker, efficiency)) { yield return(PostProcessProduct(item, recipeDef, worker)); } break; case SpecialProductType.Smelted: foreach (Thing item2 in thing2.SmeltProducts(efficiency)) { yield return(PostProcessProduct(item2, recipeDef, worker)); } break; } } } }
// Token: 0x06000017 RID: 23 RVA: 0x00003205 File Offset: 0x00001405 public static IEnumerable <Thing> MakeRecipeProducts(RecipeDef recipeDef, Pawn worker, List <Thing> ingredients, Thing dominantIngredient) { Log.Message(string.Concat(new string[] { "init WPGenRecipe: recipeDef ", (recipeDef != null) ? recipeDef.ToString() : null, " worker ", (worker != null) ? worker.ToString() : null, " ingredients ", (ingredients != null) ? ingredients.ToString() : null, " dominantIngredient ", (dominantIngredient != null) ? dominantIngredient.ToString() : null }), false); bool flag = recipeDef.efficiencyStat == null; float efficiency; if (flag) { efficiency = 1f; } else { efficiency = worker.GetStatValue(recipeDef.efficiencyStat, true); } bool flag2 = recipeDef.products != null; if (flag2) { int num2; for (int i = 0; i < recipeDef.products.Count; i = num2 + 1) { ThingDefCountClass prod = recipeDef.products[i]; bool madeFromStuff = prod.thingDef.MadeFromStuff; ThingDef stuffDef; if (madeFromStuff) { stuffDef = dominantIngredient.def; } else { stuffDef = null; } Thing product = ThingMaker.MakeThing(prod.thingDef, stuffDef); product.stackCount = Mathf.CeilToInt((float)prod.count * efficiency); bool flag3 = dominantIngredient != null; if (flag3) { product.SetColor(dominantIngredient.DrawColor, false); } CompIngredients ingredientsComp = product.TryGetComp <CompIngredients>(); bool flag4 = ingredientsComp != null; if (flag4) { for (int j = 0; j < ingredients.Count; j = num2 + 1) { ingredientsComp.RegisterIngredient(ingredients[j].def); num2 = j; } } CompFoodPoisonable foodPoisonable = product.TryGetComp <CompFoodPoisonable>(); bool flag5 = foodPoisonable != null; if (flag5) { float num = worker.GetStatValue(StatDefOf.FoodPoisonChance, true); Room room = worker.GetRoom(RegionType.Set_Passable); float chance = (room == null) ? RoomStatDefOf.FoodPoisonChance.roomlessScore : room.GetStat(RoomStatDefOf.FoodPoisonChance); bool flag6 = Rand.Chance(chance); if (flag6) { foodPoisonable.SetPoisoned(FoodPoisonCause.FilthyKitchen); } else { float statValue = worker.GetStatValue(StatDefOf.FoodPoisonChance, true); bool flag7 = Rand.Chance(statValue); if (flag7) { foodPoisonable.SetPoisoned(FoodPoisonCause.IncompetentCook); } } room = null; } yield return(WPGenRecipe.PostProcessProduct(product, recipeDef, worker)); prod = null; stuffDef = null; product = null; ingredientsComp = null; foodPoisonable = null; num2 = i; } } bool flag8 = recipeDef.specialProducts != null; if (flag8) { string str = "special recipedef not null"; List <SpecialProductType> specialProducts = recipeDef.specialProducts; Log.Message(str + ((specialProducts != null) ? specialProducts.ToString() : null), false); Log.Message("recipeDef.specialProducts.Count " + recipeDef.specialProducts.Count.ToString(), false); int num2; for (int k = 0; k < recipeDef.specialProducts.Count; k = num2 + 1) { Log.Message("recipeDef.specialProducts[j] " + recipeDef.specialProducts[k].ToString(), false); Log.Message("ingredients.Count " + ingredients.Count.ToString(), false); string str2 = "recipeDef.ingredients "; List <IngredientCount> ingredients2 = recipeDef.ingredients; Log.Message(str2 + ((ingredients2 != null) ? ingredients2.ToString() : null), false); for (int l = 0; l < ingredients.Count; l = num2 + 1) { Thing ing = ingredients[l]; string str3 = "ingredients[k] "; Thing thing = ingredients[l]; Log.Message(str3 + ((thing != null) ? thing.ToString() : null), false); string str4 = "ing "; Thing thing2 = ing; Log.Message(str4 + ((thing2 != null) ? thing2.ToString() : null), false); SpecialProductType specialProductType = recipeDef.specialProducts[k]; bool flag9 = specialProductType > SpecialProductType.Butchery; if (flag9) { Log.Message("not butchery", false); bool flag10 = specialProductType == SpecialProductType.Smelted; if (flag10) { foreach (Thing product2 in ing.SmeltProducts(efficiency)) { yield return(WPGenRecipe.PostProcessProduct(product2, recipeDef, worker)); } } } else { Log.Message("butchery", false); foreach (Thing product3 in ing.ButcherProducts(worker, efficiency)) { string[] array = new string[8]; array[0] = "recipeDef.specialProducts[k] "; array[1] = recipeDef.specialProducts[l].ToString(); array[2] = "product3 "; int num3 = 3; Thing thing3 = product3; array[num3] = ((thing3 != null) ? thing3.ToString() : null); array[4] = " recipeDef "; array[5] = ((recipeDef != null) ? recipeDef.ToString() : null); array[6] = " worker "; array[7] = ((worker != null) ? worker.ToString() : null); Log.Message(string.Concat(array), false); yield return(WPGenRecipe.PostProcessProduct(product3, recipeDef, worker)); } } ing = null; num2 = l; } num2 = k; } } Log.Message("yield break", false); yield break; }
public static IEnumerable <Thing> MakeRecipeProducts(RecipeDef recipeDef, Pawn worker, List <Thing> ingredients, Thing dominantIngredient) { float efficiency = (float)((recipeDef.efficiencyStat != null) ? worker.GetStatValue(recipeDef.efficiencyStat, true) : 1.0); if (recipeDef.products != null) { int k = 0; if (k < recipeDef.products.Count) { ThingCountClass prod = recipeDef.products[k]; ThingDef stuffDef = (!prod.thingDef.MadeFromStuff) ? null : dominantIngredient.def; Thing product3 = ThingMaker.MakeThing(prod.thingDef, stuffDef); product3.stackCount = Mathf.CeilToInt((float)prod.count * efficiency); if (dominantIngredient != null) { product3.SetColor(dominantIngredient.DrawColor, false); } CompIngredients ingredientsComp = product3.TryGetComp <CompIngredients>(); if (ingredientsComp != null) { for (int l = 0; l < ingredients.Count; l++) { ingredientsComp.RegisterIngredient(ingredients[l].def); } } CompFoodPoisonable foodPoisonable = product3.TryGetComp <CompFoodPoisonable>(); if (foodPoisonable != null) { float num = worker.GetStatValue(StatDefOf.FoodPoisonChance, true); Room room = worker.GetRoom(RegionType.Set_Passable); if (room != null) { num *= room.GetStat(RoomStatDefOf.FoodPoisonChanceFactor); } if (Rand.Value < num) { foodPoisonable.PoisonPercent = 1f; } } yield return(GenRecipe.PostProcessProduct(product3, recipeDef, worker)); /*Error: Unable to find new state assignment for yield return*/; } } if (recipeDef.specialProducts != null) { for (int j = 0; j < recipeDef.specialProducts.Count; j++) { for (int i = 0; i < ingredients.Count; i++) { Thing ing = ingredients[i]; switch (recipeDef.specialProducts[j]) { case SpecialProductType.Butchery: using (IEnumerator <Thing> enumerator2 = ing.ButcherProducts(worker, efficiency).GetEnumerator()) { if (enumerator2.MoveNext()) { Thing product = enumerator2.Current; yield return(GenRecipe.PostProcessProduct(product, recipeDef, worker)); /*Error: Unable to find new state assignment for yield return*/; } } break; case SpecialProductType.Smelted: using (IEnumerator <Thing> enumerator = ing.SmeltProducts(efficiency).GetEnumerator()) { if (enumerator.MoveNext()) { Thing product2 = enumerator.Current; yield return(GenRecipe.PostProcessProduct(product2, recipeDef, worker)); /*Error: Unable to find new state assignment for yield return*/; } } break; } } } } yield break; IL_0473: /*Error near IL_0474: Unexpected return in MoveNext()*/; }
public static IEnumerable <Thing> MakeRecipeProducts(RecipeDef recipeDef, Pawn worker, List <Thing> ingredients, Thing dominantIngredient, IBillGiver billGiver) { float efficiency = (recipeDef.efficiencyStat != null) ? worker.GetStatValue(recipeDef.efficiencyStat) : 1f; if (recipeDef.workTableEfficiencyStat != null) { Building_WorkTable building_WorkTable = billGiver as Building_WorkTable; if (building_WorkTable != null) { efficiency *= building_WorkTable.GetStatValue(recipeDef.workTableEfficiencyStat); } } if (recipeDef.products != null) { int k = 0; if (k < recipeDef.products.Count) { ThingDefCountClass prod = recipeDef.products[k]; Thing product3 = ThingMaker.MakeThing(stuff: (!prod.thingDef.MadeFromStuff) ? null : dominantIngredient.def, def: prod.thingDef); product3.stackCount = Mathf.CeilToInt((float)prod.count * efficiency); if (dominantIngredient != null) { product3.SetColor(dominantIngredient.DrawColor, reportFailure: false); } CompIngredients ingredientsComp = product3.TryGetComp <CompIngredients>(); if (ingredientsComp != null) { for (int l = 0; l < ingredients.Count; l++) { ingredientsComp.RegisterIngredient(ingredients[l].def); } } CompFoodPoisonable foodPoisonable = product3.TryGetComp <CompFoodPoisonable>(); if (foodPoisonable != null) { float chance = worker.GetRoom()?.GetStat(RoomStatDefOf.FoodPoisonChance) ?? RoomStatDefOf.FoodPoisonChance.roomlessScore; if (Rand.Chance(chance)) { foodPoisonable.SetPoisoned(FoodPoisonCause.FilthyKitchen); } else { float statValue = worker.GetStatValue(StatDefOf.FoodPoisonChance); if (Rand.Chance(statValue)) { foodPoisonable.SetPoisoned(FoodPoisonCause.IncompetentCook); } } } yield return(PostProcessProduct(product3, recipeDef, worker)); /*Error: Unable to find new state assignment for yield return*/; } } if (recipeDef.specialProducts != null) { for (int j = 0; j < recipeDef.specialProducts.Count; j++) { for (int i = 0; i < ingredients.Count; i++) { Thing ing = ingredients[i]; switch (recipeDef.specialProducts[j]) { case SpecialProductType.Butchery: using (IEnumerator <Thing> enumerator2 = ing.ButcherProducts(worker, efficiency).GetEnumerator()) { if (enumerator2.MoveNext()) { Thing product = enumerator2.Current; yield return(PostProcessProduct(product, recipeDef, worker)); /*Error: Unable to find new state assignment for yield return*/; } } break; case SpecialProductType.Smelted: using (IEnumerator <Thing> enumerator = ing.SmeltProducts(efficiency).GetEnumerator()) { if (enumerator.MoveNext()) { Thing product2 = enumerator.Current; yield return(PostProcessProduct(product2, recipeDef, worker)); /*Error: Unable to find new state assignment for yield return*/; } } break; } } } } yield break; IL_04dd: /*Error near IL_04de: Unexpected return in MoveNext()*/; }
static void Postfix(Thing __result, ThingDef def, ThingDef stuff) { if (!Settings.add_meal_ingredients || __result == null || !__result.def.IsIngestible) { return; } CompIngredients ings = __result.TryGetComp <CompIngredients>(); if (ings == null || ings.ingredients.Count > 0) { return; } RecipeDef d = hTable.TryGetValue(def); if (d == null) { List <RecipeDef> l = DefDatabase <RecipeDef> .AllDefsListForReading; if (l == null) { return; } d = l.Where(x => !x.ingredients.NullOrEmpty() && x.products.Any(y => y.thingDef == def)).RandomElement(); if (d == null) { return; } hTable.Add(def, d); } foreach (IngredientCount c in d.ingredients) { ThingFilter ic = c.filter; if (ic == null) { return; } IEnumerable <ThingDef> l = ic.AllowedThingDefs; if (l == null) { return; } l = l.Where( x => x.IsIngestible && x.comps != null && !x.comps.Any(y => y.compClass == typeof(CompIngredients)) && FoodUtility.GetMeatSourceCategory(x) != MeatSourceCategory.Humanlike && (x.ingestible.specialThoughtAsIngredient == null || x.ingestible.specialThoughtAsIngredient.stages == null || x.ingestible.specialThoughtAsIngredient.stages[0].baseMoodEffect >= 0) && (x.ingredient == null || x.ingredient.mergeCompatibilityTags.NullOrEmpty()) ); ThingDef td = null; if (l.Count() > 0) { td = l.RandomElement(); } if (td != null) { ings.RegisterIngredient(td); } } }