diff options
author | Empa <42304516+ItsEmpa@users.noreply.github.com> | 2024-08-26 11:27:58 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-26 11:27:58 +0200 |
commit | 81e8c4c0a62e1ad899a6fee612d8987814bb2c30 (patch) | |
tree | be35b0703bc8aa0614c3c899fbaea1520c91b681 /src/main/java/at/hannibal2/skyhanni/features | |
parent | 35b1a6a1b83a1504605bd5b5d3e4f6fd6e545c8e (diff) | |
download | skyhanni-81e8c4c0a62e1ad899a6fee612d8987814bb2c30.tar.gz skyhanni-81e8c4c0a62e1ad899a6fee612d8987814bb2c30.tar.bz2 skyhanni-81e8c4c0a62e1ad899a6fee612d8987814bb2c30.zip |
Feature: Motes in Session (#2323)
Co-authored-by: ItsEmpa <itsempa@users.noreply.github.com>
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/motes/MotesSession.kt | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/motes/MotesSession.kt b/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/motes/MotesSession.kt new file mode 100644 index 000000000..b62b61bb2 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/motes/MotesSession.kt @@ -0,0 +1,80 @@ +package at.hannibal2.skyhanni.features.rift.everywhere.motes + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.IslandType +import at.hannibal2.skyhanni.data.model.TabWidget +import at.hannibal2.skyhanni.events.IslandChangeEvent +import at.hannibal2.skyhanni.events.WidgetUpdateEvent +import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule +import at.hannibal2.skyhanni.utils.ChatUtils +import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators +import at.hannibal2.skyhanni.utils.NumberUtil.formatLong +import at.hannibal2.skyhanni.utils.NumberUtil.shortFormat +import at.hannibal2.skyhanni.utils.RegexUtils.firstMatcher +import at.hannibal2.skyhanni.utils.SimpleTimeMark +import at.hannibal2.skyhanni.utils.TimeUtils.format +import at.hannibal2.skyhanni.utils.inPartialHours +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +@SkyHanniModule +object MotesSession { + + private val config get() = SkyHanniMod.feature.rift.motes.motesPerSession + + private var initialMotes: Long? = null + private var currentMotes: Long? = null + private var enterRiftTime = SimpleTimeMark.farPast() + + private val repoGroup = RepoPattern.group("rift.everywhere.motes") + + /** + * REGEX-TEST: Lifetime Motes: §r§d593,922 + */ + private val lifetimeMotesPattern by repoGroup.pattern( + "lifetime", + "\\s+Lifetime Motes: §r§d(?<motes>[\\d,.]+)", + ) + + @SubscribeEvent + fun onWidgetUpdate(event: WidgetUpdateEvent) { + if (!event.isWidget(TabWidget.RIFT_INFO)) return + lifetimeMotesPattern.firstMatcher(event.widget.lines) { + val amount = group("motes").formatLong() + if (initialMotes == null) { + initialMotes = amount + enterRiftTime = SimpleTimeMark.now() + } + // TODO move into RiftAPI, rename to lifetimeMotes, reuse in custom scoreboard maybe? + currentMotes = amount + } + } + + @SubscribeEvent + fun onIslandChange(event: IslandChangeEvent) { + if (event.oldIsland == IslandType.THE_RIFT) { + sendMotesInfo() + initialMotes = null + currentMotes = null + } + } + + private fun sendMotesInfo() { + if (!config) return + val initial = initialMotes ?: return + val current = currentMotes ?: return + val gained = current - initial + if (gained == 0L) return + val timeInRift = enterRiftTime.passedSince() + val motesPerHour = (gained / timeInRift.inPartialHours).toLong() + val hover = buildList { + add("§7Gained: §d${gained.addSeparators()} motes") + add("§7Time spent: §d${timeInRift.format()}") + add("§7Motes/h: §d${motesPerHour.addSeparators()}") + } + ChatUtils.hoverableChat( + "Gained §d${gained.addSeparators()} motes §ethis Rift session! (§d${motesPerHour.shortFormat()}/h§e)", + hover, + ) + } +} |