# Calculating price increases in a virtual economy

I'm trying to design a method to have price increase depending on the number of items bought from shops in my game.

I'm fairly new to coding and I am struggling to figure out how to program the increase in price when buying multiple items.

Currently the price increase is a percentage increase based on the quantity of items in store, however if I buy 5 items, all 5 items will be charged the same. How can I get it so each item is charged at a different price?

I also need a reasonable inflation system, right now my code just determines a price increase based on the percentage of items remaining, but it's very simple and easy to exploit. It looks like this:

30 - 2 = 28

1 - (28 / 30) = 0.07 0.93

1 + 0.07 = 1.07

10 * 1.07 = 10.7

Rounded up

Price = 11

I'd like to make this more complex also.

• "More complex" is usually not the real goal. Maybe there are negative outcomes in your current system that you need to add some complexity to solve — but it's not the complexity we want, it's the solution. Can you articulate in more detail what the problem is in your current formula that you're hoping can be solved with (hopefully not too much) extra complexity? What kind of exploit do you want to prevent? Commented Apr 12, 2020 at 14:18
• Currently the calculation only takes place once based on the current items in stock. So you could buy out the entire stock while only taking the hit of a small price increase, as each subsequent item removal from the system isn't taken into account. Commented Apr 12, 2020 at 15:12
• Does this answer your question? Designing a trade / market system Commented May 14, 2020 at 8:30

I don't have enough reputation points to leave comments. So it forces me to answer this way.

First of all excuse me if my English is not very good. It is not my native language.

If I am allowed any constructive criticism, generating a price hike for each item you buy sooner or later will be a negative point for the player. I would say that sooner rather than later and I end up producing a displeasure and that in the end I end up leaving the game.

Let's say you buy the first bottle of miracle potion at 5, the 2nd at 55, the 3rd at 70, the 4th at 93, you will be paying the 5th for more than 100.

And from what I'm understanding, you want the boost value to be given regardless of whether you make all those purchases in the same transaction. That is, it does not matter if you buy the 5 together, or at different times. If you wanted to emulate the market, that is not the way.

If I go to the market today and buy 5 soda cans of the same thing, I pay it at the same price for each can, unless I find a 3x2 offer to give an employment. Tomorrow is something else, and the price may be different.

You should objectively analyze what you intend to do. Define the limits or scope of the "simulation of an inflationary process". That by the way, inflation is not given in that way.

The inflation process is largely due to an excessive increase in the money supply. More info in Money Supply.

But it is possible that achieving a mathematical model that allows you to carry a macroeconomic balance in your game is more complex than you are looking for.

It seems to me that the simplest approach you can start with is to find a way to emulate the principle of the law of supply and demand.

There is a great video that explains the basis for this.

If managing to implement even the simplest algorithm to cover the basics of that, it might be enough to satisfy your needs.

But as I said before: you should first have your limits well established. How far do you intend to go with emulating the micro and macro economic aspects?

• Keep in mind that the OP has not specified whether this was for a single player game or a multi-player game. This type of algorithm has been a fundamental gameplay mechanic in trade games such as Port Royale. Commented Apr 14, 2020 at 2:06
• I have to admit that I don't know Port Royale. But I find it hard to believe that it has an economy mechanism based on inflationary concepts and that it works without any countermeasures (direct or indirect) that control or balance it. Regardless of whether it is a singleplayer or multiplayer game, what is essential here is that it is dimensioned what it is intended to do with the economy of the game. If the economy will be one of the center pieces of the game, all the more reason I recommend that limits be set as soon as possible. Here it seems that this is still very immature. Commented Apr 14, 2020 at 2:33
• The interesting thing here is that it works both ways. You'll get a nice profit when you sell when the item is low in stock. Perhaps the concept of "inflation" is wrongly used here and it's more about pure offer and demand. Commented Apr 14, 2020 at 3:22
• Well, it would be important for Chris to spend some time analyzing in depth how he wants to manage the economy of his game. Depending on their scope and limits, we can lower the concepts to the ground and see the possibility of implementing them in the simplest possible way. Commented Apr 18, 2020 at 21:38