forked from mirror/openmw-tes3mp
Self-enchanting mechanics
This commit is contained in:
parent
a031c77619
commit
7dbc779c3a
3 changed files with 76 additions and 10 deletions
|
@ -19,7 +19,6 @@ namespace MWGui
|
|||
: WindowBase("openmw_enchanting_dialog.layout", parWindowManager)
|
||||
, EffectEditorBase(parWindowManager)
|
||||
, mItemSelectionDialog(NULL)
|
||||
, mEnchanting(MWBase::Environment::get().getWorld()->getPlayer().getPlayer())
|
||||
{
|
||||
getWidget(mName, "NameEdit");
|
||||
getWidget(mCancelButton, "CancelButton");
|
||||
|
@ -87,6 +86,9 @@ namespace MWGui
|
|||
|
||||
void EnchantingDialog::startEnchanting (MWWorld::Ptr actor)
|
||||
{
|
||||
mEnchanting.setSelfEnchanting(false);
|
||||
mEnchanting.setEnchanter(actor);
|
||||
|
||||
mPtr = actor;
|
||||
|
||||
startEditing ();
|
||||
|
@ -94,7 +96,14 @@ namespace MWGui
|
|||
|
||||
void EnchantingDialog::startSelfEnchanting(MWWorld::Ptr soulgem)
|
||||
{
|
||||
/// \todo
|
||||
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
|
||||
|
||||
mEnchanting.setSelfEnchanting(true);
|
||||
mEnchanting.setEnchanter(player);
|
||||
|
||||
mPtr = player;
|
||||
|
||||
startEditing();
|
||||
}
|
||||
|
||||
void EnchantingDialog::onReferenceUnavailable ()
|
||||
|
@ -264,8 +273,13 @@ namespace MWGui
|
|||
mEnchanting.setNewItemName(mName->getCaption());
|
||||
mEnchanting.setEffect(mEffectList);
|
||||
|
||||
mEnchanting.create();
|
||||
mWindowManager.messageBox ("#{sEnchantmentMenu12}");
|
||||
int result = mEnchanting.create();
|
||||
|
||||
if(result==1)
|
||||
mWindowManager.messageBox ("#{sEnchantmentMenu12}");
|
||||
else
|
||||
mWindowManager.messageBox ("#{sNotifyMessage34}");
|
||||
|
||||
mWindowManager.removeGuiMode (GM_Enchanting);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,10 +3,13 @@
|
|||
#include "../mwworld/manualref.hpp"
|
||||
#include "../mwworld/class.hpp"
|
||||
#include "../mwworld/containerstore.hpp"
|
||||
|
||||
#include "creaturestats.hpp"
|
||||
#include "npcstats.hpp"
|
||||
|
||||
namespace MWMechanics
|
||||
{
|
||||
Enchanting::Enchanting(MWWorld::Ptr enchanter):
|
||||
mEnchanter(enchanter),
|
||||
Enchanting::Enchanting():
|
||||
mEnchantType(0)
|
||||
{}
|
||||
|
||||
|
@ -45,11 +48,20 @@ namespace MWMechanics
|
|||
mSoulGemPtr=soulGem;
|
||||
}
|
||||
|
||||
void Enchanting::create()
|
||||
int Enchanting::create()
|
||||
{
|
||||
mOldItemPtr.getRefData().setCount(mOldItemPtr.getRefData().getCount()-1);
|
||||
mSoulGemPtr.getRefData().setCount(mSoulGemPtr.getRefData().getCount()-1);
|
||||
|
||||
if(mSelfEnchanting)
|
||||
{
|
||||
if(getEnchantChance()<std::rand()/static_cast<double> (RAND_MAX)*100)
|
||||
return 0;
|
||||
|
||||
MWWorld::Class::get (mEnchanter).skillUsageSucceeded (mEnchanter, ESM::Skill::Enchant, 1);
|
||||
}
|
||||
|
||||
mOldItemPtr.getRefData().setCount(mOldItemPtr.getRefData().getCount()-1);
|
||||
|
||||
mEnchantment.mData.mCharge = getGemCharge();
|
||||
if(mEnchantType==3)
|
||||
{
|
||||
|
@ -67,6 +79,7 @@ namespace MWMechanics
|
|||
MWWorld::Ptr result = mOldItemPtr;
|
||||
result.mPtr = newobjPtr.mPtr;
|
||||
MWWorld::Class::get (mEnchanter).getContainerStore (mEnchanter).add (result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void Enchanting::nextEnchantType()
|
||||
|
@ -110,6 +123,10 @@ namespace MWMechanics
|
|||
float cost = 0;
|
||||
std::vector<ESM::ENAMstruct> mEffects = mEffectList.mList;
|
||||
int i=mEffects.size();
|
||||
|
||||
/*
|
||||
Formula from http://www.uesp.net/wiki/Morrowind:Enchant
|
||||
*/
|
||||
for (std::vector<ESM::ENAMstruct>::const_iterator it = mEffects.begin(); it != mEffects.end(); ++it)
|
||||
{
|
||||
const ESM::MagicEffect* effect = store.get<ESM::MagicEffect>().find(it->mEffectID);
|
||||
|
@ -164,4 +181,34 @@ namespace MWMechanics
|
|||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void Enchanting::setSelfEnchanting(bool selfEnchanting)
|
||||
{
|
||||
mSelfEnchanting = selfEnchanting;
|
||||
}
|
||||
|
||||
void Enchanting::setEnchanter(MWWorld::Ptr enchanter)
|
||||
{
|
||||
mEnchanter = enchanter;
|
||||
}
|
||||
|
||||
float Enchanting::getEnchantChance()
|
||||
{
|
||||
/*
|
||||
Formula from http://www.uesp.net/wiki/Morrowind:Enchant
|
||||
*/
|
||||
const CreatureStats& creatureStats = MWWorld::Class::get (mEnchanter).getCreatureStats (mEnchanter);
|
||||
const NpcStats& npcStats = MWWorld::Class::get (mEnchanter).getNpcStats (mEnchanter);
|
||||
|
||||
float chance1 = (npcStats.getSkill (ESM::Skill::Enchant).getModified() +
|
||||
(0.25 * creatureStats.getAttribute (ESM::Attribute::Intelligence).getModified())
|
||||
+ (0.125 * creatureStats.getAttribute (ESM::Attribute::Luck).getModified()));
|
||||
|
||||
float chance2 = 2.5 * getEnchantCost();
|
||||
if(mEnchantType==3)
|
||||
{
|
||||
chance2 *= 2;
|
||||
}
|
||||
return (chance1-chance2);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@ namespace MWMechanics
|
|||
const MWWorld::Ptr *mNewItemPtr;
|
||||
int mEnchantType;
|
||||
|
||||
bool mSelfEnchanting;
|
||||
|
||||
ESM::EffectList mEffectList;
|
||||
ESM::Enchantment mEnchantment;
|
||||
|
||||
|
@ -23,17 +25,20 @@ namespace MWMechanics
|
|||
std::string mObjectType;
|
||||
std::string mOldItemId;
|
||||
public:
|
||||
Enchanting(MWWorld::Ptr enchanter);
|
||||
Enchanting();
|
||||
void setEnchanter(MWWorld::Ptr enchanter);
|
||||
void setSelfEnchanting(bool selfEnchanting);
|
||||
void setOldItem(MWWorld::Ptr oldItem);
|
||||
void setNewItemName(std::string s);
|
||||
void setEffect(ESM::EffectList effectList);
|
||||
void setSoulGem(MWWorld::Ptr soulGem);
|
||||
void create();
|
||||
int create();
|
||||
void nextEnchantType();
|
||||
int getEnchantType();
|
||||
int getEnchantCost();
|
||||
int getMaxEnchantValue();
|
||||
int getGemCharge();
|
||||
float getEnchantChance();
|
||||
bool soulEmpty();
|
||||
bool itemEmpty();
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue