Online game - resources through time
Posted: Mon Sep 29, 2008 3:47 pm
Hi, I am working on an online php text-based game. In this game, you can build/upgrade a resource gatherer (for example, a gold mine) to get more resources per hour. Let's say:
Level 1: 1000 gold per hour
Level 2: 2000 gold per hour
And so on.
I'm storing on the database the time when the last upgrade was finished, and how much gold the player had back then. That way, if he wants to know how much gold he has right now, I only have to do a little math (gold_he_had * time_passed * gold_per_hour).
The problem: If an upgrade finishes while the player is offline, I won't be able to calculate how much gold he has since the equation is no longer linear (i.e. the gold rate changed sometime we were not watching).
The solution could be on of those:
- Work on non-linear calculations (seems a little complex)
- Keep a cronjob running to check for finished upgrades and update the gathering rates on the fly (more server-resource consuming)
- Ask for user input to start gathering resources faster after an upgrade completes (that way the player couldn't have the benefit of an offline upgrade if he doesn't show up by the time the upgrade finishes)
I would like to hear more ideas for solutions, or any feedback about this part of my game. The application runs on PHP5 + MySQL. Thanks in advance.
Level 1: 1000 gold per hour
Level 2: 2000 gold per hour
And so on.
I'm storing on the database the time when the last upgrade was finished, and how much gold the player had back then. That way, if he wants to know how much gold he has right now, I only have to do a little math (gold_he_had * time_passed * gold_per_hour).
The problem: If an upgrade finishes while the player is offline, I won't be able to calculate how much gold he has since the equation is no longer linear (i.e. the gold rate changed sometime we were not watching).
The solution could be on of those:
- Work on non-linear calculations (seems a little complex)
- Keep a cronjob running to check for finished upgrades and update the gathering rates on the fly (more server-resource consuming)
- Ask for user input to start gathering resources faster after an upgrade completes (that way the player couldn't have the benefit of an offline upgrade if he doesn't show up by the time the upgrade finishes)
I would like to hear more ideas for solutions, or any feedback about this part of my game. The application runs on PHP5 + MySQL. Thanks in advance.