I'm currently working on the server side logic of a real-time online browser game build using NodeJS. Currently the logic works like this...
1. Receive an event from a player (queue something for production)
2. Calculate when the next event will happen in the game (look at when the next production will complete or when the next research project will finish)
3. Set a timeout so that the server effectively sleeps until the next event happens (unless interrupted by a player sending another event)
This seems to work very well so far. When the server wakes up from the timeout it updates the game with the amount of time passed and all production and research etc. is updated by the ellapsed time.
The problem I'm having at the moment is that the amount of money generated for a player is based on how many workers they have. Worker numbers slowly increase over time until they reach a population cap. Given the following facts...
- The player has 1 worker
- The player has no money
- A new working is created every minute
- A worker produces 100 credits per minute
How many credits does the user have after an hour? I have no idea how to predict the number of credits produced as the number of workers increases over time
I hope that makes sense!