forked from mirror/openmw-tes3mp
Add a utility function to add items to a ContainerStore by RefID
This commit is contained in:
parent
6641fd4635
commit
bab657fe2b
8 changed files with 23 additions and 26 deletions
|
@ -210,8 +210,7 @@ namespace MWGui
|
|||
|
||||
if (amount > 0)
|
||||
{
|
||||
MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), "Gold_001", amount);
|
||||
playerStore.add(ref.getPtr(), player);
|
||||
playerStore.add("gold_001", amount, player);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -32,17 +32,17 @@
|
|||
namespace
|
||||
{
|
||||
|
||||
void adjustBoundItem (const std::string& item, bool bound, const MWWorld::Ptr& ptr)
|
||||
void adjustBoundItem (const std::string& item, bool bound, const MWWorld::Ptr& actor)
|
||||
{
|
||||
if (bound)
|
||||
{
|
||||
MWWorld::ManualRef ref (MWBase::Environment::get().getWorld()->getStore(), item, 1);
|
||||
MWWorld::ActionEquip action(*ptr.getClass().getContainerStore(ptr).add(ref.getPtr(), ptr));
|
||||
action.execute(ptr);
|
||||
MWWorld::Ptr newPtr = *actor.getClass().getContainerStore(actor).add(item, 1, actor);
|
||||
MWWorld::ActionEquip action(newPtr);
|
||||
action.execute(actor);
|
||||
}
|
||||
else
|
||||
{
|
||||
ptr.getClass().getContainerStore(ptr).remove(item, 1, ptr);
|
||||
actor.getClass().getContainerStore(actor).remove(item, 1, actor);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -287,8 +287,7 @@ void MWMechanics::Alchemy::addPotion (const std::string& name)
|
|||
record = MWBase::Environment::get().getWorld()->createRecord (newRecord);
|
||||
}
|
||||
|
||||
MWWorld::ManualRef ref (MWBase::Environment::get().getWorld()->getStore(), record->mId);
|
||||
MWWorld::Class::get (mAlchemist).getContainerStore (mAlchemist).add (ref.getPtr(), mAlchemist);
|
||||
mAlchemist.getClass().getContainerStore (mAlchemist).add (record->mId, 1, mAlchemist);
|
||||
}
|
||||
|
||||
void MWMechanics::Alchemy::increaseSkill()
|
||||
|
|
|
@ -62,10 +62,7 @@ namespace MWMechanics
|
|||
|
||||
//Exception for Azura Star, new one will be added after enchanting
|
||||
if(boost::iequals(mSoulGemPtr.get<ESM::Miscellaneous>()->mBase->mId, "Misc_SoulGem_Azura"))
|
||||
{
|
||||
MWWorld::ManualRef azura (MWBase::Environment::get().getWorld()->getStore(), "Misc_SoulGem_Azura");
|
||||
store.add(azura.getPtr(), player);
|
||||
}
|
||||
store.add("Misc_SoulGem_Azura", 1, player);
|
||||
|
||||
if(mSelfEnchanting)
|
||||
{
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwbase/windowmanager.hpp"
|
||||
|
||||
#include "../mwworld/manualref.hpp"
|
||||
#include "../mwworld/class.hpp"
|
||||
#include "../mwworld/containerstore.hpp"
|
||||
#include "../mwworld/actionequip.hpp"
|
||||
|
@ -53,24 +52,23 @@ namespace MWScript
|
|||
if (count == 0)
|
||||
return;
|
||||
|
||||
MWWorld::ManualRef ref (MWBase::Environment::get().getWorld()->getStore(), item, count);
|
||||
MWWorld::Ptr itemPtr = *ptr.getClass().getContainerStore (ptr).add (item, count, ptr);
|
||||
|
||||
// Configure item's script variables
|
||||
std::string script = MWWorld::Class::get(ref.getPtr()).getScript(ref.getPtr());
|
||||
std::string script = MWWorld::Class::get(itemPtr).getScript(itemPtr);
|
||||
if (script != "")
|
||||
{
|
||||
const ESM::Script *esmscript = MWBase::Environment::get().getWorld()->getStore().get<ESM::Script>().find (script);
|
||||
ref.getPtr().getRefData().setLocals(*esmscript);
|
||||
itemPtr.getRefData().setLocals(*esmscript);
|
||||
}
|
||||
|
||||
MWWorld::Class::get (ptr).getContainerStore (ptr).add (ref.getPtr(), ptr);
|
||||
|
||||
// Spawn a messagebox (only for items added to player's inventory and if player is talking to someone)
|
||||
if (ptr == MWBase::Environment::get().getWorld ()->getPlayer ().getPlayer() )
|
||||
{
|
||||
// The two GMST entries below expand to strings informing the player of what, and how many of it has been added to their inventory
|
||||
std::string msgBox;
|
||||
std::string itemName = MWWorld::Class::get(ref.getPtr()).getName(ref.getPtr());
|
||||
std::string itemName = itemPtr.getClass().getName(itemPtr);
|
||||
if (count == 1)
|
||||
{
|
||||
msgBox = MyGUI::LanguageManager::getInstance().replaceTags("#{sNotifyMessage60}");
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
#include "../mwworld/class.hpp"
|
||||
#include "../mwworld/player.hpp"
|
||||
#include "../mwworld/manualref.hpp"
|
||||
#include "../mwworld/containerstore.hpp"
|
||||
|
||||
#include "../mwmechanics/npcstats.hpp"
|
||||
|
@ -348,12 +347,8 @@ namespace MWScript
|
|||
const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore();
|
||||
store.get<ESM::Creature>().find(creature); // This line throws an exception if it can't find the creature
|
||||
|
||||
MWWorld::ManualRef ref (MWBase::Environment::get().getWorld()->getStore(), gem, 1);
|
||||
|
||||
ref.getPtr().getCellRef().mSoul = creature;
|
||||
|
||||
MWWorld::Class::get (ptr).getContainerStore (ptr).add (ref.getPtr(), ptr);
|
||||
|
||||
MWWorld::Ptr item = *ptr.getClass().getContainerStore(ptr).add(gem, 1, ptr);
|
||||
item.getCellRef().mSoul = creature;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -118,6 +118,12 @@ bool MWWorld::ContainerStore::stacks(const Ptr& ptr1, const Ptr& ptr2)
|
|||
|| cls2.getItemMaxHealth(ptr2) == ptr2.getCellRef().mCharge);
|
||||
}
|
||||
|
||||
MWWorld::ContainerStoreIterator MWWorld::ContainerStore::add(const std::string &id, int count, const Ptr &actorPtr)
|
||||
{
|
||||
MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), id, count);
|
||||
return add(ref.getPtr(), actorPtr);
|
||||
}
|
||||
|
||||
MWWorld::ContainerStoreIterator MWWorld::ContainerStore::add (const Ptr& itemPtr, const Ptr& actorPtr)
|
||||
{
|
||||
MWWorld::ContainerStoreIterator it = addImp(itemPtr);
|
||||
|
|
|
@ -74,6 +74,9 @@ namespace MWWorld
|
|||
///
|
||||
/// @return if stacking happened, return iterator to the item that was stacked against, otherwise iterator to the newly inserted item.
|
||||
|
||||
ContainerStoreIterator add(const std::string& id, int count, const Ptr& actorPtr);
|
||||
///< Utility to construct a ManualRef and call add(ptr, actorPtr)
|
||||
|
||||
int remove(const std::string& itemId, int count, const Ptr& actor);
|
||||
///< Remove \a count item(s) designated by \a itemId from this container.
|
||||
///
|
||||
|
|
Loading…
Reference in a new issue