diff options
author | inglettronald <inglettronald@gmail.com> | 2023-07-15 23:07:15 -0500 |
---|---|---|
committer | inglettronald <inglettronald@gmail.com> | 2023-07-15 23:07:15 -0500 |
commit | 69db365139428bd0c433ccbb9d31dfded7216572 (patch) | |
tree | e0f06d3f55b2e451489187eddaf531848f360505 /src/main/kotlin/dulkirmod/utils | |
parent | 7ce99bd61bb8cbcd4f4bc81a2325bfa26847baf1 (diff) | |
download | DulkirMod-69db365139428bd0c433ccbb9d31dfded7216572.tar.gz DulkirMod-69db365139428bd0c433ccbb9d31dfded7216572.tar.bz2 DulkirMod-69db365139428bd0c433ccbb9d31dfded7216572.zip |
Added basic slayer tracker
Diffstat (limited to 'src/main/kotlin/dulkirmod/utils')
-rw-r--r-- | src/main/kotlin/dulkirmod/utils/SlayerTrackerUtil.kt | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/main/kotlin/dulkirmod/utils/SlayerTrackerUtil.kt b/src/main/kotlin/dulkirmod/utils/SlayerTrackerUtil.kt new file mode 100644 index 0000000..4dc772e --- /dev/null +++ b/src/main/kotlin/dulkirmod/utils/SlayerTrackerUtil.kt @@ -0,0 +1,58 @@ +package dulkirmod.utils + +import dulkirmod.config.DulkirConfig +import dulkirmod.events.SlayerTypeChangeEvent +import net.minecraftforge.client.event.ClientChatReceivedEvent +import net.minecraftforge.common.MinecraftForge +import net.minecraftforge.fml.common.eventhandler.EventPriority +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +object SlayerTrackerUtil { + private var sessionStartTime = 0L + var sessionXP: Int = 0 + var averageSpawnKillTime: Float = 0f + var averageBossesPerHour: Float = 0f + var averageXPPerHour: Int = 0 + var currentSlayerType: String = "" + private var lastKillTime = 0L + + val slayerQuestStartRegex = "ยป Slay (\\d{1,3}(?:,\\d{3})*) Combat XP worth of (\\w+).".toRegex() + @SubscribeEvent + fun onSlayerTypeChange(event: SlayerTypeChangeEvent) { + // reset relevant tracking features + sessionXP = 0 + averageSpawnKillTime = 0f + averageBossesPerHour = 0f + averageXPPerHour = 0 + sessionStartTime = System.currentTimeMillis() + lastKillTime = sessionStartTime + } + + @SubscribeEvent(receiveCanceled = true, priority = EventPriority.LOW) + fun onChat(event: ClientChatReceivedEvent) { + if (event.type == 2.toByte()) { + return + } + val unformatted = Utils.stripColorCodes(event.message.unformattedText).trim() + if (unformatted matches slayerQuestStartRegex) { + val type = slayerQuestStartRegex.find(unformatted)?.groupValues?.get(2) + if (type == null) { + TextUtils.info("Failed to parse slayer type, please report to dulkir.") + return + } + if (type != currentSlayerType) { + MinecraftForge.EVENT_BUS.post(SlayerTypeChangeEvent()) + currentSlayerType = type + return + } + + sessionXP += DulkirConfig.slayerXP + val totalBosses = sessionXP/DulkirConfig.slayerXP + + averageSpawnKillTime = ((averageSpawnKillTime * (totalBosses - 1) + (System.currentTimeMillis() - lastKillTime) / 1000)) / totalBosses + lastKillTime = System.currentTimeMillis() + averageBossesPerHour = 3600 / averageSpawnKillTime + averageXPPerHour = (averageBossesPerHour * 500).toInt() + } + } +}
\ No newline at end of file |