2013-03-28 17:41:00 +01:00
|
|
|
#include "enchanting.hpp"
|
2015-03-15 14:07:47 +13:00
|
|
|
|
2022-09-05 19:35:15 +02:00
|
|
|
#include <components/esm3/loadcrea.hpp>
|
|
|
|
#include <components/esm3/loadmgef.hpp>
|
2015-04-22 17:58:55 +02:00
|
|
|
#include <components/misc/rng.hpp>
|
2023-06-27 23:41:06 +02:00
|
|
|
#include <components/settings/values.hpp>
|
2015-03-15 14:07:47 +13:00
|
|
|
|
2013-03-28 17:41:00 +01:00
|
|
|
#include "../mwworld/class.hpp"
|
|
|
|
#include "../mwworld/containerstore.hpp"
|
2015-02-09 15:01:49 +01:00
|
|
|
#include "../mwworld/esmstore.hpp"
|
2016-06-17 23:07:16 +09:00
|
|
|
|
2019-02-19 01:10:55 +03:00
|
|
|
#include "../mwbase/environment.hpp"
|
2013-04-02 20:46:48 +02:00
|
|
|
#include "../mwbase/mechanicsmanager.hpp"
|
2019-02-19 01:10:55 +03:00
|
|
|
#include "../mwbase/world.hpp"
|
2013-03-30 19:08:42 +01:00
|
|
|
|
2015-08-21 21:12:39 +12:00
|
|
|
#include "actorutil.hpp"
|
2013-03-30 19:08:42 +01:00
|
|
|
#include "creaturestats.hpp"
|
2020-04-26 20:46:51 +03:00
|
|
|
#include "spellutil.hpp"
|
2019-10-20 13:30:52 +03:00
|
|
|
#include "weapontype.hpp"
|
2013-03-30 19:08:42 +01:00
|
|
|
|
2013-03-28 17:41:00 +01:00
|
|
|
namespace MWMechanics
|
|
|
|
{
|
2013-07-31 18:46:32 +02:00
|
|
|
Enchanting::Enchanting()
|
|
|
|
: mCastStyle(ESM::Enchantment::CastOnce)
|
|
|
|
, mSelfEnchanting(false)
|
2021-10-18 22:11:48 +02:00
|
|
|
, mObjectType(0)
|
2019-11-13 14:47:29 +04:00
|
|
|
, mWeaponType(-1)
|
2013-03-28 17:41:00 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-04-20 20:36:14 +09:00
|
|
|
void Enchanting::setOldItem(const MWWorld::Ptr& oldItem)
|
2013-03-28 17:41:00 +01:00
|
|
|
{
|
|
|
|
mOldItemPtr = oldItem;
|
2019-10-20 13:30:52 +03:00
|
|
|
mWeaponType = -1;
|
2021-10-11 11:46:21 +00:00
|
|
|
mObjectType = 0;
|
2013-03-28 17:41:00 +01:00
|
|
|
if (!itemEmpty())
|
|
|
|
{
|
2021-10-11 11:46:21 +00:00
|
|
|
mObjectType = mOldItemPtr.getType();
|
|
|
|
if (mObjectType == ESM::Weapon::sRecordId)
|
2019-10-20 13:30:52 +03:00
|
|
|
mWeaponType = mOldItemPtr.get<ESM::Weapon>()->mBase->mData.mType;
|
2013-03-28 17:41:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-01 17:12:47 +02:00
|
|
|
void Enchanting::setNewItemName(const std::string& s)
|
2013-03-28 17:41:00 +01:00
|
|
|
{
|
|
|
|
mNewItemName = s;
|
|
|
|
}
|
|
|
|
|
2017-04-20 20:36:14 +09:00
|
|
|
void Enchanting::setEffect(const ESM::EffectList& effectList)
|
2013-03-28 17:41:00 +01:00
|
|
|
{
|
|
|
|
mEffectList = effectList;
|
|
|
|
}
|
|
|
|
|
2013-05-27 14:42:08 +02:00
|
|
|
int Enchanting::getCastStyle() const
|
2013-03-28 17:41:00 +01:00
|
|
|
{
|
2013-05-27 14:42:08 +02:00
|
|
|
return mCastStyle;
|
2013-03-28 17:41:00 +01:00
|
|
|
}
|
|
|
|
|
2017-04-20 20:36:14 +09:00
|
|
|
void Enchanting::setSoulGem(const MWWorld::Ptr& soulGem)
|
2013-03-28 17:41:00 +01:00
|
|
|
{
|
|
|
|
mSoulGemPtr = soulGem;
|
|
|
|
}
|
|
|
|
|
2013-04-01 17:12:47 +02:00
|
|
|
bool Enchanting::create()
|
2013-03-28 17:41:00 +01:00
|
|
|
{
|
2015-08-21 21:12:39 +12:00
|
|
|
const MWWorld::Ptr& player = getPlayer();
|
2014-05-22 20:37:22 +02:00
|
|
|
MWWorld::ContainerStore& store = player.getClass().getContainerStore(player);
|
2013-04-01 17:12:47 +02:00
|
|
|
ESM::Enchantment enchantment;
|
2020-04-11 00:02:12 +03:00
|
|
|
enchantment.mData.mFlags = 0;
|
2014-10-02 00:32:22 +02:00
|
|
|
enchantment.mData.mType = mCastStyle;
|
2015-01-07 04:28:56 +01:00
|
|
|
enchantment.mData.mCost = getBaseCastCost();
|
2023-07-28 14:01:40 +04:00
|
|
|
enchantment.mRecordFlags = 0;
|
2013-04-02 22:23:38 +02:00
|
|
|
|
2023-01-16 23:51:04 +01:00
|
|
|
store.remove(mSoulGemPtr, 1);
|
2013-04-08 17:53:41 +02:00
|
|
|
|
|
|
|
// Exception for Azura Star, new one will be added after enchanting
|
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type
The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID
Slowly going through all the changes to make, still hundreds of errors
a lot of functions/structures use std::string or stringview to designate an ID. So it takes time
Continues slowly replacing ids. There are technically more and more compilation errors
I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type
Continue moving forward, changes to the stores
slowly moving along
Starting to see the fruit of those changes.
still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type.
More replacements. Things are starting to get easier
I can see more and more often the issue is that the function is awaiting a RefId, but is given a string
there is less need to go down functions and to fix a long list of them.
Still moving forward, and for the first time error count is going down!
Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably
Cells are back to using string for the name, haven't fixed everything yet. Many other changes
Under the bar of 400 compilation errors.
more good progress <100 compile errors!
More progress
Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string
some more progress on other fronts
Mostly game settings clean
one error opened a lot of other errors. Down to 18, but more will prbably appear
only link errors left??
Fixed link errors
OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
|
|
|
auto azurasStarId = ESM::RefId::stringRefId("Misc_SoulGem_Azura");
|
2022-10-18 09:26:55 +02:00
|
|
|
if (mSoulGemPtr.get<ESM::Miscellaneous>()->mBase->mId == azurasStarId)
|
2023-01-16 23:51:04 +01:00
|
|
|
store.add(azurasStarId, 1);
|
2013-03-29 12:00:09 +01:00
|
|
|
|
2013-03-30 19:08:42 +01:00
|
|
|
if (mSelfEnchanting)
|
|
|
|
{
|
2022-03-06 21:56:02 +02:00
|
|
|
auto& prng = MWBase::Environment::get().getWorld()->getPrng();
|
|
|
|
if (getEnchantChance() <= (Misc::Rng::roll0to99(prng)))
|
2013-04-01 17:12:47 +02:00
|
|
|
return false;
|
2013-03-30 19:08:42 +01:00
|
|
|
|
2014-05-22 20:37:22 +02:00
|
|
|
mEnchanter.getClass().skillUsageSucceeded(mEnchanter, ESM::Skill::Enchant, 2);
|
2013-03-30 19:08:42 +01:00
|
|
|
}
|
|
|
|
|
2013-04-01 17:12:47 +02:00
|
|
|
enchantment.mEffects = mEffectList;
|
2013-03-31 23:18:23 +02:00
|
|
|
|
2019-12-27 11:21:19 +04:00
|
|
|
int count = getEnchantItemsCount();
|
|
|
|
|
|
|
|
if (mCastStyle == ESM::Enchantment::ConstantEffect)
|
|
|
|
enchantment.mData.mCharge = 0;
|
|
|
|
else
|
|
|
|
enchantment.mData.mCharge = getGemCharge() / count;
|
|
|
|
|
|
|
|
// Try to find a dynamic enchantment with the same stats, create a new one if not found.
|
|
|
|
const ESM::Enchantment* enchantmentPtr = getRecord(enchantment);
|
|
|
|
if (enchantmentPtr == nullptr)
|
2023-04-20 21:07:53 +02:00
|
|
|
enchantmentPtr = MWBase::Environment::get().getESMStore()->insert(enchantment);
|
2019-12-27 11:21:19 +04:00
|
|
|
|
2013-08-13 01:19:33 +02:00
|
|
|
// Apply the enchantment
|
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type
The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID
Slowly going through all the changes to make, still hundreds of errors
a lot of functions/structures use std::string or stringview to designate an ID. So it takes time
Continues slowly replacing ids. There are technically more and more compilation errors
I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type
Continue moving forward, changes to the stores
slowly moving along
Starting to see the fruit of those changes.
still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type.
More replacements. Things are starting to get easier
I can see more and more often the issue is that the function is awaiting a RefId, but is given a string
there is less need to go down functions and to fix a long list of them.
Still moving forward, and for the first time error count is going down!
Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably
Cells are back to using string for the name, haven't fixed everything yet. Many other changes
Under the bar of 400 compilation errors.
more good progress <100 compile errors!
More progress
Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string
some more progress on other fronts
Mostly game settings clean
one error opened a lot of other errors. Down to 18, but more will prbably appear
only link errors left??
Fixed link errors
OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
|
|
|
const ESM::RefId& newItemId
|
2022-08-22 16:55:53 +02:00
|
|
|
= mOldItemPtr.getClass().applyEnchantment(mOldItemPtr, enchantmentPtr->mId, getGemCharge(), mNewItemName);
|
2013-03-31 23:18:23 +02:00
|
|
|
|
2023-07-14 17:06:33 +02:00
|
|
|
if (!mSelfEnchanting)
|
|
|
|
payForEnchantment(count);
|
|
|
|
|
2013-08-13 01:19:33 +02:00
|
|
|
// Add the new item to player inventory and remove the old one
|
2023-01-16 23:51:04 +01:00
|
|
|
store.remove(mOldItemPtr, count);
|
|
|
|
store.add(newItemId, count);
|
2013-04-02 20:46:48 +02:00
|
|
|
|
2013-04-01 17:12:47 +02:00
|
|
|
return true;
|
2013-03-28 17:41:00 +01:00
|
|
|
}
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2013-05-27 14:42:08 +02:00
|
|
|
void Enchanting::nextCastStyle()
|
2013-03-28 17:41:00 +01:00
|
|
|
{
|
|
|
|
if (itemEmpty())
|
|
|
|
return;
|
2013-05-27 16:08:58 +02:00
|
|
|
|
|
|
|
const bool powerfulSoul = getGemCharge() >= MWBase::Environment::get()
|
2023-04-20 21:07:53 +02:00
|
|
|
.getESMStore()
|
|
|
|
->get<ESM::GameSetting>()
|
2018-08-29 18:38:12 +03:00
|
|
|
.find("iSoulAmountForConstantEffect")
|
|
|
|
->mValue.getInteger();
|
2021-10-11 11:46:21 +00:00
|
|
|
if ((mObjectType == ESM::Armor::sRecordId) || (mObjectType == ESM::Clothing::sRecordId))
|
2013-05-27 16:08:58 +02:00
|
|
|
{ // Armor or Clothing
|
2013-05-27 14:42:08 +02:00
|
|
|
switch (mCastStyle)
|
2013-03-28 17:41:00 +01:00
|
|
|
{
|
2013-05-29 00:01:18 +02:00
|
|
|
case ESM::Enchantment::WhenUsed:
|
2013-05-27 16:08:58 +02:00
|
|
|
if (powerfulSoul)
|
2013-05-29 00:01:18 +02:00
|
|
|
mCastStyle = ESM::Enchantment::ConstantEffect;
|
2013-05-27 16:08:58 +02:00
|
|
|
return;
|
|
|
|
default: // takes care of Constant effect too
|
2013-05-29 00:01:18 +02:00
|
|
|
mCastStyle = ESM::Enchantment::WhenUsed;
|
2013-05-27 16:08:58 +02:00
|
|
|
return;
|
2013-03-28 17:41:00 +01:00
|
|
|
}
|
|
|
|
}
|
2019-10-20 13:30:52 +03:00
|
|
|
else if (mWeaponType != -1)
|
2013-05-27 16:08:58 +02:00
|
|
|
{ // Weapon
|
2019-12-27 11:21:19 +04:00
|
|
|
ESM::WeaponType::Class weapclass = MWMechanics::getWeaponType(mWeaponType)->mWeaponClass;
|
2013-05-27 14:42:08 +02:00
|
|
|
switch (mCastStyle)
|
2013-03-28 17:41:00 +01:00
|
|
|
{
|
2013-05-29 00:01:18 +02:00
|
|
|
case ESM::Enchantment::WhenStrikes:
|
2019-12-27 11:21:19 +04:00
|
|
|
if (weapclass == ESM::WeaponType::Melee || weapclass == ESM::WeaponType::Ranged)
|
|
|
|
mCastStyle = ESM::Enchantment::WhenUsed;
|
2013-05-27 20:47:53 +02:00
|
|
|
return;
|
2013-05-29 00:01:18 +02:00
|
|
|
case ESM::Enchantment::WhenUsed:
|
2019-12-27 11:21:19 +04:00
|
|
|
if (powerfulSoul && weapclass != ESM::WeaponType::Ammo && weapclass != ESM::WeaponType::Thrown)
|
2013-05-29 00:01:18 +02:00
|
|
|
mCastStyle = ESM::Enchantment::ConstantEffect;
|
2019-12-27 11:21:19 +04:00
|
|
|
else if (weapclass != ESM::WeaponType::Ranged)
|
2013-05-29 00:01:18 +02:00
|
|
|
mCastStyle = ESM::Enchantment::WhenStrikes;
|
2013-05-27 20:47:53 +02:00
|
|
|
return;
|
2013-05-27 16:08:58 +02:00
|
|
|
default: // takes care of Constant effect too
|
2019-10-20 13:30:52 +03:00
|
|
|
mCastStyle = ESM::Enchantment::WhenUsed;
|
2019-12-27 11:21:19 +04:00
|
|
|
if (weapclass != ESM::WeaponType::Ranged)
|
2019-10-20 13:30:52 +03:00
|
|
|
mCastStyle = ESM::Enchantment::WhenStrikes;
|
2013-05-27 20:47:53 +02:00
|
|
|
return;
|
2013-03-28 17:41:00 +01:00
|
|
|
}
|
|
|
|
}
|
2021-10-11 11:46:21 +00:00
|
|
|
else if (mObjectType == ESM::Book::sRecordId)
|
2013-05-27 16:08:58 +02:00
|
|
|
{ // Scroll or Book
|
2013-05-29 00:01:18 +02:00
|
|
|
mCastStyle = ESM::Enchantment::CastOnce;
|
2013-05-27 16:08:58 +02:00
|
|
|
return;
|
2013-03-28 17:41:00 +01:00
|
|
|
}
|
2013-05-27 16:08:58 +02:00
|
|
|
|
|
|
|
// Fail case
|
2013-05-29 00:01:18 +02:00
|
|
|
mCastStyle = ESM::Enchantment::CastOnce;
|
2013-03-28 17:41:00 +01:00
|
|
|
}
|
|
|
|
|
2013-05-27 20:47:53 +02:00
|
|
|
/*
|
|
|
|
* Vanilla enchant cost formula:
|
|
|
|
*
|
|
|
|
* Touch/Self: (min + max) * baseCost * 0.025 * duration + area * baseCost * 0.025
|
|
|
|
* Target: 1.5 * ((min + max) * baseCost * 0.025 * duration + area * baseCost * 0.025)
|
|
|
|
* Constant eff: (min + max) * baseCost * 2.5 + area * baseCost * 0.025
|
|
|
|
*
|
|
|
|
* For multiple effects - cost of each effect is multiplied by number of effects that follows +1.
|
|
|
|
*
|
|
|
|
* Note: Minimal value inside formula for 'min' and 'max' is 1. So in vanilla:
|
|
|
|
* (0 + 0) == (1 + 0) == (1 + 1) => 2 or (2 + 0) == (1 + 2) => 3
|
|
|
|
*
|
|
|
|
* Formula on UESPWiki is not entirely correct.
|
|
|
|
*/
|
2019-05-14 01:40:04 +03:00
|
|
|
float Enchanting::getEnchantPoints(bool precise) const
|
2013-03-28 17:41:00 +01:00
|
|
|
{
|
2013-05-27 20:47:53 +02:00
|
|
|
if (mEffectList.mList.empty())
|
|
|
|
// No effects added, cost = 0
|
|
|
|
return 0;
|
2013-05-27 14:42:08 +02:00
|
|
|
|
2023-04-20 21:07:53 +02:00
|
|
|
const MWWorld::ESMStore& store = *MWBase::Environment::get().getESMStore();
|
2019-05-14 01:40:04 +03:00
|
|
|
const float fEffectCostMult = store.get<ESM::GameSetting>().find("fEffectCostMult")->mValue.getFloat();
|
|
|
|
const float fEnchantmentConstantDurationMult
|
|
|
|
= store.get<ESM::GameSetting>().find("fEnchantmentConstantDurationMult")->mValue.getFloat();
|
2013-03-30 19:08:42 +01:00
|
|
|
|
2019-05-14 01:40:04 +03:00
|
|
|
float enchantmentCost = 0.f;
|
|
|
|
float cost = 0.f;
|
|
|
|
for (const ESM::ENAMstruct& effect : mEffectList.mList)
|
2013-03-28 17:41:00 +01:00
|
|
|
{
|
2019-05-14 01:40:04 +03:00
|
|
|
float baseCost = (store.get<ESM::MagicEffect>().find(effect.mEffectID))->mData.mBaseCost;
|
|
|
|
int magMin = std::max(1, effect.mMagnMin);
|
|
|
|
int magMax = std::max(1, effect.mMagnMax);
|
|
|
|
int area = std::max(1, effect.mArea);
|
|
|
|
float duration = static_cast<float>(effect.mDuration);
|
2013-05-29 00:01:18 +02:00
|
|
|
if (mCastStyle == ESM::Enchantment::ConstantEffect)
|
2019-05-14 01:40:04 +03:00
|
|
|
duration = fEnchantmentConstantDurationMult;
|
2013-03-28 17:41:00 +01:00
|
|
|
|
2019-05-14 01:40:04 +03:00
|
|
|
cost += ((magMin + magMax) * duration + area) * baseCost * fEffectCostMult * 0.05f;
|
2017-05-26 23:42:11 +04:00
|
|
|
|
|
|
|
cost = std::max(1.f, cost);
|
|
|
|
|
2019-05-14 01:40:04 +03:00
|
|
|
if (effect.mRange == ESM::RT_Target)
|
|
|
|
cost *= 1.5f;
|
2015-01-12 23:28:52 +01:00
|
|
|
|
2019-05-14 01:40:04 +03:00
|
|
|
enchantmentCost += precise ? cost : std::floor(cost);
|
2013-03-28 17:41:00 +01:00
|
|
|
}
|
2013-05-27 14:42:08 +02:00
|
|
|
|
2017-05-26 23:42:11 +04:00
|
|
|
return enchantmentCost;
|
2013-03-28 17:41:00 +01:00
|
|
|
}
|
2013-04-02 20:46:48 +02:00
|
|
|
|
2019-12-27 11:21:19 +04:00
|
|
|
const ESM::Enchantment* Enchanting::getRecord(const ESM::Enchantment& toFind) const
|
|
|
|
{
|
|
|
|
const MWWorld::Store<ESM::Enchantment>& enchantments
|
2023-04-20 21:07:53 +02:00
|
|
|
= MWBase::Environment::get().getESMStore()->get<ESM::Enchantment>();
|
2019-12-27 11:21:19 +04:00
|
|
|
MWWorld::Store<ESM::Enchantment>::iterator iter(enchantments.begin());
|
|
|
|
iter += (enchantments.getSize() - enchantments.getDynamicSize());
|
|
|
|
for (; iter != enchantments.end(); ++iter)
|
|
|
|
{
|
|
|
|
if (iter->mEffects.mList.size() != toFind.mEffects.mList.size())
|
|
|
|
continue;
|
|
|
|
|
2020-04-11 00:02:12 +03:00
|
|
|
if (iter->mData.mFlags != toFind.mData.mFlags || iter->mData.mType != toFind.mData.mType
|
2019-12-27 11:21:19 +04:00
|
|
|
|| iter->mData.mCost != toFind.mData.mCost || iter->mData.mCharge != toFind.mData.mCharge)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Don't choose an ID that came from the content files, would have unintended side effects
|
|
|
|
if (!enchantments.isDynamic(iter->mId))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
bool mismatch = false;
|
|
|
|
|
|
|
|
for (int i = 0; i < static_cast<int>(iter->mEffects.mList.size()); ++i)
|
|
|
|
{
|
|
|
|
const ESM::ENAMstruct& first = iter->mEffects.mList[i];
|
|
|
|
const ESM::ENAMstruct& second = toFind.mEffects.mList[i];
|
|
|
|
|
|
|
|
if (first.mEffectID != second.mEffectID || first.mArea != second.mArea || first.mRange != second.mRange
|
|
|
|
|| first.mSkill != second.mSkill || first.mAttribute != second.mAttribute
|
|
|
|
|| first.mMagnMin != second.mMagnMin || first.mMagnMax != second.mMagnMax
|
|
|
|
|| first.mDuration != second.mDuration)
|
|
|
|
{
|
|
|
|
mismatch = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mismatch)
|
|
|
|
return &(*iter);
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-05-27 18:08:12 +02:00
|
|
|
|
2015-01-07 04:28:56 +01:00
|
|
|
int Enchanting::getBaseCastCost() const
|
2013-05-27 18:08:12 +02:00
|
|
|
{
|
2013-05-29 00:01:18 +02:00
|
|
|
if (mCastStyle == ESM::Enchantment::ConstantEffect)
|
2013-05-27 20:47:53 +02:00
|
|
|
return 0;
|
2013-05-27 20:16:57 +02:00
|
|
|
|
2019-05-14 01:40:04 +03:00
|
|
|
return static_cast<int>(getEnchantPoints(false));
|
2015-01-07 04:28:56 +01:00
|
|
|
}
|
2013-05-27 18:08:12 +02:00
|
|
|
|
2015-01-07 04:28:56 +01:00
|
|
|
int Enchanting::getEffectiveCastCost() const
|
|
|
|
{
|
|
|
|
int baseCost = getBaseCastCost();
|
2015-08-21 21:12:39 +12:00
|
|
|
MWWorld::Ptr player = getPlayer();
|
2015-03-08 17:42:07 +13:00
|
|
|
return getEffectiveEnchantmentCastCost(static_cast<float>(baseCost), player);
|
2013-05-27 18:08:12 +02:00
|
|
|
}
|
|
|
|
|
2023-07-14 17:06:33 +02:00
|
|
|
int Enchanting::getEnchantPrice(int count) const
|
2013-04-02 20:46:48 +02:00
|
|
|
{
|
|
|
|
if (mEnchanter.isEmpty())
|
|
|
|
return 0;
|
|
|
|
|
2018-08-29 18:38:12 +03:00
|
|
|
float priceMultipler = MWBase::Environment::get()
|
2023-04-20 21:07:53 +02:00
|
|
|
.getESMStore()
|
|
|
|
->get<ESM::GameSetting>()
|
2018-08-29 18:38:12 +03:00
|
|
|
.find("fEnchantmentValueMult")
|
|
|
|
->mValue.getFloat();
|
2015-03-08 17:42:07 +13:00
|
|
|
int price = MWBase::Environment::get().getMechanicsManager()->getBarterOffer(
|
|
|
|
mEnchanter, static_cast<int>(getEnchantPoints() * priceMultipler), true);
|
2023-07-14 17:06:33 +02:00
|
|
|
price *= count * getTypeMultiplier();
|
2020-09-08 16:55:12 +04:00
|
|
|
return std::max(1, price);
|
2013-04-02 20:46:48 +02:00
|
|
|
}
|
|
|
|
|
2013-04-01 17:12:47 +02:00
|
|
|
int Enchanting::getGemCharge() const
|
2013-03-28 17:41:00 +01:00
|
|
|
{
|
2023-04-20 21:07:53 +02:00
|
|
|
const MWWorld::ESMStore& store = *MWBase::Environment::get().getESMStore();
|
2013-03-28 17:41:00 +01:00
|
|
|
if (soulEmpty())
|
|
|
|
return 0;
|
2023-02-17 19:20:29 +01:00
|
|
|
if (mSoulGemPtr.getCellRef().getSoul().empty())
|
2013-03-28 17:41:00 +01:00
|
|
|
return 0;
|
2018-03-08 23:38:04 +00:00
|
|
|
const ESM::Creature* soul = store.get<ESM::Creature>().search(mSoulGemPtr.getCellRef().getSoul());
|
|
|
|
if (soul)
|
|
|
|
return soul->mData.mSoul;
|
|
|
|
else
|
|
|
|
return 0;
|
2013-03-28 17:41:00 +01:00
|
|
|
}
|
|
|
|
|
2014-12-10 17:30:33 +01:00
|
|
|
int Enchanting::getMaxEnchantValue() const
|
2013-03-28 17:41:00 +01:00
|
|
|
{
|
|
|
|
if (itemEmpty())
|
|
|
|
return 0;
|
2014-01-27 01:58:04 +01:00
|
|
|
|
2023-04-20 21:07:53 +02:00
|
|
|
const MWWorld::ESMStore& store = *MWBase::Environment::get().getESMStore();
|
2014-01-27 01:58:04 +01:00
|
|
|
|
2018-08-29 18:38:12 +03:00
|
|
|
return static_cast<int>(mOldItemPtr.getClass().getEnchantmentPoints(mOldItemPtr)
|
|
|
|
* store.get<ESM::GameSetting>().find("fEnchantmentMult")->mValue.getFloat());
|
2013-03-28 17:41:00 +01:00
|
|
|
}
|
2013-04-01 17:12:47 +02:00
|
|
|
bool Enchanting::soulEmpty() const
|
2013-03-28 17:41:00 +01:00
|
|
|
{
|
2013-05-29 00:01:18 +02:00
|
|
|
return mSoulGemPtr.isEmpty();
|
2013-03-28 17:41:00 +01:00
|
|
|
}
|
|
|
|
|
2013-04-01 17:12:47 +02:00
|
|
|
bool Enchanting::itemEmpty() const
|
2013-03-28 17:41:00 +01:00
|
|
|
{
|
2013-05-29 00:01:18 +02:00
|
|
|
return mOldItemPtr.isEmpty();
|
2013-03-28 17:41:00 +01:00
|
|
|
}
|
2013-03-30 19:08:42 +01:00
|
|
|
|
|
|
|
void Enchanting::setSelfEnchanting(bool selfEnchanting)
|
|
|
|
{
|
|
|
|
mSelfEnchanting = selfEnchanting;
|
|
|
|
}
|
|
|
|
|
2017-04-20 20:36:14 +09:00
|
|
|
void Enchanting::setEnchanter(const MWWorld::Ptr& enchanter)
|
2013-03-30 19:08:42 +01:00
|
|
|
{
|
|
|
|
mEnchanter = enchanter;
|
2019-06-28 15:52:37 +03:00
|
|
|
// Reset cast style
|
|
|
|
mCastStyle = ESM::Enchantment::CastOnce;
|
2013-03-30 19:08:42 +01:00
|
|
|
}
|
|
|
|
|
2019-05-14 01:40:04 +03:00
|
|
|
int Enchanting::getEnchantChance() const
|
2013-03-30 19:08:42 +01:00
|
|
|
{
|
2018-10-08 17:06:30 +03:00
|
|
|
const CreatureStats& stats = mEnchanter.getClass().getCreatureStats(mEnchanter);
|
2014-01-27 01:58:04 +01:00
|
|
|
const MWWorld::Store<ESM::GameSetting>& gmst
|
2023-04-20 21:07:53 +02:00
|
|
|
= MWBase::Environment::get().getESMStore()->get<ESM::GameSetting>();
|
2019-05-14 01:40:04 +03:00
|
|
|
const float a = static_cast<float>(mEnchanter.getClass().getSkill(mEnchanter, ESM::Skill::Enchant));
|
|
|
|
const float b = static_cast<float>(stats.getAttribute(ESM::Attribute::Intelligence).getModified());
|
|
|
|
const float c = static_cast<float>(stats.getAttribute(ESM::Attribute::Luck).getModified());
|
|
|
|
const float fEnchantmentChanceMult = gmst.find("fEnchantmentChanceMult")->mValue.getFloat();
|
|
|
|
const float fEnchantmentConstantChanceMult = gmst.find("fEnchantmentConstantChanceMult")->mValue.getFloat();
|
2014-01-27 01:58:04 +01:00
|
|
|
|
2019-12-27 11:21:19 +04:00
|
|
|
float x = (a - getEnchantPoints() * fEnchantmentChanceMult * getTypeMultiplier() * getEnchantItemsCount()
|
|
|
|
+ 0.2f * b + 0.1f * c)
|
|
|
|
* stats.getFatigueTerm();
|
2019-05-14 01:40:04 +03:00
|
|
|
if (mCastStyle == ESM::Enchantment::ConstantEffect)
|
|
|
|
x *= fEnchantmentConstantChanceMult;
|
2013-03-30 19:08:42 +01:00
|
|
|
|
2019-05-14 01:40:04 +03:00
|
|
|
return static_cast<int>(x);
|
2013-03-30 19:08:42 +01:00
|
|
|
}
|
2013-04-02 20:46:48 +02:00
|
|
|
|
2019-12-27 11:21:19 +04:00
|
|
|
int Enchanting::getEnchantItemsCount() const
|
|
|
|
{
|
|
|
|
int count = 1;
|
|
|
|
float enchantPoints = getEnchantPoints();
|
|
|
|
if (mWeaponType != -1 && enchantPoints > 0)
|
|
|
|
{
|
|
|
|
ESM::WeaponType::Class weapclass = MWMechanics::getWeaponType(mWeaponType)->mWeaponClass;
|
|
|
|
if (weapclass == ESM::WeaponType::Thrown || weapclass == ESM::WeaponType::Ammo)
|
|
|
|
{
|
|
|
|
MWWorld::Ptr player = getPlayer();
|
2021-11-06 07:30:28 +03:00
|
|
|
count = player.getClass().getContainerStore(player).count(mOldItemPtr.getCellRef().getRefId());
|
2023-06-27 23:41:06 +02:00
|
|
|
count = std::clamp<int>(
|
|
|
|
getGemCharge() * Settings::game().mProjectilesEnchantMultiplier / enchantPoints, 1, count);
|
2019-12-27 11:21:19 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
float Enchanting::getTypeMultiplier() const
|
|
|
|
{
|
2023-06-27 23:41:06 +02:00
|
|
|
if (Settings::game().mProjectilesEnchantMultiplier > 0 && mWeaponType != -1 && getEnchantPoints() > 0)
|
2019-12-27 11:21:19 +04:00
|
|
|
{
|
|
|
|
ESM::WeaponType::Class weapclass = MWMechanics::getWeaponType(mWeaponType)->mWeaponClass;
|
|
|
|
if (weapclass == ESM::WeaponType::Thrown || weapclass == ESM::WeaponType::Ammo)
|
|
|
|
return 0.125f;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1.f;
|
|
|
|
}
|
|
|
|
|
2023-07-14 17:06:33 +02:00
|
|
|
void Enchanting::payForEnchantment(int count) const
|
2013-04-02 20:46:48 +02:00
|
|
|
{
|
2015-08-21 21:12:39 +12:00
|
|
|
const MWWorld::Ptr& player = getPlayer();
|
2014-05-22 20:37:22 +02:00
|
|
|
MWWorld::ContainerStore& store = player.getClass().getContainerStore(player);
|
2013-04-02 20:46:48 +02:00
|
|
|
|
2023-07-14 17:06:33 +02:00
|
|
|
int price = getEnchantPrice(count);
|
|
|
|
store.remove(MWWorld::ContainerStore::sGoldId, price);
|
2014-07-28 00:55:57 +02:00
|
|
|
|
|
|
|
// add gold to NPC trading gold pool
|
|
|
|
CreatureStats& enchanterStats = mEnchanter.getClass().getCreatureStats(mEnchanter);
|
2023-07-14 17:06:33 +02:00
|
|
|
enchanterStats.setGoldPool(enchanterStats.getGoldPool() + price);
|
2013-04-02 20:46:48 +02:00
|
|
|
}
|
2013-03-28 17:41:00 +01:00
|
|
|
}
|