Move onTakeItem() to item models

pull/335/head
Andrei Kortunov 7 years ago
parent d94235e3a7
commit 3604b73d60

@ -8,13 +8,13 @@
#include "../mwbase/windowmanager.hpp"
#include "../mwbase/dialoguemanager.hpp"
#include "../mwbase/mechanicsmanager.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "../mwworld/class.hpp"
#include "../mwworld/inventorystore.hpp"
#include "../mwmechanics/pickpocket.hpp"
#include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "countdialog.hpp"
#include "inventorywindow.hpp"
@ -142,8 +142,7 @@ namespace MWGui
if (mPtr.getClass().isNpc() && !loot)
{
// we are stealing stuff
MWWorld::Ptr player = MWMechanics::getPlayer();
mModel = new PickpocketItemModel(player, new InventoryItemModel(container),
mModel = new PickpocketItemModel(mPtr, new InventoryItemModel(container),
!mPtr.getClass().getCreatureStats(mPtr).getKnockedDown());
}
else
@ -271,32 +270,8 @@ namespace MWGui
bool ContainerWindow::onTakeItem(const ItemStack &item, int count)
{
MWWorld::Ptr player = MWMechanics::getPlayer();
// TODO: move to ItemModels
if (dynamic_cast<PickpocketItemModel*>(mModel)
&& !mPtr.getClass().getCreatureStats(mPtr).getKnockedDown())
{
MWMechanics::Pickpocket pickpocket(player, mPtr);
if (pickpocket.pick(item.mBase, count))
{
MWBase::Environment::get().getMechanicsManager()->commitCrime(
player, mPtr, MWBase::MechanicsManager::OT_Pickpocket, 0, true);
MWBase::Environment::get().getWindowManager()->removeGuiMode(MWGui::GM_Container);
mPickpocketDetected = true;
return false;
}
else
player.getClass().skillUsageSucceeded(player, ESM::Skill::Sneak, 1);
}
else
{
// Looting a dead corpse is considered OK
if (mPtr.getClass().isActor() && mPtr.getClass().getCreatureStats(mPtr).isDead())
return true;
else
MWBase::Environment::get().getMechanicsManager()->itemTaken(player, item.mBase, mPtr, count);
}
return true;
// TODO: mPickpocketDetected = true;
return mModel->onTakeItem(item.mBase, count);
}
}

@ -2,12 +2,15 @@
#include <algorithm>
#include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "../mwworld/containerstore.hpp"
#include "../mwworld/class.hpp"
#include "../mwbase/world.hpp"
#include "../mwbase/mechanicsmanager.hpp"
#include "../mwbase/environment.hpp"
#include "../mwbase/mechanicsmanager.hpp"
#include "../mwbase/world.hpp"
#include "../mwmechanics/actorutil.hpp"
@ -183,4 +186,21 @@ void ContainerItemModel::update()
}
}
bool ContainerItemModel::onTakeItem(const MWWorld::Ptr &item, int count)
{
if (mItemSources.empty())
return false;
MWWorld::Ptr target = mItemSources[0];
// Looting a dead corpse is considered OK
if (target.getClass().isActor() && target.getClass().getCreatureStats(target).isDead())
return true;
MWWorld::Ptr player = MWMechanics::getPlayer();
MWBase::Environment::get().getMechanicsManager()->itemTaken(player, item, target, count);
return true;
}
}

@ -26,6 +26,7 @@ namespace MWGui
virtual void removeItem (const ItemStack& item, size_t count);
virtual void update();
virtual bool onTakeItem(const MWWorld::Ptr &item, int count);
private:
std::vector<MWWorld::Ptr> mItemSources;

@ -9,6 +9,9 @@
#include "../mwworld/class.hpp"
#include "../mwworld/inventorystore.hpp"
#include "../mwbase/environment.hpp"
#include "../mwbase/mechanicsmanager.hpp"
namespace MWGui
{
@ -116,4 +119,16 @@ void InventoryItemModel::update()
}
}
bool InventoryItemModel::onTakeItem(const MWWorld::Ptr &item, int count) const
{
// Looting a dead corpse is considered OK
if (mActor.getClass().isActor() && mActor.getClass().getCreatureStats(mActor).isDead())
return true;
MWWorld::Ptr player = MWMechanics::getPlayer();
MWBase::Environment::get().getMechanicsManager()->itemTaken(player, item, mActor, count);
return true;
}
}

@ -22,6 +22,7 @@ namespace MWGui
virtual MWWorld::Ptr moveItem (const ItemStack& item, size_t count, ItemModel* otherModel);
virtual void update();
virtual bool onTakeItem(const MWWorld::Ptr &item, int count) const;
protected:
MWWorld::Ptr mActor;

@ -129,6 +129,11 @@ namespace MWGui
return true;
}
bool ItemModel::onTakeItem(const MWWorld::Ptr &item, int count)
{
return true;
}
ProxyItemModel::ProxyItemModel()
: mSourceModel(NULL)
@ -198,4 +203,8 @@ namespace MWGui
mSourceModel = sourceModel;
}
bool ProxyItemModel::onTakeItem(const MWWorld::Ptr &item, int count)
{
return mSourceModel->onTakeItem (item, count);
}
}

@ -75,6 +75,7 @@ namespace MWGui
/// Is the player allowed to insert items into this model? (default true)
virtual bool allowedToInsertItems() const;
virtual bool onTakeItem(const MWWorld::Ptr &item, int count);
private:
ItemModel(const ItemModel&);
@ -94,6 +95,7 @@ namespace MWGui
virtual MWWorld::Ptr copyItem (const ItemStack& item, size_t count, bool setNewOwner=false);
virtual void removeItem (const ItemStack& item, size_t count);
virtual ModelIndex getIndex (ItemStack item);
virtual bool onTakeItem(const MWWorld::Ptr &item, int count);
/// @note Takes ownership of the passed pointer.
void setSourceModel(ItemModel* sourceModel);

@ -3,15 +3,24 @@
#include <components/misc/rng.hpp>
#include <components/esm/loadskil.hpp>
#include "../mwmechanics/actorutil.hpp"
#include "../mwmechanics/pickpocket.hpp"
#include "../mwworld/class.hpp"
#include "../mwbase/environment.hpp"
#include "../mwbase/mechanicsmanager.hpp"
#include "../mwbase/windowmanager.hpp"
namespace MWGui
{
PickpocketItemModel::PickpocketItemModel(const MWWorld::Ptr& thief, ItemModel *sourceModel, bool hideItems)
PickpocketItemModel::PickpocketItemModel(const MWWorld::Ptr& actor, ItemModel *sourceModel, bool hideItems)
: mActor(actor)
{
MWWorld::Ptr player = MWMechanics::getPlayer();
mSourceModel = sourceModel;
int chance = thief.getClass().getSkill(thief, ESM::Skill::Sneak);
int chance = player.getClass().getSkill(player, ESM::Skill::Sneak);
mSourceModel->update();
@ -75,4 +84,20 @@ namespace MWGui
return false;
}
bool PickpocketItemModel::onTakeItem(const MWWorld::Ptr &item, int count) const
{
MWWorld::Ptr player = MWMechanics::getPlayer();
MWMechanics::Pickpocket pickpocket(player, mActor);
if (pickpocket.pick(item, count))
{
MWBase::Environment::get().getMechanicsManager()->commitCrime(
player, mActor, MWBase::MechanicsManager::OT_Pickpocket, 0, true);
MWBase::Environment::get().getWindowManager()->removeGuiMode(MWGui::GM_Container);
return false;
}
else
player.getClass().skillUsageSucceeded(player, ESM::Skill::Sneak, 1);
return true;
}
}

@ -18,6 +18,10 @@ namespace MWGui
virtual void update();
virtual void removeItem (const ItemStack& item, size_t count);
virtual bool allowedToInsertItems() const;
virtual bool onTakeItem(const MWWorld::Ptr &item, int count) const;
protected:
MWWorld::Ptr mActor;
private:
std::vector<ItemStack> mHiddenItems;

@ -311,4 +311,8 @@ namespace MWGui
std::sort(mItems.begin(), mItems.end(), cmp);
}
bool SortFilterItemModel::onTakeItem(const MWWorld::Ptr &item, int count)
{
return mSourceModel->onTakeItem (item, count);
}
}

@ -29,6 +29,8 @@ namespace MWGui
/// Use ItemStack::Type for sorting?
void setSortByType(bool sort) { mSortByType = sort; }
bool onTakeItem(const MWWorld::Ptr &item, int count);
static const int Category_Weapon = (1<<1);
static const int Category_Apparel = (1<<2);
static const int Category_Misc = (1<<3);

Loading…
Cancel
Save