From 5a6b02b6aba646816a7d27a85dd6724de554a157 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 6 Aug 2018 23:35:58 +0300 Subject: Play item usage sound to every player around. --- src/itemsoundmanager.cpp | 30 ++++++++++++++++++++++++++---- src/itemsoundmanager.h | 11 +++++++++++ src/net/eathena/inventoryrecv.cpp | 34 +++++++++++++++++++++++++--------- 3 files changed, 62 insertions(+), 13 deletions(-) diff --git a/src/itemsoundmanager.cpp b/src/itemsoundmanager.cpp index 1ea66d046..b33d2056f 100644 --- a/src/itemsoundmanager.cpp +++ b/src/itemsoundmanager.cpp @@ -53,16 +53,38 @@ void ItemSoundManager::playSfx(const FloorItem *const item, playSfx(ItemDB::get(item->getItemId()), sound); } -void ItemSoundManager::playSfx(const ItemInfo &info, - const ItemSoundEvent::Type sound) +std::string ItemSoundManager::getSoundEffect(const Being *const being, + const ItemInfo &info, + const ItemSoundEvent::Type sound) { std::string sfx = info.getSound(sound).sound; if (sfx.empty()) { + if (being == nullptr) + return std::string(); + // fallback to player race sound if no item sound. - const int id = -100 - toInt(localPlayer->getSubType(), int); + const int id = -100 - toInt(being->getSubType(), int); const ItemInfo &info2 = ItemDB::get(id); sfx = info2.getSound(sound).sound; } - soundManager.playGuiSfx(sfx); + return sfx; +} + +void ItemSoundManager::playSfx(const ItemInfo &info, + const ItemSoundEvent::Type sound) +{ + soundManager.playGuiSfx(getSoundEffect(localPlayer, info, sound)); +} + +void ItemSoundManager::playSfx(const Being *const being, + const int itemId, + const ItemSoundEvent::Type sound) +{ + if (being == nullptr) + return; + + soundManager.playSfx(getSoundEffect(being, ItemDB::get(itemId), sound), + being->getTileX(), + being->getTileY()); } diff --git a/src/itemsoundmanager.h b/src/itemsoundmanager.h index bdd77513f..daf66c732 100644 --- a/src/itemsoundmanager.h +++ b/src/itemsoundmanager.h @@ -23,8 +23,11 @@ #include "enums/resources/item/itemsoundevent.h" +#include + #include "localconsts.h" +class Being; class FloorItem; class Item; class ItemInfo; @@ -45,6 +48,14 @@ class ItemSoundManager final static void playSfx(const ItemInfo &info, const ItemSoundEvent::Type sound); + + static void playSfx(const Being *const being, + const int itemId, + const ItemSoundEvent::Type sound); + + static std::string getSoundEffect(const Being *const being, + const ItemInfo &info, + const ItemSoundEvent::Type sound); }; #endif // ITEMSOUNDMANAGER_H diff --git a/src/net/eathena/inventoryrecv.cpp b/src/net/eathena/inventoryrecv.cpp index 17e79b4da..c17db75d1 100644 --- a/src/net/eathena/inventoryrecv.cpp +++ b/src/net/eathena/inventoryrecv.cpp @@ -22,8 +22,10 @@ #include "net/eathena/inventoryrecv.h" +#include "actormanager.h" #include "notifymanager.h" #include "itemcolormanager.h" +#include "itemsoundmanager.h" #include "being/localplayer.h" @@ -1456,20 +1458,34 @@ void InventoryRecv::processPlayerInventoryUse(Net::MessageIn &msg) ? PlayerInfo::getInventory() : nullptr; const int index = msg.readInt16("index") - INVENTORY_OFFSET; - msg.readItemId("item id"); - msg.readInt32("id?"); + const int itemId = msg.readItemId("item id"); + const BeingId id = msg.readBeingId("account id"); const int amount = msg.readInt16("amount"); - msg.readUInt8("type"); + const uint8_t flag = msg.readUInt8("type"); + Being *const dstBeing = actorManager->findBeing(id); - if (inventory != nullptr) + if (dstBeing == localPlayer) { - if (Item *const item = inventory->getItem(index)) + if (flag == 0) { - if (amount != 0) - item->setQuantity(amount); - else - inventory->removeItemAt(index); + NotifyManager::notify(NotifyTypes::USE_FAILED); + return; } + if (inventory != nullptr) + { + if (Item *const item = inventory->getItem(index)) + { + if (amount != 0) + item->setQuantity(amount); + else + inventory->removeItemAt(index); + } + } + } + else + { + // +++ here can count left items in other player slot + id + amount + ItemSoundManager::playSfx(dstBeing, itemId, ItemSoundEvent::USE); } BLOCK_END("InventoryRecv::processPlayerInventoryUse") } -- cgit v1.2.3-60-g2f50