Skip to content

Commit

Permalink
Feature: Motes in Session (hannibal002#2323)
Browse files Browse the repository at this point in the history
Co-authored-by: ItsEmpa <[email protected]>
Co-authored-by: hannibal2 <[email protected]>
  • Loading branch information
3 people authored Aug 26, 2024
1 parent 35b1a6a commit 81e8c4c
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ public class MotesConfig {
@ConfigEditorSlider(minStep = 1, minValue = 0, maxValue = 5)
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
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
)
}
}
5 changes: 5 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 81e8c4c

Please sign in to comment.