| 306 | } |
| 307 | |
| 308 | void 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 | |
| 333 | void MerchantPane::updateSellTotal() { |
| 334 | m_sellTotal = 0; |
nothing calls this directly
no test coverage detected