From cea66fb45be6d0878da2985e65b3ab9869455fe6 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 23 Mar 2023 14:58:08 +0100 Subject: Added CropType.getFactor --- .../hannibal2/skyhanni/features/garden/EliteFarmingWeight.kt | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/EliteFarmingWeight.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/EliteFarmingWeight.kt index d94735ba7..76561f35a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/EliteFarmingWeight.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/EliteFarmingWeight.kt @@ -270,10 +270,10 @@ class EliteFarmingWeight { private fun calculateCollectionWeight(round: Boolean = true): MutableMap { val weightPerCrop = mutableMapOf() var totalWeight = 0.0 - for ((cropName, factor) in factorPerCrop) { - val collection = getLocalCollection(cropName) - val weight = (collection / factor).also { if (round) weight.round(2) else weight } - weightPerCrop[cropName] = weight + for (crop in CropType.values()) { + val collection = getLocalCollection(crop) + val weight = (collection / crop.getFactor()).also { if (round) weight.round(2) else weight } + weightPerCrop[crop] = weight totalWeight += weight } if (totalWeight > 0) { @@ -288,7 +288,7 @@ class EliteFarmingWeight { val doubleBreakRatio = (cactusWeight + sugarCaneWeight) / totalWeight; val normalRatio = (totalWeight - cactusWeight - sugarCaneWeight) / totalWeight; - val mushroomFactor = factorPerCrop[CropType.MUSHROOM]!! + val mushroomFactor = CropType.MUSHROOM.getFactor() val mushroomCollection = getLocalCollection(CropType.MUSHROOM) return doubleBreakRatio * (mushroomCollection / (2 * mushroomFactor)) + normalRatio * (mushroomCollection / mushroomFactor) } @@ -297,6 +297,8 @@ class EliteFarmingWeight { return localCollection[crop] ?: 0L } + private fun CropType.getFactor() = factorPerCrop[this]!! + private val factorPerCrop by lazy { mapOf( CropType.WHEAT to 100_000.0, -- cgit