aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt
diff options
context:
space:
mode:
authorCalMWolfs <94038482+CalMWolfs@users.noreply.github.com>2023-08-28 05:18:28 +1000
committerGitHub <noreply@github.com>2023-08-27 21:18:28 +0200
commit27f629589aeba6f2209f6c2e2c28af575b4ce022 (patch)
tree554c1badb15082482f7746afc9a574b870436279 /src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt
parent0f375522e6a4ac326c27b1f8b02e5de2b8491c4f (diff)
downloadskyhanni-27f629589aeba6f2209f6c2e2c28af575b4ce022.tar.gz
skyhanni-27f629589aeba6f2209f6c2e2c28af575b4ce022.tar.bz2
skyhanni-27f629589aeba6f2209f6c2e2c28af575b4ce022.zip
Merge pull request #402
* garden exp * refactored a lot of stuff * make it not break
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt165
1 files changed, 51 insertions, 114 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt b/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt
index 0742fae1e..48c16cb1c 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt
@@ -2,29 +2,18 @@ package at.hannibal2.skyhanni.data
import at.hannibal2.skyhanni.events.CropMilestoneUpdateEvent
import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
+import at.hannibal2.skyhanni.events.RepositoryReloadEvent
import at.hannibal2.skyhanni.features.garden.CropType
import at.hannibal2.skyhanni.features.garden.GardenAPI
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
+import at.hannibal2.skyhanni.utils.jsonobjects.GardenJson
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-class GardenCropMilestones {
+object GardenCropMilestones {
private val cropPattern = "§7Harvest §f(?<name>.*) §7on .*".toPattern()
private val totalPattern = "§7Total: §a(?<name>.*)".toPattern()
- // Add when api support is there
-// @SubscribeEvent
-// fun onProfileDataLoad(event: ProfileApiDataLoadedEvent) {
-// val profileData = event.profileData
-// for ((key, value) in profileData.entrySet()) {
-// if (key.startsWith("experience_skill_")) {
-// val label = key.substring(17)
-// val exp = value.asLong
-// gardenExp[label] = exp
-// }
-// }
-// }
-
@SubscribeEvent
fun onInventoryOpen(event: InventoryFullyOpenedEvent) {
if (event.inventoryName != "Crop Milestones") return
@@ -45,116 +34,64 @@ class GardenCropMilestones {
CropMilestoneUpdateEvent().postAndCatch()
}
- companion object {
- val cropCounter: MutableMap<CropType, Long>? get() = GardenAPI.config?.cropCounter
+ private var cropMilestoneData: Map<CropType, List<Int>>? = null
- // TODO make nullable
- fun CropType.getCounter() = cropCounter?.get(this) ?: 0
+ val cropCounter: MutableMap<CropType, Long>? get() = GardenAPI.config?.cropCounter
- fun CropType.setCounter(counter: Long) {
- cropCounter?.set(this, counter)
- }
+ // TODO make nullable
+ fun CropType.getCounter() = cropCounter?.get(this) ?: 0
- fun CropType.isMaxed() = getCounter() >= 1_000_000_000
+ fun CropType.setCounter(counter: Long) {
+ cropCounter?.set(this, counter)
+ }
- fun getTierForCrops(crops: Long): Int {
- var tier = 0
- var totalCrops = 0L
- for (tierCrops in cropMilestone) {
- totalCrops += tierCrops
- if (totalCrops > crops) {
- return tier
- }
- tier++
- }
+ fun CropType.isMaxed(): Boolean {
+ val maxValue = cropMilestoneData?.get(this)?.sum() ?: 1_000_000_000 // 1 bil for now
+ return getCounter() >= maxValue
+ }
- return tier
+ fun getTierForCropCount(count: Long, crop: CropType): Int {
+ var tier = 0
+ var totalCrops = 0L
+ val cropMilestone = cropMilestoneData?.get(crop) ?: return 0
+ for (tierCrops in cropMilestone) {
+ totalCrops += tierCrops
+ if (totalCrops > count) {
+ return tier
+ }
+ tier++
}
- fun getCropsForTier(requestedTier: Int): Long {
- var totalCrops = 0L
- var tier = 0
- for (tierCrops in cropMilestone) {
- totalCrops += tierCrops
- tier++
- if (tier == requestedTier) {
- return totalCrops
- }
- }
+ return tier
+ }
- return 0
+ fun getCropsForTier(requestedTier: Int, crop: CropType): Long {
+ var totalCrops = 0L
+ var tier = 0
+ val cropMilestone = cropMilestoneData?.get(crop) ?: return 0
+ for (tierCrops in cropMilestone) {
+ totalCrops += tierCrops
+ tier++
+ if (tier == requestedTier) {
+ return totalCrops
+ }
}
- fun CropType.progressToNextLevel(): Double {
- val progress = getCounter()
- val startTier = getTierForCrops(progress)
- val startCrops = getCropsForTier(startTier)
- val end = getCropsForTier(startTier + 1).toDouble()
- return (progress - startCrops) / (end - startCrops)
- }
+ return 0
+ }
- // TODO use repo
- private val cropMilestone = listOf(
- 100,
- 150,
- 250,
- 500,
- 1500,
- 2500,
- 5000,
- 5000,
- 10000,
- 25000,
- 25000,
- 25000,
- 30000,
- 70000,
- 100000,
- 200000,
- 250000,
- 250000,
- 500000,
- 1000000,
- 1500000,
- 2000000,
- 3000000,
- 4000000,
- 7000000,
- 10000000,
- 20000000,
- 25000000,
- 25000000,
- 50000000,
- 50000000,
- 50000000,
- 50000000,
- 50000000,
- 50000000,
- 50000000,
- 50000000,
- 50000000,
- 50000000,
- 50000000,
- 50000000,
- 50000000,
- 50000000,
- 50000000,
- 50000000,
- 100000000,
- )
+ fun CropType.progressToNextLevel(): Double {
+ val progress = getCounter()
+ val startTier = getTierForCropCount(progress, this)
+ val startCrops = getCropsForTier(startTier, this)
+ val end = getCropsForTier(startTier + 1, this).toDouble()
+ return (progress - startCrops) / (end - startCrops)
}
-}
-// TODO delete?
-private fun String.formatNumber(): Long {
- var text = replace(",", "")
- val multiplier = if (text.endsWith("k")) {
- text = text.substring(0, text.length - 1)
- 1_000
- } else if (text.endsWith("m")) {
- text = text.substring(0, text.length - 1)
- 1_000_000
- } else 1
- val d = text.toDouble()
- return (d * multiplier).toLong()
-}
+ @SubscribeEvent
+ fun onRepoReload(event: RepositoryReloadEvent) {
+ val data = event.getConstant<GardenJson>("Garden") ?: return
+ cropMilestoneData = data.crop_milestones
+ println("loaded stuff: $cropMilestoneData")
+ }
+} \ No newline at end of file