Skip to content

Commit

Permalink
fixed bug regarding meals introduced with #684 in #685
Browse files Browse the repository at this point in the history
  • Loading branch information
Sn1p3rr3c0n committed Mar 3, 2023
1 parent c63a822 commit f4c6dc1
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions Source/ProjectRimFactory/SAL3/Tools/ProjectSAL_Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,23 @@ static class ProjectSAL_Utilities
/// <returns></returns>
public static Thing CalculateDominantIngredient(RecipeDef RecipeDef, List<Thing> ingredients)
{
if (!ingredients.NullOrEmpty())
//Get Things that are Stuff
var stuffs = ingredients.Where(t => t.def.IsStuff).ToList();

if (!ingredients.NullOrEmpty() && stuffs.Any())
{
if (RecipeDef.productHasIngredientStuff)
{
return ingredients[0];
return stuffs[0];
}
if (RecipeDef.products.Any((ThingDefCountClass x) => x.thingDef.MadeFromStuff))
{
return ingredients.Where((Thing x) => x.def.IsStuff).RandomElementByWeight((Thing x) => x.stackCount);
return stuffs.Where((Thing x) => x.def.IsStuff).RandomElementByWeight((Thing x) => x.stackCount);
}
return ingredients.RandomElementByWeight((Thing x) => x.stackCount);
return stuffs.RandomElementByWeight((Thing x) => x.stackCount); ;
}
return null;
//Return steel instead of Null to prevent null ref in some cases
return ThingMaker.MakeThing(ThingDefOf.Steel);
}
}
}

0 comments on commit f4c6dc1

Please sign in to comment.