Page 1 of 4

Trader Gold

Posted: 26 Mar 2014, 19:40
by Jyby
I'd like to do this feature for vr0.30.0 https://bugs.openmw.org/issues/953

I was thinking of ways to do it, one was:

We could have an event let us know if its been 24 hours since the player last purchased from an NPC.

This event would use only take nano seconds of the CPU and in practice there may only be upwards of 50 events within a 24 hour period, i.e. the player purchased from 50 npc in 24 hours.

Another way would be to check the difference in time when the user asks the npc to trade and then set the gold.

Please provide me with some guidance!

EDIT: Or we could set all npcs gold at time 00:00 every day. But that is very inefficient.


Is it every 24 hours or 24 hours since the purchase?

Re: Trader Gold

Posted: 26 Mar 2014, 19:51
by Zini
We need indeed more research. Is it really 24h since the last trade with this merchant? Or does the reset happen every 24h in general? Also, are these 24h hardcoded or is there a GMST for it? Any advice I can give you regarding the implementation depends on which variant applies here.

Re: Trader Gold

Posted: 26 Mar 2014, 20:14
by Jyby
Here are the steps I took to test your 24 hour question:

Vendor 1: First Purchase
Vendor 2: Second Purchase

1) I waited for 24 hours using the rest feature.
2) I purchased from Vendor 1
3) I went out side and waited for 2 hours in game
4) I purchased from Vendor 2
5) I waited the difference (22 hours) using the wait feature
6) Went back to vendor 1, her gold was reset.
7) Immediately went to Vendor 2 and her gold was the same.
8) I waited the difference for Vendor 2's 24 hours and then her gold was reset.

It appears that gold is set 24 hours from purchase and the time from purchase is vendor independent.

Re: Trader Gold

Posted: 26 Mar 2014, 20:26
by Zini
It appears that gold is set 24 hours from purchase and the time from purchase is vendor independent.
I am not sure if I read that statement correctly. From your data it seems that every vendor has his own timer and once it passes 24h a reset happens. Is that what you mean?

In this case we need to add a MWWorld::TimeStamp to MWMechanics::CreatureStats (since creatures can also be vendors). This needs to be initialised in the ensureCustomData functions of MWClass:Npc and MWClass::Creature and checked for a 24h difference/set to the current time stamp, whenever the player trades with the respective actor.

Re: Trader Gold

Posted: 26 Mar 2014, 20:43
by Okulo
But then does it reset 24 hours after the first purchase (ie. the first time the balance has changed) or 24 hours after the last purchase (ie. the last time the balance has changed)?

Re: Trader Gold

Posted: 26 Mar 2014, 20:46
by Zini
Good question. Needs more research.

Re: Trader Gold

Posted: 26 Mar 2014, 21:16
by Nomadic1
Last purchase, from my own play experience.

Re: Trader Gold

Posted: 26 Mar 2014, 21:44
by Jyby
I am not sure if I read that statement correctly. From your data it seems that every vendor has his own timer and once it passes 24h a reset happens. Is that what you mean?


Yes!

We know this because,

1) two purchases were made two hours apart from each other
2) waited 22 hours after the first purchase (Vendor 1's gold pot was reset)
3) waited 2 more hours (Vendor 2's gold pot was reset)

Here is a time line:

Day 1
8:00PM - first purchase Vendor 1
10:00PM - second purchase Vendor 2

Day 2
8:00PM - Vendor 1 reset, Vendor 2 not reset
10:00PM - Vendor 2 reset
Okulo wrote:But then does it reset 24 hours after the first purchase (ie. the first time the balance has changed) or 24 hours after the last purchase (ie. the last time the balance has changed)?
First time balance has changed.
Nomadic1 wrote:Last purchase, from my own play experience.
Actually it is 24 hours from first purchase. Here is what I found

1 Vendor Test

1) wait 24 hours (rest feature)
2) purchase 1
3) wait in game 2 hours
4) purchase 2
5) wait 22 hours (rest feature)
6) Vendors gold reset


Results from both tests:
Gold resets 24 hours from first balance change and time-stamp is independent for each vendor.

Re: Trader Gold

Posted: 26 Mar 2014, 23:28
by Jyby
How does this look so far? Am I doing the appropriate thing with the typing? Or is there a better way?

creaturestats.cpp

Code: Select all

    void CreatureStats::setTradeTime(MWWorld::TimeStamp tradeTime) 
    {
        mTradeTime = tradeTime;
    }

    MWWorld::TimeStamp CreatureStats::getTradeTime() const
    {
        return mTradeTime;
    }
creaturestats.hpp

Code: Select all

       
   MWWorld::TimeStamp mTradeTime; 
   
   <--------------    public       ---------------->

   // Relates to NPC gold reset after waiting 24 hours
   void setTradeTime(MWWorld::TimeStamp tradeTime);
   bool getTradeTime();

EDIT:
As I was playing/reading the code I discovered that in the game NPC can store gold in containers that are available to the player. What happens during a gold reset to this gold? If the NPC has gold in a container that they use for transactions how do we know where to put the gold during a gold reset?

Code: Select all

    void TradeWindow::checkTradeTime() {
        if (MWBase::Environment::get().getWorld()->getTimeStamp() >= actor->getTimeStamp() + 24.0)
            ... Where does the gold go? ...
    }
I'm not positive I coded the above framing right.

I need guidance on what I'm allowed to use and what I should avoid.

Thanks




EDIT: What happens if we save?

The way I have it now it appears to set the actors trade time to the game time upon starting the world.

Should this trade time be a state that is saved? If a player trades and then plays a few more in game hours then saves and comes back to play again than we should load the trade time from the saved game for that actor.

Otherwise the trade time will be reset to current game time upon initialization.

Code: Select all

data->mCreatureStats.setTradeTime (MWBase::Environment::get().getWorld()->getTimeStamp());

Re: Trader Gold

Posted: 27 Mar 2014, 01:59
by heilkitty
Zini wrote:Also, are these 24h hardcoded or is there a GMST for it?
There is a GMST.