mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-22 21:53:52 +00:00
Reequip previous item only if the expired bound item was equipped
This commit is contained in:
parent
9b72a6ac69
commit
d1b1cb748d
2 changed files with 22 additions and 21 deletions
|
@ -238,15 +238,14 @@ namespace MWMechanics
|
||||||
void Actors::adjustBoundItem (const std::string& itemId, bool bound, const MWWorld::Ptr& actor)
|
void Actors::adjustBoundItem (const std::string& itemId, bool bound, const MWWorld::Ptr& actor)
|
||||||
{
|
{
|
||||||
MWWorld::InventoryStore& store = actor.getClass().getInventoryStore(actor);
|
MWWorld::InventoryStore& store = actor.getClass().getInventoryStore(actor);
|
||||||
|
int slot = getBoundItemSlot(itemId);
|
||||||
|
|
||||||
if (bound)
|
if (bound)
|
||||||
{
|
{
|
||||||
if (actor.getClass().getContainerStore(actor).count(itemId) != 0)
|
if (actor.getClass().getContainerStore(actor).count(itemId) != 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int slot = getBoundItemSlot(itemId);
|
MWWorld::ContainerStoreIterator prevItem = store.getSlot(slot);
|
||||||
|
|
||||||
MWWorld::Ptr prevItem = *store.getSlot(slot);
|
|
||||||
|
|
||||||
MWWorld::Ptr boundPtr = *store.MWWorld::ContainerStore::add(itemId, 1, actor);
|
MWWorld::Ptr boundPtr = *store.MWWorld::ContainerStore::add(itemId, 1, actor);
|
||||||
MWWorld::ActionEquip action(boundPtr);
|
MWWorld::ActionEquip action(boundPtr);
|
||||||
|
@ -264,39 +263,40 @@ namespace MWMechanics
|
||||||
if (slot == MWWorld::InventoryStore::Slot_CarriedRight)
|
if (slot == MWWorld::InventoryStore::Slot_CarriedRight)
|
||||||
MWBase::Environment::get().getWorld()->getPlayer().setDrawState(MWMechanics::DrawState_Weapon);
|
MWBase::Environment::get().getWorld()->getPlayer().setDrawState(MWMechanics::DrawState_Weapon);
|
||||||
|
|
||||||
mPreviousItems[slot] = std::make_pair(itemId, prevItem);
|
if (prevItem != store.end())
|
||||||
|
mPreviousItems[itemId] = *prevItem;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
MWWorld::ContainerStoreIterator currentItem = store.getSlot(slot);
|
||||||
|
|
||||||
|
bool wasEquipped = currentItem != store.end() && Misc::StringUtils::ciEqual((*currentItem).getCellRef().getRefId(), itemId);
|
||||||
|
|
||||||
store.remove(itemId, 1, actor, true);
|
store.remove(itemId, 1, actor, true);
|
||||||
|
|
||||||
if (actor != MWMechanics::getPlayer())
|
if (actor != MWMechanics::getPlayer())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int slot = getBoundItemSlot(itemId);
|
MWWorld::Ptr prevItem = mPreviousItems[itemId];
|
||||||
|
|
||||||
std::pair<std::string, MWWorld::Ptr> prevItem = mPreviousItems[slot];
|
mPreviousItems.erase(itemId);
|
||||||
|
|
||||||
if (prevItem.first != itemId)
|
if (prevItem.isEmpty())
|
||||||
return;
|
|
||||||
|
|
||||||
mPreviousItems.erase(slot);
|
|
||||||
|
|
||||||
if (prevItem.second.isEmpty())
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// check if the item is still in the player's inventory
|
// check if the item is still in the player's inventory
|
||||||
MWWorld::ContainerStoreIterator it = store.begin();
|
MWWorld::ContainerStoreIterator it = store.begin();
|
||||||
for (; it != store.end(); ++it)
|
for (; it != store.end(); ++it)
|
||||||
{
|
{
|
||||||
if (*it == prevItem.second)
|
if (*it == prevItem)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (it == store.end())
|
// we should equip previous item only if expired bound item was equipped.
|
||||||
|
if (it == store.end() || !wasEquipped)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
MWWorld::ActionEquip action(prevItem.second);
|
MWWorld::ActionEquip action(prevItem);
|
||||||
action.execute(actor);
|
action.execute(actor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -830,9 +830,15 @@ namespace MWMechanics
|
||||||
float magnitude = effects.get(it->first).getMagnitude();
|
float magnitude = effects.get(it->first).getMagnitude();
|
||||||
if (found != (magnitude > 0))
|
if (found != (magnitude > 0))
|
||||||
{
|
{
|
||||||
|
if (magnitude > 0)
|
||||||
|
creatureStats.mBoundItems.insert(it->first);
|
||||||
|
else
|
||||||
|
creatureStats.mBoundItems.erase(it->first);
|
||||||
|
|
||||||
std::string itemGmst = it->second;
|
std::string itemGmst = it->second;
|
||||||
std::string item = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find(
|
std::string item = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find(
|
||||||
itemGmst)->getString();
|
itemGmst)->getString();
|
||||||
|
|
||||||
if (it->first == ESM::MagicEffect::BoundGloves)
|
if (it->first == ESM::MagicEffect::BoundGloves)
|
||||||
{
|
{
|
||||||
item = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find(
|
item = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find(
|
||||||
|
@ -844,11 +850,6 @@ namespace MWMechanics
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
adjustBoundItem(item, magnitude > 0, ptr);
|
adjustBoundItem(item, magnitude > 0, ptr);
|
||||||
|
|
||||||
if (magnitude > 0)
|
|
||||||
creatureStats.mBoundItems.insert(it->first);
|
|
||||||
else
|
|
||||||
creatureStats.mBoundItems.erase(it->first);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ namespace MWMechanics
|
||||||
class Actors
|
class Actors
|
||||||
{
|
{
|
||||||
std::map<std::string, int> mDeathCount;
|
std::map<std::string, int> mDeathCount;
|
||||||
typedef std::map<int, std::pair<std::string, MWWorld::Ptr>> PreviousItems;
|
typedef std::map<std::string, MWWorld::Ptr> PreviousItems;
|
||||||
PreviousItems mPreviousItems;
|
PreviousItems mPreviousItems;
|
||||||
|
|
||||||
void adjustBoundItem (const std::string& itemId, bool bound, const MWWorld::Ptr& actor);
|
void adjustBoundItem (const std::string& itemId, bool bound, const MWWorld::Ptr& actor);
|
||||||
|
|
Loading…
Reference in a new issue