Enchanting: fix skill-based cast cost bonus being applied twice

openmw-35
scrawl 10 years ago
parent ef1b0a191b
commit 13c5bd5cc2

@ -111,7 +111,7 @@ namespace MWGui
mCharge->setCaption(boost::lexical_cast<std::string>(mEnchanting.getGemCharge()));
std::stringstream castCost;
castCost << mEnchanting.getCastCost();
castCost << mEnchanting.getEffectiveCastCost();
mCastCost->setCaption(castCost.str());
mPrice->setCaption(boost::lexical_cast<std::string>(mEnchanting.getEnchantPrice()));

@ -103,9 +103,7 @@ namespace MWGui
&& item.getClass().canBeEquipped(item, mActor).first == 0)
continue;
float enchantCost = enchant->mData.mCost;
int eSkill = mActor.getClass().getSkill(mActor, ESM::Skill::Enchant);
int castCost = std::max(1.f, enchantCost - (enchantCost / 100) * (eSkill - 10));
int castCost = MWMechanics::getEffectiveEnchantmentCastCost(enchant->mData.mCost, mActor);
std::string cost = boost::lexical_cast<std::string>(castCost);
int currentCharge = int(item.getCellRef().getEnchantmentCharge());

@ -6,6 +6,7 @@
#include "creaturestats.hpp"
#include "npcstats.hpp"
#include "spellcasting.hpp"
namespace MWMechanics
{
@ -55,7 +56,7 @@ namespace MWMechanics
enchantment.mData.mCharge = getGemCharge();
enchantment.mData.mAutocalc = 0;
enchantment.mData.mType = mCastStyle;
enchantment.mData.mCost = getCastCost();
enchantment.mData.mCost = getBaseCastCost();
store.remove(mSoulGemPtr, 1, player);
@ -199,23 +200,19 @@ namespace MWMechanics
}
int Enchanting::getCastCost() const
int Enchanting::getBaseCastCost() const
{
if (mCastStyle == ESM::Enchantment::ConstantEffect)
return 0;
const float enchantCost = getEnchantPoints();
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr();
MWMechanics::NpcStats &stats = player.getClass().getNpcStats(player);
int eSkill = stats.getSkill(ESM::Skill::Enchant).getModified();
/*
* Each point of enchant skill above/under 10 subtracts/adds
* one percent of enchantment cost while minimum is 1.
*/
const float castCost = enchantCost - (enchantCost / 100) * (eSkill - 10);
return getEnchantPoints();
}
return static_cast<int>((castCost < 1) ? 1 : castCost);
int Enchanting::getEffectiveCastCost() const
{
int baseCost = getBaseCastCost();
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr();
return getEffectiveEnchantmentCastCost(baseCost, player);
}

@ -36,7 +36,8 @@ namespace MWMechanics
void nextCastStyle(); //Set enchant type to next possible type (for mOldItemPtr object)
int getCastStyle() const;
int getEnchantPoints() const;
int getCastCost() const;
int getBaseCastCost() const; // To be saved in the enchantment's record
int getEffectiveCastCost() const; // Effective cost taking player Enchant skill into account, used for preview purposes in the UI
int getEnchantPrice() const;
int getMaxEnchantValue() const;
int getGemCharge() const;

@ -689,9 +689,7 @@ namespace MWMechanics
// Check if there's enough charge left
if (enchantment->mData.mType == ESM::Enchantment::WhenUsed || enchantment->mData.mType == ESM::Enchantment::WhenStrikes)
{
const float enchantCost = enchantment->mData.mCost;
int eSkill = mCaster.getClass().getSkill(mCaster, ESM::Skill::Enchant);
const int castCost = std::max(1.f, enchantCost - (enchantCost / 100) * (eSkill - 10));
const int castCost = getEffectiveEnchantmentCastCost(enchantment->mData.mCost, mCaster);
if (item.getCellRef().getEnchantmentCharge() == -1)
item.getCellRef().setEnchantmentCharge(enchantment->mData.mCharge);
@ -915,4 +913,16 @@ namespace MWMechanics
return true;
}
int getEffectiveEnchantmentCastCost(float castCost, const MWWorld::Ptr &actor)
{
/*
* Each point of enchant skill above/under 10 subtracts/adds
* one percent of enchantment cost while minimum is 1.
*/
int eSkill = actor.getClass().getSkill(actor, ESM::Skill::Enchant);
const float result = castCost - (castCost / 100) * (eSkill - 10);
return static_cast<int>((result < 1) ? 1 : result);
}
}

@ -58,6 +58,8 @@ namespace MWMechanics
float getEffectMultiplier(short effectId, const MWWorld::Ptr& actor, const MWWorld::Ptr& caster,
const ESM::Spell* spell = NULL, const MagicEffects* effects = NULL);
int getEffectiveEnchantmentCastCost (float castCost, const MWWorld::Ptr& actor);
class CastSpell
{
private:

Loading…
Cancel
Save