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 override void PostSplitOff(Thing piece) { base.PostSplitOff(piece); if (piece != this.parent) { CompIngredients compIngredients = piece.TryGetComp <CompIngredients>(); for (int i = 0; i < this.ingredients.Count; i++) { compIngredients.ingredients.Add(this.ingredients[i]); } } }
public static List <ThoughtDef> ThoughtsFromIngesting(Pawn ingester, Thing foodSource, ThingDef foodDef) { ingestThoughts.Clear(); if (ingester.needs == null || ingester.needs.mood == null) { return(ingestThoughts); } if (!ingester.story.traits.HasTrait(TraitDefOf.Ascetic) && foodDef.ingestible.tasteThought != null) { ingestThoughts.Add(foodDef.ingestible.tasteThought); } CompIngredients compIngredients = foodSource.TryGetComp <CompIngredients>(); Building_NutrientPasteDispenser building_NutrientPasteDispenser = foodSource as Building_NutrientPasteDispenser; if (IsHumanlikeMeat(foodDef) && ingester.RaceProps.Humanlike) { ingestThoughts.Add(ingester.story.traits.HasTrait(TraitDefOf.Cannibal) ? ThoughtDefOf.AteHumanlikeMeatDirectCannibal : ThoughtDefOf.AteHumanlikeMeatDirect); } else if (compIngredients != null) { for (int i = 0; i < compIngredients.ingredients.Count; i++) { AddIngestThoughtsFromIngredient(compIngredients.ingredients[i], ingester, ingestThoughts); } } else if (building_NutrientPasteDispenser != null) { Thing thing = building_NutrientPasteDispenser.FindFeedInAnyHopper(); if (thing != null) { AddIngestThoughtsFromIngredient(thing.def, ingester, ingestThoughts); } } if (foodDef.ingestible.specialThoughtDirect != null) { ingestThoughts.Add(foodDef.ingestible.specialThoughtDirect); } if (foodSource.IsNotFresh()) { ingestThoughts.Add(ThoughtDefOf.AteRottenFood); } if (ModsConfig.RoyaltyActive && InappropriateForTitle(foodDef, ingester, allowIfStarving: false)) { ingestThoughts.Add(ThoughtDefOf.AteFoodInappropriateForTitle); } return(ingestThoughts); }
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 static List <ThoughtDef> ThoughtsFromIngesting(Pawn ingester, Thing foodSource, ThingDef foodDef) { FoodUtility.ingestThoughts.Clear(); if (ingester.needs != null && ingester.needs.mood != null) { if (!ingester.story.traits.HasTrait(TraitDefOf.Ascetic) && foodDef.ingestible.tasteThought != null) { FoodUtility.ingestThoughts.Add(foodDef.ingestible.tasteThought); } CompIngredients compIngredients = foodSource.TryGetComp <CompIngredients>(); Building_NutrientPasteDispenser building_NutrientPasteDispenser = foodSource as Building_NutrientPasteDispenser; if (FoodUtility.IsHumanlikeMeat(foodDef) && ingester.RaceProps.Humanlike) { FoodUtility.ingestThoughts.Add((!ingester.story.traits.HasTrait(TraitDefOf.Cannibal)) ? ThoughtDefOf.AteHumanlikeMeatDirect : ThoughtDefOf.AteHumanlikeMeatDirectCannibal); } else if (compIngredients != null) { for (int i = 0; i < compIngredients.ingredients.Count; i++) { FoodUtility.AddIngestThoughtsFromIngredient(compIngredients.ingredients[i], ingester, FoodUtility.ingestThoughts); } } else if (building_NutrientPasteDispenser != null) { Thing thing = building_NutrientPasteDispenser.FindFeedInAnyHopper(); if (thing != null) { FoodUtility.AddIngestThoughtsFromIngredient(thing.def, ingester, FoodUtility.ingestThoughts); } } if (foodDef.ingestible.specialThoughtDirect != null) { FoodUtility.ingestThoughts.Add(foodDef.ingestible.specialThoughtDirect); } if (foodSource.IsNotFresh()) { FoodUtility.ingestThoughts.Add(ThoughtDefOf.AteRottenFood); } return(FoodUtility.ingestThoughts); } return(FoodUtility.ingestThoughts); }
public override void PreAbsorbStack(Thing otherStack, int count) { base.PreAbsorbStack(otherStack, count); CompIngredients compIngredients = otherStack.TryGetComp <CompIngredients>(); List <ThingDef> list = compIngredients.ingredients; for (int i = 0; i < list.Count; i++) { if (!this.ingredients.Contains(list[i])) { this.ingredients.Add(list[i]); } } if (this.ingredients.Count > 3) { this.ingredients.Shuffle <ThingDef>(); while (this.ingredients.Count > 3) { this.ingredients.Remove(this.ingredients[this.ingredients.Count - 1]); } } }
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); }