ChestTracker class
TheChestTracker maintains two counters:
Both
totalChests and unopenedChests are incremented together when chests spawn, then unopenedChests decrements as players open them.Counting spawned chests
TheSpawnChests method is patched to detect when the game spawns chests:
Key implementation details
Round state check
Round state check
The patch first verifies that tracking is enabled by checking
Plugin.disableTracker and ChargeShrineTracker.IsRoundActive. This prevents counting chests outside of active rounds.Accessing spawn count
Accessing spawn count
The
__instance parameter provides access to the original SpawnInteractables object, allowing the patch to read numChests directly from the game’s spawn system.Overlay initialization
Overlay initialization
This patch also triggers overlay creation when the first chests spawn, ensuring the GUI is ready to display tracking information.
Tracking opened chests
When a player opens a chest, the game callsTrackStats.OnChestOpened(). The patch decrements the unopened counter:
The
Mathf.Max(0, ...) ensures the unopened count never goes negative, even if there are edge cases or timing issues.Usage example
During a typical round:- Level loads and spawns 5 chests
totalChests= 5,unopenedChests= 5- Player opens first chest
totalChests= 5,unopenedChests= 4- Player opens two more chests
totalChests= 5,unopenedChests= 2
Chests: 2/5
Reset behavior
Chest counts are reset when:- A new round starts (via
GameManager.StartPlaying,TryInit, orCreateInstances) - The player dies (
GameManager.OnDied) - The game manager is destroyed (
GameManager.OnDestroy)