Skip to content

Commit

Permalink
feat: bit features
Browse files Browse the repository at this point in the history
  • Loading branch information
minhperry committed Sep 27, 2024
1 parent 6a03ba4 commit 97502b3
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions src/main/java/at/hannibal2/skyhanni/features/inventory/FannCost.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.InventoryUpdatedEvent
import at.hannibal2.skyhanni.events.LorenzToolTipEvent
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.CollectionUtils.addIfNotNull
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.NumberUtil.roundTo
import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import at.hannibal2.skyhanni.utils.RegexUtils.matches
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
Expand Down Expand Up @@ -49,6 +46,10 @@ object FannCost {
"coin",
"""(\d{1,3}(?:,\d{3})*(?:\.\d+)?|\d+\.?\d*) Coins(?: \([1-5]% off\))?""",
)
private val bitsPattern by patternGroup.pattern(
"bits",
"""(\d{1,3}(?:,\d{3})*(?:\.\d+)?|\d+\.?\d*) Bits""",
)
private val desiredLevelPatter by patternGroup.pattern(
"slot24.name.level",
"Desired Level: (200|1?[0-9]?[0-9])",
Expand All @@ -74,25 +75,29 @@ object FannCost {
TrainingMode.DAY_COUNT -> {
if (trainingType != null) {
if (trainingType == TrainingType.FREE) return
if (!showCoins) return
if (!showCoins || !showBits) return

val totalExp = tooltip.getExpEarned() ?: return
val coins = tooltip.getCoins()
val coinPerExp = coins / totalExp
tooltip.insertAfterCoin(" §6Coins/XP: ${coinPerExp.roundTo(2)}")
val coinPerExp = tooltip.getCoins() / totalExp
val xpPerBit = totalExp / tooltip.getBits()

tooltip.insertLineAfter(coinsPattern, " §6Coins/XP: ${coinPerExp.roundTo(2)}")
tooltip.insertLineAfter(bitsPattern, " §6XP/Bit: ${xpPerBit.roundTo(2)}")
}
}

TrainingMode.UNTIL_LEVEL -> {
if (trainingType != null) {
if (trainingType == TrainingType.FREE) return
if (!showCoins) return
if (!showCoins || !showBits) return

val dailyExp = tooltip.getDailyExp() ?: return
val duration = tooltip.getDuration() ?: return
val coins = tooltip.getCoins()
val coinPerExp = coins / (dailyExp * duration)
tooltip.insertAfterCoin(" §6Coins/XP: ${coinPerExp.roundTo(2)}")
val totalExp = dailyExp * duration
val coinPerExp = tooltip.getCoins() / totalExp
val xpPerBit = totalExp / tooltip.getBits()
tooltip.insertLineAfter(coinsPattern, " §6Coins/XP: ${coinPerExp.roundTo(2)}")
tooltip.insertLineAfter(bitsPattern, " §6XP/Bit: ${xpPerBit.roundTo(2)}")
}
}
}
Expand All @@ -112,11 +117,11 @@ object FannCost {
}
}

private fun MutableList<String>.insertAfterCoin(content: String) {
private fun MutableList<String>.insertLineAfter(pattern: Pattern, content: String) {
val iter = this.listIterator()
while (iter.hasNext()) {
val line = iter.next().removeColor()
if (coinsPattern.matcher(line).find()) {
if (pattern.matcher(line).find()) {
iter.add(content)
}
}
Expand All @@ -139,6 +144,10 @@ object FannCost {
return coinsPattern.read(this) { it._toDouble() } ?: 0.0
}

private fun List<String>.getBits(): Double {
return bitsPattern.read(this) { it._toDouble() } ?: 1.0
}

private fun List<String>.getExpEarned(): Double? {
return expEarnedPattern.read(this) { it._toDouble() }
}
Expand Down

0 comments on commit 97502b3

Please sign in to comment.