summaryrefslogtreecommitdiff
path: root/src/being.cpp
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-10-11 23:11:11 +0200
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-10-12 15:06:50 +0200
commit53833f3f145dd1d937d9e7754c03ffadb3db15e8 (patch)
tree3d2e26db8ef7322afcb94814741c26ad45a1678e /src/being.cpp
parent879455af96bc36ac6a9841f385d6b538aa683939 (diff)
downloadmana-53833f3f145dd1d937d9e7754c03ffadb3db15e8.tar.gz
mana-53833f3f145dd1d937d9e7754c03ffadb3db15e8.tar.bz2
mana-53833f3f145dd1d937d9e7754c03ffadb3db15e8.tar.xz
mana-53833f3f145dd1d937d9e7754c03ffadb3db15e8.zip
Added support for hit/miss sounds on equipment for all players
Previously only the local player's weapon "strike" sound would play, regardless of hit or miss. Now the sound is played in response to the SMSG_BEING_ACTION message, so it can be played for all players. Also added alias "miss", which is used by TMW in some places. Finally, when no weapon is equipped, it falls back to the sounds defined on the racesprite item (fixes punch sound on TMW). Closes #68
Diffstat (limited to 'src/being.cpp')
-rw-r--r--src/being.cpp33
1 files changed, 25 insertions, 8 deletions
diff --git a/src/being.cpp b/src/being.cpp
index 5e869662..7c77f19f 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -416,17 +416,34 @@ void Being::handleAttack(Being *victim, int damage, int attackId)
setAction(Being::ATTACK, attackId);
if (victim)
+ {
lookAt(victim->getPosition());
- if (getType() == PLAYER && victim && mEquippedWeapon)
- fireMissile(victim, mEquippedWeapon->missileParticleFile);
- else
- fireMissile(victim,
- mInfo->getAttack(attackId).missileParticleFilename);
+ if (getType() == PLAYER && mEquippedWeapon)
+ fireMissile(victim, mEquippedWeapon->missileParticleFile);
+ else
+ fireMissile(victim, mInfo->getAttack(attackId).missileParticleFilename);
+ }
+
+ if (getType() == PLAYER)
+ {
+ auto itemInfo = mEquippedWeapon;
+
+ // Fall back to racesprite item
+ if (!itemInfo)
+ itemInfo = &itemDb->get(-100 - mSubType);
- sound.playSfx(mInfo->getSound((damage > 0) ?
- SoundEvent::HIT : SoundEvent::MISS),
- getPixelX(), getPixelY());
+ const auto event = damage > 0 ? EquipmentSoundEvent::HIT
+ : EquipmentSoundEvent::STRIKE;
+ const auto &soundFile = itemInfo->getSound(event);
+ sound.playSfx(soundFile, getPixelX(), getPixelY());
+ }
+ else
+ {
+ const auto event = damage > 0 ? SoundEvent::HIT : SoundEvent::MISS;
+ const auto &soundFile = mInfo->getSound(event);
+ sound.playSfx(soundFile, getPixelX(), getPixelY());
+ }
}
void Being::setName(const std::string &name)