1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-04-11 21:06:43 +00:00

Enchanting price mechanics

This commit is contained in:
Glorf 2013-04-02 20:46:48 +02:00
parent 0856e3ebc2
commit 369cf0b4ca
3 changed files with 51 additions and 16 deletions

View file

@ -63,6 +63,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 +88,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 ();
} }
@ -103,13 +99,14 @@ namespace MWGui
void EnchantingDialog::startSelfEnchanting(MWWorld::Ptr soulgem) void EnchantingDialog::startSelfEnchanting(MWWorld::Ptr soulgem)
{ {
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
MWWorld::Ptr gem = soulgem;
mEnchanting.setSelfEnchanting(true); mEnchanting.setSelfEnchanting(true);
mEnchanting.setEnchanter(player); mEnchanting.setEnchanter(player);
mPtr = player; mPtr = player;
startEditing(); startEditing();
mEnchanting.setSoulGem(gem);
} }
void EnchantingDialog::onReferenceUnavailable () void EnchantingDialog::onReferenceUnavailable ()
@ -252,12 +249,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 +270,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)

View file

@ -3,6 +3,7 @@
#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"
@ -79,7 +80,10 @@ 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());
payForEnchantment();
return true; return true;
} }
@ -126,6 +130,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 +161,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 +233,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());
}
} }

View file

@ -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