diff --git a/apps/openmw/mwmechanics/security.cpp b/apps/openmw/mwmechanics/security.cpp index 818412b8e..11edc6450 100644 --- a/apps/openmw/mwmechanics/security.cpp +++ b/apps/openmw/mwmechanics/security.cpp @@ -13,7 +13,8 @@ namespace MWMechanics { - void Security::pickLock(const MWWorld::Ptr &actor, const MWWorld::Ptr &lock, const MWWorld::Ptr &lockpick) + void Security::pickLock(const MWWorld::Ptr &actor, const MWWorld::Ptr &lock, const MWWorld::Ptr &lockpick, + std::string& resultMessage, std::string& resultSound) { if (lock.getCellRef().mLockLevel <= 0) return; @@ -35,25 +36,21 @@ namespace MWMechanics x *= pickQuality * fatigueTerm; x += fPickLockMult * lockStrength; - bool isPlayer = actor == MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); - + resultSound = "Open Lock Fail"; if (x <= 0) - { - if (isPlayer) - MWBase::Environment::get().getWindowManager()->messageBox("#{sLockImpossible}"); - } + resultMessage = "#{sLockImpossible}"; else { int roll = static_cast (std::rand()) / RAND_MAX * 100; if (roll <= x) { MWWorld::Class::get(lock).unlock(lock); - if (isPlayer) - MWBase::Environment::get().getWindowManager()->messageBox("#{sLockSuccess}"); + resultMessage = "#{sLockSuccess}"; + resultSound = "Open Lock"; MWWorld::Class::get(actor).skillUsageSucceeded(actor, ESM::Skill::Security, 1); } - else if (isPlayer) - MWBase::Environment::get().getWindowManager()->messageBox("#{sLockFail}"); + else + resultMessage = "#{sLockFail}"; } if (lockpick.getCellRef().mCharge == -1) @@ -63,7 +60,8 @@ namespace MWMechanics lockpick.getRefData().setCount(0); } - void Security::probeTrap(const MWWorld::Ptr &actor, const MWWorld::Ptr &trap, const MWWorld::Ptr &probe) + void Security::probeTrap(const MWWorld::Ptr &actor, const MWWorld::Ptr &trap, const MWWorld::Ptr &probe, + std::string& resultMessage, std::string& resultSound) { if (trap.getCellRef().mTrap == "") return; @@ -87,25 +85,22 @@ namespace MWMechanics x += fTrapCostMult * trapSpellPoints; x *= probeQuality * fatigueTerm; - bool isPlayer = actor == MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); - + resultSound = "Disarm Trap Fail"; if (x <= 0) - { - if (isPlayer) - MWBase::Environment::get().getWindowManager()->messageBox("#{sTrapImpossible}"); - } + resultMessage = "#{sTrapImpossible}"; else { int roll = static_cast (std::rand()) / RAND_MAX * 100; if (roll <= x) { trap.getCellRef().mTrap = ""; - if (isPlayer) - MWBase::Environment::get().getWindowManager()->messageBox("#{sTrapSuccess}"); + + resultSound = "Disarm Trap"; + resultMessage = "#{sTrapSuccess}"; MWWorld::Class::get(actor).skillUsageSucceeded(actor, ESM::Skill::Security, 0); } - else if (isPlayer) - MWBase::Environment::get().getWindowManager()->messageBox("#{sTrapFail}"); + else + resultMessage = "#{sTrapFail}"; } if (probe.getCellRef().mCharge == -1) diff --git a/apps/openmw/mwmechanics/security.hpp b/apps/openmw/mwmechanics/security.hpp index 4d655f6e0..17a914459 100644 --- a/apps/openmw/mwmechanics/security.hpp +++ b/apps/openmw/mwmechanics/security.hpp @@ -10,8 +10,10 @@ namespace MWMechanics class Security { public: - static void pickLock (const MWWorld::Ptr& actor, const MWWorld::Ptr& lock, const MWWorld::Ptr& lockpick); - static void probeTrap (const MWWorld::Ptr& actor, const MWWorld::Ptr& trap, const MWWorld::Ptr& probe); + static void pickLock (const MWWorld::Ptr& actor, const MWWorld::Ptr& lock, const MWWorld::Ptr& lockpick, + std::string& resultMessage, std::string& resultSound); + static void probeTrap (const MWWorld::Ptr& actor, const MWWorld::Ptr& trap, const MWWorld::Ptr& probe, + std::string& resultMessage, std::string& resultSound); }; } diff --git a/apps/openmw/mwworld/player.cpp b/apps/openmw/mwworld/player.cpp index ca604f55d..b597dccf3 100644 --- a/apps/openmw/mwworld/player.cpp +++ b/apps/openmw/mwworld/player.cpp @@ -4,6 +4,7 @@ #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" #include "../mwbase/windowmanager.hpp" +#include "../mwbase/soundmanager.hpp" #include "../mwworld/ptr.hpp" #include "../mwworld/inventorystore.hpp" @@ -156,19 +157,26 @@ namespace MWWorld if (anim->isPriorityActive(MWMechanics::Priority_Weapon)) return; + std::string resultMessage, resultSound; + if (item.getTypeName() == typeid(ESM::Lockpick).name()) { if (!target.isEmpty()) - MWMechanics::Security::pickLock(getPlayer(), target, item); + MWMechanics::Security::pickLock(getPlayer(), target, item, resultMessage, resultSound); anim->play("pickprobe", MWMechanics::Priority_Weapon, MWRender::Animation::Group_UpperBody, true, "start", "stop", 0.0, 0); } else if (item.getTypeName() == typeid(ESM::Probe).name()) { if (!target.isEmpty()) - MWMechanics::Security::probeTrap(getPlayer(), target, item); + MWMechanics::Security::probeTrap(getPlayer(), target, item, resultMessage, resultSound); anim->play("pickprobe", MWMechanics::Priority_Weapon, MWRender::Animation::Group_UpperBody, true, "start", "stop", 0.0, 0); } + if (!resultMessage.empty()) + MWBase::Environment::get().getWindowManager()->messageBox(resultMessage); + if (!resultSound.empty()) + MWBase::Environment::get().getSoundManager()->playSound(resultSound,1,1); + // tool used up? if (!item.getRefData().getCount()) MWBase::Environment::get().getWindowManager()->setSelectedWeapon(MWWorld::Ptr());