PHP Calculating Game Energy Consumption Timescale

Viewed 491

What I Am Trying To Achieve

In an on-line game, you can achieve awards and other energy based goals. One could require a total of 24,000 energy which is a time based one, whereas others only 25. Based on starting with 0 energy and no lost energy sitting there whilst the user sleeps or whatnot, I wish to calculate how long it would take to acquire the amount of energy needed.

--------------------------------------------------------------------
|   Energy      |   Cooldown   |  Additional  |   Limit   |  wait  |
|               |              |    Energy    |           |        |
--------------------------------------------------------------------
|   Natural     |   10 minutes |     5        |   N/A     |    Y   |
|   Booster 1   |   24 hours   |     150      |   1 p/24h |    Y   |
|   Booster 2   |   6 hours    |     150      |   4 p/24h |    N   |
|   Booster 3   |   6 hours    |     250      |   4 p/24h |    Y   |
--------------------------------------------------------------------

The total energy a person can amount to in a 24 hour period is 2,470 via 720 natural energy, 150 from Booster 1, 600 from Booster 2 and 1,000 from Booster 3.

So you gain 5 natural energy every 10 minutes (600 seconds) and you can top up your energy with boosters which instantly adds the "Cooldown". So based on starting with 0 energy, you could jump to 1,000 energy. The "Wait" means you need to wait until the cooldown is over or not.


What I Have Done So Far

To calculate the days, I have done the following:

$days = floor($Energy_Needed / 2470) * 86400;

And for the remaining energy needed I have done the following:

$remaining = $Energy_Needed - (floor($Energy_Needed / 2470) * 2470);

Question

Once the $days have been calculated, it is a matter of starting of fresh again so if $remaining > 1000 (as the user can jump to this so it would just be N Days) how can I find the best remaining time?

NOTE: I am only looking for the total amount of seconds, no "prettiness".

2 Answers
Related