mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-03 17:15:35 +00:00
Handle CastOnce enchantments
This commit is contained in:
parent
1051611ffa
commit
976344f0a3
1 changed files with 31 additions and 14 deletions
|
@ -2053,27 +2053,44 @@ namespace MWWorld
|
||||||
std::string id = item.getClass().getEnchantment(item);
|
std::string id = item.getClass().getEnchantment(item);
|
||||||
const ESM::Enchantment* enchantment = getStore().get<ESM::Enchantment>().search (id);
|
const ESM::Enchantment* enchantment = getStore().get<ESM::Enchantment>().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)
|
if (enchantment->mData.mType == ESM::Enchantment::WhenUsed)
|
||||||
item.getCellRef().mEnchantmentCharge = enchantment->mData.mCharge;
|
|
||||||
|
|
||||||
if (item.getCellRef().mEnchantmentCharge < castCost)
|
|
||||||
{
|
{
|
||||||
MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicInsufficientCharge}");
|
// Check if there's enough charge left
|
||||||
return;
|
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
|
if (item.getCellRef().mEnchantmentCharge == -1)
|
||||||
item.getCellRef().mEnchantmentCharge -= castCost;
|
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);
|
std::string itemName = item.getClass().getName(item);
|
||||||
actor.getClass().getCreatureStats(actor).getActiveSpells().addSpell(id, actor, ESM::RT_Self, itemName);
|
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
|
// TODO: RT_Range, RT_Touch
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue