Fix Drop behavior for creatures that don't have an inventory

pull/3235/head
Alexei Kotov 8 months ago
parent 5b25435260
commit cc4b2e5c58

@ -704,16 +704,17 @@ namespace MWScript
if (!ptr.getClass().isActor()) if (!ptr.getClass().isActor())
return; return;
MWWorld::InventoryStore* invStorePtr = nullptr;
if (ptr.getClass().hasInventoryStore(ptr)) if (ptr.getClass().hasInventoryStore(ptr))
{ {
invStorePtr = &ptr.getClass().getInventoryStore(ptr);
// Prefer dropping unequipped items first; re-stack if possible by unequipping items before dropping // Prefer dropping unequipped items first; re-stack if possible by unequipping items before dropping
// them. // them.
MWWorld::InventoryStore& store = ptr.getClass().getInventoryStore(ptr); int numNotEquipped = invStorePtr->count(item);
int numNotEquipped = store.count(item);
for (int slot = 0; slot < MWWorld::InventoryStore::Slots; ++slot) for (int slot = 0; slot < MWWorld::InventoryStore::Slots; ++slot)
{ {
MWWorld::ConstContainerStoreIterator it = store.getSlot(slot); MWWorld::ConstContainerStoreIterator it = invStorePtr->getSlot(slot);
if (it != store.end() && it->getCellRef().getRefId() == item) if (it != invStorePtr->end() && it->getCellRef().getRefId() == item)
{ {
numNotEquipped -= it->getCellRef().getCount(); numNotEquipped -= it->getCellRef().getCount();
} }
@ -721,29 +722,30 @@ namespace MWScript
for (int slot = 0; slot < MWWorld::InventoryStore::Slots && amount > numNotEquipped; ++slot) for (int slot = 0; slot < MWWorld::InventoryStore::Slots && amount > numNotEquipped; ++slot)
{ {
MWWorld::ContainerStoreIterator it = store.getSlot(slot); MWWorld::ContainerStoreIterator it = invStorePtr->getSlot(slot);
if (it != store.end() && it->getCellRef().getRefId() == item) if (it != invStorePtr->end() && it->getCellRef().getRefId() == item)
{ {
int numToRemove = std::min(amount - numNotEquipped, it->getCellRef().getCount()); int numToRemove = std::min(amount - numNotEquipped, it->getCellRef().getCount());
store.unequipItemQuantity(*it, numToRemove); invStorePtr->unequipItemQuantity(*it, numToRemove);
numNotEquipped += numToRemove; numNotEquipped += numToRemove;
} }
} }
}
for (MWWorld::ContainerStoreIterator iter(store.begin()); iter != store.end(); ++iter) MWWorld::ContainerStore& store = ptr.getClass().getContainerStore(ptr);
for (MWWorld::ContainerStoreIterator iter(store.begin()); iter != store.end(); ++iter)
{
if (iter->getCellRef().getRefId() == item && (!invStorePtr || !invStorePtr->isEquipped(*iter)))
{ {
if (iter->getCellRef().getRefId() == item && !store.isEquipped(*iter)) int removed = store.remove(*iter, amount);
{ MWWorld::Ptr dropped
int removed = store.remove(*iter, amount); = MWBase::Environment::get().getWorld()->dropObjectOnGround(ptr, *iter, removed);
MWWorld::Ptr dropped dropped.getCellRef().setOwner(ESM::RefId());
= MWBase::Environment::get().getWorld()->dropObjectOnGround(ptr, *iter, removed);
dropped.getCellRef().setOwner(ESM::RefId());
amount -= removed; amount -= removed;
if (amount <= 0) if (amount <= 0)
break; break;
}
} }
} }

Loading…
Cancel
Save