diff options
author | hannibal2 <24389977+hannibal002@users.noreply.github.com> | 2023-06-23 00:50:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-23 00:50:09 +0200 |
commit | 1cf1600d0eec7f027c4d10d1b6eb2b2cb249309c (patch) | |
tree | 778ae39b4c35133f5117cbe9a9a4c2223a4eeeba /src/main | |
parent | c7463ccbbe3f6a7ff91ed38f0bcafe82dd1a843c (diff) | |
parent | a1efe2d469bfe9e152ffcae4cd42dd9e98818c0f (diff) | |
download | skyhanni-1cf1600d0eec7f027c4d10d1b6eb2b2cb249309c.tar.gz skyhanni-1cf1600d0eec7f027c4d10d1b6eb2b2cb249309c.tar.bz2 skyhanni-1cf1600d0eec7f027c4d10d1b6eb2b2cb249309c.zip |
Merge pull request #242
Frozen Treasure Tracker
Diffstat (limited to 'src/main')
6 files changed, 270 insertions, 4 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 76b0b88ff..92b2e9f08 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -300,6 +300,7 @@ class SkyHanniMod { loadModule(QuickModMenuSwitch) loadModule(ArachneChatMessageHider()) loadModule(ShowItemUuid()) + loadModule(FrozenTreasureTracker()) loadModule(SlayerRngMeterDisplay()) loadModule(GhostCounter) loadModule(RiftTimer()) diff --git a/src/main/java/at/hannibal2/skyhanni/config/Storage.java b/src/main/java/at/hannibal2/skyhanni/config/Storage.java index b92fcb7dd..ccae2ce25 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/Storage.java +++ b/src/main/java/at/hannibal2/skyhanni/config/Storage.java @@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.features.garden.CropAccessory; import at.hannibal2.skyhanni.features.garden.CropType; import at.hannibal2.skyhanni.features.garden.fortuneguide.FarmingItems; import at.hannibal2.skyhanni.features.garden.visitor.VisitorReward; +import at.hannibal2.skyhanni.features.misc.FrozenTreasure; import at.hannibal2.skyhanni.features.misc.GhostCounter.Option; import at.hannibal2.skyhanni.utils.LorenzVec; import com.google.gson.annotations.Expose; @@ -232,6 +233,20 @@ public class Storage { } + @Expose + public FrozenTreasureTracker frozenTreasureTracker = new FrozenTreasureTracker(); + + public static class FrozenTreasureTracker { + @Expose + public int treasuresMined = 0; + + @Expose + public int compactProcs = 0; + + @Expose + public Map<FrozenTreasure, Integer> treasureCount = new HashMap<>(); + } + public long nextCityProjectParticipationTime = 0L; @Expose diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java b/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java index ef99c5d90..8d15a46df 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java @@ -1,12 +1,13 @@ package at.hannibal2.skyhanni.config.features; -import at.hannibal2.skyhanni.config.core.config.*; -import com.google.gson.annotations.*; +import at.hannibal2.skyhanni.config.core.config.Position; +import com.google.gson.annotations.Expose; import io.github.moulberry.moulconfig.annotations.*; -import io.github.moulberry.moulconfig.observer.*; -import org.lwjgl.input.*; +import io.github.moulberry.moulconfig.observer.Property; +import org.lwjgl.input.Keyboard; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; public class Misc { @@ -482,6 +483,70 @@ public class Misc { } @Expose + @ConfigOption(name = "Frozen Treasure Tracker", desc = "") + @Accordion + public Misc.FrozenTreasureTracker frozenTreasureTracker = new Misc.FrozenTreasureTracker(); + + public static class FrozenTreasureTracker { + + @Expose + @ConfigOption( + name = "Enabled", + desc = "Tracks all of your drops from frozen treasure in the Glacial Caves\n" + + "§eIce calculations are an estimate but are relatively accurate" + ) + @ConfigEditorBoolean + public boolean enabled = true; + + @Expose + @ConfigOption( + name = "Text Format", + desc = "Drag text to change the appearance of the overlay." + ) + @ConfigEditorDraggableList( + exampleText = { + "§1§lFrozen Treasure Tracker", + "§61,636 Treasures Mined", + "§33.2m Total Ice", + "§3342,192 Ice/hr", + "§81,002 Compact Procs", + " ", + "§b182 §fWhite Gift", + "§b94 §aGreen Gift", + "§b17 §9§cRed Gift", + "§b328 §fPacked Ice", + "§b80 §aEnchanted Ice", + "§b4 §9Enchanted Packed Ice", + "§b182 §aIce Bait", + "§b3 §aGlowy Chum Bait", + "§b36 §5Glacial Fragment", + "§b6 §fGlacial Talisman", + " ", + } + ) + public List<Integer> textFormat = new ArrayList<>(Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 14, 15)); + + @Expose + @ConfigOption(name = "Only in Glacial Cave", desc = "Only shows the overlay while in the Glacial Cave.") + @ConfigEditorBoolean + public boolean onlyInCave = true; + + @Expose + @ConfigOption(name = "Show as drops", desc = "Multiplies the numbers on the display by the base drop. \n" + + "E.g. 3 Ice Bait -> 48 Ice Bait") + @ConfigEditorBoolean + public boolean showAsDrops = false; + + @Expose + @ConfigOption(name = "Hide Chat messages", desc = "Hides the chat messages from frozen treasures.") + @ConfigEditorBoolean + public boolean hideMessages = false; + + @Expose + public Position position = new Position(10, 80, false, true); + } + + @Expose @ConfigOption(name = "Exp Bottles", desc = "Hides all the experience orbs lying on the ground.") @ConfigEditorBoolean public boolean hideExpBottles = false; diff --git a/src/main/java/at/hannibal2/skyhanni/data/IslandType.kt b/src/main/java/at/hannibal2/skyhanni/data/IslandType.kt index d3357e880..91f2bed9a 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/IslandType.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/IslandType.kt @@ -18,6 +18,7 @@ enum class IslandType(val displayName: String, val apiName: String = "null") { GARDEN("Garden"), GARDEN_GUEST("Garden Guest"), SPIDER_DEN("Spider's Den"), + WINTER("Jerry's Workshop"), //todo confirm THE_RIFT("The Rift"), NONE(""), diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/FrozenTreasure.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/FrozenTreasure.kt new file mode 100644 index 000000000..e2c70cedc --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/FrozenTreasure.kt @@ -0,0 +1,19 @@ +package at.hannibal2.skyhanni.features.misc + +enum class FrozenTreasure( + val internalName: String, + val displayName: String, + val defaultAmount: Int, + val iceMultiplier: Int = 0, +) { + WHITE_GIFT("WHITE_GIFT", "§fWhite Gift", 1), + GREEN_GIFT("GREEN_GIFT", "§aGreen Gift", 1), + RED_GIFT("RED_GIFT", "§9§cRed Gift", 1), + PACKED_ICE("PACKED_ICE", "§fPacked Ice", 32, 9), + ENCHANTED_ICE("ENCHANTED_ICE", "§aEnchanted Ice", 9, 160), // wiki says 1-16 so assuming 9 + ENCHANTED_PACKED_ICE("ENCHANTED_PACKED_ICE", "§9Enchanted Packed Ice", 1, 25600), + ICE_BAIT("ICE_BAIT", "§aIce Bait", 16), + GLOWY_CHUM_BAIT("GLOWY_CHUM_BAIT", "§aGlowy Chum Bait", 16), + GLACIAL_FRAGMENT("GLACIAL_FRAGMENT", "§5Glacial Fragment", 1), + GLACIAL_TALISMAN("GLACIAL_TALISMAN", "§fGlacial Talisman", 1) +}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/FrozenTreasureTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/FrozenTreasureTracker.kt new file mode 100644 index 000000000..10c2f0bd6 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/FrozenTreasureTracker.kt @@ -0,0 +1,165 @@ +package at.hannibal2.skyhanni.features.misc + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.IslandType +import at.hannibal2.skyhanni.data.ProfileStorageData +import at.hannibal2.skyhanni.data.ScoreboardData +import at.hannibal2.skyhanni.events.ConfigLoadEvent +import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.events.PreProfileSwitchEvent +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList +import at.hannibal2.skyhanni.utils.LorenzUtils.editCopy +import at.hannibal2.skyhanni.utils.NumberUtil +import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators +import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import net.minecraftforge.event.world.WorldEvent +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.concurrent.fixedRateTimer + +class FrozenTreasureTracker { + private val config get() = SkyHanniMod.feature.misc.frozenTreasureTracker + private var display = listOf<List<Any>>() + private var treasuresMined = 0 + private var compactProcs = 0 + private var estimatedIce = 0L + private var lastEstimatedIce = 0L + private val icePerMin = mutableListOf<Long>() + private var icePerHour = 0 + private var stoppedChecks = 0 + private var compactPattern = "COMPACT! You found an Enchanted Ice!".toPattern() + + private var treasureCount = mapOf<FrozenTreasure, Int>() + + init { + fixedRateTimer(name = "skyhanni-dungeon-milestone-display", period = 15_000) { + if (!onJerryWorkshop()) return@fixedRateTimer + calculateIcePerHour() + } + } + + @SubscribeEvent + fun onWorldLoad(event: WorldEvent.Load) { + icePerHour = 0 + stoppedChecks = 0 + icePerMin.clear() + saveAndUpdate() + } + + private fun calculateIcePerHour() { + val difference = estimatedIce - lastEstimatedIce + lastEstimatedIce = estimatedIce + if (difference == 0L) { + stoppedChecks += 1 + if (stoppedChecks == 12) { + stoppedChecks = 0 + icePerMin.clear() + icePerHour = 0 + } + return + } + stoppedChecks = 0 + icePerMin.add(difference) + if (difference != estimatedIce) icePerHour = icePerMin.average().toInt() * 240 + } + + private fun formatDisplay(map: List<List<Any>>): List<List<Any>> { + val newList = mutableListOf<List<Any>>() + for (index in config.textFormat) { + newList.add(map[index]) + } + return newList + } + + @SubscribeEvent + fun onChat(event: LorenzChatEvent) { + if (!ProfileStorageData.loaded) return + if (!onJerryWorkshop()) return + + val message = event.message.removeColor().trim() + + compactPattern.matchMatcher(message) { + compactProcs += 1 + saveAndUpdate() + if (config.hideMessages) event.blockedReason = "frozen treasure tracker" + } + + for (treasure in FrozenTreasure.values()) { + if ("FROZEN TREASURE! You found ${treasure.displayName.removeColor()}!".toRegex().matches(message)) { + treasuresMined += 1 + val old = treasureCount[treasure] ?: 0 + treasureCount = treasureCount.editCopy { this[treasure] = old + 1 } + saveAndUpdate() + if (config.hideMessages) event.blockedReason = "frozen treasure tracker" + } + } + } + + @SubscribeEvent + fun onPreProfileSwitch(event: PreProfileSwitchEvent) { + display = emptyList() + } + + @SubscribeEvent + fun onConfigLoad(event: ConfigLoadEvent) { + val hidden = ProfileStorageData.profileSpecific?.frozenTreasureTracker ?: return + treasuresMined = hidden.treasuresMined + compactProcs = hidden.compactProcs + treasureCount = hidden.treasureCount + saveAndUpdate() + } + + private fun drawTreasureDisplay() = buildList<List<Any>> { + addAsSingletonList("§1§lFrozen Treasure Tracker") + addAsSingletonList("§6${formatNumber(treasuresMined)} Treasures Mined") + addAsSingletonList("§3${formatNumber(estimatedIce)} Total Ice") + addAsSingletonList("§3${formatNumber(icePerHour)} Ice/hr") + addAsSingletonList("§8${formatNumber(compactProcs)} Compact Procs") + addAsSingletonList("") + + for (treasure in FrozenTreasure.values()) { + val count = (treasureCount[treasure] ?: 0) * if (config.showAsDrops) treasure.defaultAmount else 1 + addAsSingletonList("§b${formatNumber(count)} ${treasure.displayName}") + } + addAsSingletonList("") + } + + fun formatNumber(amount: Number): String { + if (amount is Int) return amount.addSeparators() + if (amount is Long) return NumberUtil.format(amount) + return "$amount" + } + + private fun saveAndUpdate() { + val hidden = ProfileStorageData.profileSpecific?.frozenTreasureTracker ?: return + hidden.treasuresMined = treasuresMined + hidden.compactProcs = compactProcs + hidden.treasureCount = treasureCount + calculateIce() + display = formatDisplay(drawTreasureDisplay()) + } + + private fun calculateIce() { + estimatedIce = 0 + estimatedIce += compactProcs * 160 + for (treasure in FrozenTreasure.values()) { + val amount = treasureCount[treasure] ?: 0 + estimatedIce += amount * treasure.defaultAmount * treasure.iceMultiplier + } + } + + @SubscribeEvent + fun onRenderOverlay(event: GuiRenderEvent.GameOverlayRenderEvent) { + if (!config.enabled) return + if (!onJerryWorkshop()) return + if (config.onlyInCave && !inGlacialCave()) return + config.position.renderStringsAndItems(display, posLabel = "Visitor Stats") + } + + private fun onJerryWorkshop() = LorenzUtils.inIsland(IslandType.WINTER) + + private fun inGlacialCave() = onJerryWorkshop() && ScoreboardData.sidebarLinesFormatted.contains(" §7⏣ §3Glacial Cave") +}
\ No newline at end of file |