| 562 | } |
| 563 | |
| 564 | void CraftingPane::craft(int count) { |
| 565 | auto& root = Root::singleton(); |
| 566 | |
| 567 | if (m_guiList->selectedItem() != NPos) { |
| 568 | auto recipe = recipeFromSelectedWidget(); |
| 569 | |
| 570 | if (!m_player->isAdmin() && !consumeIngredients(recipe, count)) { |
| 571 | stopCrafting(); |
| 572 | return; |
| 573 | } |
| 574 | |
| 575 | ItemDescriptor itemDescriptor = recipe.output; |
| 576 | int remainingItemCount = itemDescriptor.count() * count; |
| 577 | while (remainingItemCount > 0) { |
| 578 | auto craftedItem = root.itemDatabase()->item(itemDescriptor.singular().multiply(remainingItemCount)); |
| 579 | remainingItemCount -= craftedItem->count(); |
| 580 | m_player->giveItem(craftedItem); |
| 581 | |
| 582 | for (auto& collectable : recipe.collectables) |
| 583 | m_player->addCollectable(collectable.first, collectable.second); |
| 584 | } |
| 585 | |
| 586 | m_blueprints->markAsRead(recipe.output.singular()); |
| 587 | } |
| 588 | |
| 589 | updateAvailableRecipes(); |
| 590 | |
| 591 | m_count -= count; |
| 592 | if (m_count <= 0) { |
| 593 | m_count = 1; |
| 594 | stopCrafting(); |
| 595 | } |
| 596 | countChanged(); |
| 597 | |
| 598 | updateCraftButtons(); |
| 599 | } |
| 600 | |
| 601 | void CraftingPane::countTextChanged() { |
| 602 | if (m_textBox) { |
nothing calls this directly
no test coverage detected