Merge branch 'blocksound' into 'master'

Play shield hit sound for the shield that was hit (#7774)

Closes #7774

See merge request OpenMW/openmw!3776
ini_importer_tests
Evil Eye 12 months ago
commit 5ae878c248

@ -37,23 +37,6 @@ namespace MWClass
return true; return true;
} }
void Actor::block(const MWWorld::Ptr& ptr) const
{
const MWWorld::InventoryStore& inv = getInventoryStore(ptr);
MWWorld::ConstContainerStoreIterator shield = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedLeft);
if (shield == inv.end())
return;
MWBase::SoundManager* sndMgr = MWBase::Environment::get().getSoundManager();
const ESM::RefId skill = shield->getClass().getEquipmentSkill(*shield);
if (skill == ESM::Skill::LightArmor)
sndMgr->playSound3D(ptr, ESM::RefId::stringRefId("Light Armor Hit"), 1.0f, 1.0f);
else if (skill == ESM::Skill::MediumArmor)
sndMgr->playSound3D(ptr, ESM::RefId::stringRefId("Medium Armor Hit"), 1.0f, 1.0f);
else if (skill == ESM::Skill::HeavyArmor)
sndMgr->playSound3D(ptr, ESM::RefId::stringRefId("Heavy Armor Hit"), 1.0f, 1.0f);
}
osg::Vec3f Actor::getRotationVector(const MWWorld::Ptr& ptr) const osg::Vec3f Actor::getRotationVector(const MWWorld::Ptr& ptr) const
{ {
MWMechanics::Movement& movement = getMovementSettings(ptr); MWMechanics::Movement& movement = getMovementSettings(ptr);

@ -45,8 +45,6 @@ namespace MWClass
bool useAnim() const override; bool useAnim() const override;
void block(const MWWorld::Ptr& ptr) const override;
osg::Vec3f getRotationVector(const MWWorld::Ptr& ptr) const override; osg::Vec3f getRotationVector(const MWWorld::Ptr& ptr) const override;
///< Return desired rotations, as euler angles. Sets getMovementSettings(ptr).mRotation to zero. ///< Return desired rotations, as euler angles. Sets getMovementSettings(ptr).mRotation to zero.

@ -339,10 +339,7 @@ namespace MWClass
MWMechanics::applyElementalShields(ptr, victim); MWMechanics::applyElementalShields(ptr, victim);
if (MWMechanics::blockMeleeAttack(ptr, victim, weapon, damage, attackStrength)) if (MWMechanics::blockMeleeAttack(ptr, victim, weapon, damage, attackStrength))
{
damage = 0; damage = 0;
victim.getClass().block(victim);
}
MWMechanics::diseaseContact(victim, ptr); MWMechanics::diseaseContact(victim, ptr);

@ -678,10 +678,7 @@ namespace MWClass
MWMechanics::applyElementalShields(ptr, victim); MWMechanics::applyElementalShields(ptr, victim);
if (MWMechanics::blockMeleeAttack(ptr, victim, weapon, damage, attackStrength)) if (MWMechanics::blockMeleeAttack(ptr, victim, weapon, damage, attackStrength))
{
damage = 0; damage = 0;
victim.getClass().block(victim);
}
if (victim == MWMechanics::getPlayer() && MWBase::Environment::get().getWorld()->getGodModeState()) if (victim == MWMechanics::getPlayer() && MWBase::Environment::get().getWorld()->getGodModeState())
damage = 0; damage = 0;

@ -135,6 +135,15 @@ namespace MWMechanics
auto& prng = MWBase::Environment::get().getWorld()->getPrng(); auto& prng = MWBase::Environment::get().getWorld()->getPrng();
if (Misc::Rng::roll0to99(prng) < x) if (Misc::Rng::roll0to99(prng) < x)
{ {
MWBase::SoundManager* sndMgr = MWBase::Environment::get().getSoundManager();
const ESM::RefId skill = shield->getClass().getEquipmentSkill(*shield);
if (skill == ESM::Skill::LightArmor)
sndMgr->playSound3D(blocker, ESM::RefId::stringRefId("Light Armor Hit"), 1.0f, 1.0f);
else if (skill == ESM::Skill::MediumArmor)
sndMgr->playSound3D(blocker, ESM::RefId::stringRefId("Medium Armor Hit"), 1.0f, 1.0f);
else if (skill == ESM::Skill::HeavyArmor)
sndMgr->playSound3D(blocker, ESM::RefId::stringRefId("Heavy Armor Hit"), 1.0f, 1.0f);
// Reduce shield durability by incoming damage // Reduce shield durability by incoming damage
int shieldhealth = shield->getClass().getItemHealth(*shield); int shieldhealth = shield->getClass().getItemHealth(*shield);

@ -118,11 +118,6 @@ namespace MWWorld
throw std::runtime_error("class cannot hit"); throw std::runtime_error("class cannot hit");
} }
void Class::block(const Ptr& ptr) const
{
throw std::runtime_error("class cannot block");
}
void Class::onHit(const Ptr& ptr, float damage, bool ishealth, const Ptr& object, const Ptr& attacker, void Class::onHit(const Ptr& ptr, float damage, bool ishealth, const Ptr& object, const Ptr& attacker,
const osg::Vec3f& hitPosition, bool successful, const MWMechanics::DamageSourceType sourceType) const const osg::Vec3f& hitPosition, bool successful, const MWMechanics::DamageSourceType sourceType) const
{ {

@ -151,10 +151,6 @@ namespace MWWorld
/// actor responsible for the attack. \a successful specifies if the hit is /// actor responsible for the attack. \a successful specifies if the hit is
/// successful or not. \a sourceType classifies the damage source. /// successful or not. \a sourceType classifies the damage source.
virtual void block(const Ptr& ptr) const;
///< Play the appropriate sound for a blocked attack, depending on the currently equipped shield
/// (default implementation: throw an exception)
virtual std::unique_ptr<Action> activate(const Ptr& ptr, const Ptr& actor) const; virtual std::unique_ptr<Action> activate(const Ptr& ptr, const Ptr& actor) const;
///< Generate action for activation (default implementation: return a null action). ///< Generate action for activation (default implementation: return a null action).

Loading…
Cancel
Save