1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-01 03:15:32 +00:00

Merge pull request #2633 from akortunov/equip

Improve equipment logic
This commit is contained in:
Alexei Dobrohotov 2019-12-15 16:27:09 +03:00 committed by GitHub
commit 9dc8fecdb3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 22 additions and 17 deletions

View file

@ -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
Bug #5229: Crash if mesh controller node has no data node Bug #5229: Crash if mesh controller node has no data node
Feature #1774: Handle AvoidNode Feature #1774: Handle AvoidNode

View file

@ -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.
// we should equip previous item only if expired bound item was equipped.
MWWorld::Ptr item = store.findReplacement(prevItemId);
if (!item.isEmpty() && wasEquipped)
{
MWWorld::ActionEquip action(item);
action.execute(actor);
}
}
// Find previous item (or its replacement) by id. store.remove(itemId, 1, actor);
// we should equip previous item only if expired bound item was equipped.
MWWorld::Ptr item = store.findReplacement(prevItemId);
if (item.isEmpty() || !wasEquipped)
return;
MWWorld::ActionEquip action(item);
action.execute(actor);
} }
void Actors::updateActor (const MWWorld::Ptr& ptr, float duration) void Actors::updateActor (const MWWorld::Ptr& ptr, float duration)

View file

@ -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);

View file

@ -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

View file

@ -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;

View file

@ -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