mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-24 18:39:59 +00:00
Merge branch 'tastytastyenchantments' into 'master'
Use the correct id to absorb enchantments Closes #7796 See merge request OpenMW/openmw!3813
This commit is contained in:
commit
df6e104e6f
@ -133,6 +133,7 @@
|
||||
Bug #7765: OpenMW-CS: Touch Record option is broken
|
||||
Bug #7770: Sword of the Perithia: Script execution failure
|
||||
Bug #7780: Non-ASCII texture paths in NIF files don't work
|
||||
Bug #7796: Absorbed enchantments don't restore magicka
|
||||
Feature #2566: Handle NAM9 records for manual cell references
|
||||
Feature #3537: Shader-based water ripples
|
||||
Feature #5173: Support for NiFogProperty
|
||||
|
@ -174,6 +174,25 @@ namespace MWMechanics
|
||||
mWorsenings = -1;
|
||||
}
|
||||
|
||||
ESM::RefId ActiveSpells::ActiveSpellParams::getEnchantment() const
|
||||
{
|
||||
// Enchantment id is not stored directly. Instead the enchanted item is stored.
|
||||
const auto& store = MWBase::Environment::get().getESMStore();
|
||||
switch (store->find(mId))
|
||||
{
|
||||
case ESM::REC_ARMO:
|
||||
return store->get<ESM::Armor>().find(mId)->mEnchant;
|
||||
case ESM::REC_BOOK:
|
||||
return store->get<ESM::Book>().find(mId)->mEnchant;
|
||||
case ESM::REC_CLOT:
|
||||
return store->get<ESM::Clothing>().find(mId)->mEnchant;
|
||||
case ESM::REC_WEAP:
|
||||
return store->get<ESM::Weapon>().find(mId)->mEnchant;
|
||||
default:
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
void ActiveSpells::update(const MWWorld::Ptr& ptr, float duration)
|
||||
{
|
||||
if (mIterating)
|
||||
@ -438,21 +457,8 @@ namespace MWMechanics
|
||||
if (store->get<ESM::Enchantment>().search(id) == nullptr)
|
||||
return false;
|
||||
|
||||
// Enchantment id is not stored directly. Instead the enchanted item is stored.
|
||||
return std::find_if(mSpells.begin(), mSpells.end(), [&](const auto& spell) {
|
||||
switch (store->find(spell.mId))
|
||||
{
|
||||
case ESM::REC_ARMO:
|
||||
return store->get<ESM::Armor>().find(spell.mId)->mEnchant == id;
|
||||
case ESM::REC_BOOK:
|
||||
return store->get<ESM::Book>().find(spell.mId)->mEnchant == id;
|
||||
case ESM::REC_CLOT:
|
||||
return store->get<ESM::Clothing>().find(spell.mId)->mEnchant == id;
|
||||
case ESM::REC_WEAP:
|
||||
return store->get<ESM::Weapon>().find(spell.mId)->mEnchant == id;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return spell.getEnchantment() == id;
|
||||
}) != mSpells.end();
|
||||
}
|
||||
|
||||
|
@ -73,6 +73,7 @@ namespace MWMechanics
|
||||
const std::string& getDisplayName() const { return mDisplayName; }
|
||||
|
||||
ESM::RefNum getItem() const { return mItem; }
|
||||
ESM::RefId getEnchantment() const;
|
||||
|
||||
// Increments worsenings count and sets the next timestamp
|
||||
void worsen();
|
||||
|
@ -279,7 +279,8 @@ namespace
|
||||
return false;
|
||||
}
|
||||
|
||||
void absorbSpell(const ESM::RefId& spellId, const MWWorld::Ptr& caster, const MWWorld::Ptr& target)
|
||||
void absorbSpell(const MWMechanics::ActiveSpells::ActiveSpellParams& spellParams, const MWWorld::Ptr& caster,
|
||||
const MWWorld::Ptr& target)
|
||||
{
|
||||
const auto& esmStore = *MWBase::Environment::get().getESMStore();
|
||||
const ESM::Static* absorbStatic = esmStore.get<ESM::Static>().find(ESM::RefId::stringRefId("VFX_Absorb"));
|
||||
@ -287,15 +288,14 @@ namespace
|
||||
if (animation && !absorbStatic->mModel.empty())
|
||||
animation->addEffect(Misc::ResourceHelpers::correctMeshPath(absorbStatic->mModel),
|
||||
ESM::MagicEffect::indexToName(ESM::MagicEffect::SpellAbsorption), false);
|
||||
const ESM::Spell* spell = esmStore.get<ESM::Spell>().search(spellId);
|
||||
int spellCost = 0;
|
||||
if (spell)
|
||||
if (const ESM::Spell* spell = esmStore.get<ESM::Spell>().search(spellParams.getId()))
|
||||
{
|
||||
spellCost = MWMechanics::calcSpellCost(*spell);
|
||||
}
|
||||
else
|
||||
{
|
||||
const ESM::Enchantment* enchantment = esmStore.get<ESM::Enchantment>().search(spellId);
|
||||
const ESM::Enchantment* enchantment = esmStore.get<ESM::Enchantment>().search(spellParams.getEnchantment());
|
||||
if (enchantment)
|
||||
spellCost = MWMechanics::getEffectiveEnchantmentCastCost(*enchantment, caster);
|
||||
}
|
||||
@ -342,7 +342,7 @@ namespace
|
||||
{
|
||||
if (canAbsorb && Misc::Rng::roll0to99(prng) < activeEffect.mMagnitude)
|
||||
{
|
||||
absorbSpell(spellParams.getId(), caster, target);
|
||||
absorbSpell(spellParams, caster, target);
|
||||
return MWMechanics::MagicApplicationResult::Type::REMOVED;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user