mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-21 10:23:52 +00:00
Trader Gold Reset Delay
Implemented traded gold reset delay. Note: Traders gold pool is still in inventory.
This commit is contained in:
parent
235dbdf18e
commit
2a8bf46607
6 changed files with 84 additions and 1 deletions
|
@ -123,6 +123,11 @@ namespace MWClass
|
||||||
else
|
else
|
||||||
data->mContainerStore = new MWWorld::ContainerStore();
|
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
|
// store
|
||||||
ptr.getRefData().setCustomData (data.release());
|
ptr.getRefData().setCustomData (data.release());
|
||||||
|
|
||||||
|
|
|
@ -357,6 +357,11 @@ namespace MWClass
|
||||||
data->mInventoryStore.fill(ref->mBase->mInventory, getId(ptr), "",
|
data->mInventoryStore.fill(ref->mBase->mInventory, getId(ptr), "",
|
||||||
MWBase::Environment::get().getWorld()->getStore());
|
MWBase::Environment::get().getWorld()->getStore());
|
||||||
|
|
||||||
|
// Relates to NPC gold reset delay
|
||||||
|
data->mNpcStats.setTradeTime(MWBase::Environment::get().getWorld()->getTimeStamp());
|
||||||
|
|
||||||
|
data->mNpcStats.setGoldPool(gold);
|
||||||
|
|
||||||
// store
|
// store
|
||||||
ptr.getRefData().setCustomData (data.release());
|
ptr.getRefData().setCustomData (data.release());
|
||||||
|
|
||||||
|
@ -365,6 +370,8 @@ namespace MWClass
|
||||||
getContainerStore(ptr).add(MWWorld::ContainerStore::sGoldId, gold, ptr);
|
getContainerStore(ptr).add(MWWorld::ContainerStore::sGoldId, gold, ptr);
|
||||||
|
|
||||||
getInventoryStore(ptr).autoEquip(ptr);
|
getInventoryStore(ptr).autoEquip(ptr);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -84,8 +84,11 @@ namespace MWGui
|
||||||
mCurrentBalance = 0;
|
mCurrentBalance = 0;
|
||||||
mCurrentMerchantOffer = 0;
|
mCurrentMerchantOffer = 0;
|
||||||
|
|
||||||
|
checkTradeTime();
|
||||||
|
|
||||||
std::vector<MWWorld::Ptr> itemSources;
|
std::vector<MWWorld::Ptr> itemSources;
|
||||||
MWBase::Environment::get().getWorld()->getContainersOwnedBy(actor, itemSources);
|
MWBase::Environment::get().getWorld()->getContainersOwnedBy(actor, itemSources);
|
||||||
|
|
||||||
// Important: actor goes last, so that items purchased by the merchant go into his inventory
|
// Important: actor goes last, so that items purchased by the merchant go into his inventory
|
||||||
itemSources.push_back(actor);
|
itemSources.push_back(actor);
|
||||||
std::vector<MWWorld::Ptr> worldItems;
|
std::vector<MWWorld::Ptr> worldItems;
|
||||||
|
@ -360,6 +363,8 @@ namespace MWGui
|
||||||
addOrRemoveGold(-mCurrentBalance, mPtr);
|
addOrRemoveGold(-mCurrentBalance, mPtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateTradeTime();
|
||||||
|
|
||||||
MWBase::Environment::get().getWindowManager()->getDialogueWindow()->addResponse(
|
MWBase::Environment::get().getWindowManager()->getDialogueWindow()->addResponse(
|
||||||
MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("sBarterDialog5")->getString());
|
MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("sBarterDialog5")->getString());
|
||||||
|
|
||||||
|
@ -474,4 +479,34 @@ namespace MWGui
|
||||||
}
|
}
|
||||||
return merchantGold;
|
return merchantGold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Relates to NPC gold reset delay
|
||||||
|
void TradeWindow::checkTradeTime()
|
||||||
|
{
|
||||||
|
MWWorld::ContainerStore store = mPtr.getClass().getContainerStore(mPtr);
|
||||||
|
MWWorld::LiveCellRef<ESM::NPC> *ref = mPtr.get<ESM::NPC>();
|
||||||
|
const MWMechanics::CreatureStats &sellerStats = mPtr.getClass().getCreatureStats(mPtr);
|
||||||
|
double delay = boost::lexical_cast<double>(MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().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<double>(MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().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());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,6 +100,10 @@ namespace MWGui
|
||||||
virtual void onReferenceUnavailable();
|
virtual void onReferenceUnavailable();
|
||||||
|
|
||||||
int getMerchantGold();
|
int getMerchantGold();
|
||||||
|
|
||||||
|
// Relates to NPC gold reset delay
|
||||||
|
void checkTradeTime();
|
||||||
|
void updateTradeTime();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -476,4 +476,24 @@ namespace MWMechanics
|
||||||
for (int i=0; i<3; ++i)
|
for (int i=0; i<3; ++i)
|
||||||
mDynamic[i].readState (state.mDynamic[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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,11 @@ namespace MWMechanics
|
||||||
bool mRecalcDynamicStats;
|
bool mRecalcDynamicStats;
|
||||||
|
|
||||||
std::map<std::string, MWWorld::TimeStamp> mUsedPowers;
|
std::map<std::string, MWWorld::TimeStamp> mUsedPowers;
|
||||||
|
|
||||||
|
MWWorld::TimeStamp mTradeTime; // Relates to NPC gold reset delay
|
||||||
|
|
||||||
|
int mGoldPool; // the pool of merchant gold not in inventory
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool mIsWerewolf;
|
bool mIsWerewolf;
|
||||||
AttributeValue mWerewolfAttributes[8];
|
AttributeValue mWerewolfAttributes[8];
|
||||||
|
@ -221,6 +226,13 @@ namespace MWMechanics
|
||||||
void writeState (ESM::CreatureStats& state) const;
|
void writeState (ESM::CreatureStats& state) const;
|
||||||
|
|
||||||
void readState (const ESM::CreatureStats& state);
|
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;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue