From 2a8bf46607429dfa788338689cb92d06f6ad6904 Mon Sep 17 00:00:00 2001 From: Jeffrey Haines Date: Thu, 27 Mar 2014 01:23:56 -0400 Subject: [PATCH 1/2] Trader Gold Reset Delay Implemented traded gold reset delay. Note: Traders gold pool is still in inventory. --- apps/openmw/mwclass/creature.cpp | 7 ++++- apps/openmw/mwclass/npc.cpp | 7 +++++ apps/openmw/mwgui/tradewindow.cpp | 35 +++++++++++++++++++++++ apps/openmw/mwgui/tradewindow.hpp | 4 +++ apps/openmw/mwmechanics/creaturestats.cpp | 20 +++++++++++++ apps/openmw/mwmechanics/creaturestats.hpp | 12 ++++++++ 6 files changed, 84 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index 0f7ffdc48..a224de71e 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -123,6 +123,11 @@ namespace MWClass else data->mContainerStore = new MWWorld::ContainerStore(); + // Relates to NPC gold reset delay + data->mCreatureStats.setTradeTime (MWBase::Environment::get().getWorld()->getTimeStamp()); + + data->mCreatureStats.setGoldPool(ref->mBase->mData.mGold); + // store ptr.getRefData().setCustomData (data.release()); @@ -134,7 +139,7 @@ namespace MWClass getContainerStore(ptr).add(MWWorld::ContainerStore::sGoldId, ref->mBase->mData.mGold, ptr); if (ref->mBase->mFlags & ESM::Creature::Weapon) - getInventoryStore(ptr).autoEquip(ptr); + getInventoryStore(ptr).autoEquip(ptr); } } diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 3fbd0d5b2..502ff6ef6 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -357,6 +357,11 @@ namespace MWClass data->mInventoryStore.fill(ref->mBase->mInventory, getId(ptr), "", MWBase::Environment::get().getWorld()->getStore()); + // Relates to NPC gold reset delay + data->mNpcStats.setTradeTime(MWBase::Environment::get().getWorld()->getTimeStamp()); + + data->mNpcStats.setGoldPool(gold); + // store ptr.getRefData().setCustomData (data.release()); @@ -365,6 +370,8 @@ namespace MWClass getContainerStore(ptr).add(MWWorld::ContainerStore::sGoldId, gold, ptr); getInventoryStore(ptr).autoEquip(ptr); + + } } diff --git a/apps/openmw/mwgui/tradewindow.cpp b/apps/openmw/mwgui/tradewindow.cpp index 92ba9470d..41c3cd197 100644 --- a/apps/openmw/mwgui/tradewindow.cpp +++ b/apps/openmw/mwgui/tradewindow.cpp @@ -84,8 +84,11 @@ namespace MWGui mCurrentBalance = 0; mCurrentMerchantOffer = 0; + checkTradeTime(); + std::vector itemSources; MWBase::Environment::get().getWorld()->getContainersOwnedBy(actor, itemSources); + // Important: actor goes last, so that items purchased by the merchant go into his inventory itemSources.push_back(actor); std::vector worldItems; @@ -360,6 +363,8 @@ namespace MWGui addOrRemoveGold(-mCurrentBalance, mPtr); } + updateTradeTime(); + MWBase::Environment::get().getWindowManager()->getDialogueWindow()->addResponse( MWBase::Environment::get().getWorld()->getStore().get().find("sBarterDialog5")->getString()); @@ -474,4 +479,34 @@ namespace MWGui } return merchantGold; } + + // Relates to NPC gold reset delay + void TradeWindow::checkTradeTime() + { + MWWorld::ContainerStore store = mPtr.getClass().getContainerStore(mPtr); + MWWorld::LiveCellRef *ref = mPtr.get(); + const MWMechanics::CreatureStats &sellerStats = mPtr.getClass().getCreatureStats(mPtr); + double delay = boost::lexical_cast(MWBase::Environment::get().getWorld()->getStore().get().find("fBarterGoldResetDelay")->getInt()); + + // if time stamp longer than gold reset delay, reset gold. + if (MWBase::Environment::get().getWorld()->getTimeStamp() >= sellerStats.getTradeTime() + delay) + { + addOrRemoveGold(-store.count(MWWorld::ContainerStore::sGoldId), mPtr); + addOrRemoveGold(+ref->mBase->mNpdt52.mGold, mPtr); + } + } + + void TradeWindow::updateTradeTime() + { + MWWorld::ContainerStore store = mPtr.getClass().getContainerStore(mPtr); + MWMechanics::CreatureStats &sellerStats = mPtr.getClass().getCreatureStats(mPtr); + double delay = boost::lexical_cast(MWBase::Environment::get().getWorld()->getStore().get().find("fBarterGoldResetDelay")->getInt()); + + // If trade timestamp is within reset delay don't set + if ( ! (MWBase::Environment::get().getWorld()->getTimeStamp() >= sellerStats.getTradeTime() && + MWBase::Environment::get().getWorld()->getTimeStamp() < sellerStats.getTradeTime() + delay) ) + { + sellerStats.setTradeTime(MWBase::Environment::get().getWorld()->getTimeStamp()); + } + } } diff --git a/apps/openmw/mwgui/tradewindow.hpp b/apps/openmw/mwgui/tradewindow.hpp index 1a8999e6e..5c154d425 100644 --- a/apps/openmw/mwgui/tradewindow.hpp +++ b/apps/openmw/mwgui/tradewindow.hpp @@ -100,6 +100,10 @@ namespace MWGui virtual void onReferenceUnavailable(); int getMerchantGold(); + + // Relates to NPC gold reset delay + void checkTradeTime(); + void updateTradeTime(); }; } diff --git a/apps/openmw/mwmechanics/creaturestats.cpp b/apps/openmw/mwmechanics/creaturestats.cpp index d61b96739..feed8d182 100644 --- a/apps/openmw/mwmechanics/creaturestats.cpp +++ b/apps/openmw/mwmechanics/creaturestats.cpp @@ -476,4 +476,24 @@ namespace MWMechanics for (int i=0; i<3; ++i) mDynamic[i].readState (state.mDynamic[i]); } + + // Relates to NPC gold reset delay + void CreatureStats::setTradeTime(MWWorld::TimeStamp tradeTime) + { + mTradeTime = tradeTime; + } + + MWWorld::TimeStamp CreatureStats::getTradeTime() const + { + return mTradeTime; + } + + void CreatureStats::setGoldPool(int pool) + { + mGoldPool = pool; + } + int CreatureStats::getGoldPool() const + { + return mGoldPool; + } } diff --git a/apps/openmw/mwmechanics/creaturestats.hpp b/apps/openmw/mwmechanics/creaturestats.hpp index 94e506fc4..20a9a5799 100644 --- a/apps/openmw/mwmechanics/creaturestats.hpp +++ b/apps/openmw/mwmechanics/creaturestats.hpp @@ -54,6 +54,11 @@ namespace MWMechanics bool mRecalcDynamicStats; std::map mUsedPowers; + + MWWorld::TimeStamp mTradeTime; // Relates to NPC gold reset delay + + int mGoldPool; // the pool of merchant gold not in inventory + protected: bool mIsWerewolf; AttributeValue mWerewolfAttributes[8]; @@ -221,6 +226,13 @@ namespace MWMechanics void writeState (ESM::CreatureStats& state) const; void readState (const ESM::CreatureStats& state); + + // Relates to NPC gold reset delay + void setTradeTime(MWWorld::TimeStamp tradeTime); + MWWorld::TimeStamp getTradeTime() const; + + void setGoldPool(int pool); + int getGoldPool() const; }; } From 6896142db17a53f5df20a156df8ac136c67b6b59 Mon Sep 17 00:00:00 2001 From: Jeffrey Haines Date: Thu, 27 Mar 2014 07:30:24 -0400 Subject: [PATCH 2/2] Trader Gold Reset Delay MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Trade Time initialized to 0 Gold pot set correctly for npc’s and creatures --- apps/openmw/mwclass/creature.cpp | 4 ++-- apps/openmw/mwclass/npc.cpp | 2 +- apps/openmw/mwgui/tradewindow.cpp | 3 +-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index a224de71e..72b315484 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -124,12 +124,12 @@ namespace MWClass data->mContainerStore = new MWWorld::ContainerStore(); // Relates to NPC gold reset delay - data->mCreatureStats.setTradeTime (MWBase::Environment::get().getWorld()->getTimeStamp()); + data->mCreatureStats.setTradeTime(MWWorld::TimeStamp(0.0, 0)); data->mCreatureStats.setGoldPool(ref->mBase->mData.mGold); // store - ptr.getRefData().setCustomData (data.release()); + ptr.getRefData().setCustomData(data.release()); getContainerStore(ptr).fill(ref->mBase->mInventory, getId(ptr), "", MWBase::Environment::get().getWorld()->getStore()); diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 502ff6ef6..020f3b3af 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -358,7 +358,7 @@ namespace MWClass MWBase::Environment::get().getWorld()->getStore()); // Relates to NPC gold reset delay - data->mNpcStats.setTradeTime(MWBase::Environment::get().getWorld()->getTimeStamp()); + data->mNpcStats.setTradeTime(MWWorld::TimeStamp(0.0, 0)); data->mNpcStats.setGoldPool(gold); diff --git a/apps/openmw/mwgui/tradewindow.cpp b/apps/openmw/mwgui/tradewindow.cpp index 41c3cd197..0525a97ae 100644 --- a/apps/openmw/mwgui/tradewindow.cpp +++ b/apps/openmw/mwgui/tradewindow.cpp @@ -484,7 +484,6 @@ namespace MWGui void TradeWindow::checkTradeTime() { MWWorld::ContainerStore store = mPtr.getClass().getContainerStore(mPtr); - MWWorld::LiveCellRef *ref = mPtr.get(); const MWMechanics::CreatureStats &sellerStats = mPtr.getClass().getCreatureStats(mPtr); double delay = boost::lexical_cast(MWBase::Environment::get().getWorld()->getStore().get().find("fBarterGoldResetDelay")->getInt()); @@ -492,7 +491,7 @@ namespace MWGui if (MWBase::Environment::get().getWorld()->getTimeStamp() >= sellerStats.getTradeTime() + delay) { addOrRemoveGold(-store.count(MWWorld::ContainerStore::sGoldId), mPtr); - addOrRemoveGold(+ref->mBase->mNpdt52.mGold, mPtr); + addOrRemoveGold(+sellerStats.getGoldPool(), mPtr); } }