diff --git a/CHANGELOG.md b/CHANGELOG.md index 81e0c36fff..292d9c8c0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,7 @@ Bug #7415: Unbreakable lock discrepancies Bug #7428: AutoCalc flag is not used to calculate enchantment costs Bug #7459: Icons get stacked on the cursor when picking up multiple items simultaneously + Bug #7472: Crash when enchanting last projectiles Feature #3537: Shader-based water ripples Feature #5492: Let rain and snow collide with statics Feature #6447: Add LOD support to Object Paging diff --git a/apps/openmw/mwgui/enchantingdialog.cpp b/apps/openmw/mwgui/enchantingdialog.cpp index 77bccc374f..33dcf87c48 100644 --- a/apps/openmw/mwgui/enchantingdialog.cpp +++ b/apps/openmw/mwgui/enchantingdialog.cpp @@ -357,9 +357,7 @@ namespace MWGui } } - int result = mEnchanting.create(); - - if (result == 1) + if (mEnchanting.create()) { MWBase::Environment::get().getWindowManager()->playSound(ESM::RefId::stringRefId("enchant success")); MWBase::Environment::get().getWindowManager()->messageBox("#{sEnchantmentMenu12}"); diff --git a/apps/openmw/mwmechanics/enchanting.cpp b/apps/openmw/mwmechanics/enchanting.cpp index f7393874fb..66630d8b90 100644 --- a/apps/openmw/mwmechanics/enchanting.cpp +++ b/apps/openmw/mwmechanics/enchanting.cpp @@ -104,13 +104,13 @@ namespace MWMechanics const ESM::RefId& newItemId = mOldItemPtr.getClass().applyEnchantment(mOldItemPtr, enchantmentPtr->mId, getGemCharge(), mNewItemName); + if (!mSelfEnchanting) + payForEnchantment(count); + // Add the new item to player inventory and remove the old one store.remove(mOldItemPtr, count); store.add(newItemId, count); - if (!mSelfEnchanting) - payForEnchantment(); - return true; } @@ -277,7 +277,7 @@ namespace MWMechanics return getEffectiveEnchantmentCastCost(static_cast(baseCost), player); } - int Enchanting::getEnchantPrice() const + int Enchanting::getEnchantPrice(int count) const { if (mEnchanter.isEmpty()) return 0; @@ -289,7 +289,7 @@ namespace MWMechanics ->mValue.getFloat(); int price = MWBase::Environment::get().getMechanicsManager()->getBarterOffer( mEnchanter, static_cast(getEnchantPoints() * priceMultipler), true); - price *= getEnchantItemsCount() * getTypeMultiplier(); + price *= count * getTypeMultiplier(); return std::max(1, price); } @@ -390,15 +390,16 @@ namespace MWMechanics return 1.f; } - void Enchanting::payForEnchantment() const + void Enchanting::payForEnchantment(int count) const { const MWWorld::Ptr& player = getPlayer(); MWWorld::ContainerStore& store = player.getClass().getContainerStore(player); - store.remove(MWWorld::ContainerStore::sGoldId, getEnchantPrice()); + int price = getEnchantPrice(count); + store.remove(MWWorld::ContainerStore::sGoldId, price); // add gold to NPC trading gold pool CreatureStats& enchanterStats = mEnchanter.getClass().getCreatureStats(mEnchanter); - enchanterStats.setGoldPool(enchanterStats.getGoldPool() + getEnchantPrice()); + enchanterStats.setGoldPool(enchanterStats.getGoldPool() + price); } } diff --git a/apps/openmw/mwmechanics/enchanting.hpp b/apps/openmw/mwmechanics/enchanting.hpp index 53c3fc3f91..5db02b8cba 100644 --- a/apps/openmw/mwmechanics/enchanting.hpp +++ b/apps/openmw/mwmechanics/enchanting.hpp @@ -27,6 +27,11 @@ namespace MWMechanics int mWeaponType; const ESM::Enchantment* getRecord(const ESM::Enchantment& newEnchantment) const; + int getBaseCastCost() const; // To be saved in the enchantment's record + int getEnchantItemsCount() const; + float getTypeMultiplier() const; + void payForEnchantment(int count) const; + int getEnchantPrice(int count) const; public: Enchanting(); @@ -42,18 +47,14 @@ namespace MWMechanics void nextCastStyle(); // Set enchant type to next possible type (for mOldItemPtr object) int getCastStyle() const; float getEnchantPoints(bool precise = true) 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 getEnchantPrice() const { return getEnchantPrice(getEnchantItemsCount()); } int getMaxEnchantValue() const; int getGemCharge() const; int getEnchantChance() const; - int getEnchantItemsCount() const; - float getTypeMultiplier() const; bool soulEmpty() const; // Return true if empty bool itemEmpty() const; // Return true if empty - void payForEnchantment() const; }; } #endif