mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-05 22:45:33 +00:00
Merge remote-tracking branch 'glorf/enchanting'
This commit is contained in:
commit
32d3fe0e35
5 changed files with 77 additions and 19 deletions
|
@ -32,6 +32,7 @@ namespace MWGui
|
||||||
getWidget(mTypeButton, "TypeButton");
|
getWidget(mTypeButton, "TypeButton");
|
||||||
getWidget(mBuyButton, "BuyButton");
|
getWidget(mBuyButton, "BuyButton");
|
||||||
getWidget(mPrice, "PriceLabel");
|
getWidget(mPrice, "PriceLabel");
|
||||||
|
getWidget(mPriceText, "PriceTextLabel");
|
||||||
|
|
||||||
setWidgets(mAvailableEffectsList, mUsedEffectsView);
|
setWidgets(mAvailableEffectsList, mUsedEffectsView);
|
||||||
|
|
||||||
|
@ -63,6 +64,8 @@ namespace MWGui
|
||||||
|
|
||||||
mCastCost->setCaption(boost::lexical_cast<std::string>(mEnchanting.getEnchantCost()));
|
mCastCost->setCaption(boost::lexical_cast<std::string>(mEnchanting.getEnchantCost()));
|
||||||
|
|
||||||
|
mPrice->setCaption(boost::lexical_cast<std::string>(mEnchanting.getEnchantPrice()));
|
||||||
|
|
||||||
switch(mEnchanting.getEnchantType())
|
switch(mEnchanting.getEnchantType())
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -86,16 +89,10 @@ namespace MWGui
|
||||||
|
|
||||||
void EnchantingDialog::startEnchanting (MWWorld::Ptr actor)
|
void EnchantingDialog::startEnchanting (MWWorld::Ptr actor)
|
||||||
{
|
{
|
||||||
|
|
||||||
/*Now there's no need to use other enchanters, player is the enchanter here,
|
|
||||||
even if the enchanted object is created by NPC. Could be changed later, probably
|
|
||||||
with some price formulas */
|
|
||||||
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
|
|
||||||
|
|
||||||
mEnchanting.setSelfEnchanting(false);
|
mEnchanting.setSelfEnchanting(false);
|
||||||
mEnchanting.setEnchanter(player);
|
mEnchanting.setEnchanter(actor);
|
||||||
|
|
||||||
mPtr = player;
|
mPtr = actor;
|
||||||
|
|
||||||
startEditing ();
|
startEditing ();
|
||||||
}
|
}
|
||||||
|
@ -108,8 +105,23 @@ namespace MWGui
|
||||||
mEnchanting.setEnchanter(player);
|
mEnchanting.setEnchanter(player);
|
||||||
|
|
||||||
mPtr = player;
|
mPtr = player;
|
||||||
|
|
||||||
startEditing();
|
startEditing();
|
||||||
|
mEnchanting.setSoulGem(soulgem);
|
||||||
|
|
||||||
|
MyGUI::ImageBox* image = mSoulBox->createWidget<MyGUI::ImageBox>("ImageBox", MyGUI::IntCoord(0, 0, 32, 32), MyGUI::Align::Default);
|
||||||
|
std::string path = std::string("icons\\");
|
||||||
|
path += MWWorld::Class::get(soulgem).getInventoryIcon(soulgem);
|
||||||
|
int pos = path.rfind(".");
|
||||||
|
path.erase(pos);
|
||||||
|
path.append(".dds");
|
||||||
|
image->setImageTexture (path);
|
||||||
|
image->setUserString ("ToolTipType", "ItemPtr");
|
||||||
|
image->setUserData(soulgem);
|
||||||
|
image->eventMouseButtonClick += MyGUI::newDelegate(this, &EnchantingDialog::onRemoveSoul);
|
||||||
|
|
||||||
|
mPrice->setVisible(false);
|
||||||
|
mPriceText->setVisible(false);
|
||||||
|
updateLabels();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EnchantingDialog::onReferenceUnavailable ()
|
void EnchantingDialog::onReferenceUnavailable ()
|
||||||
|
@ -252,12 +264,6 @@ namespace MWGui
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (boost::lexical_cast<int>(mPrice->getCaption()) > mWindowManager.getInventoryWindow()->getPlayerGold())
|
|
||||||
{
|
|
||||||
mWindowManager.messageBox ("#{sNotifyMessage18}");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mEnchanting.soulEmpty())
|
if (mEnchanting.soulEmpty())
|
||||||
{
|
{
|
||||||
mWindowManager.messageBox ("#{sNotifyMessage52}");
|
mWindowManager.messageBox ("#{sNotifyMessage52}");
|
||||||
|
@ -279,6 +285,12 @@ namespace MWGui
|
||||||
mEnchanting.setNewItemName(mName->getCaption());
|
mEnchanting.setNewItemName(mName->getCaption());
|
||||||
mEnchanting.setEffect(mEffectList);
|
mEnchanting.setEffect(mEffectList);
|
||||||
|
|
||||||
|
if (mEnchanting.getEnchantPrice() > mWindowManager.getInventoryWindow()->getPlayerGold())
|
||||||
|
{
|
||||||
|
mWindowManager.messageBox ("#{sNotifyMessage18}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int result = mEnchanting.create();
|
int result = mEnchanting.create();
|
||||||
|
|
||||||
if(result==1)
|
if(result==1)
|
||||||
|
|
|
@ -56,6 +56,7 @@ namespace MWGui
|
||||||
MyGUI::TextBox* mCastCost;
|
MyGUI::TextBox* mCastCost;
|
||||||
MyGUI::TextBox* mCharge;
|
MyGUI::TextBox* mCharge;
|
||||||
MyGUI::TextBox* mPrice;
|
MyGUI::TextBox* mPrice;
|
||||||
|
MyGUI::TextBox* mPriceText;
|
||||||
|
|
||||||
MWMechanics::Enchanting mEnchanting;
|
MWMechanics::Enchanting mEnchanting;
|
||||||
ESM::EffectList mEffectList;
|
ESM::EffectList mEffectList;
|
||||||
|
|
|
@ -3,9 +3,11 @@
|
||||||
#include "../mwworld/manualref.hpp"
|
#include "../mwworld/manualref.hpp"
|
||||||
#include "../mwworld/class.hpp"
|
#include "../mwworld/class.hpp"
|
||||||
#include "../mwworld/containerstore.hpp"
|
#include "../mwworld/containerstore.hpp"
|
||||||
|
#include "../mwbase/mechanicsmanager.hpp"
|
||||||
|
|
||||||
#include "creaturestats.hpp"
|
#include "creaturestats.hpp"
|
||||||
#include "npcstats.hpp"
|
#include "npcstats.hpp"
|
||||||
|
#include <boost/algorithm/string.hpp>
|
||||||
|
|
||||||
namespace MWMechanics
|
namespace MWMechanics
|
||||||
{
|
{
|
||||||
|
@ -53,7 +55,12 @@ namespace MWMechanics
|
||||||
{
|
{
|
||||||
ESM::Enchantment enchantment;
|
ESM::Enchantment enchantment;
|
||||||
enchantment.mData.mCharge = getGemCharge();
|
enchantment.mData.mCharge = getGemCharge();
|
||||||
mSoulGemPtr.getRefData().setCount (mSoulGemPtr.getRefData().getCount()-1);
|
|
||||||
|
//Exception for Azura Star, it's not destroyed after enchanting
|
||||||
|
if(boost::iequals(mSoulGemPtr.get<ESM::Miscellaneous>()->mBase->mId, "Misc_SoulGem_Azura"))
|
||||||
|
mSoulGemPtr.getCellRef().mSoul="";
|
||||||
|
else
|
||||||
|
mSoulGemPtr.getRefData().setCount (mSoulGemPtr.getRefData().getCount()-1);
|
||||||
|
|
||||||
if(mSelfEnchanting)
|
if(mSelfEnchanting)
|
||||||
{
|
{
|
||||||
|
@ -79,7 +86,11 @@ namespace MWMechanics
|
||||||
|
|
||||||
MWWorld::ManualRef ref (MWBase::Environment::get().getWorld()->getStore(), mOldItemId);
|
MWWorld::ManualRef ref (MWBase::Environment::get().getWorld()->getStore(), mOldItemId);
|
||||||
ref.getPtr().getRefData().setCount (mOldItemCount-1);
|
ref.getPtr().getRefData().setCount (mOldItemCount-1);
|
||||||
MWWorld::Class::get (mEnchanter).getContainerStore (mEnchanter).add (ref.getPtr());
|
|
||||||
|
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
|
||||||
|
MWWorld::Class::get (player).getContainerStore (player).add (ref.getPtr());
|
||||||
|
if(!mSelfEnchanting)
|
||||||
|
payForEnchantment();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -126,6 +137,8 @@ namespace MWMechanics
|
||||||
float cost = 0;
|
float cost = 0;
|
||||||
std::vector<ESM::ENAMstruct> mEffects = mEffectList.mList;
|
std::vector<ESM::ENAMstruct> mEffects = mEffectList.mList;
|
||||||
int i=mEffects.size();
|
int i=mEffects.size();
|
||||||
|
if(i<=0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Formula from http://www.uesp.net/wiki/Morrowind:Enchant
|
Formula from http://www.uesp.net/wiki/Morrowind:Enchant
|
||||||
|
@ -155,6 +168,17 @@ namespace MWMechanics
|
||||||
}
|
}
|
||||||
return cost;
|
return cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Enchanting::getEnchantPrice() const
|
||||||
|
{
|
||||||
|
if(mEnchanter.isEmpty())
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
float priceMultipler = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find ("fEnchantmentValueMult")->getFloat();
|
||||||
|
int price = MWBase::Environment::get().getMechanicsManager()->getBarterOffer(mEnchanter, (getEnchantCost() * priceMultipler), true);
|
||||||
|
return price;
|
||||||
|
}
|
||||||
|
|
||||||
int Enchanting::getGemCharge() const
|
int Enchanting::getGemCharge() const
|
||||||
{
|
{
|
||||||
const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore();
|
const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore();
|
||||||
|
@ -216,4 +240,23 @@ namespace MWMechanics
|
||||||
}
|
}
|
||||||
return (chance1-chance2);
|
return (chance1-chance2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Enchanting::payForEnchantment() const
|
||||||
|
{
|
||||||
|
MWWorld::Ptr gold;
|
||||||
|
|
||||||
|
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
|
||||||
|
MWWorld::ContainerStore& store = MWWorld::Class::get(player).getContainerStore(player);
|
||||||
|
|
||||||
|
for (MWWorld::ContainerStoreIterator it = store.begin();
|
||||||
|
it != store.end(); ++it)
|
||||||
|
{
|
||||||
|
if (Misc::StringUtils::ciEqual(it->getCellRef().mRefID, "gold_001"))
|
||||||
|
{
|
||||||
|
gold = *it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
gold.getRefData().setCount(gold.getRefData().getCount() - getEnchantPrice());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,11 +36,13 @@ namespace MWMechanics
|
||||||
void nextEnchantType(); //Set enchant type to next possible type (for mOldItemPtr object)
|
void nextEnchantType(); //Set enchant type to next possible type (for mOldItemPtr object)
|
||||||
int getEnchantType() const;
|
int getEnchantType() const;
|
||||||
int getEnchantCost() const;
|
int getEnchantCost() const;
|
||||||
|
int getEnchantPrice() const;
|
||||||
int getMaxEnchantValue() const;
|
int getMaxEnchantValue() const;
|
||||||
int getGemCharge() const;
|
int getGemCharge() const;
|
||||||
float getEnchantChance() const;
|
float getEnchantChance() const;
|
||||||
bool soulEmpty() const; //Return true if empty
|
bool soulEmpty() const; //Return true if empty
|
||||||
bool itemEmpty() const; //Return true if empty
|
bool itemEmpty() const; //Return true if empty
|
||||||
|
void payForEnchantment() const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -97,11 +97,11 @@
|
||||||
<UserString key="HStretch" value="true"/>
|
<UserString key="HStretch" value="true"/>
|
||||||
</Widget>
|
</Widget>
|
||||||
|
|
||||||
<Widget type="AutoSizedTextBox" skin="NormalText">
|
<Widget type="AutoSizedTextBox" skin="NormalText" name="PriceTextLabel">
|
||||||
<Property key="Caption" value="#{sBarterDialog7}"/>
|
<Property key="Caption" value="#{sBarterDialog7}"/>
|
||||||
</Widget>
|
</Widget>
|
||||||
<Widget type="AutoSizedTextBox" skin="SandText" name="PriceLabel">
|
<Widget type="AutoSizedTextBox" skin="SandText" name="PriceLabel">
|
||||||
<Property key="Caption" value="30"/>
|
<Property key="Caption" value="0"/>
|
||||||
</Widget>
|
</Widget>
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue