Skip to content

Commit

Permalink
fixed click requirement bug, caused another
Browse files Browse the repository at this point in the history
Signed-off-by: Erymanthus[#5074] | (u/)RayDeeUx <[email protected]>
  • Loading branch information
RayDeeUx committed Jan 15, 2024
1 parent ac2b249 commit a8f4405
Showing 1 changed file with 61 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber
import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNecessary
import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings
import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables
import at.hannibal2.skyhanni.utils.StringUtils
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.renderables.Renderable
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.inventory.GuiChest
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.math.abs
import kotlin.math.ceil
Expand Down Expand Up @@ -57,29 +57,31 @@ class CommissionsCalculator {
"(?:§.)*Milestone (?<milestone>\\S+) Rewards"
)

private val display: MutableList<String> = mutableListOf<String>()
private val display: MutableList<Renderable> = mutableListOf<Renderable>()
private val firstLine: String = "§lCommissions Calculator:"
private val fatDisclaimer: List<String> = listOf(
"§c§lDisclaimer: §r§cThis calculator does not include",
"§cother potential sources of HOTM XP, including the",
"§c900 HOTM XP Daily Bonus.",
"§cTo update these calculations, please open /hotm."
private val fatDisclaimer: List<Renderable> = listOf<Renderable>(
Renderable.string("§c§lDisclaimer: §r§cThis calculator does not include"),
Renderable.string("§cother potential sources of HOTM XP, including the"),
Renderable.string("§c900 HOTM XP Daily Bonus or potential boosts from"),
Renderable.string("§cthe Bingo pet."),
Renderable.string("§cTo update these calculations, please open /hotm.")
)

private var currentHOTMLevel: Int = 0
private var currentHOTMXP: Int = 0
private var currentHOTMLevel: Int = 7
private var currentHOTMXP: Int = 150000

private enum class HOTMProgression(
val tier: Int,
val toNextTier: Int,
val perComm: Double
) {
ONE(1, 3000, 100.0),
TWO(2, 9000, 200.0),
THREE(3, 25000, 400.0),
FOUR(4,60000,400.0),
FIVE(5, 100000,400.0),
ONE(1, 3000, 100.0),
TWO(2, 9000, 200.0),
THREE(3, 25000, 400.0),
FOUR(4, 60000, 400.0),
FIVE(5, 100000, 400.0),
SIX(6, 150000, 400.0),
SEVEN(7, 200000, 400.0),
;
}

Expand All @@ -88,14 +90,15 @@ class CommissionsCalculator {
if (!LorenzUtils.inSkyBlock) return
if (!inMiningIsland()) return
if (!isEnabled()) return
if (mc.currentScreen !is GuiChest) return
val chestName = event.inventoryName
if (chestName.isNotValidChestName()) return
val colorCode = if (DWARVEN.isInIsland()) "§2" else "§5" //themed based on mining island
if (currentHOTMLevel == 0) {
listOf(
"$colorCode$firstLine",
"§cPlease open the Heart of the Mountain (/hotm)."
Renderable.string("$colorCode$firstLine"),
Renderable.clickAndHover("§cOpen the §e/hotm §ctree.",
listOf("Click to run §e/hotm"), onClick = { LorenzUtils.sendCommandToServer("hotm") }
),
).update()
return
}
Expand All @@ -104,27 +107,9 @@ class CommissionsCalculator {
val toNextTier = hotmInfo.toNextTier
val items = event.inventoryItems
val commsToNextTier = ceil(abs(toNextTier - currentHOTMXP) / perComm).roundToInt()
if (chestName == "Commissions") {
var hotmXP: Long = 0
loop@ for ((_, item) in items) {
commissionItemPattern.matchMatcher(item.cleanName()) {
val lore = item.getLore()
if (lore.none { it == "§a§lCOMPLETED" } && config.completedOnly) continue@loop
for (line in lore) {
hotmXPPattern.matchMatcher(line) {
hotmXP += group("xp").formatNumber()
}
}
}
}
listOf(
"$colorCode$firstLine",
" §7- §f(At least $colorCode${hotmXP.addSeparators()} HOTM XP §fto be gained from claiming completed commissions)",
" §7- $colorCode${commsToNextTier.addSeparators()} §fmore commissions to ${colorCode}HOTM ${currentHOTMLevel + 1}",
" §7- §f(to reach $colorCode${toNextTier.addSeparators()} HOTM XP §ffrom $colorCode${currentHOTMXP.addSeparators()} HOTM XP§f)",
).update()
return
}
val newList = mutableListOf<Renderable>(
Renderable.string("$colorCode$firstLine"),
)
if (chestName == "Heart of the Mountain") {
for ((_, item) in items) {
tierItemPattern.matchMatcher(item.cleanName()) {
Expand All @@ -136,42 +121,62 @@ class CommissionsCalculator {
}
}
}
listOf(
"$colorCode$firstLine",
" §7- §fCurrent HOTM Level: $colorCode$currentHOTMLevel",
" §7- §fCurrent HOTM XP: $colorCode${currentHOTMXP.addSeparators()}",
"§c(Remember to scroll up the HOTM tree!)"
).update()
newList.addAll(
listOf(
Renderable.string(" §e(Remember to scroll up the HOTM tree!)"),
Renderable.string(" §7- §fCurrent HOTM Level: $colorCode$currentHOTMLevel"),
Renderable.string(" §7- §fCurrent HOTM XP: $colorCode${currentHOTMXP.addSeparators()}"),
)
)
newList.update()
return
}
if (chestName == "Commissions") {
var hotmXP: Long = 0
loop@for ((_, item) in items) {
commissionItemPattern.matchMatcher(item.cleanName()) {
val lore = item.getLore()
if (lore.none { it == "§a§lCOMPLETED" } && config.completedOnly) continue@loop
for (line in lore) {
hotmXPPattern.matchMatcher(line) {
hotmXP += group("xp").formatNumber()
}
}
}
}
newList.add(Renderable.string(" §7- §f(At least $colorCode${hotmXP.addSeparators()} HOTM XP §fto be gained from claiming completed commissions)"),)
}
if (chestName == "Commission Milestones") {
for ((_, item) in items) {
milestoneRewardsItemPattern.matchMatcher(item.cleanName()) {
val milestoneInt = group("milestone").romanToDecimalIfNecessary()
val milestone = group("milestone").romanToDecimalIfNecessary()
for (line in item.getLore()) {
mileProgressPattern.matchMatcher(line) {
val completed = group("completed").groupToInt()
val required = group("required").groupToInt()
val remaining = abs(required - completed)
if (completed < required) {
if (completed < required || mc.thePlayer.name == "Erymanthus") {
val remainingPlural = StringUtils.optionalPlural(remaining, "commission", "commissions")
val hotmXPGain = (remaining * perComm).roundToInt()
listOf(
"$colorCode$firstLine",
" §7- $colorCode$remainingPlural §fleft to complete §6Milestone $milestoneInt §f($colorCode+${hotmXPGain.addSeparators()} HOTM XP§f)",
" §7- $colorCode${commsToNextTier.addSeparators()} §fmore commissions to ${colorCode}HOTM ${currentHOTMLevel + 1}",
" §7- §f(to reach $colorCode${toNextTier.addSeparators()} HOTM XP §ffrom $colorCode${currentHOTMXP.addSeparators()} HOTM XP§f)",
).update()
return
newList.add(
Renderable.string(" §7- $colorCode$remainingPlural §fleft to complete §6Milestone $milestone §f($colorCode+${hotmXPGain.addSeparators()} HOTM XP§f)"),
)
}
}
}
}
}
}
newList.addAll(
listOf(
Renderable.string(" §7- $colorCode${commsToNextTier.addSeparators()} §fmore commissions to ${colorCode}HOTM ${currentHOTMLevel + 1}"),
Renderable.string(" §7- §f(to reach $colorCode${toNextTier.addSeparators()} HOTM XP §ffrom $colorCode${currentHOTMXP.addSeparators()} HOTM XP§f)"),
)
)
newList.update()
}

private fun List<String>.update() {
private fun List<Renderable>.update() {
display.clear()
display.addAll(this)
if (currentHOTMLevel != 0) display.addAll(fatDisclaimer)
Expand All @@ -182,7 +187,7 @@ class CommissionsCalculator {
if (!inMiningIsland()) return
if (!isEnabled()) return
if (InventoryUtils.openInventoryName().isNotValidChestName()) return
config.position.renderStrings(display, posLabel = "Commissions Calculator")
config.position.renderRenderables(display, posLabel = "Commissions Calculator")
}

private fun isEnabled() = config.enabled
Expand Down

0 comments on commit a8f4405

Please sign in to comment.