diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-04-13 06:42:24 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-04-13 06:42:24 +0200 |
commit | c8f81f0fc19ffe0778ea3d0ebb7e34d7f7ac76da (patch) | |
tree | 2f12ac9dc1f30c314904ff0cebc0d81a95fb27b0 /src/main/java/at/hannibal2/skyhanni | |
parent | ca01ffa10846f8fabc0fe77d915575171e895160 (diff) | |
download | skyhanni-c8f81f0fc19ffe0778ea3d0ebb7e34d7f7ac76da.tar.gz skyhanni-c8f81f0fc19ffe0778ea3d0ebb7e34d7f7ac76da.tar.bz2 skyhanni-c8f81f0fc19ffe0778ea3d0ebb7e34d7f7ac76da.zip |
hopefully fixed finnegan perk detection and calculation logic
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/data/MayorElectionData.kt | 13 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt | 34 |
2 files changed, 33 insertions, 14 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/MayorElectionData.kt b/src/main/java/at/hannibal2/skyhanni/data/MayorElectionData.kt index 634958217..70f30a021 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/MayorElectionData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/MayorElectionData.kt @@ -53,9 +53,14 @@ class MayorElectionData { SkyHanniMod.coroutineScope.launch { val url = "https://api.hypixel.net/resources/skyblock/election" val jsonObject = withContext(Dispatchers.IO) { APIUtil.getJSONResponse(url) } - rawMayorData = gson.fromJson(jsonObject, MayorData::class.java).also { - candidates = mapOf(it.mayor.election.getPairs(), it.current.getPairs()) + rawMayorData = gson.fromJson(jsonObject, MayorData::class.java) + val data = rawMayorData ?: return@launch + val map = mutableMapOf<Int, Candidate>() + map put data.mayor.election.getPairs() + data.current?.let { + map put data.current.getPairs() } + candidates = map } } @@ -79,4 +84,8 @@ class MayorElectionData { private fun MayorData.Election.getPairs() = year + 1 to candidates.bestCandidate() private fun List<MayorData.Candidate>.bestCandidate() = maxBy { it.votes } + + private infix fun <K, V> MutableMap<K, V>.put(pairs: Pair<K, V>) { + this[pairs.first] = pairs.second + } }
\ No newline at end of file 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 b53627699..4be321a0f 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt @@ -128,14 +128,7 @@ class GardenCropMilestoneDisplay { val crop = item.getCropType() ?: return if (cultivatingData.containsKey(crop)) { val old = cultivatingData[crop]!! -// val finneganPerkFactor = if (finneganPerkActive() && Random.nextDouble() <= 0.25) 0.5 else 1.0 -// val finneganPerkFactor = if (finneganPerkActive()) 0.8 else 1.0 - - // 1/(1 + 0.25*2) - val multiplier = 0.6666 - val finneganPerkFactor = if (finneganPerkActive()) multiplier else 1.0 - val addedCounter = ((counter - old) * finneganPerkFactor).toInt() - println("addedCounter: $addedCounter") + val addedCounter = counter - old if (GardenCropMilestones.cropCounter.isEmpty()) { for (innerCrop in CropType.values()) { @@ -147,8 +140,9 @@ class GardenCropMilestoneDisplay { cropType.setSpeed(-1) } } - - crop.setCounter(crop.getCounter() + addedCounter) + if (!finneganPerkActive()) { + crop.setCounter(crop.getCounter() + addedCounter) + } EliteFarmingWeight.addCrop(crop, addedCounter) if (currentCrop == crop) { calculateSpeed(addedCounter) @@ -162,8 +156,14 @@ class GardenCropMilestoneDisplay { } } - private fun finneganPerkActive() = - config.forcefullyEnabledAlwaysFinnegan || MayorElectionData.isPerkActive("Finnegan", "Farming Simulator") + private fun finneganPerkActive(): Boolean { + val forcefullyEnabledAlwaysFinnegan = config.forcefullyEnabledAlwaysFinnegan + val perkActive = MayorElectionData.isPerkActive("Finnegan", "Farming Simulator") + MayorElectionData.currentCandidate?.let { + + } + return forcefullyEnabledAlwaysFinnegan || perkActive + } @SubscribeEvent fun onBlockClick(event: BlockClickEvent) { @@ -209,6 +209,10 @@ class GardenCropMilestoneDisplay { } private fun checkSpeed() { + if (finneganPerkActive()) { + currentSpeed = (currentSpeed.toDouble() * 0.8).toInt() + } + if (countInLastSecond > 8) { allCounters.add(currentSpeed) while (allCounters.size > 30) { @@ -217,6 +221,12 @@ class GardenCropMilestoneDisplay { averageSpeedPerSecond = allCounters.average().toInt() } countInLastSecond = 0 + + if (finneganPerkActive()) { + currentCrop?.let { + it.setCounter(it.getCounter() + currentSpeed) + } + } currentSpeed = 0 lastBlocksPerSecond = blocksBroken |