forked from teamnwah/openmw-tes3coop
scripts run for items added to containers, and scripted items in player inv handled correctly
This commit is contained in:
parent
7c8b3f1239
commit
6fc64e8a4e
3 changed files with 29 additions and 2 deletions
|
@ -15,6 +15,8 @@
|
|||
#include "manualref.hpp"
|
||||
#include "refdata.hpp"
|
||||
#include "class.hpp"
|
||||
#include "localscripts.hpp"
|
||||
#include "player.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
@ -71,6 +73,30 @@ bool MWWorld::ContainerStore::stacks(const Ptr& ptr1, const Ptr& ptr2)
|
|||
}
|
||||
|
||||
MWWorld::ContainerStoreIterator MWWorld::ContainerStore::add (const Ptr& ptr)
|
||||
{
|
||||
MWWorld::ContainerStoreIterator it = realAdd(ptr);
|
||||
MWWorld::Ptr item = *it;
|
||||
|
||||
std::string script = MWWorld::Class::get(item).getScript(item);
|
||||
if(script != "")
|
||||
{
|
||||
CellStore *cell;
|
||||
|
||||
Ptr player = MWBase::Environment::get().getWorld ()->getPlayer().getPlayer();
|
||||
// Items in players inventory have cell set to 0, so their scripts will never be removed
|
||||
if(&(MWWorld::Class::get (player).getContainerStore (player)) == this)
|
||||
cell = 0;
|
||||
else
|
||||
cell = player.getCell();
|
||||
|
||||
item.mCell = cell;
|
||||
MWBase::Environment::get().getWorld()->getLocalScripts().add(script, item);
|
||||
}
|
||||
|
||||
return it;
|
||||
}
|
||||
|
||||
MWWorld::ContainerStoreIterator MWWorld::ContainerStore::realAdd (const Ptr& ptr)
|
||||
{
|
||||
int type = getType(ptr);
|
||||
|
||||
|
@ -162,7 +188,7 @@ void MWWorld::ContainerStore::fill (const ESM::InventoryList& items, const MWWor
|
|||
}
|
||||
|
||||
ref.getPtr().getRefData().setCount (std::abs(iter->mCount)); /// \todo implement item restocking (indicated by negative count)
|
||||
add (ref.getPtr());
|
||||
realAdd (ref.getPtr());
|
||||
}
|
||||
|
||||
flagAsModified();
|
||||
|
|
|
@ -52,6 +52,7 @@ namespace MWWorld
|
|||
int mStateId;
|
||||
mutable float mCachedWeight;
|
||||
mutable bool mWeightUpToDate;
|
||||
ContainerStoreIterator realAdd (const Ptr& ptr);
|
||||
|
||||
public:
|
||||
|
||||
|
|
|
@ -134,7 +134,7 @@ void MWWorld::LocalScripts::clearCell (Ptr::CellStore *cell)
|
|||
|
||||
while (iter!=mScripts.end())
|
||||
{
|
||||
if (iter->second.getCell()==cell)
|
||||
if (iter->second.mCell==cell)
|
||||
{
|
||||
if (iter==mIter)
|
||||
++mIter;
|
||||
|
|
Loading…
Reference in a new issue