From 65a88f27b994f7ade178368c569d466f6344ded6 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 4 Oct 2013 17:38:19 +0300 Subject: add sound effects for equip/unequip/use items for local player. It using: "equip", "unequip", "use" effects from items. If no item effect present, fallback to same effects from player race. --- src/being/localplayer.cpp | 10 +++++----- src/being/playerinfo.cpp | 41 ++++++++++++++++++++++++++++++++++++----- src/being/playerinfo.h | 12 +++++++----- 3 files changed, 48 insertions(+), 15 deletions(-) (limited to 'src/being') diff --git a/src/being/localplayer.cpp b/src/being/localplayer.cpp index 22a214168..657436f49 100644 --- a/src/being/localplayer.cpp +++ b/src/being/localplayer.cpp @@ -2349,7 +2349,7 @@ void LocalPlayer::changeEquipmentBeforeAttack(const Being *const target) const // if sword not equiped if (!item->isEquipped()) - PlayerInfo::equipItem(item); + PlayerInfo::equipItem(item, true); // if need equip shield too if (mAttackWeaponType == 3) @@ -2359,7 +2359,7 @@ void LocalPlayer::changeEquipmentBeforeAttack(const Being *const target) const if (!item) item = inv->findItem(602, 0); if (item && !item->isEquipped()) - PlayerInfo::equipItem(item); + PlayerInfo::equipItem(item, true); } } // big distance. allowed only bow @@ -2376,7 +2376,7 @@ void LocalPlayer::changeEquipmentBeforeAttack(const Being *const target) const return; if (!item->isEquipped()) - PlayerInfo::equipItem(item); + PlayerInfo::equipItem(item, true); } } @@ -3981,7 +3981,7 @@ void LocalPlayer::imitateOutfit(Being *const player, const int sprite) const const Item *const item = inv->findItemBySprite(path, player->getGender(), player->getSubType()); if (item && !item->isEquipped()) - PlayerInfo::equipItem(item); + PlayerInfo::equipItem(item, false); } else { @@ -3996,7 +3996,7 @@ void LocalPlayer::imitateOutfit(Being *const player, const int sprite) const if (item) { // logger->log("unequiping"); - PlayerInfo::unequipItem(item); + PlayerInfo::unequipItem(item, false); } } } diff --git a/src/being/playerinfo.cpp b/src/being/playerinfo.cpp index 954cb20f4..3d311dd91 100644 --- a/src/being/playerinfo.cpp +++ b/src/being/playerinfo.cpp @@ -25,6 +25,7 @@ #include "configuration.h" #include "depricatedevent.h" #include "inventory.h" +#include "itemsoundmanager.h" #include "gui/windows/inventorywindow.h" #include "gui/windows/npcdialog.h" @@ -245,55 +246,85 @@ void setEquipmentBackend(Equipment::Backend *const backend) mEquipment->setBackend(backend); } -void equipItem(const Item *const item) +void equipItem(const Item *const item, bool sfx) { + if (sfx) + ItemSoundManager::playSfx(item, SOUND_EVENT_EQUIP); Net::getInventoryHandler()->equipItem(item); } -void unequipItem(const Item *const item) +void unequipItem(const Item *const item, bool sfx) { + if (sfx) + ItemSoundManager::playSfx(item, SOUND_EVENT_UNEQUIP); Net::getInventoryHandler()->unequipItem(item); } -void useItem(const Item *const item) +void useItem(const Item *const item, bool sfx) { + if (sfx) + ItemSoundManager::playSfx(item, SOUND_EVENT_USE); Net::getInventoryHandler()->useItem(item); } -void useEquipItem(const Item *const item) +void useEquipItem(const Item *const item, bool sfx) { if (item) { if (item->isEquipment()) { if (item->isEquipped()) + { + if (sfx) + ItemSoundManager::playSfx(item, SOUND_EVENT_UNEQUIP); Net::getInventoryHandler()->unequipItem(item); + } else + { + if (sfx) + ItemSoundManager::playSfx(item, SOUND_EVENT_EQUIP); Net::getInventoryHandler()->equipItem(item); + } } else { if (mProtectedItems.find(item->getId()) == mProtectedItems.end()) + { Net::getInventoryHandler()->useItem(item); + if (sfx) + ItemSoundManager::playSfx(item, SOUND_EVENT_USE); + } } } } -void useEquipItem2(const Item *const item) +void useEquipItem2(const Item *const item, bool sfx) { if (item) { if (!item->isEquipment()) { if (item->isEquipped()) + { + if (sfx) + ItemSoundManager::playSfx(item, SOUND_EVENT_UNEQUIP); Net::getInventoryHandler()->unequipItem(item); + } else + { + if (sfx) + ItemSoundManager::playSfx(item, SOUND_EVENT_EQUIP); Net::getInventoryHandler()->equipItem(item); + } } else { if (mProtectedItems.find(item->getId()) == mProtectedItems.end()) + { Net::getInventoryHandler()->useItem(item); + if (sfx) + ItemSoundManager::playSfx(item, SOUND_EVENT_USE); + } } } } diff --git a/src/being/playerinfo.h b/src/being/playerinfo.h index 052fbe966..cd454692f 100644 --- a/src/being/playerinfo.h +++ b/src/being/playerinfo.h @@ -24,6 +24,8 @@ #include "equipment.h" +#include "resources/soundinfo.h" + #include #include @@ -255,15 +257,15 @@ namespace PlayerInfo void setEquipmentBackend(Equipment::Backend *const backend); - void equipItem(const Item *const item); + void equipItem(const Item *const item, bool sfx); - void unequipItem(const Item *const item); + void unequipItem(const Item *const item, bool sfx); - void useItem(const Item *const item); + void useItem(const Item *const item, bool sfx); - void useEquipItem(const Item *const item); + void useEquipItem(const Item *const item, bool sfx); - void useEquipItem2(const Item *const item); + void useEquipItem2(const Item *const item, bool sfx); void protectItem(const int id); -- cgit v1.2.3-70-g09d2