diff options
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/mining/KingTalismanHelper.kt | 54 |
1 files changed, 35 insertions, 19 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/KingTalismanHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/KingTalismanHelper.kt index 33d5b174c..e9fc47dca 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/mining/KingTalismanHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/mining/KingTalismanHelper.kt @@ -23,7 +23,23 @@ import java.util.Collections class KingTalismanHelper { private val config get() = SkyHanniMod.feature.mining.kingTalisman - private var currentOffset: Int? = null + + companion object { + private var currentOffset: Int? = null + private var skyblockYear = 0 + + private fun getCurrentOffset(): Int? { + if (SkyBlockTime.now().year != skyblockYear) { + return null + } + return currentOffset + } + + fun kingFix() { + currentOffset = null + LorenzUtils.chat("§e[SkyHanni] Reset internal offset of King Talisman Helper.") + } + } private val kingLocation = LorenzVec(129.6, 196.5, 194.1) private val kingCircles = listOf( @@ -37,7 +53,7 @@ class KingTalismanHelper { ) private var allKingsDisplay = emptyList<String>() - private var farDisplay = "Visit the king to sync up." + private var farDisplay = "" private var display = emptyList<String>() private fun isNearby() = IslandType.DWARVEN_MINES.isInIsland() && LorenzUtils.skyBlockArea == "Royal Palace" && @@ -46,21 +62,22 @@ class KingTalismanHelper { @SubscribeEvent fun onTick(event: LorenzTickEvent) { if (!event.isMod(20)) return + if (!isEnabled()) return + val profileSpecific = ProfileStorageData.profileSpecific ?: return - if (!isEnabled()) { - display = emptyList() - return - } val nearby = isNearby() - if (nearby) { - if (currentOffset == null) { - checkOffset() - } + if (nearby && getCurrentOffset() == null) { + checkOffset() } - if (currentOffset == null) return + val kingsTalkedTo = profileSpecific.mining.kingsTalkedTo + if (getCurrentOffset() == null) { + val allKings = kingsTalkedTo.size == kingCircles.size + display = if (allKings) emptyList() else listOf("§cVisit the king to sync up.") + return + } - update() + update(kingsTalkedTo) display = if (nearby) allKingsDisplay else Collections.singletonList(farDisplay) } @@ -74,6 +91,7 @@ class KingTalismanHelper { val currentId = kingCircles.indexOf(getCurrentKing()) val foundId = kingCircles.indexOf(foundKing) currentOffset = currentId - foundId + skyblockYear = SkyBlockTime.now().year } fun isEnabled() = config.enabled && LorenzUtils.inSkyBlock @@ -83,7 +101,7 @@ class KingTalismanHelper { fun onInventoryOpen(event: InventoryFullyOpenedEvent) { if (event.inventoryName != "Commissions") return if (!isEnabled()) return - if (currentOffset == null) return + if (getCurrentOffset() == null) return if (!isNearby()) return val profileSpecific = ProfileStorageData.profileSpecific ?: return @@ -92,14 +110,12 @@ class KingTalismanHelper { if (currentKing !in kingsTalkedTo) { LorenzUtils.debug("Found new king!") kingsTalkedTo.add(currentKing) - update() + update(kingsTalkedTo) display = allKingsDisplay } } - private fun update() { - val profileSpecific = ProfileStorageData.profileSpecific ?: return - val kingsTalkedTo = profileSpecific.mining.kingsTalkedTo + private fun update(kingsTalkedTo: MutableList<String>) { if (kingsTalkedTo.size == kingCircles.size) { allKingsDisplay = Collections.singletonList("§eAll Kings found.") farDisplay = "" @@ -147,7 +163,7 @@ class KingTalismanHelper { } private fun getKingTimes(): MutableMap<String, Long> { - val currentOffset = currentOffset ?: 0 + val currentOffset = getCurrentOffset() ?: 0 val oneSbDay = 1000 * 60 * 20 val oneCircleTime = oneSbDay * kingCircles.size val kingTime = mutableMapOf<String, Long>() @@ -169,7 +185,7 @@ class KingTalismanHelper { @SubscribeEvent fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) { - if (!config.enabled) return + if (!isEnabled()) return config.position.renderStrings(display, posLabel = "King Talisman Helper") } |