1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-30 21:15:33 +00:00

Equip previous item after a bound item expires (bug #2326)

This commit is contained in:
Andrei Kortunov 2017-11-23 19:57:36 +04:00
parent 926ddcd47e
commit 0375bedab2
2 changed files with 91 additions and 19 deletions

View file

@ -50,27 +50,36 @@ bool isConscious(const MWWorld::Ptr& ptr)
return !stats.isDead() && !stats.getKnockedDown(); return !stats.isDead() && !stats.getKnockedDown();
} }
void adjustBoundItem (const std::string& item, bool bound, const MWWorld::Ptr& actor) int getBoundItemSlot (const std::string& itemId)
{ {
if (bound) static std::map<std::string, int> boundItemsMap;
if (boundItemsMap.empty())
{ {
if (actor.getClass().getContainerStore(actor).count(item) == 0) std::string boundId = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("sMagicBoundBootsID")->getString();
{ boundItemsMap[boundId] = MWWorld::InventoryStore::Slot_Boots;
MWWorld::InventoryStore& store = actor.getClass().getInventoryStore(actor);
MWWorld::Ptr newPtr = *store.MWWorld::ContainerStore::add(item, 1, actor); boundId = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("sMagicBoundCuirassID")->getString();
MWWorld::ActionEquip action(newPtr); boundItemsMap[boundId] = MWWorld::InventoryStore::Slot_Cuirass;
action.execute(actor);
MWWorld::ConstContainerStoreIterator rightHand = store.getSlot(MWWorld::InventoryStore::Slot_CarriedRight); boundId = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("sMagicBoundLeftGauntletID")->getString();
// change draw state only if the item is in player's right hand boundItemsMap[boundId] = MWWorld::InventoryStore::Slot_LeftGauntlet;
if (actor == MWMechanics::getPlayer()
&& rightHand != store.end() && newPtr == *rightHand) boundId = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("sMagicBoundRightGauntletID")->getString();
{ boundItemsMap[boundId] = MWWorld::InventoryStore::Slot_RightGauntlet;
MWBase::Environment::get().getWorld()->getPlayer().setDrawState(MWMechanics::DrawState_Weapon);
boundId = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("sMagicBoundHelmID")->getString();
boundItemsMap[boundId] = MWWorld::InventoryStore::Slot_Helmet;
boundId = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("sMagicBoundShieldID")->getString();
boundItemsMap[boundId] = MWWorld::InventoryStore::Slot_CarriedLeft;
} }
}
} int slot = MWWorld::InventoryStore::Slot_CarriedRight;
else std::map<std::string, int>::iterator it = boundItemsMap.find(itemId);
actor.getClass().getInventoryStore(actor).remove(item, 1, actor, true); if (it != boundItemsMap.end())
slot = it->second;
return slot;
} }
class CheckActorCommanded : public MWMechanics::EffectSourceVisitor class CheckActorCommanded : public MWMechanics::EffectSourceVisitor
@ -139,7 +148,6 @@ void getRestorationPerHourOfSleep (const MWWorld::Ptr& ptr, float& health, float
namespace MWMechanics namespace MWMechanics
{ {
const float aiProcessingDistance = 7168; const float aiProcessingDistance = 7168;
const float sqrAiProcessingDistance = aiProcessingDistance*aiProcessingDistance; const float sqrAiProcessingDistance = aiProcessingDistance*aiProcessingDistance;
@ -227,6 +235,65 @@ namespace MWMechanics
} }
}; };
void Actors::adjustBoundItem (const std::string& itemId, bool bound, const MWWorld::Ptr& actor)
{
MWWorld::InventoryStore& store = actor.getClass().getInventoryStore(actor);
if (bound)
{
if (actor.getClass().getContainerStore(actor).count(itemId) != 0)
return;
int slot = getBoundItemSlot(itemId);
MWWorld::Ptr prevItem = *store.getSlot(slot);
MWWorld::Ptr boundPtr = *store.MWWorld::ContainerStore::add(itemId, 1, actor);
MWWorld::ActionEquip action(boundPtr);
action.execute(actor);
if (actor != MWMechanics::getPlayer())
return;
MWWorld::Ptr newItem = *store.getSlot(slot);
if (newItem.isEmpty() || boundPtr != newItem)
return;
// change draw state only if the item is in player's right hand
if (slot == MWWorld::InventoryStore::Slot_CarriedRight)
MWBase::Environment::get().getWorld()->getPlayer().setDrawState(MWMechanics::DrawState_Weapon);
mPreviousItems[slot] = std::make_pair(itemId, prevItem.isEmpty() ? "" : prevItem.getCellRef().getRefId());
}
else
{
store.remove(itemId, 1, actor, true);
if (actor != MWMechanics::getPlayer())
return;
int slot = getBoundItemSlot(itemId);
std::pair<std::string, std::string> prevItem = mPreviousItems[slot];
if (prevItem.first != itemId)
return;
MWWorld::Ptr ptr = MWWorld::Ptr();
if (prevItem.second != "")
ptr = store.search (prevItem.second);
mPreviousItems.erase(slot);
if (ptr.isEmpty())
return;
MWWorld::ActionEquip action(ptr);
action.execute(actor);
}
}
void Actors::updateActor (const MWWorld::Ptr& ptr, float duration) void Actors::updateActor (const MWWorld::Ptr& ptr, float duration)
{ {
// magic effects // magic effects
@ -1875,6 +1942,7 @@ namespace MWMechanics
} }
mActors.clear(); mActors.clear();
mDeathCount.clear(); mDeathCount.clear();
mPreviousItems.clear();
} }
void Actors::updateMagicEffects(const MWWorld::Ptr &ptr) void Actors::updateMagicEffects(const MWWorld::Ptr &ptr)

View file

@ -25,6 +25,10 @@ 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, std::string>> PreviousItems;
PreviousItems mPreviousItems;
void adjustBoundItem (const std::string& itemId, bool bound, const MWWorld::Ptr& actor);
void updateNpc(const MWWorld::Ptr &ptr, float duration); void updateNpc(const MWWorld::Ptr &ptr, float duration);