diff options
Diffstat (limited to 'src/main/java')
5 files changed, 173 insertions, 1 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java index 1922c3492..04f33c824 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java @@ -216,6 +216,7 @@ public class SkyHanniMod { loadModule(new ChickenHeadTimer()); loadModule(new GardenOptimalSpeed()); loadModule(new GardenDeskInSBMenu()); + loadModule(new GardenLevelDisplay()); Commands.INSTANCE.init(); diff --git a/src/main/java/at/hannibal2/skyhanni/config/Features.java b/src/main/java/at/hannibal2/skyhanni/config/Features.java index c9ab200ca..ec666b099 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/Features.java +++ b/src/main/java/at/hannibal2/skyhanni/config/Features.java @@ -203,6 +203,11 @@ public class Features extends Config { editOverlay(activeConfigCategory, 200, 16, garden.optimalSpeedPos); return; } + + if (runnableId.equals("gardenLevel")) { + editOverlay(activeConfigCategory, 200, 16, garden.gardenLevelPos); + return; + } } @Expose diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java b/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java index a288113ed..9230247ee 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java @@ -282,7 +282,7 @@ public class Garden { public boolean optimalSpeedEnabled = true; @Expose - @ConfigOption(name = "Enabled", desc = "Warn via title when you don't have the optimal speed.") + @ConfigOption(name = "Warning Title", desc = "Warn via title when you don't have the optimal speed.") @ConfigEditorBoolean @ConfigAccordionId(id = 9) public boolean optimalSpeedWarning = false; @@ -294,6 +294,23 @@ public class Garden { public Position optimalSpeedPos = new Position(188, -105, false, true); @Expose + @ConfigOption(name = "Garden Level", desc = "") + @ConfigEditorAccordion(id = 10) + public boolean gardenLevel = false; + + @Expose + @ConfigOption(name = "Display", desc = "Show the current garden level and progress to the next level.") + @ConfigEditorBoolean + @ConfigAccordionId(id = 10) + public boolean gardenLevelDisplay = true; + + @Expose + @ConfigOption(name = "Garden Level Position", desc = "") + @ConfigEditorButton(runnableId = "gardenLevel", buttonText = "Edit") + @ConfigAccordionId(id = 10) + public Position gardenLevelPos = new Position(-375, -215, false, true); + + @Expose @ConfigOption(name = "Plot Price", desc = "Show the price of the plot in coins when inside the Configure Plots inventory.") @ConfigEditorBoolean public boolean plotPrice = true; diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Hidden.java b/src/main/java/at/hannibal2/skyhanni/config/features/Hidden.java index 5bd2b3ba4..c8604aeb3 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Hidden.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Hidden.java @@ -38,4 +38,7 @@ public class Hidden { @Expose public Map<String, Integer> gardenCropsPerSecond = new HashMap<>(); + + @Expose + public int gardenExp = -1; } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenLevelDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenLevelDisplay.kt new file mode 100644 index 000000000..f40b4edc3 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenLevelDisplay.kt @@ -0,0 +1,146 @@ +package at.hannibal2.skyhanni.features.garden + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.events.InventoryOpenEvent +import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.events.ProfileJoinEvent +import at.hannibal2.skyhanni.utils.ItemUtils.getLore +import at.hannibal2.skyhanni.utils.ItemUtils.name +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNeeded +import at.hannibal2.skyhanni.utils.RenderUtils.renderString +import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import java.util.regex.Pattern + +class GardenLevelDisplay { + private val config get() = SkyHanniMod.feature.garden + private val overflowPattern = Pattern.compile("(?:.*) §e(.*)§6\\/(?:.*)") + private val namePattern = Pattern.compile("Garden Level (.*)") + private var gardenExp + get() = SkyHanniMod.feature.hidden.gardenExp + set(value) { + SkyHanniMod.feature.hidden.gardenExp = value + } + private var display = "" + private var visitorRewardPattern = Pattern.compile(" {4}§r§8\\+§r§2(.*) §r§7Garden Experience") + + @SubscribeEvent + fun onProfileJoin(event: ProfileJoinEvent) { + update() + } + + @SubscribeEvent(receiveCanceled = true) + fun onChatMessage(event: LorenzChatEvent) { + if (!isEnabled()) return + + val matcher = visitorRewardPattern.matcher(event.message) + if (matcher.matches()) { + val moreExp = matcher.group(1).toInt() + gardenExp += moreExp + update() + } + } + + @SubscribeEvent + fun onInventoryOpen(event: InventoryOpenEvent) { + if (!isEnabled()) return + if (event.inventoryName != "Desk") return + val item = event.inventoryItems[4]!! + + val name = item.name!!.removeColor() + val nameMatcher = namePattern.matcher(name) + if (!nameMatcher.matches()) return + val currentLevel = nameMatcher.group(1).romanToDecimalIfNeeded() + var overflow = 0 + for (line in item.getLore()) { + val matcher = overflowPattern.matcher(line) + if (matcher.matches()) { + overflow = matcher.group(1).replace(",", "").toInt() + break + } + } + val expForLevel = getExpForLevel(currentLevel).toInt() + gardenExp = expForLevel + overflow + update() + } + + private fun update() { + display = drawDisplay() + } + + private fun drawDisplay(): String { + if (gardenExp == -1) return "§aGarden Level ? §cOpen the desk!" + val currentLevel = getLevelForExp(gardenExp.toLong()) + val needForLevel = getExpForLevel(currentLevel).toInt() + val nextLevel = currentLevel + 1 + val needForNextLevel = getExpForLevel(nextLevel).toInt() + + return "§aGarden Level $currentLevel" + if (needForNextLevel != 0) { + val overflow = gardenExp - needForLevel + val needForOnlyNextLvl = needForNextLevel - needForLevel + + val need = LorenzUtils.formatInteger(overflow) + val have = LorenzUtils.formatInteger(needForOnlyNextLvl) + " §7(§e$need§7/§e$have§7)" + } else "" + } + + private fun getLevelForExp(gardenExp: Long): Int { + var tier = 0 + var totalCrops = 0L + for (tierCrops in gardenExperience) { + totalCrops += tierCrops + if (totalCrops > gardenExp) { + return tier + } + tier++ + } + + return tier + } + + // TODO make table utils method + private fun getExpForLevel(requestedLevel: Int): Long { + var totalCrops = 0L + var tier = 0 + for (tierCrops in gardenExperience) { + totalCrops += tierCrops + tier++ + if (tier == requestedLevel) { + return totalCrops + } + } + + return 0 + } + + @SubscribeEvent + fun onRenderOverlay(event: GuiRenderEvent.GameOverlayRenderEvent) { + if (!isEnabled()) return + + config.gardenLevelPos.renderString(display) + } + + private fun isEnabled() = GardenAPI.inGarden() && config.gardenLevelDisplay + + // TODO use repo + private val gardenExperience = listOf( + 0, + 70, + 100, + 140, + 240, + 600, + 1500, + 2000, + 2500, + 3000, + 10000, + 10000, + 10000, + 10000, + 10000, + ) +}
\ No newline at end of file |