Page 1 of 1

Energy Regeneration

PostPosted: Sat Jan 04, 2020 10:57 am
by Fireal
Hey guys, I'm trying to figure out the best way to handle how energy restores for my game. At first I was just going to run a cron every 10 minutes adding 10 energy points to all users. However, that didn't seem right because certain users perform energy depleting actions at different times, and I would want the regeneration to be 10 minutes from their last action. With that said, how would you handle this?

Add 10 to a user's energy 10 minutes after they performed their last action.

Only thing I can think of is starting to use timestamps in the user tables. By the way I am using PHP/MySQL. :mrgreen:

Re: Energy Regeneration

PostPosted: Mon Jan 06, 2020 7:22 am
by a_bertrand
You could have different ways to do it:
1) Have a cron every min which queries who did an action before 10 min ago => restore energy
2) When a page load you run basically the same as in point 1 (but doesn't require a cron, yet it may be run a lot more often, so you may need to have some way to make it less frequent or extremely quick)
3) When a page load for a given user, the check (of point 1) is done on his/her player only

Re: Energy Regeneration

PostPosted: Sat Jan 11, 2020 11:07 am
by hallsofvallhalla
yeah a timestamp in the table then every reload checks the timestamp but you could also not make it a static minute or amount, you could make each action affect the time and amount based on the action.