1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-01 00:15:32 +00:00

Merge remote-tracking branch 'glorf/enchanting'

This commit is contained in:
Marc Zinnschlag 2013-04-03 19:39:18 +02:00
commit 32d3fe0e35
5 changed files with 77 additions and 19 deletions

View file

@ -32,6 +32,7 @@ namespace MWGui
getWidget(mTypeButton, "TypeButton");
getWidget(mBuyButton, "BuyButton");
getWidget(mPrice, "PriceLabel");
getWidget(mPriceText, "PriceTextLabel");
setWidgets(mAvailableEffectsList, mUsedEffectsView);
@ -63,6 +64,8 @@ namespace MWGui
mCastCost->setCaption(boost::lexical_cast<std::string>(mEnchanting.getEnchantCost()));
mPrice->setCaption(boost::lexical_cast<std::string>(mEnchanting.getEnchantPrice()));
switch(mEnchanting.getEnchantType())
{
case 0:
@ -86,16 +89,10 @@ namespace MWGui
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.setEnchanter(player);
mEnchanting.setEnchanter(actor);
mPtr = player;
mPtr = actor;
startEditing ();
}
@ -108,8 +105,23 @@ namespace MWGui
mEnchanting.setEnchanter(player);
mPtr = player;
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 ()
@ -252,12 +264,6 @@ namespace MWGui
return;
}
if (boost::lexical_cast<int>(mPrice->getCaption()) > mWindowManager.getInventoryWindow()->getPlayerGold())
{
mWindowManager.messageBox ("#{sNotifyMessage18}");
return;
}
if (mEnchanting.soulEmpty())
{
mWindowManager.messageBox ("#{sNotifyMessage52}");
@ -279,6 +285,12 @@ namespace MWGui
mEnchanting.setNewItemName(mName->getCaption());
mEnchanting.setEffect(mEffectList);
if (mEnchanting.getEnchantPrice() > mWindowManager.getInventoryWindow()->getPlayerGold())
{
mWindowManager.messageBox ("#{sNotifyMessage18}");
return;
}
int result = mEnchanting.create();
if(result==1)

View file

@ -56,6 +56,7 @@ namespace MWGui
MyGUI::TextBox* mCastCost;
MyGUI::TextBox* mCharge;
MyGUI::TextBox* mPrice;
MyGUI::TextBox* mPriceText;
MWMechanics::Enchanting mEnchanting;
ESM::EffectList mEffectList;

View file

@ -3,9 +3,11 @@
#include "../mwworld/manualref.hpp"
#include "../mwworld/class.hpp"
#include "../mwworld/containerstore.hpp"
#include "../mwbase/mechanicsmanager.hpp"
#include "creaturestats.hpp"
#include "npcstats.hpp"
#include <boost/algorithm/string.hpp>
namespace MWMechanics
{
@ -53,7 +55,12 @@ namespace MWMechanics
{
ESM::Enchantment enchantment;
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)
{
@ -79,7 +86,11 @@ namespace MWMechanics
MWWorld::ManualRef ref (MWBase::Environment::get().getWorld()->getStore(), mOldItemId);
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;
}
@ -126,6 +137,8 @@ namespace MWMechanics
float cost = 0;
std::vector<ESM::ENAMstruct> mEffects = mEffectList.mList;
int i=mEffects.size();
if(i<=0)
return 0;
/*
Formula from http://www.uesp.net/wiki/Morrowind:Enchant
@ -155,6 +168,17 @@ namespace MWMechanics
}
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
{
const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore();
@ -216,4 +240,23 @@ namespace MWMechanics
}
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());
}
}

View file

@ -36,11 +36,13 @@ namespace MWMechanics
void nextEnchantType(); //Set enchant type to next possible type (for mOldItemPtr object)
int getEnchantType() const;
int getEnchantCost() const;
int getEnchantPrice() const;
int getMaxEnchantValue() const;
int getGemCharge() const;
float getEnchantChance() const;
bool soulEmpty() const; //Return true if empty
bool itemEmpty() const; //Return true if empty
void payForEnchantment() const;
};
}
#endif

View file

@ -97,11 +97,11 @@
<UserString key="HStretch" value="true"/>
</Widget>
<Widget type="AutoSizedTextBox" skin="NormalText">
<Widget type="AutoSizedTextBox" skin="NormalText" name="PriceTextLabel">
<Property key="Caption" value="#{sBarterDialog7}"/>
</Widget>
<Widget type="AutoSizedTextBox" skin="SandText" name="PriceLabel">
<Property key="Caption" value="30"/>
<Property key="Caption" value="0"/>
</Widget>