mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 05:19:55 +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.
67 lines
1.9 KiB
C++
67 lines
1.9 KiB
C++
#include "pickpocketitemmodel.hpp"
|
|
|
|
#include <openengine/misc/rng.hpp>
|
|
|
|
#include "../mwmechanics/npcstats.hpp"
|
|
#include "../mwworld/class.hpp"
|
|
|
|
namespace MWGui
|
|
{
|
|
|
|
PickpocketItemModel::PickpocketItemModel(const MWWorld::Ptr& thief, ItemModel *sourceModel, bool hideItems)
|
|
{
|
|
mSourceModel = sourceModel;
|
|
int chance = thief.getClass().getSkill(thief, ESM::Skill::Sneak);
|
|
|
|
mSourceModel->update();
|
|
|
|
// build list of items that player is unable to find when attempts to pickpocket.
|
|
if (hideItems)
|
|
{
|
|
for (size_t i = 0; i<mSourceModel->getItemCount(); ++i)
|
|
{
|
|
if (chance <= OEngine::Misc::Rng::roll0to99())
|
|
mHiddenItems.push_back(mSourceModel->getItem(i));
|
|
}
|
|
}
|
|
}
|
|
|
|
ItemStack PickpocketItemModel::getItem (ModelIndex index)
|
|
{
|
|
if (index < 0)
|
|
throw std::runtime_error("Invalid index supplied");
|
|
if (mItems.size() <= static_cast<size_t>(index))
|
|
throw std::runtime_error("Item index out of range");
|
|
return mItems[index];
|
|
}
|
|
|
|
size_t PickpocketItemModel::getItemCount()
|
|
{
|
|
return mItems.size();
|
|
}
|
|
|
|
void PickpocketItemModel::update()
|
|
{
|
|
mSourceModel->update();
|
|
mItems.clear();
|
|
for (size_t i = 0; i<mSourceModel->getItemCount(); ++i)
|
|
{
|
|
const ItemStack& item = mSourceModel->getItem(i);
|
|
|
|
// Bound items may not be stolen
|
|
if (item.mFlags & ItemStack::Flag_Bound)
|
|
continue;
|
|
|
|
if (std::find(mHiddenItems.begin(), mHiddenItems.end(), item) == mHiddenItems.end()
|
|
&& item.mType != ItemStack::Type_Equipped)
|
|
mItems.push_back(item);
|
|
}
|
|
}
|
|
|
|
void PickpocketItemModel::removeItem (const ItemStack &item, size_t count)
|
|
{
|
|
ProxyItemModel::removeItem(item, count);
|
|
/// \todo check if player is detected
|
|
}
|
|
|
|
}
|