mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-09 21:42:13 +00:00
3f28634d1f
Note, I suspect Rng::rollClosedProbability() is not needed. The only difference between it and rollProbability() is that one time in 37k (on Windows), it will give an output of 1.0. On some versions of Linux, the value of 1.0 will occur about 1 time in 4 billion.
72 lines
2.3 KiB
C++
72 lines
2.3 KiB
C++
#include "pickpocket.hpp"
|
|
|
|
#include <openengine/misc/rng.hpp>
|
|
|
|
#include "../mwworld/class.hpp"
|
|
#include "../mwworld/esmstore.hpp"
|
|
|
|
#include "../mwbase/world.hpp"
|
|
#include "../mwbase/environment.hpp"
|
|
|
|
#include "npcstats.hpp"
|
|
|
|
namespace MWMechanics
|
|
{
|
|
|
|
Pickpocket::Pickpocket(const MWWorld::Ptr &thief, const MWWorld::Ptr &victim)
|
|
: mThief(thief)
|
|
, mVictim(victim)
|
|
{
|
|
}
|
|
|
|
float Pickpocket::getChanceModifier(const MWWorld::Ptr &ptr, float add)
|
|
{
|
|
NpcStats& stats = ptr.getClass().getNpcStats(ptr);
|
|
float agility = static_cast<float>(stats.getAttribute(ESM::Attribute::Agility).getModified());
|
|
float luck = static_cast<float>(stats.getAttribute(ESM::Attribute::Luck).getModified());
|
|
float sneak = static_cast<float>(ptr.getClass().getSkill(ptr, ESM::Skill::Sneak));
|
|
return (add + 0.2f * agility + 0.1f * luck + sneak) * stats.getFatigueTerm();
|
|
}
|
|
|
|
bool Pickpocket::getDetected(float valueTerm)
|
|
{
|
|
float x = getChanceModifier(mThief);
|
|
float y = getChanceModifier(mVictim, valueTerm);
|
|
|
|
float t = 2*x - y;
|
|
|
|
float pcSneak = static_cast<float>(mThief.getClass().getSkill(mThief, ESM::Skill::Sneak));
|
|
int iPickMinChance = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>()
|
|
.find("iPickMinChance")->getInt();
|
|
int iPickMaxChance = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>()
|
|
.find("iPickMaxChance")->getInt();
|
|
|
|
int roll = OEngine::Misc::Rng::roll0to99();
|
|
if (t < pcSneak / iPickMinChance)
|
|
{
|
|
return (roll > int(pcSneak / iPickMinChance));
|
|
}
|
|
else
|
|
{
|
|
t = std::min(float(iPickMaxChance), t);
|
|
return (roll > int(t));
|
|
}
|
|
}
|
|
|
|
bool Pickpocket::pick(MWWorld::Ptr item, int count)
|
|
{
|
|
float stackValue = static_cast<float>(item.getClass().getValue(item) * count);
|
|
float fPickPocketMod = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>()
|
|
.find("fPickPocketMod")->getFloat();
|
|
float valueTerm = 10 * fPickPocketMod * stackValue;
|
|
|
|
return getDetected(valueTerm);
|
|
}
|
|
|
|
bool Pickpocket::finish()
|
|
{
|
|
return getDetected(0.f);
|
|
}
|
|
|
|
}
|