Tracking Offline Activity
An offline activity is defined as a game state progression that happens in the game while the app is closed or in the background. These could be IGeneratorEntity
automatic collection or ITimedBoost
expirations. The moment the app resumes IdleKit's ActivityTrackingService
will attempt to process those offline activities by simulating time since the player left the game and updating game state accordingly. This simulation starts when the player exits and brings the game up to date with SystemTime
.
The Flow
Note
Any time an action is performed in the game or when the app is sent to the background the GameTime
is recorded in the IUserSavedData
along with the current ContentId
. This serialized timestamp allows the ActivityTrackingService
to know the time at which the player went offline.
Note
Refer to the startup document to learn more about the startup process.
-
During startup or when the app is paused the
ActivityTrackingService
reads the timestamp inIUserSavedData
corresponding to the currentContentId
(the timestamp of the last activity performed in the currentIContent
). -
The timestamp from the
IUserSavedData
is used to set theGameTime
as the starting point of the offline catchup. -
After the
IContent
is initialized or the app is unpaused (returned to the foreground) before any other gameplay logic happens, theActivityTrackingService
would then catch up from the previously setGameTime
to the currentSystemTime
. -
The first half of the catchup process involves gathering all the
timer listeners
that have expired between theGameTime
(start of the offline activities) and theSystemTime
(end of the offline activities). The list is then filtered as we are only interested listeners that effect payout in the game (i.e.,timed boosts
). Lastly, the list gets sorted based on thetimer listeners
endTime chronologically. -
During the second half of the catchup logic, we set the
GameTime
to each sortedtimer listeners
expiration time. Doing so allows us to perform time evaluations before each listener has expired (i.e., performIGeneratorEntity
collect evaluation before anITimedBoost
expires). After all thetimer listeners
have been processed, the offline catchup logic is complete, and theGameTime
is set to theSystemTime
.