| 319 | } |
| 320 | |
| 321 | ItemRecipe ItemDatabase::getPreciseRecipeForMaterials(String const& group, List<ItemPtr> const& bag, StringMap<uint64_t> const& availableCurrencies) const { |
| 322 | // picks the recipe that: |
| 323 | // * can be crafted (duh) |
| 324 | // * uses all the input material types |
| 325 | // * uses the most materials (if recipes exist with the same input materials) |
| 326 | |
| 327 | auto options = recipesFromBagContents(bag, availableCurrencies); |
| 328 | ItemRecipe result; |
| 329 | int ingredientsCount = 0; |
| 330 | for (auto const& recipe : options) { |
| 331 | if (!recipe.groups.contains(group)) |
| 332 | continue; |
| 333 | bool usesAllItemTypes = true; |
| 334 | for (auto const& item : bag) { |
| 335 | bool match = false; |
| 336 | for (auto const& input : recipe.inputs) |
| 337 | if (item->matches(input, recipe.matchInputParameters)) |
| 338 | match = true; |
| 339 | if (!match) |
| 340 | usesAllItemTypes = false; |
| 341 | } |
| 342 | if (!usesAllItemTypes) |
| 343 | continue; |
| 344 | int count = 0; |
| 345 | for (auto const& input : recipe.inputs) |
| 346 | count += input.count(); |
| 347 | if (count > ingredientsCount) |
| 348 | result = recipe; |
| 349 | } |
| 350 | return result; |
| 351 | } |
| 352 | |
| 353 | ItemRecipe ItemDatabase::parseRecipe(Json const& config) const { |
| 354 | ItemRecipe res; |
no test coverage detected