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 | |
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')
4 files changed, 92 insertions, 1 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/rift/RiftConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/rift/RiftConfig.java index 147709752..9c24e810f 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/rift/RiftConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/rift/RiftConfig.java @@ -31,7 +31,7 @@ public class RiftConfig { public RiftAreasConfig area = new RiftAreasConfig(); @Expose - @Category(name = "Motes", desc = "Motes Sell Price") + @Category(name = "Motes", desc = "") public MotesConfig motes = new MotesConfig(); @Expose diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/rift/motes/MotesConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/rift/motes/MotesConfig.java index d9e45f8fe..e02b7e589 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/rift/motes/MotesConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/rift/motes/MotesConfig.java @@ -21,6 +21,12 @@ public class MotesConfig { public int burgerStacks = 0; @Expose + @ConfigOption(name = "Motes per Session", desc = "Show how many motes you got this session when leaving the rift.") + @ConfigEditorBoolean + @FeatureToggle + public boolean motesPerSession = true; + + @Expose @ConfigOption(name = "Inventory Value", desc = "") @Accordion public RiftInventoryValueConfig inventoryValue = new RiftInventoryValueConfig(); 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, + ) + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt index 4d7b7ad4d..201c294e5 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt @@ -163,3 +163,8 @@ enum class TimeUnit(val factor: Long, val shortName: String, val longName: Strin fun format(value: Int, longFormat: Boolean = false) = value.addSeparators() + getName(value, longFormat) } + +val Duration.inPartialSeconds: Double get() = inWholeMilliseconds.toDouble() / 1000 +val Duration.inPartialMinutes: Double get() = inPartialSeconds / 60 +val Duration.inPartialHours: Double get() = inPartialSeconds / 3600 +val Duration.inPartialDays: Double get() = inPartialSeconds / 86_400 |