From 976344f0a352c6904c04a6f13996aa140035b520 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 9 Nov 2013 08:07:40 +0100 Subject: [PATCH] Handle CastOnce enchantments --- apps/openmw/mwworld/worldimp.cpp | 45 ++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 5b7eb7bb1..a91f1e00c 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -2053,27 +2053,44 @@ namespace MWWorld std::string id = item.getClass().getEnchantment(item); const ESM::Enchantment* enchantment = getStore().get().search (id); - // Check if there's enough charge left - const float enchantCost = enchantment->mData.mCost; - MWMechanics::NpcStats &stats = MWWorld::Class::get(actor).getNpcStats(actor); - int eSkill = stats.getSkill(ESM::Skill::Enchant).getModified(); - const float castCost = enchantCost - (enchantCost / 100) * (eSkill - 10); - if (item.getCellRef().mEnchantmentCharge == -1) - item.getCellRef().mEnchantmentCharge = enchantment->mData.mCharge; - - if (item.getCellRef().mEnchantmentCharge < castCost) + if (enchantment->mData.mType == ESM::Enchantment::WhenUsed) { - MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicInsufficientCharge}"); - return; - } + // Check if there's enough charge left + const float enchantCost = enchantment->mData.mCost; + MWMechanics::NpcStats &stats = MWWorld::Class::get(actor).getNpcStats(actor); + int eSkill = stats.getSkill(ESM::Skill::Enchant).getModified(); + const float castCost = enchantCost - (enchantCost / 100) * (eSkill - 10); - // Reduce charge - item.getCellRef().mEnchantmentCharge -= castCost; + if (item.getCellRef().mEnchantmentCharge == -1) + item.getCellRef().mEnchantmentCharge = enchantment->mData.mCharge; + + if (item.getCellRef().mEnchantmentCharge < castCost) + { + MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicInsufficientCharge}"); + return; + } + + // Reduce charge + item.getCellRef().mEnchantmentCharge -= castCost; + } + if (enchantment->mData.mType == ESM::Enchantment::CastOnce) + { + item.getRefData().setCount(item.getRefData().getCount()-1); + } std::string itemName = item.getClass().getName(item); actor.getClass().getCreatureStats(actor).getActiveSpells().addSpell(id, actor, ESM::RT_Self, itemName); + if (!item.getRefData().getCount()) + { + // Item was used up + MWBase::Environment::get().getWindowManager()->unsetSelectedSpell(); + inv.setSelectedEnchantItem(inv.end()); + } + else + MWBase::Environment::get().getWindowManager()->setSelectedEnchantItem(item); // Set again to show the modified charge + // TODO: RT_Range, RT_Touch }