What I wanted to make is just a very simple starting point for a system where there are a number of items at a game market of some kind. At any given moment each item can be bought or sold at the market, and the current price of the items will go up and down within a certain range. The player can then buy an item at the market at a low price, and then later on sell it back when they are worth more to make money.
This trade simulator might just be a feature of a game, or I guess it could be the central focal point of the game actually. There are a lot of little details here, and there when it comes to something like this, such as the logic at play that will set prices, and how often prices will change. However I have to start somewhere when it comes to something like this, so in this post I will just be going over a very simple, basic, example of this sort of thing.
I will then want to create a main state object for this module that will hold current market process for these items in the database. In addition it can also be used as a way to create, and mutate a players collection of these items, and mutate a state object that contains a money property.
This is more or less the kind of module that I had in mind, there might be a lot more to add to it, but much of that might change a little from one project to the next. For this example at least, I just wanted to have a simple hello world type form of the module. So with that said I think this might be more or less what I had in mind.
This module is just used to create a main game state, and does so once when it first starts. I can then call TradeSim.startNew to create a new game in the console if I want to. The main way that I work with this then is to call the action method of this module, I can then pass a buy, or sell value for a kind of action, then an item key followed by a count of that item.
One thing that might work would be to create some kind of life simulator type game, and this kind of feature might pop up in one or more places in the game. For example there could be a stock exchange type place, and something not all that more involve than this could be one way to go about buying and selling shares of places in the game. In that kind of situation I might use something just a little more advanced than this where certain actions can be preformed at the corresponding places in the game to increase and decrease the stock prices of the places. Also I could have it so that the stocks will pay out dividends over time, so it would make sense to just sit on stock and wait. this is of course just one idea that comes to mind that i may or may not get to at some point.
However maybe a game that would make use of this does not really need to be all that more advanced that what i have hear all ready. If I get some time, maybe I will get around to just making some kind of canvas project that makes use of this module that will just be in a slightly different form than it is now.