mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-30 22:45:34 +00:00
Merge branch 'free_from_bondage' into 'master'
Do not assume the bound item cache is valid after loading a save Closes #6069 See merge request OpenMW/openmw!931
This commit is contained in:
commit
c39c0266a9
2 changed files with 43 additions and 19 deletions
|
@ -1239,7 +1239,7 @@ namespace MWMechanics
|
||||||
// Update bound effects
|
// Update bound effects
|
||||||
// Note: in vanilla MW multiple bound items of the same type can be created by different spells.
|
// Note: in vanilla MW multiple bound items of the same type can be created by different spells.
|
||||||
// As these extra copies are kinda useless this may or may not be important.
|
// As these extra copies are kinda useless this may or may not be important.
|
||||||
static std::map<int, std::string> boundItemsMap;
|
static std::map<ESM::MagicEffect::Effects, std::string> boundItemsMap;
|
||||||
if (boundItemsMap.empty())
|
if (boundItemsMap.empty())
|
||||||
{
|
{
|
||||||
boundItemsMap[ESM::MagicEffect::BoundBattleAxe] = "sMagicBoundBattleAxeID";
|
boundItemsMap[ESM::MagicEffect::BoundBattleAxe] = "sMagicBoundBattleAxeID";
|
||||||
|
@ -1255,28 +1255,30 @@ namespace MWMechanics
|
||||||
boundItemsMap[ESM::MagicEffect::BoundSpear] = "sMagicBoundSpearID";
|
boundItemsMap[ESM::MagicEffect::BoundSpear] = "sMagicBoundSpearID";
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::map<int, std::string>::iterator it = boundItemsMap.begin(); it != boundItemsMap.end(); ++it)
|
if(ptr.getClass().hasInventoryStore(ptr))
|
||||||
{
|
{
|
||||||
bool found = creatureStats.mBoundItems.find(it->first) != creatureStats.mBoundItems.end();
|
for (const auto& [effect, itemGmst] : boundItemsMap)
|
||||||
float magnitude = effects.get(it->first).getMagnitude();
|
|
||||||
if (found != (magnitude > 0))
|
|
||||||
{
|
{
|
||||||
if (magnitude > 0)
|
bool found = creatureStats.mBoundItems.find(effect) != creatureStats.mBoundItems.end();
|
||||||
creatureStats.mBoundItems.insert(it->first);
|
float magnitude = effects.get(effect).getMagnitude();
|
||||||
else
|
if (found != (magnitude > 0))
|
||||||
creatureStats.mBoundItems.erase(it->first);
|
|
||||||
|
|
||||||
std::string itemGmst = it->second;
|
|
||||||
std::string item = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find(
|
|
||||||
itemGmst)->mValue.getString();
|
|
||||||
|
|
||||||
magnitude > 0 ? addBoundItem(item, ptr) : removeBoundItem(item, ptr);
|
|
||||||
|
|
||||||
if (it->first == ESM::MagicEffect::BoundGloves)
|
|
||||||
{
|
{
|
||||||
item = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find(
|
if (magnitude > 0)
|
||||||
"sMagicBoundRightGauntletID")->mValue.getString();
|
creatureStats.mBoundItems.insert(effect);
|
||||||
|
else
|
||||||
|
creatureStats.mBoundItems.erase(effect);
|
||||||
|
|
||||||
|
std::string item = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find(
|
||||||
|
itemGmst)->mValue.getString();
|
||||||
|
|
||||||
magnitude > 0 ? addBoundItem(item, ptr) : removeBoundItem(item, ptr);
|
magnitude > 0 ? addBoundItem(item, ptr) : removeBoundItem(item, ptr);
|
||||||
|
|
||||||
|
if (effect == ESM::MagicEffect::BoundGloves)
|
||||||
|
{
|
||||||
|
item = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find(
|
||||||
|
"sMagicBoundRightGauntletID")->mValue.getString();
|
||||||
|
magnitude > 0 ? addBoundItem(item, ptr) : removeBoundItem(item, ptr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -601,6 +601,28 @@ namespace MWMechanics
|
||||||
mAiSequence.readState(state.mAiSequence);
|
mAiSequence.readState(state.mAiSequence);
|
||||||
mMagicEffects.readState(state.mMagicEffects);
|
mMagicEffects.readState(state.mMagicEffects);
|
||||||
|
|
||||||
|
// Rebuild the bound item cache
|
||||||
|
for(int effectId = ESM::MagicEffect::BoundDagger; effectId <= ESM::MagicEffect::BoundGloves; effectId++)
|
||||||
|
{
|
||||||
|
if(mMagicEffects.get(effectId).getMagnitude() > 0)
|
||||||
|
mBoundItems.insert(effectId);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Check active spell effects
|
||||||
|
// We can't use mActiveSpells::getMagicEffects here because it doesn't include expired effects
|
||||||
|
auto spell = std::find_if(mActiveSpells.begin(), mActiveSpells.end(), [&] (const auto& spell)
|
||||||
|
{
|
||||||
|
const auto& effects = spell.second.mEffects;
|
||||||
|
return std::find_if(effects.begin(), effects.end(), [&] (const auto& effect)
|
||||||
|
{
|
||||||
|
return effect.mEffectId == effectId;
|
||||||
|
}) != effects.end();
|
||||||
|
});
|
||||||
|
if(spell != mActiveSpells.end())
|
||||||
|
mBoundItems.insert(effectId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mSummonedCreatures = state.mSummonedCreatureMap;
|
mSummonedCreatures = state.mSummonedCreatureMap;
|
||||||
mSummonGraveyard = state.mSummonGraveyard;
|
mSummonGraveyard = state.mSummonGraveyard;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue