MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / consumeIngredients

Method consumeIngredients

source/frontend/StarCraftingInterface.cpp:503–535  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

501}
502
503bool 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
537void CraftingPane::stopCrafting() {
538 if (m_craftingSound)

Callers

nothing calls this directly

Calls 13

singletonClass · 0.85
ItemDescriptorClass · 0.85
itemDatabaseMethod · 0.80
availableItemsMethod · 0.80
inventoryMethod · 0.80
availableCurrenciesMethod · 0.80
getCountOfItemMethod · 0.80
consumeCurrencyMethod · 0.80
valueMethod · 0.45
countMethod · 0.45
consumeItemsMethod · 0.45
nameMethod · 0.45

Tested by

no test coverage detected