1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-06-19 02:11:33 +00:00

Move werewolf/ranged weapon swish logic to playSwishSound

This commit is contained in:
Alexei Kotov 2022-08-08 21:37:08 +03:00
parent 09141388ad
commit ad62f5cda3

View file

@ -1613,20 +1613,7 @@ bool CharacterController::updateWeaponState()
mAttackStrength = std::min(1.f, 0.1f + Misc::Rng::rollClosedProbability(prng)); mAttackStrength = std::min(1.f, 0.1f + Misc::Rng::rollClosedProbability(prng));
} }
if(weapclass != ESM::WeaponType::Ranged && weapclass != ESM::WeaponType::Thrown)
{
if (isWerewolf)
{
const MWWorld::ESMStore &store = world->getStore();
const ESM::Sound *sound = store.get<ESM::Sound>().searchRandom("WolfSwing", prng);
if(sound)
sndMgr->playSound3D(mPtr, sound->mId, 1.0f, 1.0f);
}
else
{
playSwishSound(mAttackStrength); playSwishSound(mAttackStrength);
}
}
if (animPlaying) if (animPlaying)
mAnimation->disable(mCurrentWeapon); mAnimation->disable(mCurrentWeapon);
@ -1719,7 +1706,6 @@ bool CharacterController::updateWeaponState()
} }
world->breakInvisibility(mPtr); world->breakInvisibility(mPtr);
if(weapclass != ESM::WeaponType::Ranged && weapclass != ESM::WeaponType::Thrown)
playSwishSound(0.0f); playSwishSound(0.0f);
} }
@ -2782,15 +2768,33 @@ void CharacterController::setHeadTrackTarget(const MWWorld::ConstPtr &target)
void CharacterController::playSwishSound(float attackStrength) const void CharacterController::playSwishSound(float attackStrength) const
{ {
MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager(); ESM::WeaponType::Class weapclass = getWeaponType(mWeaponType)->mWeaponClass;
if (weapclass == ESM::WeaponType::Ranged || weapclass == ESM::WeaponType::Thrown)
return;
std::string sound = "Weapon Swish"; std::string soundId;
if(attackStrength < 0.5f) float pitch = 1.f;
sndMgr->playSound3D(mPtr, sound, 1.0f, 0.8f); //Weak attack
else if(attackStrength < 1.0f) const MWWorld::Class &cls = mPtr.getClass();
sndMgr->playSound3D(mPtr, sound, 1.0f, 1.0f); //Medium attack if (cls.isNpc() && cls.getNpcStats(mPtr).isWerewolf())
{
MWBase::World* world = MWBase::Environment::get().getWorld();
const MWWorld::ESMStore &store = world->getStore();
const ESM::Sound *sound = store.get<ESM::Sound>().searchRandom("WolfSwing", world->getPrng());
if (sound)
soundId = sound->mId;
}
else else
sndMgr->playSound3D(mPtr, sound, 1.0f, 1.2f); //Strong attack {
soundId = "Weapon Swish";
if (attackStrength < 0.5f)
pitch = 0.8f; // Weak attack
else if (attackStrength >= 1.f)
pitch = 1.2f; // Strong attack
}
if (!soundId.empty())
MWBase::Environment::get().getSoundManager()->playSound3D(mPtr, soundId, 1.0f, pitch);
} }
void CharacterController::updateHeadTracking(float duration) void CharacterController::updateHeadTracking(float duration)