diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-09-10 11:18:18 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-09-10 11:18:18 +0200 |
commit | 99b4db7a09e9b537195c6d59225b817e98713ebf (patch) | |
tree | 8f83f77b0b01e21b066ff5d9bc4a9ab6c1ca8cf6 /src | |
parent | c33364944f8f288cded166f47375df96f988448e (diff) | |
download | skyhanni-99b4db7a09e9b537195c6d59225b817e98713ebf.tar.gz skyhanni-99b4db7a09e9b537195c6d59225b817e98713ebf.tar.bz2 skyhanni-99b4db7a09e9b537195c6d59225b817e98713ebf.zip |
splitting into multiple methods
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobContestTimeNeeded.kt | 182 |
1 files changed, 100 insertions, 82 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobContestTimeNeeded.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobContestTimeNeeded.kt index 2cfde32ba..0c669e802 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobContestTimeNeeded.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobContestTimeNeeded.kt @@ -35,88 +35,7 @@ class JacobContestTimeNeeded { val sorted = mutableMapOf<CropType, Double>() val map = mutableMapOf<CropType, Renderable>() for (crop in CropType.entries) { - var lowBPSWarning = listOf<String>() - val speed = crop.getSpeed() - if (speed == null) { - sorted[crop] = Double.MAX_VALUE - map[crop] = Renderable.hoverTips( - "§9${crop.cropName} §cNo speed data!", - listOf("§cFarm ${crop.cropName} to show data!") - ) - continue - } - - val averages = FarmingContestAPI.calculateAverages(crop).second - if (averages.isEmpty()) { - sorted[crop] = Double.MAX_VALUE - 2 - map[crop] = Renderable.hoverTips( - "§9${crop.cropName} §cNo contest data!", - listOf( - "§cOpen more pages or participate", - "§cin a ${crop.cropName} Contest to show data!" - ) - ) - continue - } - - val rawSpeed = speed.toDouble() - val speedForFormular = crop.getLatestBlocksPerSecond()?.let { - if (it < 15) { - val v = rawSpeed / it - (v * 19.9).toInt() - } else speed - } ?: speed - var showLine = "" - val brackets = mutableListOf<String>() - for ((bracket, amount) in averages) { - val timeInMinutes = amount.toDouble() / speedForFormular / 60 - val formatDuration = TimeUtils.formatDuration((timeInMinutes * 60 * 1000).toLong()) - val color = if (timeInMinutes < 20) "§b" else "§c" - var marking = "" - var bracketText = "${bracket.displayName} $color$formatDuration" - var blocksPerSecond = crop.getLatestBlocksPerSecond() - if (blocksPerSecond == null) { - marking += "§0§l !" //hoping this never shows - blocksPerSecond = 19.9 - lowBPSWarning = listOf("§cYour Blocks/second is too low,", "§cshowing 19.9 Blocks/second instead!") - } else { - if (blocksPerSecond < 15.0) { - marking += "§4§l !" - blocksPerSecond = 19.9 - lowBPSWarning = - listOf("§cYour Blocks/second is too low,", "§cshowing 19.9 Blocks/second instead!") - } else { - marking += " " - lowBPSWarning = listOf("§aYour Blocks/second is good :)") - } - } - val line = if (timeInMinutes < 20) { - "§9${crop.cropName} §b$formatDuration" + marking - } else { - val cropFF = crop.getLatestTrueFarmingFortune() ?: 0.0 - val cropsPerSecond = amount.toDouble() / blocksPerSecond / 60 - val ffNeeded = cropsPerSecond * 100 / 20 / crop.baseDrops - val missing = (ffNeeded - cropFF).toInt() - bracketText += " §7(${missing.addSeparators()} more FF needed!)" - "§9${crop.cropName} §cNo ${currentBracket.displayName} §cMedal!" + marking - } - brackets.add(bracketText) - if (bracket == currentBracket) { - sorted[crop] = timeInMinutes - showLine = line - } - } - - map[crop] = Renderable.hoverTips(showLine, buildList { - add("§7Time Needed for §9${crop.cropName} Medals§7:") - addAll(brackets) - add("") - val latestFF = crop.getLatestTrueFarmingFortune() ?: 0.0 - add("§7Latest FF: §e${(latestFF).addSeparators()}") - val bps = crop.getLatestBlocksPerSecond()?.round(1) ?: 0 - add("§7Blocks/Second: §e${bps.addSeparators()}") - addAll(lowBPSWarning) - }) + testCrop(crop, sorted, map) } this.display = buildList { @@ -139,6 +58,105 @@ class JacobContestTimeNeeded { } } + private fun testCrop( + crop: CropType, + sorted: MutableMap<CropType, Double>, + map: MutableMap<CropType, Renderable> + ) { + val speed = crop.getSpeed() + if (speed == null) { + sorted[crop] = Double.MAX_VALUE + map[crop] = Renderable.hoverTips( + "§9${crop.cropName} §cNo speed data!", + listOf("§cFarm ${crop.cropName} to show data!") + ) + return + } + + val averages = FarmingContestAPI.calculateAverages(crop).second + if (averages.isEmpty()) { + sorted[crop] = Double.MAX_VALUE - 2 + map[crop] = Renderable.hoverTips( + "§9${crop.cropName} §cNo contest data!", + listOf( + "§cOpen more pages or participate", + "§cin a ${crop.cropName} Contest to show data!" + ) + ) + return + } + + renderCrop(speed, crop, averages, sorted, map) + } + + private fun renderCrop( + speed: Int, + crop: CropType, + averages: Map<ContestBracket, Int>, + sorted: MutableMap<CropType, Double>, + map: MutableMap<CropType, Renderable> + ) { + val lowBPSWarning = listOf<String>() + var lowBPSWarning1 = lowBPSWarning + val rawSpeed = speed.toDouble() + val speedForFormular = crop.getLatestBlocksPerSecond()?.let { + if (it < 15) { + val v = rawSpeed / it + (v * 19.9).toInt() + } else speed + } ?: speed + var showLine = "" + val brackets = mutableListOf<String>() + for ((bracket, amount) in averages) { + val timeInMinutes = amount.toDouble() / speedForFormular / 60 + val formatDuration = TimeUtils.formatDuration((timeInMinutes * 60 * 1000).toLong()) + val color = if (timeInMinutes < 20) "§b" else "§c" + var marking = "" + var bracketText = "${bracket.displayName} $color$formatDuration" + var blocksPerSecond = crop.getLatestBlocksPerSecond() + if (blocksPerSecond == null) { + marking += "§0§l !" //hoping this never shows + blocksPerSecond = 19.9 + lowBPSWarning1 = listOf("§cYour Blocks/second is too low,", "§cshowing 19.9 Blocks/second instead!") + } else { + if (blocksPerSecond < 15.0) { + marking += "§4§l !" + blocksPerSecond = 19.9 + lowBPSWarning1 = + listOf("§cYour Blocks/second is too low,", "§cshowing 19.9 Blocks/second instead!") + } else { + marking += " " + lowBPSWarning1 = listOf("§aYour Blocks/second is good :)") + } + } + val line = if (timeInMinutes < 20) { + "§9${crop.cropName} §b$formatDuration" + marking + } else { + val cropFF = crop.getLatestTrueFarmingFortune() ?: 0.0 + val cropsPerSecond = amount.toDouble() / blocksPerSecond / 60 + val ffNeeded = cropsPerSecond * 100 / 20 / crop.baseDrops + val missing = (ffNeeded - cropFF).toInt() + bracketText += " §7(${missing.addSeparators()} more FF needed!)" + "§9${crop.cropName} §cNo ${currentBracket.displayName} §cMedal!" + marking + } + brackets.add(bracketText) + if (bracket == currentBracket) { + sorted[crop] = timeInMinutes + showLine = line + } + } + map[crop] = Renderable.hoverTips(showLine, buildList { + add("§7Time Needed for §9${crop.cropName} Medals§7:") + addAll(brackets) + add("") + val latestFF = crop.getLatestTrueFarmingFortune() ?: 0.0 + add("§7Latest FF: §e${(latestFF).addSeparators()}") + val bps = crop.getLatestBlocksPerSecond()?.round(1) ?: 0 + add("§7Blocks/Second: §e${bps.addSeparators()}") + addAll(lowBPSWarning1) + }) + } + @SubscribeEvent fun onRenderOverlay(event: GuiRenderEvent.ChestBackgroundRenderEvent) { if (!isEnabled()) return |