mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-01 03:15:34 +00:00
Support enchantment absorption
This commit is contained in:
parent
acdf4cb5e3
commit
f8389c6c37
3 changed files with 22 additions and 10 deletions
|
@ -12,6 +12,7 @@
|
||||||
#include "../mwworld/inventorystore.hpp"
|
#include "../mwworld/inventorystore.hpp"
|
||||||
|
|
||||||
#include "creaturestats.hpp"
|
#include "creaturestats.hpp"
|
||||||
|
#include "spellutil.hpp"
|
||||||
|
|
||||||
namespace MWMechanics
|
namespace MWMechanics
|
||||||
{
|
{
|
||||||
|
@ -43,9 +44,9 @@ namespace MWMechanics
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
bool absorbSpell (const ESM::Spell* spell, const MWWorld::Ptr& caster, const MWWorld::Ptr& target)
|
bool absorbSpell (const std::string& spellId, const MWWorld::Ptr& caster, const MWWorld::Ptr& target)
|
||||||
{
|
{
|
||||||
if (!spell || caster == target || !target.getClass().isActor())
|
if (spellId.empty() || caster == target || !target.getClass().isActor())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
CreatureStats& stats = target.getClass().getCreatureStats(target);
|
CreatureStats& stats = target.getClass().getCreatureStats(target);
|
||||||
|
@ -62,13 +63,27 @@ namespace MWMechanics
|
||||||
if (Misc::Rng::roll0to99() >= chance)
|
if (Misc::Rng::roll0to99() >= chance)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const ESM::Static* absorbStatic = MWBase::Environment::get().getWorld()->getStore().get<ESM::Static>().find("VFX_Absorb");
|
const auto& esmStore = MWBase::Environment::get().getWorld()->getStore();
|
||||||
|
const ESM::Static* absorbStatic = esmStore.get<ESM::Static>().find("VFX_Absorb");
|
||||||
MWRender::Animation* animation = MWBase::Environment::get().getWorld()->getAnimation(target);
|
MWRender::Animation* animation = MWBase::Environment::get().getWorld()->getAnimation(target);
|
||||||
if (animation && !absorbStatic->mModel.empty())
|
if (animation && !absorbStatic->mModel.empty())
|
||||||
animation->addEffect( "meshes\\" + absorbStatic->mModel, ESM::MagicEffect::SpellAbsorption, false, std::string());
|
animation->addEffect( "meshes\\" + absorbStatic->mModel, ESM::MagicEffect::SpellAbsorption, false, std::string());
|
||||||
|
const ESM::Spell* spell = esmStore.get<ESM::Spell>().search(spellId);
|
||||||
|
int spellCost = 0;
|
||||||
|
if (spell)
|
||||||
|
{
|
||||||
|
spellCost = spell->mData.mCost;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const ESM::Enchantment* enchantment = esmStore.get<ESM::Enchantment>().search(spellId);
|
||||||
|
if (enchantment)
|
||||||
|
spellCost = getEffectiveEnchantmentCastCost(static_cast<float>(enchantment->mData.mCost), caster);
|
||||||
|
}
|
||||||
|
|
||||||
// Magicka is increased by the cost of the spell
|
// Magicka is increased by the cost of the spell
|
||||||
DynamicStat<float> magicka = stats.getMagicka();
|
DynamicStat<float> magicka = stats.getMagicka();
|
||||||
magicka.setCurrent(magicka.getCurrent() + spell->mData.mCost);
|
magicka.setCurrent(magicka.getCurrent() + spellCost);
|
||||||
stats.setMagicka(magicka);
|
stats.setMagicka(magicka);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
#ifndef MWMECHANICS_SPELLABSORPTION_H
|
#ifndef MWMECHANICS_SPELLABSORPTION_H
|
||||||
#define MWMECHANICS_SPELLABSORPTION_H
|
#define MWMECHANICS_SPELLABSORPTION_H
|
||||||
|
|
||||||
namespace ESM
|
#include <string>
|
||||||
{
|
|
||||||
struct Spell;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace MWWorld
|
namespace MWWorld
|
||||||
{
|
{
|
||||||
|
@ -14,7 +11,7 @@ namespace MWWorld
|
||||||
namespace MWMechanics
|
namespace MWMechanics
|
||||||
{
|
{
|
||||||
// Try to absorb a spell based on the magnitude of every Spell Absorption effect source on the target.
|
// Try to absorb a spell based on the magnitude of every Spell Absorption effect source on the target.
|
||||||
bool absorbSpell(const ESM::Spell* spell, const MWWorld::Ptr& caster, const MWWorld::Ptr& target);
|
bool absorbSpell(const std::string& spellId, const MWWorld::Ptr& caster, const MWWorld::Ptr& target);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -119,7 +119,7 @@ namespace MWMechanics
|
||||||
// effects, we display a "can't re-cast" message
|
// effects, we display a "can't re-cast" message
|
||||||
|
|
||||||
// Try absorbing the spell. Some handling must still happen for absorbed effects.
|
// Try absorbing the spell. Some handling must still happen for absorbed effects.
|
||||||
bool absorbed = absorbSpell(spell, caster, target);
|
bool absorbed = absorbSpell(mId, caster, target);
|
||||||
|
|
||||||
int currentEffectIndex = 0;
|
int currentEffectIndex = 0;
|
||||||
for (std::vector<ESM::ENAMstruct>::const_iterator effectIt (effects.mList.begin());
|
for (std::vector<ESM::ENAMstruct>::const_iterator effectIt (effects.mList.begin());
|
||||||
|
|
Loading…
Reference in a new issue