Improve equipment logic (bug #5223)

pull/2633/head
Andrei Kortunov 5 years ago
parent abe7d25844
commit 97ee4bc349

@ -182,6 +182,7 @@
Bug #5218: Crash when disabling ToggleBorders Bug #5218: Crash when disabling ToggleBorders
Bug #5220: GetLOS crashes when actor isn't loaded Bug #5220: GetLOS crashes when actor isn't loaded
Bug #5222: Empty cell name subrecords are not saved Bug #5222: Empty cell name subrecords are not saved
Bug #5223: Bow replacement during attack animation removes attached arrow
Bug #5226: Reputation should be capped Bug #5226: Reputation should be capped
Feature #1774: Handle AvoidNode Feature #1774: Handle AvoidNode
Feature #2229: Improve pathfinding AI Feature #2229: Improve pathfinding AI

@ -299,10 +299,10 @@ namespace MWMechanics
bool wasEquipped = currentItem != store.end() && Misc::StringUtils::ciEqual(currentItem->getCellRef().getRefId(), itemId); bool wasEquipped = currentItem != store.end() && Misc::StringUtils::ciEqual(currentItem->getCellRef().getRefId(), itemId);
store.remove(itemId, 1, actor);
if (actor != MWMechanics::getPlayer()) if (actor != MWMechanics::getPlayer())
{ {
store.remove(itemId, 1, actor);
// Equip a replacement // Equip a replacement
if (!wasEquipped) if (!wasEquipped)
return; return;
@ -329,17 +329,19 @@ namespace MWMechanics
std::string prevItemId = player.getPreviousItem(itemId); std::string prevItemId = player.getPreviousItem(itemId);
player.erasePreviousItem(itemId); player.erasePreviousItem(itemId);
if (prevItemId.empty()) if (!prevItemId.empty())
return; {
// Find previous item (or its replacement) by id.
// Find previous item (or its replacement) by id. // we should equip previous item only if expired bound item was equipped.
// we should equip previous item only if expired bound item was equipped. MWWorld::Ptr item = store.findReplacement(prevItemId);
MWWorld::Ptr item = store.findReplacement(prevItemId); if (!item.isEmpty() && wasEquipped)
if (item.isEmpty() || !wasEquipped) {
return; MWWorld::ActionEquip action(item);
action.execute(actor);
}
}
MWWorld::ActionEquip action(item); store.remove(itemId, 1, actor);
action.execute(actor);
} }
void Actors::updateActor (const MWWorld::Ptr& ptr, float duration) void Actors::updateActor (const MWWorld::Ptr& ptr, float duration)

@ -598,7 +598,7 @@ void NpcAnimation::updateParts()
}; };
static const size_t slotlistsize = sizeof(slotlist)/sizeof(slotlist[0]); static const size_t slotlistsize = sizeof(slotlist)/sizeof(slotlist[0]);
bool wasArrowAttached = (mAmmunition.get() != nullptr); bool wasArrowAttached = isArrowAttached();
mAmmunition.reset(); mAmmunition.reset();
const MWWorld::InventoryStore& inv = mPtr.getClass().getInventoryStore(mPtr); const MWWorld::InventoryStore& inv = mPtr.getClass().getInventoryStore(mPtr);

@ -93,7 +93,7 @@ namespace MWWorld
{ {
for (slot=slots_.first.begin();slot!=slots_.first.end(); ++slot) for (slot=slots_.first.begin();slot!=slots_.first.end(); ++slot)
{ {
invStore.unequipSlot(*slot, actor); invStore.unequipSlot(*slot, actor, false);
if (slot+1 != slots_.first.end()) if (slot+1 != slots_.first.end())
invStore.equip(*slot, invStore.getSlot(*(slot+1)), actor); invStore.equip(*slot, invStore.getSlot(*(slot+1)), actor);
else else

@ -779,7 +779,7 @@ int MWWorld::InventoryStore::remove(const Ptr& item, int count, const Ptr& actor
return retCount; return retCount;
} }
MWWorld::ContainerStoreIterator MWWorld::InventoryStore::unequipSlot(int slot, const MWWorld::Ptr& actor) MWWorld::ContainerStoreIterator MWWorld::InventoryStore::unequipSlot(int slot, const MWWorld::Ptr& actor, bool fireEvent)
{ {
if (slot<0 || slot>=static_cast<int> (mSlots.size())) if (slot<0 || slot>=static_cast<int> (mSlots.size()))
throw std::runtime_error ("slot number out of range"); throw std::runtime_error ("slot number out of range");
@ -811,7 +811,9 @@ MWWorld::ContainerStoreIterator MWWorld::InventoryStore::unequipSlot(int slot, c
} }
} }
fireEquipmentChangedEvent(actor); if (fireEvent)
fireEquipmentChangedEvent(actor);
updateMagicEffects(actor); updateMagicEffects(actor);
return retval; return retval;

@ -173,7 +173,7 @@ namespace MWWorld
/// ///
/// @return the number of items actually removed /// @return the number of items actually removed
ContainerStoreIterator unequipSlot(int slot, const Ptr& actor); ContainerStoreIterator unequipSlot(int slot, const Ptr& actor, bool fireEvent=true);
///< Unequip \a slot. ///< Unequip \a slot.
/// ///
/// @return an iterator to the item that was previously in the slot /// @return an iterator to the item that was previously in the slot

Loading…
Cancel
Save