1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-20 05:23:51 +00:00

Handle CastOnce enchantments

This commit is contained in:
scrawl 2013-11-09 08:07:40 +01:00
parent 1051611ffa
commit 976344f0a3

View file

@ -2053,6 +2053,9 @@ namespace MWWorld
std::string id = item.getClass().getEnchantment(item);
const ESM::Enchantment* enchantment = getStore().get<ESM::Enchantment>().search (id);
if (enchantment->mData.mType == ESM::Enchantment::WhenUsed)
{
// Check if there's enough charge left
const float enchantCost = enchantment->mData.mCost;
MWMechanics::NpcStats &stats = MWWorld::Class::get(actor).getNpcStats(actor);
@ -2070,10 +2073,24 @@ namespace MWWorld
// 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
}