Trader Gold

Everything about development and the OpenMW source code.
User avatar
Jyby
Posts: 408
Joined: 10 Dec 2013, 04:16

Re: Trader Gold

Post by Jyby »

Sorry I'm a noob still! I found the gsmt in question!

its fBarterGoldResetDelay

:`D Not bad for my first real contribution.

Tell me if I did anything terrible...

I just need to figure out how to get the original base gold:

This line from bellow is in question: addOrRemoveGold(+ref->mBase->mNpdt12.mGold, mPtr);

Code: Select all

    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);
        int 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->mNpdt12.mGold, mPtr);
        }
            
    }

    void TradeWindow::updateTradeTime() 
    {
        MWWorld::ContainerStore store = mPtr.getClass().getContainerStore(mPtr);
        MWMechanics::CreatureStats &sellerStats = mPtr.getClass().getCreatureStats(mPtr);
        int delay = boost::lexical_cast<double>(MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fBarterGoldResetDelay")->getInt());

        // If trade timestamp is within 24 hours 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());
        }
    }
I'm sure there are better ways to do things. Please do tell!
User avatar
scrawl
Posts: 2152
Joined: 18 Feb 2012, 11:51

Re: Trader Gold

Post by scrawl »

As mentioned in the issue description (and I'm 90% sure about this), I think there is a difference between the trading gold pool and the gold item. If you kill a merchant that has 5000 starting "gold", he drops none of it (unless you gave him additional gold by selling something first).

So, I think we need to add an additional state (mGoldPool) to CreatureStats. The actual gold available for trading would then be mGoldPool + (number of gold pieces in inventory), whereas when you inspect the merchant's inventory (looting or stealing) only the gold pieces are there for taking.
User avatar
Jyby
Posts: 408
Joined: 10 Dec 2013, 04:16

Re: Trader Gold

Post by Jyby »

scrawl wrote:As mentioned in the issue description (and I'm 90% sure about this), I think there is a difference between the trading gold pool and the gold item. If you kill a merchant that has 5000 starting "gold", he drops none of it (unless you gave him additional gold by selling something first).

So, I think we need to add an additional state (mGoldPool) to CreatureStats. The actual gold available for trading would then be mGoldPool + (number of gold pieces in inventory), whereas when you inspect the merchant's inventory (looting or stealing) only the gold pieces are there for taking.
So if I trade gold? If I sell gold to the merchant does he get that gold in his inventory?

I agree we need a gold pool.

I've got the gold reset delay 100% working now. I will fix this next!
Nomadic1
Posts: 79
Joined: 16 Apr 2012, 09:08

Re: Trader Gold

Post by Nomadic1 »

Jyby wrote:
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.
Wow, that's not how I remembered it at all.
User avatar
Jyby
Posts: 408
Joined: 10 Dec 2013, 04:16

Re: Trader Gold

Post by Jyby »

Please do test and challenge my procedure!
User avatar
scrawl
Posts: 2152
Joined: 18 Feb 2012, 11:51

Re: Trader Gold

Post by scrawl »

So if I trade gold? If I sell gold to the merchant does he get that gold in his inventory?
In OpenMW, selling gold is no longer possible. That was nonsense anyway.
User avatar
Zini
Posts: 5538
Joined: 06 Aug 2011, 15:16

Re: Trader Gold

Post by Zini »

What a mess. Been a while since I have seen a more arbitrary game mechanic.

@scrawl: When you say "starting gold", you mean the mGold value in the actors record, right? If the actor also starts out with gold items in his inventory, would we have mGold+those coins initially? Also, when the vendor is buying something, which gold pool is used first? The one in the inventory or the other one? From your description it seems that when the vendor is selling something the gold will always go into the inventory.
Is the reset only affecting only the separate gold pool or also the inventory?

And do we know if and how bribery plays into this?

I guess more research is in order. If it hadn't the potential to break things, I would say abolish the whole system and go with what we have implemented now.
User avatar
Jyby
Posts: 408
Joined: 10 Dec 2013, 04:16

Re: Trader Gold

Post by Jyby »

So if the gold pool also contains gold from the vendors in game containers than we have to know where to put the gold during a gold reset.

We would need to find a case where this happens in vanilla Morrowind if you want it tested. I've started a new character and can look for such a case. But it may be impossible, i.e. guess and check would take a long time.

From what I gather,
- the vendor has mGold (the base vendor gold), and
- the vendor also has inventory gold.

Scrawl suggests mGoldPool could be used to track the amount of merchant gold left from mGold.

Two solutions I could think of:
1) We could remove the vendor gold from the inventory when we load a vendor actor.
2) We could separate vendor gold into mGoldPool (not base gold) and inventory before we load.

In either case we need to keep track of the amount of vendor gold and the gold the vendor has from bribe, and possible sale?

Tests:
I will test whether or not an NPC will pocket the gold you used to buy from them.
User avatar
Zini
Posts: 5538
Joined: 06 Aug 2011, 15:16

Re: Trader Gold

Post by Zini »

So if the gold pool also contains gold from the vendors in game containers than we have to know where to put the gold during a gold reset.
Note that this was purely speculation from my side. I have neither any evidence in favour or against this theory.
User avatar
Jyby
Posts: 408
Joined: 10 Dec 2013, 04:16

Re: Trader Gold

Post by Jyby »

Testing so far:

Test Case: Gold used in trade is not stored in actor inventory.
Steps to prove theory:
1) Go to any vendor.
2) Buy something to vendor.
3) Kill vendor, check for gold.

Scenario: Merchant Mudcrab.
Result: No gold in inventory after buying or selling.


Test Case: Gold used in bribe is stored in actor inventory.
Steps to prove theory:
1) Go to any vendor.
2) Bribe vendor.
3) Kill vendor, check for gold.

Scenario: Random vendor.
Result: Gold in inventory after bribing.


Conclusion:
mGold is not stored in inventory. Therefore the amount of mGold must be tracked in an inaccessible container or possible mGoldPool.

Note: Items that are sold to player can be in inventory or in the vendors environment or are in an inaccessible container.
This is already the case from what I've played so far in OpenMW.

Could merchant gold be flagged? Could we store it in an inaccessible container?
Or would it be better to use a variable such as mGoldPool to keep track of merchant gold and never add it to the vendors inventory?

Are these other scenarios relevant to our implementation?
List of other scenarios:
What happens when you give gold to NPC for quest? e.g. bandit
Where is gold coming from for completing a quest?
Last edited by Jyby on 28 Mar 2014, 00:23, edited 1 time in total.
Post Reply