From 994272c82ceaaab10cfd9ec23880f8800c428c47 Mon Sep 17 00:00:00 2001 From: Cal Date: Sat, 20 Apr 2024 21:42:24 +1000 Subject: [PATCH 1/5] show time tower usages and warn when none left --- .../java/at/hannibal2/skyhanni/SkyHanniMod.kt | 4 +- .../event/ChocolateFactoryConfig.java | 6 +++ .../storage/ProfileSpecificStorage.java | 9 ++++ .../repo/HoppityEggLocationsJson.kt | 1 + .../chocolatefactory/ChocolateFactoryAPI.kt | 48 ++++++++++++++----- .../ChocolateFactoryBarnManager.kt | 7 +-- .../chocolatefactory/ChocolateFactoryStats.kt | 9 ++-- .../ChocolateFactoryTimeTowerManager.kt | 44 +++++++++++++++++ 8 files changed, 109 insertions(+), 19 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryTimeTowerManager.kt diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index a91d6bcad0b1..a927b7d13b3a 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -129,6 +129,7 @@ import at.hannibal2.skyhanni.features.event.chocolatefactory.ChocolateFactoryAPI import at.hannibal2.skyhanni.features.event.chocolatefactory.ChocolateFactoryBarnManager import at.hannibal2.skyhanni.features.event.chocolatefactory.ChocolateFactoryInventory import at.hannibal2.skyhanni.features.event.chocolatefactory.ChocolateFactoryStats +import at.hannibal2.skyhanni.features.event.chocolatefactory.ChocolateFactoryTimeTowerManager import at.hannibal2.skyhanni.features.event.chocolatefactory.HoppityEggLocator import at.hannibal2.skyhanni.features.event.chocolatefactory.HoppityEggsManager import at.hannibal2.skyhanni.features.event.chocolatefactory.HoppityEggsShared @@ -618,10 +619,11 @@ class SkyHanniMod { loadModule(MobHighlight()) loadModule(ChocolateFactoryBarnManager) loadModule(ChocolateFactoryInventory) + loadModule(ChocolateFactoryStats) + loadModule(ChocolateFactoryTimeTowerManager) loadModule(HoppityEggsManager) loadModule(HoppityEggLocator) loadModule(HoppityEggsShared) - loadModule(ChocolateFactoryStats) loadModule(SpawnTimers()) loadModule(MarkedPlayerManager()) loadModule(SlayerMiniBossFeatures()) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/event/ChocolateFactoryConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/event/ChocolateFactoryConfig.java index ad129e0e3558..1638297f24f6 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/event/ChocolateFactoryConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/event/ChocolateFactoryConfig.java @@ -53,6 +53,7 @@ public class ChocolateFactoryConfig { ChocolateFactoryStat.EMPTY_2, ChocolateFactoryStat.MULTIPLIER, ChocolateFactoryStat.BARN, + ChocolateFactoryStat.TIME_TOWER, ChocolateFactoryStat.LEADERBOARD_POS )); @@ -84,6 +85,11 @@ public class ChocolateFactoryConfig { @ConfigEditorSlider(minValue = 3, maxValue = 20, minStep = 1) public int barnCapacityThreshold = 6; + @Expose + @ConfigOption(name = "Time Tower Warning", desc = "Warn when you have 3 time tower uses stacked up.") + @ConfigEditorBoolean + public boolean timeTowerWarning = true; + @Expose @ConfigLink(owner = ChocolateFactoryConfig.class, field = "statsDisplay") public Position position = new Position(183, 160, false, true); diff --git a/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java b/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java index b802b22817db..65530928e55e 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java +++ b/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java @@ -57,6 +57,15 @@ public static class ChocolateFactoryStorage { @Expose public int maxRabbits = -1; + + @Expose + public long nextTimeTower = -1; + + @Expose + public int currentTimeTowerUses = -1; + + @Expose + public int maxTimeTowerUses = 3; } @Expose diff --git a/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/HoppityEggLocationsJson.kt b/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/HoppityEggLocationsJson.kt index 1aed170413f9..b5b4c699e9cf 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/HoppityEggLocationsJson.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/HoppityEggLocationsJson.kt @@ -15,5 +15,6 @@ data class HoppityEggLocationsJson( @Expose val prestigeIndex: Int, @Expose val milestoneIndex: Int, @Expose val leaderboardIndex: Int, + @Expose val timeTowerIndex: Int, @Expose val maxRabbits: Int, ) diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryAPI.kt index 9f77ea0cf29e..ee579751c634 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryAPI.kt @@ -74,6 +74,14 @@ object ChocolateFactoryAPI { "leaderboard.place", "§7You are §8#§b(?[\\d,]+)" ) + private val timeTowerAmountPattern by patternGroup.pattern( + "timetower.amount", + "§7Charges: §.(?\\d+)§7/§a(?\\d+)" + ) + private val timeTowerStatusPattern by patternGroup.pattern( + "timetower.status", + "§7Status: §.§l(?INACTIVE|ACTIVE).*" + ) var rabbitSlots = mapOf() var otherUpgradeSlots = setOf() @@ -84,6 +92,7 @@ object ChocolateFactoryAPI { private var prestigeIndex = 28 var milestoneIndex = 53 private var leaderboardIndex = 51 + private var timeTowerIndex = 39 var maxRabbits = 395 var inChocolateFactory = false @@ -95,6 +104,7 @@ object ChocolateFactoryAPI { var chocolateThisPrestige = 0L var chocolateMultiplier = 1.0 var leaderboardPosition: Int? = null + var timeTowerActive = false val upgradeableSlots: MutableSet = mutableSetOf() var bestUpgrade: Int? = null @@ -120,14 +130,14 @@ object ChocolateFactoryAPI { } private fun updateInventoryItems(inventory: Map) { - val profileStorage = profileStorage ?: return - val infoItem = InventoryUtils.getItemAtSlotIndex(infoIndex) ?: return val prestigeItem = InventoryUtils.getItemAtSlotIndex(prestigeIndex) ?: return val productionInfoItem = InventoryUtils.getItemAtSlotIndex(productionInfoIndex) ?: return val leaderboardItem = InventoryUtils.getItemAtSlotIndex(leaderboardIndex) ?: return + val barnItem = InventoryUtils.getItemAtSlotIndex(barnIndex) ?: return + val timeTowerItem = InventoryUtils.getItemAtSlotIndex(timeTowerIndex) ?: return - processInfoItems(infoItem, prestigeItem, productionInfoItem, leaderboardItem) + processInfoItems(infoItem, prestigeItem, productionInfoItem, leaderboardItem, barnItem, timeTowerItem) bestUpgrade = null upgradeableSlots.clear() @@ -144,15 +154,6 @@ object ChocolateFactoryAPI { val lore = item.getLore() val upgradeCost = lore.getUpgradeCost() ?: continue - if (slotIndex == barnIndex) { - lore.matchFirst(barnAmountPattern) { - profileStorage.currentRabbits = group("rabbits").formatInt() - profileStorage.maxRabbits = group("max").formatInt() - - ChocolateFactoryBarnManager.trySendBarnFullMessage() - } - } - val canAfford = upgradeCost <= chocolateCurrent if (canAfford) upgradeableSlots.add(slotIndex) @@ -177,7 +178,11 @@ object ChocolateFactoryAPI { prestigeItem: ItemStack, productionItem: ItemStack, leaderboardItem: ItemStack, + barnItem: ItemStack, + timeTowerItem: ItemStack, ) { + val profileStorage = profileStorage ?: return + chocolateAmountPattern.matchMatcher(chocolateItem.name.removeColor()) { chocolateCurrent = group("amount").formatLong() } @@ -201,6 +206,24 @@ object ChocolateFactoryAPI { leaderboardItem.getLore().matchFirst(leaderboardPlacePattern) { leaderboardPosition = group("position").formatInt() } + barnItem.getLore().matchFirst(barnAmountPattern) { + profileStorage.currentRabbits = group("rabbits").formatInt() + profileStorage.maxRabbits = group("max").formatInt() + ChocolateFactoryBarnManager.trySendBarnFullMessage() + } + for (line in timeTowerItem.getLore()) { + timeTowerStatusPattern.matchMatcher(line) { + timeTowerAmountPattern.matchMatcher(line) { + profileStorage.currentTimeTowerUses = group("uses").formatInt() + profileStorage.maxTimeTowerUses = group("max").formatInt() + ChocolateFactoryTimeTowerManager.trySendTimeTowerFullMessage() + } + } + timeTowerStatusPattern.matchMatcher(line) { + timeTowerActive = group("status") == "ACTIVE" + } + } + if (!config.statsDisplay) return ChocolateFactoryStats.updateDisplay() } @@ -234,6 +257,7 @@ object ChocolateFactoryAPI { prestigeIndex = data.prestigeIndex milestoneIndex = data.milestoneIndex leaderboardIndex = data.leaderboardIndex + timeTowerIndex = data.timeTowerIndex maxRabbits = data.maxRabbits val disabledFeatures = event.getConstant("DisabledFeatures") diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryBarnManager.kt b/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryBarnManager.kt index 353e0dfe3144..c1eebe504adc 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryBarnManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryBarnManager.kt @@ -46,9 +46,10 @@ object ChocolateFactoryBarnManager { if (!ChocolateFactoryAPI.isEnabled()) return val profileStorage = profileStorage ?: return + if (profileStorage.maxRabbits >= ChocolateFactoryAPI.maxRabbits) return + val remainingSpace = profileStorage.maxRabbits - profileStorage.currentRabbits - barnFull = - remainingSpace <= config.barnCapacityThreshold && profileStorage.maxRabbits < ChocolateFactoryAPI.maxRabbits + barnFull = remainingSpace <= config.barnCapacityThreshold if (!barnFull) return if (lastBarnFullWarning.passedSince() < 30.seconds) return @@ -63,7 +64,7 @@ object ChocolateFactoryBarnManager { ChatUtils.clickableChat( "§cYour barn is almost full! " + - "§7(${barnStatus()}). §cUpgrade it so they don't get crushed", + "§7(${barnStatus()}). §cUpgrade it so they don't get crushed!", "cf" ) SoundUtils.playBeepSound() diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryStats.kt b/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryStats.kt index e1df1672d258..ad3d62176d3f 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryStats.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryStats.kt @@ -46,19 +46,21 @@ object ChocolateFactoryStats { add("") add("") add("") + + add("§eTime Tower: §6${ChocolateFactoryTimeTowerManager.timeTowerCharges()}") }) } private fun formatList(list: List): List { return config.statsDisplayList - .filter { ChocolateFactoryAPI.currentPrestige != 1 || it != ChocolateFactoryStat.THIS_PRESTIGE } + .filter { it.shouldDisplay() } .map { list[it.ordinal] } } - enum class ChocolateFactoryStat(private val display: String) { + enum class ChocolateFactoryStat(private val display: String, val shouldDisplay: () -> Boolean = { true }) { HEADER("§6§lChocolate Factory Stats"), CURRENT("§eCurrent Chocolate: §65,272,230"), - THIS_PRESTIGE("§eThis Prestige: §6483,023,853"), + THIS_PRESTIGE("§eThis Prestige: §6483,023,853", { ChocolateFactoryAPI.currentPrestige != 1 }), ALL_TIME("§eAll-time: §6641,119,115"), PER_SECOND("§ePer Second: §63,780.72"), PER_MINUTE("§ePer Minute: §6226,843.2"), @@ -70,6 +72,7 @@ object ChocolateFactoryStats { EMPTY(""), EMPTY_2(""), EMPTY_3(""), + TIME_TOWER("§eTime Tower: §62/3 Charges", { ChocolateFactoryTimeTowerManager.currentCharges() != -1 }), ; override fun toString(): String { diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryTimeTowerManager.kt b/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryTimeTowerManager.kt new file mode 100644 index 000000000000..9d832c98790e --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryTimeTowerManager.kt @@ -0,0 +1,44 @@ +package at.hannibal2.skyhanni.features.event.chocolatefactory + +import at.hannibal2.skyhanni.utils.ChatUtils +import at.hannibal2.skyhanni.utils.SimpleTimeMark +import at.hannibal2.skyhanni.utils.SoundUtils +import kotlin.time.Duration.Companion.seconds + +object ChocolateFactoryTimeTowerManager { + + private val config get() = ChocolateFactoryAPI.config + private val profileStorage get() = ChocolateFactoryAPI.profileStorage + + private var lastWarningSent = SimpleTimeMark.farPast() + + fun trySendTimeTowerFullMessage() { + if (!ChocolateFactoryAPI.isEnabled()) return + if (!config.timeTowerWarning) return + val profileStorage = profileStorage ?: return + + val timeTowerFull = profileStorage.currentTimeTowerUses >= profileStorage.maxTimeTowerUses + + if (!timeTowerFull) return + + if (lastWarningSent.passedSince() < 30.seconds) return + lastWarningSent = SimpleTimeMark.now() + + ChatUtils.clickableChat( + "§cYour Time Tower is full §7(${timeTowerCharges()}§c, " + + "Use it to avoid wasting time tower usages!", + "cf" + ) + SoundUtils.playBeepSound() + lastWarningSent = SimpleTimeMark.now() + } + + fun timeTowerCharges(): String { + val profileStorage = profileStorage ?: return "Unknown" + return "${profileStorage.currentTimeTowerUses}/${profileStorage.maxTimeTowerUses} Charges" + } + + fun currentCharges(): Int { + return profileStorage?.currentTimeTowerUses ?: -1 + } +} From b86f08eeeb377c6530227b2e66eb678edffce953 Mon Sep 17 00:00:00 2001 From: Cal Date: Sun, 21 Apr 2024 09:45:08 +1000 Subject: [PATCH 2/5] finish feature --- .../event/ChocolateFactoryConfig.java | 6 +- .../storage/ProfileSpecificStorage.java | 2 +- .../chocolatefactory/ChocolateFactoryAPI.kt | 21 ++++-- .../chocolatefactory/ChocolateFactoryStats.kt | 7 +- .../ChocolateFactoryTimeTowerManager.kt | 68 +++++++++++++++---- 5 files changed, 81 insertions(+), 23 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/event/ChocolateFactoryConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/event/ChocolateFactoryConfig.java index 1638297f24f6..e62675a67a0c 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/event/ChocolateFactoryConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/event/ChocolateFactoryConfig.java @@ -86,9 +86,11 @@ public class ChocolateFactoryConfig { public int barnCapacityThreshold = 6; @Expose - @ConfigOption(name = "Time Tower Warning", desc = "Warn when you have 3 time tower uses stacked up.") + @ConfigOption(name = "Time Tower Warning", desc = "Notification when you have a new time tower usage available and " + + "continuously warn when your time tower is full.") @ConfigEditorBoolean - public boolean timeTowerWarning = true; + @FeatureToggle + public boolean timeTowerWarning = false; @Expose @ConfigLink(owner = ChocolateFactoryConfig.class, field = "statsDisplay") diff --git a/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java b/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java index 65530928e55e..5259e1edc0e5 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java +++ b/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java @@ -59,7 +59,7 @@ public static class ChocolateFactoryStorage { public int maxRabbits = -1; @Expose - public long nextTimeTower = -1; + public long nextTimeTower = 0; @Expose public int currentTimeTowerUses = -1; diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryAPI.kt index ee579751c634..7579db347cd3 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryAPI.kt @@ -21,12 +21,14 @@ import at.hannibal2.skyhanni.utils.NumberUtil.formatDouble import at.hannibal2.skyhanni.utils.NumberUtil.formatInt import at.hannibal2.skyhanni.utils.NumberUtil.formatLong import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimal +import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.SkyblockSeason import at.hannibal2.skyhanni.utils.SoundUtils import at.hannibal2.skyhanni.utils.StringUtils.matchFirst import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.matches import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import at.hannibal2.skyhanni.utils.TimeUtils import at.hannibal2.skyhanni.utils.UtilsPatterns import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraft.item.ItemStack @@ -82,6 +84,10 @@ object ChocolateFactoryAPI { "timetower.status", "§7Status: §.§l(?INACTIVE|ACTIVE).*" ) + private val timeTowerRechargePattern by patternGroup.pattern( + "timetower.recharge", + "§7Next Charge: §a(?\\w+)" + ) var rabbitSlots = mapOf() var otherUpgradeSlots = setOf() @@ -212,16 +218,19 @@ object ChocolateFactoryAPI { ChocolateFactoryBarnManager.trySendBarnFullMessage() } for (line in timeTowerItem.getLore()) { - timeTowerStatusPattern.matchMatcher(line) { - timeTowerAmountPattern.matchMatcher(line) { - profileStorage.currentTimeTowerUses = group("uses").formatInt() - profileStorage.maxTimeTowerUses = group("max").formatInt() - ChocolateFactoryTimeTowerManager.trySendTimeTowerFullMessage() - } + timeTowerAmountPattern.matchMatcher(line) { + profileStorage.currentTimeTowerUses = group("uses").formatInt() + profileStorage.maxTimeTowerUses = group("max").formatInt() + ChocolateFactoryTimeTowerManager.checkTimeTowerWarning(true) } timeTowerStatusPattern.matchMatcher(line) { timeTowerActive = group("status") == "ACTIVE" } + timeTowerRechargePattern.matchMatcher(line) { + val timeUntilTower = TimeUtils.getDuration(group("duration")) + val nextTimeTower = SimpleTimeMark.now() + timeUntilTower + profileStorage.nextTimeTower = nextTimeTower.toMillis() + } } if (!config.statsDisplay) return diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryStats.kt b/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryStats.kt index ad3d62176d3f..0cbc917b02e6 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryStats.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryStats.kt @@ -25,6 +25,11 @@ object ChocolateFactoryStats { val perHour = perMinute * 60 val perDay = perHour * 24 val position = ChocolateFactoryAPI.leaderboardPosition?.addSeparators() ?: "???" + val timeTowerInfo = if (ChocolateFactoryAPI.timeTowerActive) { + "§d§lActive" + } else { + "§6${ChocolateFactoryTimeTowerManager.timeTowerCharges()}" + } displayList = formatList(buildList { add("§6§lChocolate Factory Stats") @@ -47,7 +52,7 @@ object ChocolateFactoryStats { add("") add("") - add("§eTime Tower: §6${ChocolateFactoryTimeTowerManager.timeTowerCharges()}") + add("§eTime Tower: §6$timeTowerInfo") }) } diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryTimeTowerManager.kt b/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryTimeTowerManager.kt index 9d832c98790e..9345a46b4687 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryTimeTowerManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryTimeTowerManager.kt @@ -1,8 +1,15 @@ package at.hannibal2.skyhanni.features.event.chocolatefactory +import at.hannibal2.skyhanni.events.ProfileJoinEvent +import at.hannibal2.skyhanni.events.SecondPassedEvent +import at.hannibal2.skyhanni.features.fame.ReminderUtils import at.hannibal2.skyhanni.utils.ChatUtils +import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.SoundUtils +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.time.Duration.Companion.hours +import kotlin.time.Duration.Companion.minutes import kotlin.time.Duration.Companion.seconds object ChocolateFactoryTimeTowerManager { @@ -10,35 +17,70 @@ object ChocolateFactoryTimeTowerManager { private val config get() = ChocolateFactoryAPI.config private val profileStorage get() = ChocolateFactoryAPI.profileStorage - private var lastWarningSent = SimpleTimeMark.farPast() + private var lastTimeTowerWarning = SimpleTimeMark.farPast() - fun trySendTimeTowerFullMessage() { - if (!ChocolateFactoryAPI.isEnabled()) return - if (!config.timeTowerWarning) return + @SubscribeEvent + fun onSecondPassed(event: SecondPassedEvent) { + if (!LorenzUtils.inSkyBlock) return + if (ChocolateFactoryAPI.inChocolateFactory) return val profileStorage = profileStorage ?: return - val timeTowerFull = profileStorage.currentTimeTowerUses >= profileStorage.maxTimeTowerUses + val nextCharge = SimpleTimeMark(profileStorage.nextTimeTower) - if (!timeTowerFull) return + if (nextCharge.isInPast() && !nextCharge.isFarPast() && currentCharges() < maxCharges()) { + profileStorage.currentTimeTowerUses++ - if (lastWarningSent.passedSince() < 30.seconds) return - lastWarningSent = SimpleTimeMark.now() + // todo in future once have Einstein rabbit account for that + val nextTimeTower = SimpleTimeMark(profileStorage.nextTimeTower) + 8.hours + profileStorage.nextTimeTower = nextTimeTower.toMillis() + + if (!config.timeTowerWarning) return + ChatUtils.clickableChat( + "Your Time Tower has another charge available §7(${timeTowerCharges()})§e, " + + "Click here to use one", + "cf" + ) + SoundUtils.playBeepSound() + lastTimeTowerWarning = SimpleTimeMark.now() + return + } + checkTimeTowerWarning(false) + } + + fun checkTimeTowerWarning(inInventory: Boolean) { + if (!ChocolateFactoryAPI.isEnabled()) return + if (!config.timeTowerWarning) return + if (!timeTowerFull()) return + if (ReminderUtils.isBusy()) return + + val warningSeparation = if (inInventory) 30.seconds else 5.minutes + if (lastTimeTowerWarning.passedSince() < warningSeparation) return ChatUtils.clickableChat( - "§cYour Time Tower is full §7(${timeTowerCharges()}§c, " + - "Use it to avoid wasting time tower usages!", + "§cYour Time Tower is full §7(${timeTowerCharges()})§c, " + + "Use one to avoid wasting time tower usages!", "cf" ) SoundUtils.playBeepSound() - lastWarningSent = SimpleTimeMark.now() + lastTimeTowerWarning = SimpleTimeMark.now() } fun timeTowerCharges(): String { - val profileStorage = profileStorage ?: return "Unknown" - return "${profileStorage.currentTimeTowerUses}/${profileStorage.maxTimeTowerUses} Charges" + return "${currentCharges()}/${maxCharges()} Charges" } fun currentCharges(): Int { return profileStorage?.currentTimeTowerUses ?: -1 } + + private fun maxCharges(): Int { + return profileStorage?.maxTimeTowerUses ?: 3 + } + + private fun timeTowerFull() = currentCharges() >= maxCharges() + + @SubscribeEvent + fun onProfileChange(event: ProfileJoinEvent) { + lastTimeTowerWarning = SimpleTimeMark.farPast() + } } From 94676a12cc8520425c43994c17d95b7cab51411d Mon Sep 17 00:00:00 2001 From: Cal Date: Mon, 22 Apr 2024 07:38:20 +1000 Subject: [PATCH 3/5] fix highlighting on switched profile without time tower --- .../features/event/chocolatefactory/ChocolateFactoryAPI.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryAPI.kt index 7579db347cd3..fbecccdde171 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryAPI.kt @@ -189,6 +189,9 @@ object ChocolateFactoryAPI { ) { val profileStorage = profileStorage ?: return + chocolateMultiplier = 1.0 + timeTowerActive = false + chocolateAmountPattern.matchMatcher(chocolateItem.name.removeColor()) { chocolateCurrent = group("amount").formatLong() } From 2822efe962aa974d44f9f9e89367728de49e8ec0 Mon Sep 17 00:00:00 2001 From: Cal Date: Mon, 22 Apr 2024 09:42:24 +1000 Subject: [PATCH 4/5] fix not getting minutes or hours --- .../features/event/chocolatefactory/ChocolateFactoryAPI.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryAPI.kt index fbecccdde171..e54a69b962f9 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryAPI.kt @@ -230,7 +230,10 @@ object ChocolateFactoryAPI { timeTowerActive = group("status") == "ACTIVE" } timeTowerRechargePattern.matchMatcher(line) { - val timeUntilTower = TimeUtils.getDuration(group("duration")) + // todo in future fix this issue with TimeUtils.getDuration + val formattedGroup = group("duration").replace("h", "h ").replace("m", "m ") + + val timeUntilTower = TimeUtils.getDuration(formattedGroup) val nextTimeTower = SimpleTimeMark.now() + timeUntilTower profileStorage.nextTimeTower = nextTimeTower.toMillis() } From dc1d91d8dcee1fd0b8e226be0a60599ff719323e Mon Sep 17 00:00:00 2001 From: Cal Date: Wed, 24 Apr 2024 19:56:54 +1000 Subject: [PATCH 5/5] fix merge --- .../chocolatefactory/ChocolateFactoryTimeTowerManager.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryTimeTowerManager.kt b/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryTimeTowerManager.kt index 9345a46b4687..28f601b66789 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryTimeTowerManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/ChocolateFactoryTimeTowerManager.kt @@ -4,6 +4,7 @@ import at.hannibal2.skyhanni.events.ProfileJoinEvent import at.hannibal2.skyhanni.events.SecondPassedEvent import at.hannibal2.skyhanni.features.fame.ReminderUtils import at.hannibal2.skyhanni.utils.ChatUtils +import at.hannibal2.skyhanni.utils.HypixelCommands import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.SoundUtils @@ -38,7 +39,9 @@ object ChocolateFactoryTimeTowerManager { ChatUtils.clickableChat( "Your Time Tower has another charge available §7(${timeTowerCharges()})§e, " + "Click here to use one", - "cf" + onClick = { + HypixelCommands.chocolateFactory() + } ) SoundUtils.playBeepSound() lastTimeTowerWarning = SimpleTimeMark.now() @@ -59,7 +62,9 @@ object ChocolateFactoryTimeTowerManager { ChatUtils.clickableChat( "§cYour Time Tower is full §7(${timeTowerCharges()})§c, " + "Use one to avoid wasting time tower usages!", - "cf" + onClick = { + HypixelCommands.chocolateFactory() + } ) SoundUtils.playBeepSound() lastTimeTowerWarning = SimpleTimeMark.now()