mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-03-03 13:19:40 +00:00
Add instant spell effects to the actor's magic effect list
Via http://forum.openmw.org/viewtopic.php?f=2&t=3212&start=20#p36208
This commit is contained in:
parent
d6bcb7906d
commit
689dea4cb3
3 changed files with 46 additions and 40 deletions
|
@ -497,7 +497,12 @@ namespace MWMechanics
|
||||||
if (it->second.getMagnitude() > 0)
|
if (it->second.getMagnitude() > 0)
|
||||||
{
|
{
|
||||||
CastSpell cast(ptr, ptr);
|
CastSpell cast(ptr, ptr);
|
||||||
cast.applyInstantEffect(ptr, ptr, it->first, it->second.getMagnitude());
|
if (cast.applyInstantEffect(ptr, ptr, it->first, it->second.getMagnitude()))
|
||||||
|
{
|
||||||
|
creatureStats.getActiveSpells().purgeEffect(it->first.mId);
|
||||||
|
if (ptr.getClass().hasInventoryStore(ptr))
|
||||||
|
ptr.getClass().getInventoryStore(ptr).purgeEffect(it->first.mId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -452,42 +452,18 @@ namespace MWMechanics
|
||||||
float magnitude = effectIt->mMagnMin + (effectIt->mMagnMax - effectIt->mMagnMin) * random;
|
float magnitude = effectIt->mMagnMin + (effectIt->mMagnMax - effectIt->mMagnMin) * random;
|
||||||
magnitude *= magnitudeMult;
|
magnitude *= magnitudeMult;
|
||||||
|
|
||||||
bool hasDuration = !(magicEffect->mData.mFlags & ESM::MagicEffect::NoDuration);
|
if (!target.getClass().isActor())
|
||||||
if (target.getClass().isActor() && hasDuration && effectIt->mDuration > 0)
|
|
||||||
{
|
{
|
||||||
ActiveSpells::ActiveEffect effect;
|
// non-actor objects have no list of active magic effects, so have to apply instantly
|
||||||
effect.mEffectId = effectIt->mEffectID;
|
if (!applyInstantEffect(target, caster, EffectKey(*effectIt), magnitude))
|
||||||
effect.mArg = MWMechanics::EffectKey(*effectIt).mArg;
|
continue;
|
||||||
effect.mDuration = static_cast<float>(effectIt->mDuration);
|
|
||||||
effect.mMagnitude = magnitude;
|
|
||||||
|
|
||||||
targetEffects.add(MWMechanics::EffectKey(*effectIt), MWMechanics::EffectParam(effect.mMagnitude));
|
|
||||||
|
|
||||||
appliedLastingEffects.push_back(effect);
|
|
||||||
|
|
||||||
// For absorb effects, also apply the effect to the caster - but with a negative
|
|
||||||
// magnitude, since we're transfering stats from the target to the caster
|
|
||||||
if (!caster.isEmpty() && caster.getClass().isActor())
|
|
||||||
{
|
|
||||||
for (int i=0; i<5; ++i)
|
|
||||||
{
|
|
||||||
if (effectIt->mEffectID == ESM::MagicEffect::AbsorbAttribute+i)
|
|
||||||
{
|
|
||||||
std::vector<ActiveSpells::ActiveEffect> effects;
|
|
||||||
ActiveSpells::ActiveEffect effect_ = effect;
|
|
||||||
effect_.mMagnitude *= -1;
|
|
||||||
effects.push_back(effect_);
|
|
||||||
// Also make sure to set casterActorId = target, so that the effect on the caster gets purged when the target dies
|
|
||||||
caster.getClass().getCreatureStats(caster).getActiveSpells().addSpell("", true,
|
|
||||||
effects, mSourceName, target.getClass().getCreatureStats(target).getActorId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else // target.getClass().isActor() == true
|
||||||
{
|
{
|
||||||
if (hasDuration && target.getClass().isActor())
|
bool hasDuration = !(magicEffect->mData.mFlags & ESM::MagicEffect::NoDuration);
|
||||||
|
if (hasDuration && effectIt->mDuration == 0)
|
||||||
{
|
{
|
||||||
|
// duration 0 means apply full magnitude instantly
|
||||||
bool wasDead = target.getClass().getCreatureStats(target).isDead();
|
bool wasDead = target.getClass().getCreatureStats(target).isDead();
|
||||||
effectTick(target.getClass().getCreatureStats(target), target, EffectKey(*effectIt), magnitude);
|
effectTick(target.getClass().getCreatureStats(target), target, EffectKey(*effectIt), magnitude);
|
||||||
bool isDead = target.getClass().getCreatureStats(target).isDead();
|
bool isDead = target.getClass().getCreatureStats(target).isDead();
|
||||||
|
@ -495,8 +471,38 @@ namespace MWMechanics
|
||||||
if (!wasDead && isDead)
|
if (!wasDead && isDead)
|
||||||
MWBase::Environment::get().getMechanicsManager()->actorKilled(target, caster);
|
MWBase::Environment::get().getMechanicsManager()->actorKilled(target, caster);
|
||||||
}
|
}
|
||||||
else if (!applyInstantEffect(target, caster, EffectKey(*effectIt), magnitude))
|
else
|
||||||
continue;
|
{
|
||||||
|
// add to list of active effects, to apply in next frame
|
||||||
|
ActiveSpells::ActiveEffect effect;
|
||||||
|
effect.mEffectId = effectIt->mEffectID;
|
||||||
|
effect.mArg = MWMechanics::EffectKey(*effectIt).mArg;
|
||||||
|
effect.mDuration = static_cast<float>(effectIt->mDuration);
|
||||||
|
effect.mMagnitude = magnitude;
|
||||||
|
|
||||||
|
targetEffects.add(MWMechanics::EffectKey(*effectIt), MWMechanics::EffectParam(effect.mMagnitude));
|
||||||
|
|
||||||
|
appliedLastingEffects.push_back(effect);
|
||||||
|
|
||||||
|
// For absorb effects, also apply the effect to the caster - but with a negative
|
||||||
|
// magnitude, since we're transfering stats from the target to the caster
|
||||||
|
if (!caster.isEmpty() && caster.getClass().isActor())
|
||||||
|
{
|
||||||
|
for (int i=0; i<5; ++i)
|
||||||
|
{
|
||||||
|
if (effectIt->mEffectID == ESM::MagicEffect::AbsorbAttribute+i)
|
||||||
|
{
|
||||||
|
std::vector<ActiveSpells::ActiveEffect> effects;
|
||||||
|
ActiveSpells::ActiveEffect effect_ = effect;
|
||||||
|
effect_.mMagnitude *= -1;
|
||||||
|
effects.push_back(effect_);
|
||||||
|
// Also make sure to set casterActorId = target, so that the effect on the caster gets purged when the target dies
|
||||||
|
caster.getClass().getCreatureStats(caster).getActiveSpells().addSpell("", true,
|
||||||
|
effects, mSourceName, target.getClass().getCreatureStats(target).getActorId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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.
|
||||||
|
|
|
@ -410,11 +410,6 @@ void MWWorld::InventoryStore::updateMagicEffects(const Ptr& actor)
|
||||||
// the items should appear as if they'd always been equipped.
|
// the items should appear as if they'd always been equipped.
|
||||||
mListener->permanentEffectAdded(magicEffect, !mFirstAutoEquip,
|
mListener->permanentEffectAdded(magicEffect, !mFirstAutoEquip,
|
||||||
!mFirstAutoEquip && effectIt == enchantment.mEffects.mList.begin());
|
!mFirstAutoEquip && effectIt == enchantment.mEffects.mList.begin());
|
||||||
|
|
||||||
// Apply instant effects
|
|
||||||
MWMechanics::CastSpell cast(actor, actor);
|
|
||||||
if (magnitude)
|
|
||||||
cast.applyInstantEffect(actor, actor, effectIt->mEffectID, magnitude);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (magnitude)
|
if (magnitude)
|
||||||
|
|
Loading…
Reference in a new issue