From 1055c493987469ca143cb6890c6455f45cdf9ac0 Mon Sep 17 00:00:00 2001 From: alexia Date: Sat, 9 Dec 2023 21:35:21 +0100 Subject: Display Farming Fortune reduction from pests on HUD (#782) Display Farming Fortune reduction from pests on HUD. #782 --- .../features/garden/FarmingFortuneDisplay.kt | 24 ++++++++++++++++++++++ .../skyhanni/features/garden/pests/PestFinder.kt | 6 ++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/FarmingFortuneDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/FarmingFortuneDisplay.kt index 9fa7d7257..edd91e8c8 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/FarmingFortuneDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/FarmingFortuneDisplay.kt @@ -6,6 +6,7 @@ import at.hannibal2.skyhanni.data.CropAccessoryData import at.hannibal2.skyhanni.data.GardenCropMilestones import at.hannibal2.skyhanni.data.GardenCropMilestones.getCounter import at.hannibal2.skyhanni.data.GardenCropUpgrades.Companion.getUpgradeLevel +import at.hannibal2.skyhanni.data.ScoreboardData import at.hannibal2.skyhanni.events.GardenToolChangeEvent import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.LorenzTickEvent @@ -13,6 +14,7 @@ import at.hannibal2.skyhanni.events.PreProfileSwitchEvent import at.hannibal2.skyhanni.events.TabListUpdateEvent import at.hannibal2.skyhanni.features.garden.CropType.Companion.getTurboCrop import at.hannibal2.skyhanni.features.garden.GardenAPI.addCropIcon +import at.hannibal2.skyhanni.features.garden.pests.PestFinder import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.LorenzUtils @@ -122,6 +124,17 @@ class FarmingFortuneDisplay { } }) + for (line in ScoreboardData.sidebarLinesFormatted) { + PestFinder.pestsInScoreboardPattern.matchMatcher(line) { + val pests = group("pests").toInt() + val ffReduction = getPestFFReduction(pests) + if (ffReduction > 0) { + updatedDisplay.addAsSingletonList("§cPests are reducing your fortune by §e$ffReduction%§c!") + } + break + } + } + if (wrongTabCrop) { var text = "§cBreak §e${GardenAPI.cropInHand?.cropName}§c to see" if (farmingFortune != -1.0) text += " latest" @@ -147,6 +160,17 @@ class FarmingFortuneDisplay { private fun isEnabled(): Boolean = GardenAPI.inGarden() && config.display + private fun getPestFFReduction(pests: Int): Int { + return when (pests) { + in 0..3 -> 0 + 4 -> 5 + 5 -> 15 + 6 -> 30 + 7 -> 50 + else -> 75 + } + } + companion object { private val config get() = GardenAPI.config.farmingFortunes private val latestFF: MutableMap? get() = GardenAPI.storage?.latestTrueFarmingFortune diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestFinder.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestFinder.kt index f2241090d..e1b0e2055 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestFinder.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestFinder.kt @@ -38,8 +38,6 @@ class PestFinder { private val config get() = PestAPI.config.pestFinder - private val pestsInScoreboardPattern = " §7⏣ §[ac]The Garden §4§lൠ§7 x(?.*)".toPattern() - private var display = emptyList() private var scoreboardPests = 0 private var lastTimeVacuumHold = SimpleTimeMark.farPast() @@ -233,4 +231,8 @@ class PestFinder { } fun isEnabled() = GardenAPI.inGarden() && (config.showDisplay || config.showPlotInWorld) + + companion object { + val pestsInScoreboardPattern = " §7⏣ §[ac]The Garden §4§lൠ§7 x(?.*)".toPattern() + } } -- cgit