1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-19 20:53:50 +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()));
mPrice->setCaption(boost::lexical_cast<std::string>(mEnchanting.getEnchantPrice()));
switch(mEnchanting.getEnchantType())
{
case 0:
@ -86,16 +88,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 ();
}
@ -103,13 +99,14 @@ namespace MWGui
void EnchantingDialog::startSelfEnchanting(MWWorld::Ptr soulgem)
{
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
MWWorld::Ptr gem = soulgem;
mEnchanting.setSelfEnchanting(true);
mEnchanting.setEnchanter(player);
mPtr = player;
startEditing();
mEnchanting.setSoulGem(gem);
}
void EnchantingDialog::onReferenceUnavailable ()
@ -252,12 +249,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 +270,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

@ -3,6 +3,7 @@
#include "../mwworld/manualref.hpp"
#include "../mwworld/class.hpp"
#include "../mwworld/containerstore.hpp"
#include "../mwbase/mechanicsmanager.hpp"
#include "creaturestats.hpp"
#include "npcstats.hpp"
@ -79,7 +80,10 @@ 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());
payForEnchantment();
return true;
}
@ -126,6 +130,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 +161,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 +233,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