From 1a152bbcfc63445287cc96bbbff325cce3092789 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 30 Dec 2012 20:24:32 +0300 Subject: Add support for different sounds from different weapons. Also fixed sounds from non local player. --- src/being.cpp | 37 +++++++++++++++++++++++++++++++++++-- src/defaults.cpp | 1 + src/localplayer.cpp | 3 ++- src/resources/iteminfo.h | 2 ++ 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/being.cpp b/src/being.cpp index 1f92030ab..d5ac23f4a 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -758,8 +758,41 @@ void Being::handleAttack(Being *const victim, const int damage, if (damage && victim->mType == PLAYER && victim->mAction == SIT) victim->setAction(STAND); - sound.playSfx(mInfo->getSound((damage > 0) ? - SOUND_EVENT_HIT : SOUND_EVENT_MISS), mX, mY); + if (mType == PLAYER) + { + if (mSpriteIDs.size() >= 10) + { + // here 10 is weapon slot + const int weaponId = mSpriteIDs[10]; + std::string soundFile; + if (weaponId > 0) + { + const ItemInfo &info = ItemDB::get(weaponId); + soundFile = info.getSound((damage > 0) ? + EQUIP_EVENT_HIT : EQUIP_EVENT_STRIKE); + } + else + { + soundFile = mInfo->getSound((damage > 0) ? + SOUND_EVENT_HIT : SOUND_EVENT_MISS); + } + if (!soundFile.empty()) + { + sound.playSfx(soundFile, mX, mY); + } + else + { + sound.playSfx(paths.getValue((damage > 0) + ? "attackSfxFile" : "missSfxFile", + "fist-swish.ogg"), mX, mY); + } + } + } + else + { + sound.playSfx(mInfo->getSound((damage > 0) ? + SOUND_EVENT_HIT : SOUND_EVENT_MISS), mX, mY); + } } void Being::handleSkill(Being *const victim, const int damage, diff --git a/src/defaults.cpp b/src/defaults.cpp index 42d6f1fd9..9ff313ae3 100644 --- a/src/defaults.cpp +++ b/src/defaults.cpp @@ -359,6 +359,7 @@ DefaultsData* getPathsDefaults() AddDEF("sfx", "sfx/"); AddDEF("attackSfxFile", "fist-swish.ogg"); + AddDEF("missSfxFile", "fist-swish.ogg"); AddDEF("music", "music/"); AddDEF("wallpapers", "graphics/images/"); diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 890191bcc..a23811bd3 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -1350,6 +1350,7 @@ void LocalPlayer::attack(Being *const target, const bool keep, { setAction(ATTACK); +/* if (mEquippedWeapon) { std::string soundFile = mEquippedWeapon->getSound( @@ -1361,7 +1362,7 @@ void LocalPlayer::attack(Being *const target, const bool keep, { sound.playSfx(paths.getValue("attackSfxFile", "fist-swish.ogg")); } - +*/ if (!Client::limitPackets(PACKET_ATTACK)) return; diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h index e8a11c2a5..8e6cc2ee0 100644 --- a/src/resources/iteminfo.h +++ b/src/resources/iteminfo.h @@ -32,7 +32,9 @@ enum EquipmentSoundEvent { + // miss EQUIP_EVENT_STRIKE = 0, + // hit EQUIP_EVENT_HIT }; -- cgit v1.2.3-70-g09d2