public virtual Thing TryDispenseFood() { if (!CanDispenseNow) { return(null); } float num = def.building.nutritionCostPerDispense - 0.0001f; List <ThingDef> list = new List <ThingDef>(); do { Thing thing = FindFeedInAnyHopper(); if (thing == null) { Log.Error("Did not find enough food in hoppers while trying to dispense."); return(null); } int num2 = Mathf.Min(thing.stackCount, Mathf.CeilToInt(num / thing.GetStatValue(StatDefOf.Nutrition))); num -= (float)num2 * thing.GetStatValue(StatDefOf.Nutrition); list.Add(thing.def); thing.SplitOff(num2); }while (!(num <= 0f)); def.building.soundDispense.PlayOneShot(new TargetInfo(base.Position, base.Map)); Thing thing2 = ThingMaker.MakeThing(ThingDefOf.MealNutrientPaste); CompIngredients compIngredients = thing2.TryGetComp <CompIngredients>(); for (int i = 0; i < list.Count; i++) { compIngredients.RegisterIngredient(list[i]); } return(thing2); }
public virtual Thing TryDispenseFood() { Thing result; if (!this.CanDispenseNow) { result = null; } else { float num = this.def.building.nutritionCostPerDispense - 0.0001f; List <ThingDef> list = new List <ThingDef>(); for (;;) { Thing thing = this.FindFeedInAnyHopper(); if (thing == 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); return(null); Block_3: this.def.building.soundDispense.PlayOneShot(new TargetInfo(base.Position, base.Map, false)); Thing thing2 = ThingMaker.MakeThing(ThingDefOf.MealNutrientPaste, null); CompIngredients compIngredients = thing2.TryGetComp <CompIngredients>(); for (int i = 0; i < list.Count; i++) { compIngredients.RegisterIngredient(list[i]); } result = thing2; } return(result); }
public virtual Thing TryDispenseFood() { if (!this.CanDispenseNow) { return(null); } float num = (float)(base.def.building.nutritionCostPerDispense - 9.9999997473787516E-05); List <ThingDef> list = new List <ThingDef>(); while (true) { Thing thing = this.FindFeedInAnyHopper(); if (thing == null) { Log.Error("Did not find enough food in hoppers while trying to dispense."); return(null); } int num2 = Mathf.Min(thing.stackCount, Mathf.CeilToInt(num / thing.def.ingestible.nutrition)); num -= (float)num2 * thing.def.ingestible.nutrition; list.Add(thing.def); thing.SplitOff(num2); if (num <= 0.0) { break; } } base.def.building.soundDispense.PlayOneShot(new TargetInfo(base.Position, base.Map, false)); Thing thing2 = ThingMaker.MakeThing(ThingDefOf.MealNutrientPaste, null); CompIngredients compIngredients = thing2.TryGetComp <CompIngredients>(); for (int i = 0; i < list.Count; i++) { compIngredients.RegisterIngredient(list[i]); } return(thing2); }