diff --git a/apps/opencs/model/world/nestedcoladapterimp.hpp b/apps/opencs/model/world/nestedcoladapterimp.hpp index bd566c692b..b5a7175630 100644 --- a/apps/opencs/model/world/nestedcoladapterimp.hpp +++ b/apps/opencs/model/world/nestedcoladapterimp.hpp @@ -321,28 +321,32 @@ namespace CSMWorld throw std::runtime_error("index out of range"); ESM::ENAMstruct effect = effectsList[subRowIndex].mData; + bool targetSkill = false, targetAttribute = false; + if (mMagicEffects) + { + int recordIndex = mMagicEffects->searchId(effect.mEffectID); + if (recordIndex != -1) + { + const ESM::MagicEffect& mgef = mMagicEffects->getRecord(recordIndex).get(); + targetSkill = mgef.mData.mFlags & ESM::MagicEffect::TargetSkill; + targetAttribute = mgef.mData.mFlags & ESM::MagicEffect::TargetAttribute; + } + } + switch (subColIndex) { case 0: return ESM::MagicEffect::refIdToIndex(effect.mEffectID); case 1: { - if (effect.mEffectID == ESM::MagicEffect::DrainSkill - || effect.mEffectID == ESM::MagicEffect::DamageSkill - || effect.mEffectID == ESM::MagicEffect::RestoreSkill - || effect.mEffectID == ESM::MagicEffect::FortifySkill - || effect.mEffectID == ESM::MagicEffect::AbsorbSkill) + if (targetSkill) return effect.mSkill; else return QVariant(); } case 2: { - if (effect.mEffectID == ESM::MagicEffect::DrainAttribute - || effect.mEffectID == ESM::MagicEffect::DamageAttribute - || effect.mEffectID == ESM::MagicEffect::RestoreAttribute - || effect.mEffectID == ESM::MagicEffect::FortifyAttribute - || effect.mEffectID == ESM::MagicEffect::AbsorbAttribute) + if (targetAttribute) return effect.mAttribute; else return QVariant(); @@ -372,22 +376,26 @@ namespace CSMWorld throw std::runtime_error("index out of range"); ESM::ENAMstruct effect = effectsList[subRowIndex].mData; + bool targetSkill = false, targetAttribute = false; + switch (subColIndex) { case 0: { effect.mEffectID = ESM::MagicEffect::indexToRefId(value.toInt()); - if (effect.mEffectID == ESM::MagicEffect::DrainSkill - || effect.mEffectID == ESM::MagicEffect::DamageSkill - || effect.mEffectID == ESM::MagicEffect::RestoreSkill - || effect.mEffectID == ESM::MagicEffect::FortifySkill - || effect.mEffectID == ESM::MagicEffect::AbsorbSkill) + if (mMagicEffects) + { + int recordIndex = mMagicEffects->searchId(effect.mEffectID); + if (recordIndex != -1) + { + const ESM::MagicEffect& mgef = mMagicEffects->getRecord(recordIndex).get(); + targetSkill = mgef.mData.mFlags & ESM::MagicEffect::TargetSkill; + targetAttribute = mgef.mData.mFlags & ESM::MagicEffect::TargetAttribute; + } + } + if (targetSkill) effect.mAttribute = -1; - else if (effect.mEffectID == ESM::MagicEffect::DrainAttribute - || effect.mEffectID == ESM::MagicEffect::DamageAttribute - || effect.mEffectID == ESM::MagicEffect::RestoreAttribute - || effect.mEffectID == ESM::MagicEffect::FortifyAttribute - || effect.mEffectID == ESM::MagicEffect::AbsorbAttribute) + else if (targetAttribute) effect.mSkill = -1; else { diff --git a/apps/opencs/model/world/refidadapterimp.cpp b/apps/opencs/model/world/refidadapterimp.cpp index 87093934b3..55d817355f 100644 --- a/apps/opencs/model/world/refidadapterimp.cpp +++ b/apps/opencs/model/world/refidadapterimp.cpp @@ -13,6 +13,7 @@ #include #include +#include "idcollection.hpp" #include "nestedtablewrapper.hpp" CSMWorld::PotionColumns::PotionColumns(const InventoryColumns& columns) @@ -145,6 +146,17 @@ QVariant CSMWorld::IngredEffectRefIdAdapter::getNestedData( throw std::runtime_error("index out of range"); ESM::RefId effectId = record.get().mData.mEffectID[subRowIndex]; + bool targetSkill = false, targetAttribute = false; + if (!effectId.empty() && mMagicEffects) + { + int recordIndex = mMagicEffects->searchId(effectId); + if (recordIndex != -1) + { + const ESM::MagicEffect& mgef = mMagicEffects->getRecord(recordIndex).get(); + targetSkill = mgef.mData.mFlags & ESM::MagicEffect::TargetSkill; + targetAttribute = mgef.mData.mFlags & ESM::MagicEffect::TargetAttribute; + } + } switch (subColIndex) { @@ -152,18 +164,14 @@ QVariant CSMWorld::IngredEffectRefIdAdapter::getNestedData( return ESM::MagicEffect::refIdToIndex(effectId); case 1: { - if (effectId == ESM::MagicEffect::DrainSkill || effectId == ESM::MagicEffect::DamageSkill - || effectId == ESM::MagicEffect::RestoreSkill || effectId == ESM::MagicEffect::FortifySkill - || effectId == ESM::MagicEffect::AbsorbSkill) + if (targetSkill) return record.get().mData.mSkills[subRowIndex]; else return QVariant(); } case 2: { - if (effectId == ESM::MagicEffect::DrainAttribute || effectId == ESM::MagicEffect::DamageAttribute - || effectId == ESM::MagicEffect::RestoreAttribute || effectId == ESM::MagicEffect::FortifyAttribute - || effectId == ESM::MagicEffect::AbsorbAttribute) + if (targetAttribute) return record.get().mData.mAttributes[subRowIndex]; else return QVariant(); @@ -184,18 +192,26 @@ void CSMWorld::IngredEffectRefIdAdapter::setNestedData( throw std::runtime_error("index out of range"); ESM::RefId effectId = ESM::MagicEffect::indexToRefId(value.toInt()); + bool targetSkill = false, targetAttribute = false; switch (subColIndex) { case 0: ingredient.mData.mEffectID[subRowIndex] = effectId; - if (effectId == ESM::MagicEffect::DrainSkill || effectId == ESM::MagicEffect::DamageSkill - || effectId == ESM::MagicEffect::RestoreSkill || effectId == ESM::MagicEffect::FortifySkill - || effectId == ESM::MagicEffect::AbsorbSkill) + if (!effectId.empty() && mMagicEffects) + { + int recordIndex = mMagicEffects->searchId(effectId); + if (recordIndex != -1) + { + const ESM::MagicEffect& mgef = mMagicEffects->getRecord(recordIndex).get(); + targetSkill = mgef.mData.mFlags & ESM::MagicEffect::TargetSkill; + targetAttribute = mgef.mData.mFlags & ESM::MagicEffect::TargetAttribute; + } + } + + if (targetSkill) ingredient.mData.mAttributes[subRowIndex] = -1; - else if (effectId == ESM::MagicEffect::DrainAttribute || effectId == ESM::MagicEffect::DamageAttribute - || effectId == ESM::MagicEffect::RestoreAttribute || effectId == ESM::MagicEffect::FortifyAttribute - || effectId == ESM::MagicEffect::AbsorbAttribute) + else if (targetAttribute) ingredient.mData.mSkills[subRowIndex] = -1; else { diff --git a/apps/openmw/mwgui/widgets.cpp b/apps/openmw/mwgui/widgets.cpp index a4ca75d21d..34a56adcc5 100644 --- a/apps/openmw/mwgui/widgets.cpp +++ b/apps/openmw/mwgui/widgets.cpp @@ -25,6 +25,24 @@ namespace MWGui::Widgets { + /* SpellEffectParams */ + + bool SpellEffectParams::operator==(const SpellEffectParams& other) const + { + if (mEffectID != other.mEffectID) + return false; + if (mEffectID.empty()) + return true; + + const ESM::MagicEffect* mgef + = MWBase::Environment::get().getESMStore()->get().find(mEffectID); + bool involvesSkill = mgef->mData.mFlags & ESM::MagicEffect::TargetSkill; + bool involvesAttribute = mgef->mData.mFlags & ESM::MagicEffect::TargetAttribute; + + return ((other.mSkill == mSkill) || !involvesSkill) && ((other.mAttribute == mAttribute) && !involvesAttribute) + && (other.mArea == mArea); + } + /* MWSkill */ MWSkill::MWSkill() diff --git a/apps/openmw/mwgui/widgets.hpp b/apps/openmw/mwgui/widgets.hpp index b45eb531f1..e63e46ee2b 100644 --- a/apps/openmw/mwgui/widgets.hpp +++ b/apps/openmw/mwgui/widgets.hpp @@ -64,21 +64,7 @@ namespace MWGui // value of 0 -> no area effect int mArea; - bool operator==(const SpellEffectParams& other) const - { - if (mEffectID != other.mEffectID) - return false; - - bool involvesAttribute = (mEffectID == ESM::MagicEffect::RestoreAttribute - || mEffectID == ESM::MagicEffect::AbsorbAttribute || mEffectID == ESM::MagicEffect::DrainAttribute - || mEffectID == ESM::MagicEffect::FortifyAttribute - || mEffectID == ESM::MagicEffect::DamageAttribute); - bool involvesSkill = (mEffectID == ESM::MagicEffect::RestoreSkill - || mEffectID == ESM::MagicEffect::AbsorbSkill || mEffectID == ESM::MagicEffect::DrainSkill - || mEffectID == ESM::MagicEffect::FortifySkill || mEffectID == ESM::MagicEffect::DamageSkill); - return ((other.mSkill == mSkill) || !involvesSkill) - && ((other.mAttribute == mAttribute) && !involvesAttribute) && (other.mArea == mArea); - } + bool operator==(const SpellEffectParams& other) const; }; typedef std::vector SpellEffectList;