Mechanical press !
This commit is contained in:
@@ -92,3 +92,17 @@ export function parse_processing(
|
||||
if (json?.heat_requirement !== undefined) problems.push(`${type.id} can't have a heat_requirement`);
|
||||
return problems.length > 0 ? { problems } : { ingredients, results };
|
||||
}
|
||||
|
||||
// the first recipe that takes the item, like a machine's getRecipe
|
||||
export function processing_for(recipes: ProcessingRecipe[], item: Id): ProcessingRecipe | undefined {
|
||||
return recipes.find((recipe) => recipe.ingredients[0]?.includes(item));
|
||||
}
|
||||
|
||||
// what one go of a recipe makes: each result, with each of its count kept by its chance, like rollResults
|
||||
export function roll_results(recipe: ProcessingRecipe, random = Math.random): { id: Id; count: number }[] {
|
||||
return recipe.results.flatMap(({ id, count, chance }) => {
|
||||
let kept = count;
|
||||
if (chance < 1) { for (let i = 0; i < count; i++) if (random() > chance) kept--; }
|
||||
return kept > 0 ? [{ id, count: kept }] : [];
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user