From 42cc27194b89d9ff2737d96d76c1e3a56590073e Mon Sep 17 00:00:00 2001 From: capostrophic Date: Sat, 4 Jan 2020 16:07:59 +0300 Subject: [PATCH] Fix reported spellcasting discrepancies Make ExplodeSpell behavior closer to Cast behavior (#5242) Nullify on-self absorb spells in a different way (#5241) Allow casting permanent spells through Cast/ExplodeSpell --- CHANGELOG.md | 2 ++ apps/openmw/mwmechanics/spellcasting.cpp | 19 +++++++++++++-- apps/openmw/mwscript/miscextensions.cpp | 31 ++++++++++++++++++------ 3 files changed, 43 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ea093d8f..d4649c46d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -188,6 +188,8 @@ Bug #5226: Reputation should be capped Bug #5229: Crash if mesh controller node has no data node Bug #5239: OpenMW-CS does not support non-ASCII characters in path names + Bug #5241: On-self absorb spells cannot be detected + Bug #5242: ExplodeSpell behavior differs from Cast behavior Feature #1774: Handle AvoidNode Feature #2229: Improve pathfinding AI Feature #3025: Analogue gamepad movement controls diff --git a/apps/openmw/mwmechanics/spellcasting.cpp b/apps/openmw/mwmechanics/spellcasting.cpp index 4598cd75b..5d3b83a62 100644 --- a/apps/openmw/mwmechanics/spellcasting.cpp +++ b/apps/openmw/mwmechanics/spellcasting.cpp @@ -447,9 +447,9 @@ namespace MWMechanics if (!checkEffectTarget(effectIt->mEffectID, target, caster, castByPlayer)) continue; - // caster needs to be an actor that's not the target for linked effects (e.g. Absorb) + // caster needs to be an actor for linked effects (e.g. Absorb) if (magicEffect->mData.mFlags & ESM::MagicEffect::CasterLinked - && (caster.isEmpty() || !caster.getClass().isActor() || caster == target)) + && (caster.isEmpty() || !caster.getClass().isActor())) continue; // If player is healing someone, show the target's HP bar @@ -552,6 +552,20 @@ namespace MWMechanics effect.mArg = MWMechanics::EffectKey(*effectIt).mArg; effect.mMagnitude = magnitude; + // Avoid applying absorb effects if the caster is the target + // We still need the spell to be added + if (caster == target) + { + for (int i=0; i<5; ++i) + { + if (effectIt->mEffectID == ESM::MagicEffect::AbsorbAttribute+i) + { + effect.mMagnitude = 0; + break; + } + } + } + bool hasDuration = !(magicEffect->mData.mFlags & ESM::MagicEffect::NoDuration); if (hasDuration && effectIt->mDuration == 0) { @@ -614,6 +628,7 @@ namespace MWMechanics else caster.getClass().getCreatureStats(caster).getActiveSpells().addSpell("", true, absorbEffects, mSourceName, target.getClass().getCreatureStats(target).getActorId()); + break; } } } diff --git a/apps/openmw/mwscript/miscextensions.cpp b/apps/openmw/mwscript/miscextensions.cpp index 8be3945a9..4f84cfe47 100644 --- a/apps/openmw/mwscript/miscextensions.cpp +++ b/apps/openmw/mwscript/miscextensions.cpp @@ -1109,12 +1109,6 @@ namespace MWScript return; } - if (spell->mData.mType != ESM::Spell::ST_Spell && spell->mData.mType != ESM::Spell::ST_Power) - { - runtime.getContext().report("spellcasting failed: you can only cast spells and powers."); - return; - } - if (ptr == MWMechanics::getPlayer()) { MWWorld::InventoryStore& store = ptr.getClass().getInventoryStore(ptr); @@ -1152,9 +1146,32 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string spell = runtime.getStringLiteral (runtime[0].mInteger); + std::string spellId = runtime.getStringLiteral (runtime[0].mInteger); runtime.pop(); + const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get().search(spellId); + if (!spell) + { + runtime.getContext().report("spellcasting failed: cannot find spell \""+spellId+"\""); + return; + } + + if (ptr == MWMechanics::getPlayer()) + { + MWWorld::InventoryStore& store = ptr.getClass().getInventoryStore(ptr); + store.setSelectedEnchantItem(store.end()); + MWBase::Environment::get().getWindowManager()->setSelectedSpell(spellId, int(MWMechanics::getSpellSuccessChance(spellId, ptr))); + MWBase::Environment::get().getWindowManager()->updateSpellWindow(); + return; + } + + if (ptr.getClass().isActor()) + { + MWMechanics::AiCast castPackage(ptr.getCellRef().getRefId(), spellId, true); + ptr.getClass().getCreatureStats (ptr).getAiSequence().stack(castPackage, ptr); + return; + } + MWMechanics::CastSpell cast(ptr, ptr, false, true); cast.mHitPosition = ptr.getRefData().getPosition().asVec3(); cast.mAlwaysSucceed = true;