1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-03-27 05:10:26 +00:00

Merge branch 'awholelottanothing' into 'master'

Don't crash on spells or enchantments without effects

Closes #7712

See merge request OpenMW/openmw!3643
This commit is contained in:
Alexei Kotov 2023-12-11 13:02:51 +00:00
commit ad8392b7d1
7 changed files with 71 additions and 65 deletions

View file

@ -103,6 +103,7 @@
Bug #7665: Alchemy menu is missing the ability to deselect and choose different qualities of an apparatus Bug #7665: Alchemy menu is missing the ability to deselect and choose different qualities of an apparatus
Bug #7675: Successful lock spell doesn't produce a sound Bug #7675: Successful lock spell doesn't produce a sound
Bug #7679: Scene luminance value flashes when toggling shaders Bug #7679: Scene luminance value flashes when toggling shaders
Bug #7712: Casting doesn't support spells and enchantments with no effects
Feature #3537: Shader-based water ripples Feature #3537: Shader-based water ripples
Feature #5492: Let rain and snow collide with statics Feature #5492: Let rain and snow collide with statics
Feature #6149: Dehardcode Lua API_REVISION Feature #6149: Dehardcode Lua API_REVISION

View file

@ -423,18 +423,22 @@ namespace MWGui
mSpellBox->setUserString("Spell", spellId.serialize()); mSpellBox->setUserString("Spell", spellId.serialize());
mSpellBox->setUserData(MyGUI::Any::Null); mSpellBox->setUserData(MyGUI::Any::Null);
if (!spell->mEffects.mList.empty())
{
// use the icon of the first effect // use the icon of the first effect
const ESM::MagicEffect* effect = MWBase::Environment::get().getESMStore()->get<ESM::MagicEffect>().find( const ESM::MagicEffect* effect = MWBase::Environment::get().getESMStore()->get<ESM::MagicEffect>().find(
spell->mEffects.mList.front().mEffectID); spell->mEffects.mList.front().mEffectID);
std::string icon = effect->mIcon; std::string icon = effect->mIcon;
std::replace(icon.begin(), icon.end(), '/', '\\'); std::replace(icon.begin(), icon.end(), '/', '\\');
int slashPos = icon.rfind('\\'); size_t slashPos = icon.rfind('\\');
icon.insert(slashPos + 1, "b_"); icon.insert(slashPos + 1, "b_");
icon = Misc::ResourceHelpers::correctIconPath(icon, MWBase::Environment::get().getResourceSystem()->getVFS()); icon = Misc::ResourceHelpers::correctIconPath(
icon, MWBase::Environment::get().getResourceSystem()->getVFS());
mSpellImage->setSpellIcon(icon); mSpellImage->setSpellIcon(icon);
} }
else
mSpellImage->setSpellIcon({});
}
void HUD::setSelectedEnchantItem(const MWWorld::Ptr& item, int chargePercent) void HUD::setSelectedEnchantItem(const MWWorld::Ptr& item, int chargePercent)
{ {

View file

@ -202,7 +202,7 @@ namespace MWGui
setIcon(ptr); setIcon(ptr);
} }
void SpellWidget::setSpellIcon(const std::string& icon) void SpellWidget::setSpellIcon(std::string_view icon)
{ {
if (mFrame && !mCurrentFrame.empty()) if (mFrame && !mCurrentFrame.empty())
{ {

View file

@ -58,7 +58,7 @@ namespace MWGui
{ {
MYGUI_RTTI_DERIVED(SpellWidget) MYGUI_RTTI_DERIVED(SpellWidget)
public: public:
void setSpellIcon(const std::string& icon); void setSpellIcon(std::string_view icon);
}; };
} }

View file

@ -237,14 +237,16 @@ namespace MWGui
params.mNoTarget = false; params.mNoTarget = false;
effects.push_back(params); effects.push_back(params);
} }
if (MWMechanics::spellIncreasesSkill( // display school of spells that contribute to skill progress
spell)) // display school of spells that contribute to skill progress if (MWMechanics::spellIncreasesSkill(spell))
{ {
MWWorld::Ptr player = MWMechanics::getPlayer(); ESM::RefId id = MWMechanics::getSpellSchool(spell, MWMechanics::getPlayer());
const auto& school if (!id.empty())
= store->get<ESM::Skill>().find(MWMechanics::getSpellSchool(spell, player))->mSchool; {
const auto& school = store->get<ESM::Skill>().find(id)->mSchool;
info.text = "#{sSchool}: " + MyGUI::TextIterator::toTagsString(school->mName).asUTF8(); info.text = "#{sSchool}: " + MyGUI::TextIterator::toTagsString(school->mName).asUTF8();
} }
}
auto cost = focus->getUserString("SpellCost"); auto cost = focus->getUserString("SpellCost");
if (!cost.empty() && cost != "0") if (!cost.empty() && cost != "0")
info.text info.text

View file

@ -1605,6 +1605,8 @@ namespace MWMechanics
effects = &spell->mEffects.mList; effects = &spell->mEffects.mList;
cast.playSpellCastingEffects(spell); cast.playSpellCastingEffects(spell);
} }
if (!effects->empty())
{
if (mCanCast) if (mCanCast)
{ {
const ESM::MagicEffect* effect = store.get<ESM::MagicEffect>().find( const ESM::MagicEffect* effect = store.get<ESM::MagicEffect>().find(
@ -1613,10 +1615,9 @@ namespace MWMechanics
const ESM::Static* castStatic const ESM::Static* castStatic
= world->getStore().get<ESM::Static>().find(ESM::RefId::stringRefId("VFX_Hands")); = world->getStore().get<ESM::Static>().find(ESM::RefId::stringRefId("VFX_Hands"));
const VFS::Manager* const vfs = MWBase::Environment::get().getResourceSystem()->getVFS(); const VFS::Manager* const vfs
= MWBase::Environment::get().getResourceSystem()->getVFS();
if (!effects->empty())
{
if (mAnimation->getNode("Bip01 L Hand")) if (mAnimation->getNode("Bip01 L Hand"))
mAnimation->addEffect( mAnimation->addEffect(
Misc::ResourceHelpers::correctMeshPath(castStatic->mModel, vfs), -1, false, Misc::ResourceHelpers::correctMeshPath(castStatic->mModel, vfs), -1, false,
@ -1627,9 +1628,8 @@ namespace MWMechanics
Misc::ResourceHelpers::correctMeshPath(castStatic->mModel, vfs), -1, false, Misc::ResourceHelpers::correctMeshPath(castStatic->mModel, vfs), -1, false,
"Bip01 R Hand", effect->mParticle); "Bip01 R Hand", effect->mParticle);
} }
} // first effect used for casting animation
const ESM::ENAMstruct& firstEffect = effects->front();
const ESM::ENAMstruct& firstEffect = effects->at(0); // first effect used for casting animation
std::string startKey; std::string startKey;
std::string stopKey; std::string stopKey;
@ -1662,10 +1662,11 @@ namespace MWMechanics
stopKey = mAttackType + " stop"; stopKey = mAttackType + " stop";
} }
mAnimation->play(mCurrentWeapon, priorityWeapon, MWRender::Animation::BlendMask_All, false, 1, mAnimation->play(mCurrentWeapon, priorityWeapon, MWRender::Animation::BlendMask_All, false,
startKey, stopKey, 0.0f, 0); 1, startKey, stopKey, 0.0f, 0);
mUpperBodyState = UpperBodyState::Casting; mUpperBodyState = UpperBodyState::Casting;
} }
}
else else
{ {
resetIdle = false; resetIdle = false;

View file

@ -524,11 +524,9 @@ namespace MWWorld
const ESM::Enchantment* enchantment const ESM::Enchantment* enchantment
= MWBase::Environment::get().getESMStore()->get<ESM::Enchantment>().search(enchantmentName); = MWBase::Environment::get().getESMStore()->get<ESM::Enchantment>().search(enchantmentName);
if (!enchantment) if (!enchantment || enchantment->mEffects.mList.empty())
return result; return result;
assert(enchantment->mEffects.mList.size());
const ESM::MagicEffect* magicEffect = MWBase::Environment::get().getESMStore()->get<ESM::MagicEffect>().search( const ESM::MagicEffect* magicEffect = MWBase::Environment::get().getESMStore()->get<ESM::MagicEffect>().search(
enchantment->mEffects.mList.front().mEffectID); enchantment->mEffects.mList.front().mEffectID);
if (!magicEffect) if (!magicEffect)