mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-03-30 16:20:21 +00:00
Cast spell even if target Ptr is empty. It happens when enchanted arrows
hit water or ground.
This commit is contained in:
parent
c7f8a4faae
commit
7d0483d7ad
@ -60,10 +60,8 @@ namespace MWMechanics
|
|||||||
void CastSpell::inflict(const MWWorld::Ptr &target, const MWWorld::Ptr &caster,
|
void CastSpell::inflict(const MWWorld::Ptr &target, const MWWorld::Ptr &caster,
|
||||||
const ESM::EffectList &effects, ESM::RangeType range, bool reflected, bool exploded)
|
const ESM::EffectList &effects, ESM::RangeType range, bool reflected, bool exploded)
|
||||||
{
|
{
|
||||||
if (target.isEmpty())
|
const bool targetIsActor = !target.isEmpty() && target.getClass().isActor();
|
||||||
return;
|
if (targetIsActor)
|
||||||
|
|
||||||
if (target.getClass().isActor())
|
|
||||||
{
|
{
|
||||||
// Early-out for characters that have departed.
|
// Early-out for characters that have departed.
|
||||||
const auto& stats = target.getClass().getCreatureStats(target);
|
const auto& stats = target.getClass().getCreatureStats(target);
|
||||||
@ -85,7 +83,7 @@ namespace MWMechanics
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().search (mId);
|
const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().search (mId);
|
||||||
if (spell && target.getClass().isActor() && (spell->mData.mType == ESM::Spell::ST_Disease || spell->mData.mType == ESM::Spell::ST_Blight))
|
if (spell && targetIsActor && (spell->mData.mType == ESM::Spell::ST_Disease || spell->mData.mType == ESM::Spell::ST_Blight))
|
||||||
{
|
{
|
||||||
int requiredResistance = (spell->mData.mType == ESM::Spell::ST_Disease) ?
|
int requiredResistance = (spell->mData.mType == ESM::Spell::ST_Disease) ?
|
||||||
ESM::MagicEffect::ResistCommonDisease
|
ESM::MagicEffect::ResistCommonDisease
|
||||||
@ -108,13 +106,13 @@ namespace MWMechanics
|
|||||||
// This is required for Weakness effects in a spell to apply to any subsequent effects in the spell.
|
// This is required for Weakness effects in a spell to apply to any subsequent effects in the spell.
|
||||||
// Otherwise, they'd only apply after the whole spell was added.
|
// Otherwise, they'd only apply after the whole spell was added.
|
||||||
MagicEffects targetEffects;
|
MagicEffects targetEffects;
|
||||||
if (target.getClass().isActor())
|
if (targetIsActor)
|
||||||
targetEffects += target.getClass().getCreatureStats(target).getMagicEffects();
|
targetEffects += target.getClass().getCreatureStats(target).getMagicEffects();
|
||||||
|
|
||||||
bool castByPlayer = (!caster.isEmpty() && caster == getPlayer());
|
bool castByPlayer = (!caster.isEmpty() && caster == getPlayer());
|
||||||
|
|
||||||
ActiveSpells targetSpells;
|
ActiveSpells targetSpells;
|
||||||
if (target.getClass().isActor())
|
if (targetIsActor)
|
||||||
targetSpells = target.getClass().getCreatureStats(target).getActiveSpells();
|
targetSpells = target.getClass().getCreatureStats(target).getActiveSpells();
|
||||||
|
|
||||||
bool canCastAnEffect = false; // For bound equipment.If this remains false
|
bool canCastAnEffect = false; // For bound equipment.If this remains false
|
||||||
@ -126,7 +124,7 @@ namespace MWMechanics
|
|||||||
|
|
||||||
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());
|
||||||
effectIt != effects.mList.end(); ++effectIt, ++currentEffectIndex)
|
!target.isEmpty() && effectIt != effects.mList.end(); ++effectIt, ++currentEffectIndex)
|
||||||
{
|
{
|
||||||
if (effectIt->mRange != range)
|
if (effectIt->mRange != range)
|
||||||
continue;
|
continue;
|
||||||
@ -270,7 +268,7 @@ namespace MWMechanics
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Re-casting a summon effect will remove the creature from previous castings of that effect.
|
// Re-casting a summon effect will remove the creature from previous castings of that effect.
|
||||||
if (isSummoningEffect(effectIt->mEffectID) && target.getClass().isActor())
|
if (isSummoningEffect(effectIt->mEffectID) && targetIsActor)
|
||||||
{
|
{
|
||||||
CreatureStats& targetStats = target.getClass().getCreatureStats(target);
|
CreatureStats& targetStats = target.getClass().getCreatureStats(target);
|
||||||
ESM::SummonKey key(effectIt->mEffectID, mId, currentEffectIndex);
|
ESM::SummonKey key(effectIt->mEffectID, mId, currentEffectIndex);
|
||||||
@ -313,16 +311,19 @@ namespace MWMechanics
|
|||||||
if (!exploded)
|
if (!exploded)
|
||||||
MWBase::Environment::get().getWorld()->explodeSpell(mHitPosition, effects, caster, target, range, mId, mSourceName, mFromProjectile);
|
MWBase::Environment::get().getWorld()->explodeSpell(mHitPosition, effects, caster, target, range, mId, mSourceName, mFromProjectile);
|
||||||
|
|
||||||
if (!reflectedEffects.mList.empty())
|
if (!target.isEmpty())
|
||||||
inflict(caster, target, reflectedEffects, range, true, exploded);
|
|
||||||
|
|
||||||
if (!appliedLastingEffects.empty())
|
|
||||||
{
|
{
|
||||||
int casterActorId = -1;
|
if (!reflectedEffects.mList.empty())
|
||||||
if (!caster.isEmpty() && caster.getClass().isActor())
|
inflict(caster, target, reflectedEffects, range, true, exploded);
|
||||||
casterActorId = caster.getClass().getCreatureStats(caster).getActorId();
|
|
||||||
target.getClass().getCreatureStats(target).getActiveSpells().addSpell(mId, mStack, appliedLastingEffects,
|
if (!appliedLastingEffects.empty())
|
||||||
mSourceName, casterActorId);
|
{
|
||||||
|
int casterActorId = -1;
|
||||||
|
if (!caster.isEmpty() && caster.getClass().isActor())
|
||||||
|
casterActorId = caster.getClass().getCreatureStats(caster).getActorId();
|
||||||
|
target.getClass().getCreatureStats(target).getActiveSpells().addSpell(mId, mStack, appliedLastingEffects,
|
||||||
|
mSourceName, casterActorId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user