diff options
author | HiZe_ <superhize@hotmail.com> | 2023-07-31 17:23:36 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-31 17:23:36 +0200 |
commit | e3b530846ad54b2ffe0b84d547189a20e8ccf5ef (patch) | |
tree | 0d22d0cae2f52bf62b3406a0822330ca8da60408 /src | |
parent | 64f6c78b40f616e2f11264a8c7acaaa78248a385 (diff) | |
download | skyhanni-e3b530846ad54b2ffe0b84d547189a20e8ccf5ef.tar.gz skyhanni-e3b530846ad54b2ffe0b84d547189a20e8ccf5ef.tar.bz2 skyhanni-e3b530846ad54b2ffe0b84d547189a20e8ccf5ef.zip |
Ghostcounter fix (#333)
Co-authored-by: superhize <superhize@gmail.com>
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src')
4 files changed, 89 insertions, 72 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/ghostcounter/GhostCounter.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/ghostcounter/GhostCounter.kt index f02e23512..c62f466c6 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/ghostcounter/GhostCounter.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/ghostcounter/GhostCounter.kt @@ -56,7 +56,7 @@ object GhostCounter { private val combatSectionPattern = ".*[+](?<gained>[0-9,.]+) (?<skillName>[A-Za-z]+) \\((?<progress>(?:(?:(?:(?<current>[0-9.,]+)\\/(?<total>[0-9.,]+))|(?:(?<percent>[0-9.]+)%))))\\).*".toPattern() private val killComboExpiredPattern = "§cYour Kill Combo has expired! You reached a (?<combo>.*) Kill Combo!".toPattern() private val ghostXPPattern = "(?<current>\\d+(?:\\.\\d+)?(?:,\\d+)?[kK]?)\\/(?<total>\\d+(?:\\.\\d+)?(?:,\\d+)?[kKmM]?)".toPattern() - private val bestiaryPattern = ".*(?:§\\d|§\\w)+BESTIARY (?:§\\d|§\\w)+Ghost (?:§\\d|§\\w)(?<previousLevel>\\d)➜(?:§\\d|§\\w)(?<nextLevel>\\d+).*".toPattern() // &r&3&lBESTIARY &b&lGhost &89➜&b10&r + private val bestiaryPattern = ".*(?:§\\d|§\\w)+BESTIARY (?:§\\d|§\\w)+Ghost (?:§\\d|§\\w)(?<previousLevel>\\d+)➜(?:§\\d|§\\w)(?<nextLevel>\\d+).*".toPattern() // &3&lBESTIARY &b&lGhost &89➜&b10 private val skillLevelPattern = ".*§e§lSkills: §r§a(?<skillName>.*) (?<skillLevel>\\d+).*".toPattern() private val format = NumberFormat.getInstance() private var percent: Float = 0.0f @@ -75,6 +75,8 @@ object GhostCounter { private var currentSkill = "" private var currentSkillLevel = -1 + var bestiaryUpdate = false + @SubscribeEvent fun onRenderOverlay(event: GuiRenderEvent.GameOverlayRenderEvent) { if (!isEnabled()) return @@ -152,8 +154,10 @@ object GhostCounter { } val etaFormatting = config.textFormatting.etaFormatting + //TODO: update + val max = if (bestiaryUpdate) 100_000 else 3_000_000 val remaining: Int = when (config.showMax) { - true -> 3_000_000 - bestiaryCurrentKill + true -> max - bestiaryCurrentKill false -> killNeeded - currentKill } @@ -245,12 +249,7 @@ object GhostCounter { val gained = group("gained").formatNumber().toDouble() val current = group("current") if (current != lastXp) { - val res = if (current.contains(".")) { - // current.split(".")[0] ?: "0" - "([0-9,]+).*".toRegex().find(current)?.groupValues?.get(1) ?: "0" - } else { - current.replace("\\D".toRegex(), "") - } + val res = current.formatNumber().toString() gain = (res.toLong() - lastXp.toLong()).toDouble().roundToInt() num = (gain.toDouble() / gained) if (gained in 150.0..450.0) { @@ -308,7 +307,8 @@ object GhostCounter { var parse = true if (skillPercent) { percent = nf.parse(group("percent")).toFloat() - val level = if (currentSkill == "Combat" && currentSkillLevel != -1) currentSkillLevel else XPInformation.getInstance().getSkillInfo(skillName)?.level ?: 0 + val level = if (currentSkill == "Combat" && currentSkillLevel != -1) currentSkillLevel else XPInformation.getInstance().getSkillInfo(skillName)?.level + ?: 0 if (level > 0) { totalSkillXp = SkillExperience.getExpForNextLevel(level) currentSkillXp = totalSkillXp * percent / 100 @@ -340,15 +340,16 @@ object GhostCounter { } @SubscribeEvent - fun onTabUpdate(event: TabListUpdateEvent){ + fun onTabUpdate(event: TabListUpdateEvent) { if (!isEnabled()) return - for (line in event.tabList){ - skillLevelPattern.matchMatcher(line){ + for (line in event.tabList) { + skillLevelPattern.matchMatcher(line) { currentSkill = group("skillName") currentSkillLevel = group("skillLevel").toInt() } } } + @SubscribeEvent fun onChat(event: LorenzChatEvent) { if (!isEnabled()) return @@ -397,11 +398,12 @@ object GhostCounter { //replace with BestiaryLevelUpEvent ? bestiaryPattern.matchMatcher(event.message.removeColor()) { val currentLevel = group("newLevel").toInt() - - when (val nextLevel = if (currentLevel >= 46) 47 else currentLevel + 1) { - 47 -> { + val max = if (bestiaryUpdate) 100_000.0 else 3_000_000.0 + val maxLevel = if (bestiaryUpdate) 26 else 47 + when (val nextLevel = if (currentLevel >= maxLevel - 1) maxLevel else currentLevel + 1) { + maxLevel -> { hidden?.bestiaryNextLevel = -1.0 - hidden?.bestiaryCurrentKill = 3_000_000.0 + hidden?.bestiaryCurrentKill = max hidden?.bestiaryKillNeeded = 0.0 } @@ -429,12 +431,12 @@ object GhostCounter { fun onInventoryOpen(event: InventoryOpenEvent) { if (!LorenzUtils.inSkyBlock) return val inventoryName = event.inventoryName - if (inventoryName != "Bestiary ➜ Deep Caverns") return + val name = if (bestiaryUpdate) "Bestiary ➜ Dwarven Mines" else "Bestiary ➜ Deep Caverns" + if (inventoryName != name) return val stacks = event.inventoryItems - val ghostStack = stacks[13] ?: return - val bestiaryNextLevel = if (ghostStack.displayName == "§cGhost") 1 else { - ghostStack.displayName.substring(8).romanToDecimal() + 1 - } + val stack = if (bestiaryUpdate) 10 else 13 + val ghostStack = stacks[stack] ?: return + val bestiaryNextLevel = if (ghostStack.displayName == "§cGhost") 1 else ghostStack.displayName.substring(8).romanToDecimal() + 1 hidden?.bestiaryNextLevel = bestiaryNextLevel.toDouble() for (line in ghostStack.getLore()) { ghostXPPattern.matchMatcher(line.removeColor().trim()) { diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/ghostcounter/GhostData.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/ghostcounter/GhostData.kt index de5696ee8..1ba330244 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/ghostcounter/GhostData.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/ghostcounter/GhostData.kt @@ -20,22 +20,44 @@ object GhostData { ) val bestiaryData = mutableMapOf<Int, Int>().apply { - val commonValue = 100_000 - for (i in 1..46) { - this[i] = when (i) { - 1 -> 10 - 2 -> 15 - 3 -> 75 - 4 -> 150 - 5 -> 250 - 6 -> 500 - 7 -> 1_500 - 8 -> 2_500 - 9 -> 5_000 - 10 -> 15_000 - 11 -> 25_000 - 12 -> 50_000 - else -> commonValue + + if (GhostCounter.bestiaryUpdate) { + val commonValue = 100_000 + for (i in 1..46) { + this[i] = when (i) { + 1 -> 10 + 2 -> 15 + 3 -> 75 + 4 -> 150 + 5 -> 250 + 6 -> 500 + 7 -> 1_500 + 8 -> 2_500 + 9 -> 5_000 + 10 -> 15_000 + 11 -> 25_000 + 12 -> 50_000 + else -> commonValue + } + } + } else { + val commonValue = 100_000 + for (i in 1..46) { + this[i] = when (i) { + 1 -> 10 + 2 -> 15 + 3 -> 75 + 4 -> 150 + 5 -> 250 + 6 -> 500 + 7 -> 1_500 + 8 -> 2_500 + 9 -> 5_000 + 10 -> 15_000 + 11 -> 25_000 + 12 -> 50_000 + else -> commonValue + } } } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/ghostcounter/GhostUtil.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/ghostcounter/GhostUtil.kt index 154349dcf..2067af8f0 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/ghostcounter/GhostUtil.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/ghostcounter/GhostUtil.kt @@ -92,10 +92,11 @@ object GhostUtil { } fun String.formatBestiary(currentKill: Int, killNeeded: Int): String { + val maxLevel = if (GhostCounter.bestiaryUpdate) "25" else "46" val bestiaryNextLevel = GhostCounter.hidden?.bestiaryNextLevel val currentLevel = - bestiaryNextLevel?.let { if (it.toInt() < 0) "46" else "${it.toInt() - 1}" } ?: "§cNo Bestiary Level Data!" - val nextLevel = bestiaryNextLevel?.let { if (GhostCounter.config.showMax) "46" else "${it.toInt()}" } + bestiaryNextLevel?.let { if (it.toInt() < 0) maxLevel else "${it.toInt() - 1}" } ?: "§cNo Bestiary Level Data!" + val nextLevel = bestiaryNextLevel?.let { if (GhostCounter.config.showMax) maxLevel else "${it.toInt()}" } ?: "§cNo Bestiary Level data!" return Utils.chromaStringByColourCode( @@ -109,6 +110,7 @@ object GhostUtil { } private fun percent(number: Double): String { - return "${((number / 3_000_000) * 100).roundToPrecision(4)}" + val max = if (GhostCounter.bestiaryUpdate) 3_000_000 else 100_000 + return "${((number / max) * 100).roundToPrecision(4)}" } }
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/utils/CombatUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/CombatUtils.kt index 5fdc63f46..8f64a2d6e 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/CombatUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/CombatUtils.kt @@ -65,44 +65,35 @@ object CombatUtils { lastTotalXp = totalXp } - /* - Must be a better way to do this than repeating the calculateXP function - */ fun calculateETA() { lastKillUpdate = System.currentTimeMillis() killGainHourLast = killGainHour - val nextLevel = GhostCounter.hidden?.bestiaryNextLevel?.toInt() ?: return - val kill = GhostCounter.hidden?.bestiaryCurrentKill?.toInt() ?: return - val sum = GhostData.bestiaryData.filterKeys { it <= nextLevel - 1 }.values.sum() - val cKill = sum + kill - val totalKill = if (GhostCounter.config.showMax) GhostCounter.bestiaryCurrentKill else cKill - if (lastTotalKill > 0) { - val delta: Int = totalKill - lastTotalKill - if (delta in 1..19) { - gainTimer = GhostCounter.config.pauseTimer - killGainQueue.add(0, delta) - while (killGainQueue.size > 30) { - killGainQueue.removeLast() - } - var totalGain = 0 - for (f in killGainQueue) totalGain += f - killGainHour = totalGain * (60 * 60) / killGainQueue.size - _isKilling = true - } else if (gainTimer > 0) { - gainTimer-- - killGainQueue.add(0, 0) - while (killGainQueue.size > 30) { - killGainQueue.removeLast() + + GhostCounter.hidden?.bestiaryNextLevel?.toInt()?.let { nextLevel -> + GhostCounter.hidden?.bestiaryCurrentKill?.toInt()?.let { kill -> + val sum = GhostData.bestiaryData.filterKeys { it <= nextLevel - 1 }.values.sum() + val cKill = sum + kill + val totalKill = if (GhostCounter.config.showMax) GhostCounter.bestiaryCurrentKill else cKill + + if (lastTotalKill > 0) { + val delta: Int = totalKill - lastTotalKill + if (delta in 1..10 || gainTimer > 0) { + gainTimer = maxOf(gainTimer - 1, 0) + killGainQueue.add(0, delta) + while (killGainQueue.size > 30) { + killGainQueue.removeLast() + } + + val totalGain = killGainQueue.sum() + killGainHour = totalGain * 3600 / killGainQueue.size + _isKilling = true + } else if (delta <= 0) { + _isKilling = false + } } - var totalGain = 0 - for (f in killGainQueue) totalGain += f - killGainHour = totalGain * (60 * 60) / killGainQueue.size - _isKilling = true - } else if (delta <= 0) { - _isKilling = false + lastTotalKill = totalKill } } - lastTotalKill = totalKill } /** |