mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-03-14 01:19:59 +00:00
Fix soul gems losing their souls when splitting stacks between containers.
This commit is contained in:
parent
950d65a382
commit
ae4bf04798
@ -7,6 +7,7 @@
|
||||
|
||||
#include "../mwworld/class.hpp"
|
||||
#include "../mwworld/containerstore.hpp"
|
||||
#include "../mwworld/manualref.hpp"
|
||||
|
||||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwbase/mechanicsmanager.hpp"
|
||||
@ -114,7 +115,8 @@ namespace MWGui
|
||||
MWWorld::ContainerStore& store = source.first.getClass().getContainerStore(source.first);
|
||||
if (item.mBase.getContainerStore() == &store)
|
||||
throw std::runtime_error("Item to copy needs to be from a different container!");
|
||||
return *store.add(item.mBase.getCellRef().getRefId(), count, allowAutoEquip);
|
||||
MWWorld::ManualRef newRef(*MWBase::Environment::get().getESMStore(), item.mBase, count);
|
||||
return *store.add(newRef.getPtr(), count, allowAutoEquip);
|
||||
}
|
||||
|
||||
void ContainerItemModel::removeItem(const ItemStack& item, size_t count)
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "../mwworld/class.hpp"
|
||||
#include "../mwworld/containerstore.hpp"
|
||||
#include "../mwworld/inventorystore.hpp"
|
||||
#include "../mwworld/manualref.hpp"
|
||||
|
||||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwbase/mechanicsmanager.hpp"
|
||||
@ -57,8 +58,9 @@ namespace MWGui
|
||||
{
|
||||
if (item.mBase.getContainerStore() == &mActor.getClass().getContainerStore(mActor))
|
||||
throw std::runtime_error("Item to copy needs to be from a different container!");
|
||||
return *mActor.getClass().getContainerStore(mActor).add(
|
||||
item.mBase.getCellRef().getRefId(), count, allowAutoEquip);
|
||||
|
||||
MWWorld::ManualRef newRef(*MWBase::Environment::get().getESMStore(), item.mBase, count);
|
||||
return *mActor.getClass().getContainerStore(mActor).add(newRef.getPtr(), count, allowAutoEquip);
|
||||
}
|
||||
|
||||
void InventoryItemModel::removeItem(const ItemStack& item, size_t count)
|
||||
|
@ -19,6 +19,14 @@ namespace
|
||||
refValue = MWWorld::LiveCellRef<T>(cellRef, base);
|
||||
ptrValue = MWWorld::Ptr(&std::any_cast<MWWorld::LiveCellRef<T>&>(refValue), nullptr);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void create(
|
||||
const MWWorld::Store<T>& list, const MWWorld::Ptr& template_, std::any& refValue, MWWorld::Ptr& ptrValue)
|
||||
{
|
||||
refValue = *static_cast<MWWorld::LiveCellRef<T>*>(template_.getBase());
|
||||
ptrValue = MWWorld::Ptr(&std::any_cast<MWWorld::LiveCellRef<T>&>(refValue), nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
MWWorld::ManualRef::ManualRef(const MWWorld::ESMStore& store, const ESM::RefId& name, const int count)
|
||||
@ -103,3 +111,89 @@ MWWorld::ManualRef::ManualRef(const MWWorld::ESMStore& store, const ESM::RefId&
|
||||
|
||||
mPtr.getCellRef().setCount(count);
|
||||
}
|
||||
|
||||
MWWorld::ManualRef::ManualRef(const ESMStore& store, const Ptr& template_, const int count)
|
||||
{
|
||||
ESM::RefId name = template_.getCellRef().getRefId();
|
||||
switch (store.find(name))
|
||||
{
|
||||
case ESM::REC_ACTI:
|
||||
create(store.get<ESM::Activator>(), template_, mRef, mPtr);
|
||||
break;
|
||||
case ESM::REC_ALCH:
|
||||
create(store.get<ESM::Potion>(), template_, mRef, mPtr);
|
||||
break;
|
||||
case ESM::REC_APPA:
|
||||
create(store.get<ESM::Apparatus>(), template_, mRef, mPtr);
|
||||
break;
|
||||
case ESM::REC_ARMO:
|
||||
create(store.get<ESM::Armor>(), template_, mRef, mPtr);
|
||||
break;
|
||||
case ESM::REC_BOOK:
|
||||
create(store.get<ESM::Book>(), template_, mRef, mPtr);
|
||||
break;
|
||||
case ESM::REC_CLOT:
|
||||
create(store.get<ESM::Clothing>(), template_, mRef, mPtr);
|
||||
break;
|
||||
case ESM::REC_CONT:
|
||||
create(store.get<ESM::Container>(), template_, mRef, mPtr);
|
||||
break;
|
||||
case ESM::REC_CREA:
|
||||
create(store.get<ESM::Creature>(), template_, mRef, mPtr);
|
||||
break;
|
||||
case ESM::REC_DOOR:
|
||||
create(store.get<ESM::Door>(), template_, mRef, mPtr);
|
||||
break;
|
||||
case ESM::REC_INGR:
|
||||
create(store.get<ESM::Ingredient>(), template_, mRef, mPtr);
|
||||
break;
|
||||
case ESM::REC_LEVC:
|
||||
create(store.get<ESM::CreatureLevList>(), template_, mRef, mPtr);
|
||||
break;
|
||||
case ESM::REC_LEVI:
|
||||
create(store.get<ESM::ItemLevList>(), template_, mRef, mPtr);
|
||||
break;
|
||||
case ESM::REC_LIGH:
|
||||
create(store.get<ESM::Light>(), template_, mRef, mPtr);
|
||||
break;
|
||||
case ESM::REC_LOCK:
|
||||
create(store.get<ESM::Lockpick>(), template_, mRef, mPtr);
|
||||
break;
|
||||
case ESM::REC_MISC:
|
||||
create(store.get<ESM::Miscellaneous>(), template_, mRef, mPtr);
|
||||
break;
|
||||
case ESM::REC_NPC_:
|
||||
create(store.get<ESM::NPC>(), template_, mRef, mPtr);
|
||||
break;
|
||||
case ESM::REC_PROB:
|
||||
create(store.get<ESM::Probe>(), template_, mRef, mPtr);
|
||||
break;
|
||||
case ESM::REC_REPA:
|
||||
create(store.get<ESM::Repair>(), template_, mRef, mPtr);
|
||||
break;
|
||||
case ESM::REC_STAT:
|
||||
create(store.get<ESM::Static>(), template_, mRef, mPtr);
|
||||
break;
|
||||
case ESM::REC_WEAP:
|
||||
create(store.get<ESM::Weapon>(), template_, mRef, mPtr);
|
||||
break;
|
||||
case ESM::REC_BODY:
|
||||
create(store.get<ESM::BodyPart>(), template_, mRef, mPtr);
|
||||
break;
|
||||
case ESM::REC_STAT4:
|
||||
create(store.get<ESM4::Static>(), template_, mRef, mPtr);
|
||||
break;
|
||||
case ESM::REC_TERM4:
|
||||
create(store.get<ESM4::Terminal>(), template_, mRef, mPtr);
|
||||
break;
|
||||
case 0:
|
||||
throw std::logic_error("failed to create manual cell ref for " + name.toDebugString() + " (unknown ID)");
|
||||
|
||||
default:
|
||||
throw std::logic_error("failed to create manual cell ref for " + name.toDebugString() + " (unknown type)");
|
||||
}
|
||||
|
||||
mPtr.getCellRef().setCount(count);
|
||||
mPtr.getCellRef().unsetRefNum();
|
||||
mPtr.getRefData().setLuaScripts(nullptr);
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ namespace MWWorld
|
||||
|
||||
public:
|
||||
ManualRef(const MWWorld::ESMStore& store, const ESM::RefId& name, const int count = 1);
|
||||
ManualRef(const MWWorld::ESMStore& store, const MWWorld::Ptr& template_, const int count = 1);
|
||||
|
||||
const Ptr& getPtr() const { return mPtr; }
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user