1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-15 22:19:54 +00:00
openmw-tes3mp/apps/openmw/mwmechanics/security.cpp

115 lines
4.1 KiB
C++
Raw Normal View History

2013-05-19 16:40:37 +00:00
#include "security.hpp"
2015-04-22 15:58:55 +00:00
#include <components/misc/rng.hpp>
2013-05-19 16:40:37 +00:00
#include "../mwworld/class.hpp"
#include "../mwworld/containerstore.hpp"
2014-02-23 19:11:05 +00:00
#include "../mwworld/esmstore.hpp"
2013-05-19 16:40:37 +00:00
#include "../mwbase/world.hpp"
#include "../mwbase/environment.hpp"
2014-01-10 20:26:24 +00:00
#include "../mwbase/mechanicsmanager.hpp"
2013-05-19 16:40:37 +00:00
#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 = actor.getClass().getCreatureStats(actor);
mAgility = static_cast<float>(creatureStats.getAttribute(ESM::Attribute::Agility).getModified());
mLuck = static_cast<float>(creatureStats.getAttribute(ESM::Attribute::Luck).getModified());
2018-10-08 14:06:30 +00:00
mSecuritySkill = static_cast<float>(actor.getClass().getSkill(actor, ESM::Skill::Security));
2013-05-19 21:19:48 +00:00
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().getLockLevel() <= 0 ||
lock.getCellRef().getLockLevel() == ESM::UnbreakableLock ||
!lock.getClass().hasToolTip(lock)) //If it's unlocked or can not be unlocked back out immediately
2013-05-19 16:40:37 +00:00
return;
int lockStrength = lock.getCellRef().getLockLevel();
2013-05-19 16:40:37 +00:00
float pickQuality = lockpick.get<ESM::Lockpick>()->mBase->mData.mQuality;
2018-08-29 15:38:12 +00:00
float fPickLockMult = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fPickLockMult")->mValue.getFloat();
2013-05-19 16:40:37 +00:00
float x = 0.2f * mAgility + 0.1f * mLuck + mSecuritySkill;
2013-05-19 21:19:48 +00:00
x *= pickQuality * mFatigueTerm;
2013-05-19 16:40:37 +00:00
x += fPickLockMult * lockStrength;
MWBase::Environment::get().getMechanicsManager()->unlockAttempted(mActor, lock);
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
{
2015-04-22 15:58:55 +00:00
if (Misc::Rng::roll0to99() <= x)
2013-05-19 16:40:37 +00:00
{
2019-09-17 18:30:37 +00:00
lock.getCellRef().unlock();
2013-05-19 17:48:51 +00:00
resultMessage = "#{sLockSuccess}";
resultSound = "Open Lock";
mActor.getClass().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
}
int uses = lockpick.getClass().getItemHealth(lockpick);
--uses;
lockpick.getCellRef().setCharge(uses);
if (!uses)
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().getTrap() == "")
2013-05-19 16:40:37 +00:00
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().getTrap());
int trapSpellPoints = trapSpell->mData.mCost;
2013-05-19 16:40:37 +00:00
2018-08-29 15:38:12 +00:00
float fTrapCostMult = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fTrapCostMult")->mValue.getFloat();
2013-05-19 16:40:37 +00:00
float x = 0.2f * mAgility + 0.1f * 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
MWBase::Environment::get().getMechanicsManager()->unlockAttempted(mActor, trap);
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
{
2015-04-22 15:58:55 +00:00
if (Misc::Rng::roll0to99() <= x)
2013-05-19 16:40:37 +00:00
{
trap.getCellRef().setTrap("");
2013-05-19 17:48:51 +00:00
resultSound = "Disarm Trap";
resultMessage = "#{sTrapSuccess}";
mActor.getClass().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
}
int uses = probe.getClass().getItemHealth(probe);
--uses;
probe.getCellRef().setCharge(uses);
if (!uses)
probe.getContainerStore()->remove(probe, 1, mActor);
2013-05-19 16:40:37 +00:00
}
}