mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-26 09:35:28 +00:00
Enchaning values import, fixed constness
This commit is contained in:
parent
d29a42dcbe
commit
1bff6ed872
@ -29,7 +29,7 @@ namespace MWMechanics
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Enchanting::setNewItemName(std::string s)
|
void Enchanting::setNewItemName(const std::string& s)
|
||||||
{
|
{
|
||||||
mNewItemName=s;
|
mNewItemName=s;
|
||||||
}
|
}
|
||||||
@ -39,7 +39,7 @@ namespace MWMechanics
|
|||||||
mEffectList=effectList;
|
mEffectList=effectList;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Enchanting::getEnchantType()
|
int Enchanting::getEnchantType() const
|
||||||
{
|
{
|
||||||
return mEnchantType;
|
return mEnchantType;
|
||||||
}
|
}
|
||||||
@ -49,30 +49,31 @@ namespace MWMechanics
|
|||||||
mSoulGemPtr=soulGem;
|
mSoulGemPtr=soulGem;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Enchanting::create()
|
bool Enchanting::create()
|
||||||
{
|
{
|
||||||
mEnchantment.mData.mCharge = getGemCharge();
|
ESM::Enchantment enchantment;
|
||||||
|
enchantment.mData.mCharge = getGemCharge();
|
||||||
mSoulGemPtr.getRefData().setCount (mSoulGemPtr.getRefData().getCount()-1);
|
mSoulGemPtr.getRefData().setCount (mSoulGemPtr.getRefData().getCount()-1);
|
||||||
|
|
||||||
if(mSelfEnchanting)
|
if(mSelfEnchanting)
|
||||||
{
|
{
|
||||||
if(getEnchantChance()<std::rand()/static_cast<double> (RAND_MAX)*100)
|
if(getEnchantChance()<std::rand()/static_cast<double> (RAND_MAX)*100)
|
||||||
return 0;
|
return false;
|
||||||
|
|
||||||
MWWorld::Class::get (mEnchanter).skillUsageSucceeded (mEnchanter, ESM::Skill::Enchant, 1);
|
MWWorld::Class::get (mEnchanter).skillUsageSucceeded (mEnchanter, ESM::Skill::Enchant, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mEnchantType==3)
|
if(mEnchantType==3)
|
||||||
{
|
{
|
||||||
mEnchantment.mData.mCharge=0;
|
enchantment.mData.mCharge=0;
|
||||||
}
|
}
|
||||||
mEnchantment.mData.mType = mEnchantType;
|
enchantment.mData.mType = mEnchantType;
|
||||||
mEnchantment.mData.mCost = getEnchantCost();
|
enchantment.mData.mCost = getEnchantCost();
|
||||||
mEnchantment.mEffects = mEffectList;
|
enchantment.mEffects = mEffectList;
|
||||||
|
|
||||||
const ESM::Enchantment *enchantment = MWBase::Environment::get().getWorld()->createRecord (mEnchantment);
|
const ESM::Enchantment *enchantmentPtr = MWBase::Environment::get().getWorld()->createRecord (enchantment);
|
||||||
|
|
||||||
MWWorld::Class::get(mOldItemPtr).applyEnchantment(mOldItemPtr, enchantment->mId, getGemCharge(), mNewItemName);
|
MWWorld::Class::get(mOldItemPtr).applyEnchantment(mOldItemPtr, enchantmentPtr->mId, getGemCharge(), mNewItemName);
|
||||||
|
|
||||||
mOldItemPtr.getRefData().setCount(1);
|
mOldItemPtr.getRefData().setCount(1);
|
||||||
|
|
||||||
@ -80,7 +81,7 @@ namespace MWMechanics
|
|||||||
ref.getPtr().getRefData().setCount (mOldItemCount-1);
|
ref.getPtr().getRefData().setCount (mOldItemCount-1);
|
||||||
MWWorld::Class::get (mEnchanter).getContainerStore (mEnchanter).add (ref.getPtr());
|
MWWorld::Class::get (mEnchanter).getContainerStore (mEnchanter).add (ref.getPtr());
|
||||||
|
|
||||||
return 1;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Enchanting::nextEnchantType()
|
void Enchanting::nextEnchantType()
|
||||||
@ -93,12 +94,13 @@ namespace MWMechanics
|
|||||||
}
|
}
|
||||||
if ((mObjectType == typeid(ESM::Armor).name())||(mObjectType == typeid(ESM::Clothing).name()))
|
if ((mObjectType == typeid(ESM::Armor).name())||(mObjectType == typeid(ESM::Clothing).name()))
|
||||||
{
|
{
|
||||||
|
int soulConstAmount = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find ("iSoulAmountForConstantEffect")->getInt();
|
||||||
switch(mEnchantType)
|
switch(mEnchantType)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
mEnchantType = 2;
|
mEnchantType = 2;
|
||||||
case 3:
|
case 3:
|
||||||
if(getGemCharge()<400)
|
if(getGemCharge()<soulConstAmount)
|
||||||
mEnchantType=2;
|
mEnchantType=2;
|
||||||
case 4:
|
case 4:
|
||||||
mEnchantType = 2;
|
mEnchantType = 2;
|
||||||
@ -118,7 +120,7 @@ namespace MWMechanics
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Enchanting::getEnchantCost()
|
int Enchanting::getEnchantCost() const
|
||||||
{
|
{
|
||||||
const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore();
|
const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore();
|
||||||
float cost = 0;
|
float cost = 0;
|
||||||
@ -138,7 +140,8 @@ namespace MWMechanics
|
|||||||
|
|
||||||
if(mEnchantType==3)
|
if(mEnchantType==3)
|
||||||
{
|
{
|
||||||
cost1 *= 100;
|
int constDurationMultipler = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find ("fEnchantmentConstantDurationMult")->getFloat();
|
||||||
|
cost1 *= constDurationMultipler;
|
||||||
cost2 *= 2;
|
cost2 *= 2;
|
||||||
}
|
}
|
||||||
if(effect->mData.mFlags & ESM::MagicEffect::CastTarget)
|
if(effect->mData.mFlags & ESM::MagicEffect::CastTarget)
|
||||||
@ -152,7 +155,7 @@ namespace MWMechanics
|
|||||||
}
|
}
|
||||||
return cost;
|
return cost;
|
||||||
}
|
}
|
||||||
int Enchanting::getGemCharge()
|
int Enchanting::getGemCharge() const
|
||||||
{
|
{
|
||||||
const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore();
|
const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore();
|
||||||
if(soulEmpty())
|
if(soulEmpty())
|
||||||
@ -163,20 +166,20 @@ namespace MWMechanics
|
|||||||
return soul->mData.mSoul;
|
return soul->mData.mSoul;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Enchanting::getMaxEnchantValue()
|
int Enchanting::getMaxEnchantValue() const
|
||||||
{
|
{
|
||||||
if (itemEmpty())
|
if (itemEmpty())
|
||||||
return 0;
|
return 0;
|
||||||
return MWWorld::Class::get(mOldItemPtr).getEnchantmentPoints(mOldItemPtr);
|
return MWWorld::Class::get(mOldItemPtr).getEnchantmentPoints(mOldItemPtr);
|
||||||
}
|
}
|
||||||
bool Enchanting::soulEmpty()
|
bool Enchanting::soulEmpty() const
|
||||||
{
|
{
|
||||||
if (mSoulGemPtr.isEmpty())
|
if (mSoulGemPtr.isEmpty())
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Enchanting::itemEmpty()
|
bool Enchanting::itemEmpty() const
|
||||||
{
|
{
|
||||||
if(mOldItemPtr.isEmpty())
|
if(mOldItemPtr.isEmpty())
|
||||||
return true;
|
return true;
|
||||||
@ -193,7 +196,7 @@ namespace MWMechanics
|
|||||||
mEnchanter = enchanter;
|
mEnchanter = enchanter;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Enchanting::getEnchantChance()
|
float Enchanting::getEnchantChance() const
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
Formula from http://www.uesp.net/wiki/Morrowind:Enchant
|
Formula from http://www.uesp.net/wiki/Morrowind:Enchant
|
||||||
@ -208,7 +211,8 @@ namespace MWMechanics
|
|||||||
float chance2 = 2.5 * getEnchantCost();
|
float chance2 = 2.5 * getEnchantCost();
|
||||||
if(mEnchantType==3)
|
if(mEnchantType==3)
|
||||||
{
|
{
|
||||||
chance2 *= 2;
|
float constantChance = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find ("fEnchantmentConstantChanceMult")->getFloat();
|
||||||
|
chance2 /= constantChance;
|
||||||
}
|
}
|
||||||
return (chance1-chance2);
|
return (chance1-chance2);
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ namespace MWMechanics
|
|||||||
{
|
{
|
||||||
class Enchanting
|
class Enchanting
|
||||||
{
|
{
|
||||||
|
|
||||||
MWWorld::Ptr mOldItemPtr;
|
MWWorld::Ptr mOldItemPtr;
|
||||||
MWWorld::Ptr mSoulGemPtr;
|
MWWorld::Ptr mSoulGemPtr;
|
||||||
MWWorld::Ptr mEnchanter;
|
MWWorld::Ptr mEnchanter;
|
||||||
@ -19,7 +18,6 @@ namespace MWMechanics
|
|||||||
bool mSelfEnchanting;
|
bool mSelfEnchanting;
|
||||||
|
|
||||||
ESM::EffectList mEffectList;
|
ESM::EffectList mEffectList;
|
||||||
ESM::Enchantment mEnchantment;
|
|
||||||
|
|
||||||
std::string mNewItemName;
|
std::string mNewItemName;
|
||||||
std::string mObjectType;
|
std::string mObjectType;
|
||||||
@ -31,18 +29,18 @@ namespace MWMechanics
|
|||||||
void setEnchanter(MWWorld::Ptr enchanter);
|
void setEnchanter(MWWorld::Ptr enchanter);
|
||||||
void setSelfEnchanting(bool selfEnchanting);
|
void setSelfEnchanting(bool selfEnchanting);
|
||||||
void setOldItem(MWWorld::Ptr oldItem);
|
void setOldItem(MWWorld::Ptr oldItem);
|
||||||
void setNewItemName(std::string s);
|
void setNewItemName(const std::string& s);
|
||||||
void setEffect(ESM::EffectList effectList);
|
void setEffect(ESM::EffectList effectList);
|
||||||
void setSoulGem(MWWorld::Ptr soulGem);
|
void setSoulGem(MWWorld::Ptr soulGem);
|
||||||
int create();
|
bool create(); //Return true if created, false if failed.
|
||||||
void nextEnchantType();
|
void nextEnchantType(); //Set enchant type to next possible type (for mOldItemPtr object)
|
||||||
int getEnchantType();
|
int getEnchantType() const;
|
||||||
int getEnchantCost();
|
int getEnchantCost() const;
|
||||||
int getMaxEnchantValue();
|
int getMaxEnchantValue() const;
|
||||||
int getGemCharge();
|
int getGemCharge() const;
|
||||||
float getEnchantChance();
|
float getEnchantChance() const;
|
||||||
bool soulEmpty();
|
bool soulEmpty() const; //Return true if empty
|
||||||
bool itemEmpty();
|
bool itemEmpty() const; //Return true if empty
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user