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

Method buy

source/frontend/StarMerchantInterface.cpp:308–331  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

306}
307
308void MerchantPane::buy() {
309 if (m_buyTotal > 0 && m_player->inventory()->consumeCurrency("money", m_buyTotal)) {
310 auto countRemaining = m_buyCount;
311 while (countRemaining > 0) {
312 auto buyItem = m_selectedItem->clone();
313 buyItem->setCount(m_selectedItem->count() * countRemaining);
314 countRemaining -= buyItem->count();
315 m_player->giveItem(buyItem);
316 }
317
318 auto reportItem = m_selectedItem->clone();
319 reportItem->setCount(reportItem->count() * m_buyCount, true);
320 auto buySummary = JsonObject{{"item", reportItem->descriptor().toJson()}, {"total", m_buyTotal}};
321 if (m_sourceEntityId != NullEntityId)
322 m_worldClient->sendEntityMessage(m_sourceEntityId, "onBuy", {buySummary});
323
324 auto& guiContext = GuiContext::singleton();
325 guiContext.playAudio(Root::singleton().assets()->json("/merchant.config:buySound").toString());
326
327 buildItemList();
328
329 updateBuyTotal();
330 }
331}
332
333void MerchantPane::updateSellTotal() {
334 m_sellTotal = 0;

Callers

nothing calls this directly

Calls 14

singletonClass · 0.85
consumeCurrencyMethod · 0.80
inventoryMethod · 0.80
giveItemMethod · 0.80
playAudioMethod · 0.80
jsonMethod · 0.80
assetsMethod · 0.80
cloneMethod · 0.45
setCountMethod · 0.45
countMethod · 0.45
toJsonMethod · 0.45
descriptorMethod · 0.45

Tested by

no test coverage detected