2014-01-07 02:01:33 +00:00
|
|
|
#include "pickpocket.hpp"
|
|
|
|
|
2015-04-22 15:58:55 +00:00
|
|
|
#include <components/misc/rng.hpp>
|
2015-03-15 01:07:47 +00:00
|
|
|
|
2014-01-07 02:01:33 +00:00
|
|
|
#include "../mwworld/class.hpp"
|
2014-02-23 19:11:05 +00:00
|
|
|
#include "../mwworld/esmstore.hpp"
|
|
|
|
|
2014-01-07 02:01:33 +00:00
|
|
|
#include "../mwbase/world.hpp"
|
|
|
|
#include "../mwbase/environment.hpp"
|
2014-02-23 19:11:05 +00:00
|
|
|
|
2014-01-07 02:01:33 +00:00
|
|
|
#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);
|
2018-12-23 11:18:33 +00:00
|
|
|
float agility = stats.getAttribute(ESM::Attribute::Agility).getModified();
|
|
|
|
float luck = stats.getAttribute(ESM::Attribute::Luck).getModified();
|
2015-03-08 04:42:07 +00:00
|
|
|
float sneak = static_cast<float>(ptr.getClass().getSkill(ptr, ESM::Skill::Sneak));
|
|
|
|
return (add + 0.2f * agility + 0.1f * luck + sneak) * stats.getFatigueTerm();
|
2014-01-07 02:01:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Pickpocket::getDetected(float valueTerm)
|
|
|
|
{
|
|
|
|
float x = getChanceModifier(mThief);
|
|
|
|
float y = getChanceModifier(mVictim, valueTerm);
|
|
|
|
|
|
|
|
float t = 2*x - y;
|
|
|
|
|
2015-03-08 04:42:07 +00:00
|
|
|
float pcSneak = static_cast<float>(mThief.getClass().getSkill(mThief, ESM::Skill::Sneak));
|
2014-01-07 02:01:33 +00:00
|
|
|
int iPickMinChance = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>()
|
2018-08-29 15:38:12 +00:00
|
|
|
.find("iPickMinChance")->mValue.getInteger();
|
2014-01-07 02:01:33 +00:00
|
|
|
int iPickMaxChance = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>()
|
2018-08-29 15:38:12 +00:00
|
|
|
.find("iPickMaxChance")->mValue.getInteger();
|
2014-01-07 02:01:33 +00:00
|
|
|
|
2015-04-22 15:58:55 +00:00
|
|
|
int roll = Misc::Rng::roll0to99();
|
2014-01-07 02:01:33 +00:00
|
|
|
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)
|
|
|
|
{
|
2015-03-08 04:42:07 +00:00
|
|
|
float stackValue = static_cast<float>(item.getClass().getValue(item) * count);
|
2014-01-07 02:01:33 +00:00
|
|
|
float fPickPocketMod = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>()
|
2018-08-29 15:38:12 +00:00
|
|
|
.find("fPickPocketMod")->mValue.getFloat();
|
2014-01-07 02:01:33 +00:00
|
|
|
float valueTerm = 10 * fPickPocketMod * stackValue;
|
|
|
|
|
|
|
|
return getDetected(valueTerm);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Pickpocket::finish()
|
|
|
|
{
|
|
|
|
return getDetected(0.f);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|