| 501 | } |
| 502 | |
| 503 | bool CraftingPane::consumeIngredients(ItemRecipe& recipe, int count) { |
| 504 | auto itemDb = Root::singleton().itemDatabase(); |
| 505 | |
| 506 | auto normalizedBag = m_player->inventory()->availableItems(); |
| 507 | auto availableCurrencies = m_player->inventory()->availableCurrencies(); |
| 508 | |
| 509 | // make sure we still have the currencies and items avaialable |
| 510 | for (auto const& p : recipe.currencyInputs) { |
| 511 | uint64_t countRequired = p.second * count; |
| 512 | if (availableCurrencies.value(p.first) < countRequired) { |
| 513 | updateAvailableRecipes(); |
| 514 | return false; |
| 515 | } |
| 516 | } |
| 517 | for (auto input : recipe.inputs) { |
| 518 | size_t countRequired = input.count() * count; |
| 519 | if (itemDb->getCountOfItem(normalizedBag, input, recipe.matchInputParameters) < countRequired) { |
| 520 | updateAvailableRecipes(); |
| 521 | return false; |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | // actually consume the currencies and items |
| 526 | for (auto const& p : recipe.currencyInputs) { |
| 527 | if (p.second > 0) |
| 528 | m_player->inventory()->consumeCurrency(p.first, p.second * count); |
| 529 | } |
| 530 | for (auto input : recipe.inputs) { |
| 531 | if (count > 0) |
| 532 | m_player->inventory()->consumeItems(ItemDescriptor(input.name(), input.count() * count, input.parameters()), recipe.matchInputParameters); |
| 533 | } |
| 534 | return true; |
| 535 | } |
| 536 | |
| 537 | void CraftingPane::stopCrafting() { |
| 538 | if (m_craftingSound) |
nothing calls this directly
no test coverage detected