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

add/remove gold from the player at the end of the transaction.

This commit is contained in:
scrawl 2012-05-18 22:21:44 +02:00
parent c004f5d570
commit c30b9e4bb9

View file

@ -5,6 +5,7 @@
#include "../mwbase/environment.hpp"
#include "../mwworld/world.hpp"
#include "../mwworld/inventorystore.hpp"
#include "../mwworld/manualref.hpp"
#include "window_manager.hpp"
#include "inventorywindow.hpp"
@ -206,6 +207,31 @@ namespace MWGui
transferBoughtItems();
mWindowManager.getInventoryWindow()->transferBoughtItems();
// add or remove gold from the player.
bool goldFound = false;
MWWorld::Ptr gold;
MWWorld::ContainerStore& playerStore = mWindowManager.getInventoryWindow()->getContainerStore();
for (MWWorld::ContainerStoreIterator it = playerStore.begin();
it != playerStore.end(); ++it)
{
if (MWWorld::Class::get(*it).getName(*it) == MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sGold")->str)
{
goldFound = true;
gold = *it;
}
}
if (goldFound)
{
gold.getRefData().setCount(gold.getRefData().getCount() + mCurrentBalance);
}
else
{
assert(mCurrentBalance > 0);
MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), "Gold_001");
ref.getPtr().getRefData().setCount(mCurrentBalance);
playerStore.add(ref.getPtr());
}
mWindowManager.setGuiMode(GM_Game);
}