forked from hannibal002/SkyHanni
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Motes in Session (hannibal002#2323)
Co-authored-by: ItsEmpa <[email protected]> Co-authored-by: hannibal2 <[email protected]>
- Loading branch information
1 parent
35b1a6a
commit 81e8c4c
Showing
4 changed files
with
92 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/motes/MotesSession.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters