diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-03-23 15:08:33 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-03-23 15:08:33 +0100 |
commit | fc824ace3d40a6392f05f626887d7bfe80c04eb9 (patch) | |
tree | 1f9e1069036a56a2c208a4775e3adad5b2ee7a99 | |
parent | cea66fb45be6d0878da2985e65b3ab9869455fe6 (diff) | |
download | skyhanni-fc824ace3d40a6392f05f626887d7bfe80c04eb9.tar.gz skyhanni-fc824ace3d40a6392f05f626887d7bfe80c04eb9.tar.bz2 skyhanni-fc824ace3d40a6392f05f626887d7bfe80c04eb9.zip |
Added CropType.getLocalCounter
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/garden/EliteFarmingWeight.kt | 32 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt | 12 |
2 files changed, 20 insertions, 24 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 76561f35a..2c21a10a5 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/EliteFarmingWeight.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/EliteFarmingWeight.kt @@ -60,7 +60,7 @@ class EliteFarmingWeight { companion object { private val config get() = SkyHanniMod.feature.garden - private val localCollection = mutableMapOf<CropType, Long>() + private val localCounter = mutableMapOf<CropType, Long>() private var display = mutableListOf<String>() private var profileId = "" @@ -182,14 +182,12 @@ class EliteFarmingWeight { private fun isEnabled() = GardenAPI.inGarden() && config.eliteFarmingWeightDisplay private fun isEtaEnabled() = config.eliteFarmingWeightOvertakeETA - fun addCrop(crop: CropType, diff: Int) { - val old = localCollection[crop] ?: 0L + fun addCrop(crop: CropType, addedCounter: Int) { + val before = getExactWeight() + localCounter[crop] = crop.getLocalCounter() + addedCounter + val after = getExactWeight() - val before = calculateExactWeight() - localCollection[crop] = old + diff - val after = calculateExactWeight() - - updateWeightPerSecond(crop, before, after, diff) + updateWeightPerSecond(crop, before, after, addedCounter) dirtyCropWeight = true } @@ -202,7 +200,7 @@ class EliteFarmingWeight { } } - private fun calculateExactWeight(): Double { + private fun getExactWeight(): Double { val values = calculateCollectionWeight(false).values return if (values.isNotEmpty()) { values.sum() @@ -250,7 +248,7 @@ class EliteFarmingWeight { profileId = profileEntry.key weight = profile["farming"].asJsonObject["total"].asDouble - localCollection.clear() + localCounter.clear() dirtyCropWeight = true return @@ -271,10 +269,10 @@ class EliteFarmingWeight { val weightPerCrop = mutableMapOf<CropType, Double>() var totalWeight = 0.0 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 + val weight = crop.getLocalCounter() / crop.getFactor() + val roundedWeight = weight.let { if (round) it.round(2) else it } + weightPerCrop[crop] = roundedWeight + totalWeight += roundedWeight } if (totalWeight > 0) { weightPerCrop[CropType.MUSHROOM] = specialMushroomWeight(weightPerCrop, totalWeight) @@ -289,13 +287,11 @@ class EliteFarmingWeight { val normalRatio = (totalWeight - cactusWeight - sugarCaneWeight) / totalWeight; val mushroomFactor = CropType.MUSHROOM.getFactor() - val mushroomCollection = getLocalCollection(CropType.MUSHROOM) + val mushroomCollection = CropType.MUSHROOM.getLocalCounter() return doubleBreakRatio * (mushroomCollection / (2 * mushroomFactor)) + normalRatio * (mushroomCollection / mushroomFactor) } - private fun getLocalCollection(crop: CropType): Long { - return localCollection[crop] ?: 0L - } + private fun CropType.getLocalCounter() = localCounter[this] ?: 0L private fun CropType.getFactor() = factorPerCrop[this]!! diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt index a52e474ff..c5108be32 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt @@ -83,18 +83,18 @@ class GardenCropMilestoneDisplay { val crop = GardenAPI.getCropTypeFromItem(item) ?: return if (cultivatingData.containsKey(crop)) { val old = cultivatingData[crop]!! - val diff = counter - old + val addedCounter = counter - old try { - GardenCropMilestones.cropCounter[crop] = crop.getCounter() + diff + GardenCropMilestones.cropCounter[crop] = crop.getCounter() + addedCounter } catch (e: NullPointerException) { println("crop: '$crop'") println("GardenCropMilestones.cropCounter: '${GardenCropMilestones.cropCounter.keys}'") LorenzUtils.debug("NPE at OwnInventorItemUpdateEvent with GardenCropMilestones.cropCounter") e.printStackTrace() } - EliteFarmingWeight.addCrop(crop, diff) + EliteFarmingWeight.addCrop(crop, addedCounter) if (currentCrop == crop) { - calculateSpeed(diff) + calculateSpeed(addedCounter) update() } } @@ -117,7 +117,7 @@ class GardenCropMilestoneDisplay { allCounters.clear() } - private fun calculateSpeed(diff: Int) { + private fun calculateSpeed(addedCounter: Int) { if (System.currentTimeMillis() > lastSecondStart + 1_000) { lastSecondStart = System.currentTimeMillis() if (countInLastSecond > 8) { @@ -130,7 +130,7 @@ class GardenCropMilestoneDisplay { countInLastSecond = 0 currentSpeed = 0 } - currentSpeed += diff + currentSpeed += addedCounter countInLastSecond++ } |