diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-04-18 01:32:58 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-04-18 23:29:17 +0300 |
commit | cef2952156ab09371ed04beec00d0f1e8615ada9 (patch) | |
tree | b5347f9025bdeafaafe38f41f796c97b58ba2656 | |
parent | 67d3b8c193b51bbf892fd965547746511e8ddf87 (diff) | |
download | mv-cef2952156ab09371ed04beec00d0f1e8615ada9.tar.gz mv-cef2952156ab09371ed04beec00d0f1e8615ada9.tar.bz2 mv-cef2952156ab09371ed04beec00d0f1e8615ada9.tar.xz mv-cef2952156ab09371ed04beec00d0f1e8615ada9.zip |
add support for using sound delays.
hurt sounds now can be delayed for "delay" of hit sound.
-rw-r--r-- | src/being.cpp | 79 | ||||
-rw-r--r-- | src/being.h | 21 | ||||
-rw-r--r-- | src/net/ea/beinghandler.cpp | 14 |
3 files changed, 90 insertions, 24 deletions
diff --git a/src/being.cpp b/src/being.cpp index ec682ba7d..c5116039a 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -654,7 +654,7 @@ void Being::takeDamage(Being *const attacker, const int amount, mDamageTaken += amount; if (mInfo) { - playSfx(mInfo->getSound(SOUND_EVENT_HURT), mX, mY); + playSfx(mInfo->getSound(SOUND_EVENT_HURT), this, false, mX, mY); if (!mInfo->isStaticMaxHP()) { @@ -812,13 +812,13 @@ void Being::handleAttack(Being *const victim, const int damage, weaponId = -100 - mSubType; const ItemInfo &info = ItemDB::get(weaponId); playSfx(info.getSound((damage > 0) ? - SOUND_EVENT_HIT : SOUND_EVENT_MISS), mX, mY); + SOUND_EVENT_HIT : SOUND_EVENT_MISS), victim, true, mX, mY); } } else { playSfx(mInfo->getSound((damage > 0) ? - SOUND_EVENT_HIT : SOUND_EVENT_MISS), mX, mY); + SOUND_EVENT_HIT : SOUND_EVENT_MISS), victim, true, mX, mY); } } @@ -857,14 +857,14 @@ void Being::handleSkill(Being *const victim, const int damage, if (data) { if (damage > 0) - playSfx(data->soundHit, mX, mY); + playSfx(data->soundHit, victim, true, mX, mY); else - playSfx(data->soundMiss, mX, mY); + playSfx(data->soundMiss, victim, true, mX, mY); } else { playSfx(mInfo->getSound((damage > 0) ? - SOUND_EVENT_HIT : SOUND_EVENT_MISS), mX, mY); + SOUND_EVENT_HIT : SOUND_EVENT_MISS), victim, true, mX, mY); } } @@ -1100,7 +1100,7 @@ void Being::setAction(const Action &action, const int attackId) if (mInfo) { playSfx(mInfo->getSound( - SOUND_EVENT_MOVE), mX, mY); + SOUND_EVENT_MOVE), nullptr, true, mX, mY); } currentAction = SpriteAction::MOVE; // Note: When adding a run action, @@ -1116,7 +1116,7 @@ void Being::setAction(const Action &action, const int attackId) event = SOUND_EVENT_SITTOP; else event = SOUND_EVENT_SIT; - playSfx(mInfo->getSound(event), mX, mY); + playSfx(mInfo->getSound(event), nullptr, true, mX, mY); } break; case ATTACK: @@ -1163,14 +1163,15 @@ void Being::setAction(const Action &action, const int attackId) case HURT: if (mInfo) { - playSfx(mInfo->getSound(SOUND_EVENT_HURT), mX, mY); + playSfx(mInfo->getSound(SOUND_EVENT_HURT), + this, false, mX, mY); } break; case DEAD: currentAction = SpriteAction::DEAD; if (mInfo) { - playSfx(mInfo->getSound(SOUND_EVENT_DIE), mX, mY); + playSfx(mInfo->getSound(SOUND_EVENT_DIE), this, true, mX, mY); if (mType == MONSTER || mType == NPC) mYDiff = mInfo->getDeadSortOffsetY(); } @@ -1180,7 +1181,10 @@ void Being::setAction(const Action &action, const int attackId) break; case SPAWN: if (mInfo) - playSfx(mInfo->getSound(SOUND_EVENT_SPAWN), mX, mY); + { + playSfx(mInfo->getSound(SOUND_EVENT_SPAWN), + nullptr, true, mX, mY); + } currentAction = SpriteAction::SPAWN; break; default: @@ -1499,6 +1503,20 @@ void Being::logic() if (mType != PLAYER && actorSpriteManager) actorSpriteManager->destroy(this); } + + const SoundInfo *const sound = mNextSound.sound; + if (sound) + { + const int time2 = tick_time; + if (time2 > mNextSound.time) + { + soundManager.playSfx(sound->sound, mNextSound.x, mNextSound.y); + + mNextSound.sound = nullptr; + mNextSound.time = time2 + sound->delay; + } + } + BLOCK_END("Being::logic") } @@ -2910,6 +2928,40 @@ void Being::updatePets() } } +void Being::playSfx(const SoundInfo &sound, Being *const being, + const bool main, const int x, const int y) +{ + if (being) + { + // here need add timer and delay sound + const int time = tick_time; + if (main) + { + being->mNextSound.sound = nullptr; + being->mNextSound.time = time + sound.delay; + being->mNextSound.sound = nullptr; + soundManager.playSfx(sound.sound, x, y); + } + else if (mNextSound.time <= time) + { // old event sound time is gone. we can play new sound + being->mNextSound.sound = nullptr; + being->mNextSound.time = time + sound.delay; + being->mNextSound.sound = nullptr; + soundManager.playSfx(sound.sound, x, y); + } + else + { // old event sound in progress. need save sound and wait + being->mNextSound.sound = &sound; + being->mNextSound.x = x; + being->mNextSound.y = y; + } + } + else + { + soundManager.playSfx(sound.sound, x, y); + } +} + BeingEquipBackend::BeingEquipBackend(Being *const being): mBeing(being) { @@ -2932,11 +2984,6 @@ BeingEquipBackend::BeingEquipBackend(Being *const being): } } -void Being::playSfx(const SoundInfo &sound, const int x, const int y) -{ - soundManager.playSfx(sound.sound, x, y); -} - BeingEquipBackend::~BeingEquipBackend() { clear(); diff --git a/src/being.h b/src/being.h index c1adbbbcb..8a07330f5 100644 --- a/src/being.h +++ b/src/being.h @@ -72,6 +72,22 @@ enum Gender }; +struct NextSoundInfo +{ + NextSoundInfo() : + sound(nullptr), + x(0), + y(0), + time(0) + { + } + + const SoundInfo *sound; + int x; + int y; + int time; +}; + class BeingEquipBackend final : public Equipment::Backend { public: @@ -878,12 +894,15 @@ class Being : public ActorSprite, public ConfigListener void setOwner(Being *const owner) { mOwner = owner; } - void playSfx(const SoundInfo &sound, const int x, const int y); + void playSfx(const SoundInfo &sound, Being *const being, + const bool main, const int x, const int y); static uint8_t genderToInt(const Gender sex) A_WARN_UNUSED; static Gender intToGender(uint8_t sex) A_WARN_UNUSED; + NextSoundInfo mNextSound; + protected: /** * Sets the new path for this being. diff --git a/src/net/ea/beinghandler.cpp b/src/net/ea/beinghandler.cpp index 8fb443803..db3db9dd4 100644 --- a/src/net/ea/beinghandler.cpp +++ b/src/net/ea/beinghandler.cpp @@ -454,10 +454,10 @@ void BeingHandler::processSkillDamage(Net::MessageIn &msg) const const int level = msg.readInt16(); // Skill level msg.readInt16(); // Div msg.readInt8(); // Skill hit/type (?) - if (dstBeing) - dstBeing->takeDamage(srcBeing, param1, Being::SKILL, id); if (srcBeing) srcBeing->handleSkill(dstBeing, param1, id, level); + if (dstBeing) + dstBeing->takeDamage(srcBeing, param1, Being::SKILL, id); } void BeingHandler::processBeingAction(Net::MessageIn &msg) const @@ -483,11 +483,6 @@ void BeingHandler::processBeingAction(Net::MessageIn &msg) const case Being::MULTI: // Critical Damage case Being::REFLECT: // Reflected Damage case Being::FLEE: // Lucky Dodge - if (dstBeing) - { - dstBeing->takeDamage(srcBeing, param1, - static_cast<Being::AttackType>(type)); - } if (srcBeing) { if (srcSpeed && srcBeing->getType() == Being::PLAYER) @@ -497,6 +492,11 @@ void BeingHandler::processBeingAction(Net::MessageIn &msg) const if (srcBeing->getType() == Being::PLAYER) srcBeing->setAttackTime(); } + if (dstBeing) + { + dstBeing->takeDamage(srcBeing, param1, + static_cast<Being::AttackType>(type)); + } break; case 0x01: // dead |