1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-09 21:42:13 +00:00
OpenMW/apps/openmw/mwmechanics/security.cpp

111 lines
4.0 KiB
C++
Raw Normal View History

2013-05-19 16:40:37 +00:00
#include "security.hpp"
#include "../mwworld/class.hpp"
#include "../mwworld/player.hpp"
#include "../mwworld/containerstore.hpp"
2013-05-19 16:40:37 +00:00
#include "../mwbase/world.hpp"
#include "../mwbase/environment.hpp"
#include "../mwbase/windowmanager.hpp"
#include "npcstats.hpp"
#include "creaturestats.hpp"
namespace MWMechanics
{
2013-05-19 21:19:48 +00:00
Security::Security(const MWWorld::Ptr &actor)
2013-05-20 10:42:11 +00:00
: mActor(actor)
2013-05-19 21:19:48 +00:00
{
CreatureStats& creatureStats = MWWorld::Class::get(actor).getCreatureStats(actor);
NpcStats& npcStats = MWWorld::Class::get(actor).getNpcStats(actor);
mAgility = creatureStats.getAttribute(ESM::Attribute::Agility).getModified();
mLuck = creatureStats.getAttribute(ESM::Attribute::Luck).getModified();
mSecuritySkill = npcStats.getSkill(ESM::Skill::Security).getModified();
mFatigueTerm = creatureStats.getFatigueTerm();
}
void Security::pickLock(const MWWorld::Ptr &lock, const MWWorld::Ptr &lockpick,
2013-05-19 17:48:51 +00:00
std::string& resultMessage, std::string& resultSound)
2013-05-19 16:40:37 +00:00
{
if (lock.getCellRef().mLockLevel <= 0)
return;
int lockStrength = lock.getCellRef().mLockLevel;
float pickQuality = lockpick.get<ESM::Lockpick>()->mBase->mData.mQuality;
float fPickLockMult = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fPickLockMult")->getFloat();
2013-05-19 21:19:48 +00:00
float x = 0.2 * mAgility + 0.1 * mLuck + mSecuritySkill;
x *= pickQuality * mFatigueTerm;
2013-05-19 16:40:37 +00:00
x += fPickLockMult * lockStrength;
2013-05-19 17:48:51 +00:00
resultSound = "Open Lock Fail";
2013-05-19 16:40:37 +00:00
if (x <= 0)
2013-05-19 17:48:51 +00:00
resultMessage = "#{sLockImpossible}";
2013-05-19 16:40:37 +00:00
else
{
int roll = static_cast<float> (std::rand()) / RAND_MAX * 100;
if (roll <= x)
{
MWWorld::Class::get(lock).unlock(lock);
2013-05-19 17:48:51 +00:00
resultMessage = "#{sLockSuccess}";
resultSound = "Open Lock";
2013-05-19 21:19:48 +00:00
MWWorld::Class::get(mActor).skillUsageSucceeded(mActor, ESM::Skill::Security, 1);
2013-05-19 16:40:37 +00:00
}
2013-05-19 17:48:51 +00:00
else
resultMessage = "#{sLockFail}";
2013-05-19 16:40:37 +00:00
}
if (lockpick.getCellRef().mCharge == -1)
lockpick.getCellRef().mCharge = lockpick.get<ESM::Lockpick>()->mBase->mData.mUses;
--lockpick.getCellRef().mCharge;
if (!lockpick.getCellRef().mCharge)
lockpick.getContainerStore()->remove(lockpick, 1, mActor);
2013-05-19 16:40:37 +00:00
}
2013-05-19 21:19:48 +00:00
void Security::probeTrap(const MWWorld::Ptr &trap, const MWWorld::Ptr &probe,
2013-05-19 17:48:51 +00:00
std::string& resultMessage, std::string& resultSound)
2013-05-19 16:40:37 +00:00
{
if (trap.getCellRef().mTrap == "")
return;
float probeQuality = probe.get<ESM::Probe>()->mBase->mData.mQuality;
const ESM::Spell* trapSpell = MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().find(trap.getCellRef().mTrap);
float trapSpellPoints = trapSpell->mData.mCost;
float fTrapCostMult = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fTrapCostMult")->getFloat();
2013-05-19 21:19:48 +00:00
float x = 0.2 * mAgility + 0.1 * mLuck + mSecuritySkill;
2013-05-19 16:40:37 +00:00
x += fTrapCostMult * trapSpellPoints;
2013-05-19 21:19:48 +00:00
x *= probeQuality * mFatigueTerm;
2013-05-19 16:40:37 +00:00
2013-05-19 17:48:51 +00:00
resultSound = "Disarm Trap Fail";
2013-05-19 16:40:37 +00:00
if (x <= 0)
2013-05-19 17:48:51 +00:00
resultMessage = "#{sTrapImpossible}";
2013-05-19 16:40:37 +00:00
else
{
int roll = static_cast<float> (std::rand()) / RAND_MAX * 100;
if (roll <= x)
{
trap.getCellRef().mTrap = "";
2013-05-19 17:48:51 +00:00
resultSound = "Disarm Trap";
resultMessage = "#{sTrapSuccess}";
2013-05-19 21:19:48 +00:00
MWWorld::Class::get(mActor).skillUsageSucceeded(mActor, ESM::Skill::Security, 0);
2013-05-19 16:40:37 +00:00
}
2013-05-19 17:48:51 +00:00
else
resultMessage = "#{sTrapFail}";
2013-05-19 16:40:37 +00:00
}
if (probe.getCellRef().mCharge == -1)
probe.getCellRef().mCharge = probe.get<ESM::Probe>()->mBase->mData.mUses;
--probe.getCellRef().mCharge;
if (!probe.getCellRef().mCharge)
probe.getContainerStore()->remove(probe, 1, mActor);
2013-05-19 16:40:37 +00:00
}
}