Help Calculating Offline Progress With Different Boost Durations

Hi everyone,

I’m having some trouble calculating offline progress for my tycoon game. So I’ve calculated the total income a player can make, that part was no problem. But I also have a feature in my game called “boosts.” Boosts can be used by the player to multiply their income by a certain amount. Boosts can also be stacked on top of each other additively. For example, a player could activate a 2x, 5x, and 10x boost, which would mean a 17x boost in total.

The problem is that each boost can have a different duration. If each active boost has a duration greater or equal than the offline time of the player, then its no problem calculating their total income. But if a boost or multiple boosts have a duration less than offline time, then I don’t know what to do.

Here’s what I tried so far,. This is only taking in to account one boost, which is somewhat simple.

local boostedTime = math.min(boostDuration, offlineTime)
local unboostedTime = offlineTime - boostedTime

local boostedIncome = baseIncomePerSecond * boostedTime * boostMultiplier
local unboostedIncome = baseIncomePerSecond * unboostedTime

local totalIncome = boostedIncome + unboostedIncome

I think I might need to create some sort of timeline with when boosts end? I’m stuck and any help would be appreciated.

1 Like

i would put all the boosts into a list sorted by how much effect they have

subtract all boosts by the one with the lowest duration, then get that time and multiply it by all boosts and income to get the amount of money made while that boost was active

repeat until either they pass the time in which they have logged on or there are no more boosts left

then just add up all the calculations

1 Like

(you could add the time in which the player logged back on as a 1x boost and end that loop if that boost is removed)

HI Exozorcus,

Thank you for the solution. I got it working.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.