aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni
diff options
context:
space:
mode:
authorCalMWolfs <94038482+CalMWolfs@users.noreply.github.com>2024-04-23 17:30:45 +1000
committerGitHub <noreply@github.com>2024-04-23 09:30:45 +0200
commit4ab19885da1b16862b13fa1ce1d5a2aa4a478795 (patch)
tree89f83bfe062b42e84ce1bbd68932832d39032b15 /src/main/java/at/hannibal2/skyhanni
parentfc19e6b99f4a8b97300b98d14222fb22fbb7fbd0 (diff)
downloadskyhanni-4ab19885da1b16862b13fa1ce1d5a2aa4a478795.tar.gz
skyhanni-4ab19885da1b16862b13fa1ce1d5a2aa4a478795.tar.bz2
skyhanni-4ab19885da1b16862b13fa1ce1d5a2aa4a478795.zip
Feature: Hoppety rabbit collection stats (#1482)
Co-authored-by: Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/event/ChocolateFactoryConfig.java10
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/HoppityCollectionStats.kt189
3 files changed, 202 insertions, 1 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
index 3726e022e..841f024dd 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.HoppityCollectionStats
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(HoppityEggsManager)
loadModule(HoppityEggLocator)
loadModule(HoppityEggsShared)
- loadModule(ChocolateFactoryStats)
+ loadModule(HoppityCollectionStats())
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 ad129e0e3..669184a9e 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
@@ -85,6 +85,16 @@ public class ChocolateFactoryConfig {
public int barnCapacityThreshold = 6;
@Expose
+ @ConfigOption(name = "Hoppity Collection Stats", desc = "Shows info about your hoppity rabbit collection.")
+ @ConfigEditorBoolean
+ @FeatureToggle
+ public boolean hoppityCollectionStats = true;
+
+ @Expose
@ConfigLink(owner = ChocolateFactoryConfig.class, field = "statsDisplay")
public Position position = new Position(183, 160, false, true);
+
+ @Expose
+ @ConfigLink(owner = ChocolateFactoryConfig.class, field = "hoppityCollectionStats")
+ public Position hoppityStatsPosition = new Position(183, 160, false, true);
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/HoppityCollectionStats.kt b/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/HoppityCollectionStats.kt
new file mode 100644
index 000000000..90895468c
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/HoppityCollectionStats.kt
@@ -0,0 +1,189 @@
+package at.hannibal2.skyhanni.features.event.chocolatefactory
+
+import at.hannibal2.skyhanni.events.GuiRenderEvent
+import at.hannibal2.skyhanni.events.InventoryCloseEvent
+import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
+import at.hannibal2.skyhanni.events.ProfileJoinEvent
+import at.hannibal2.skyhanni.utils.DisplayTableEntry
+import at.hannibal2.skyhanni.utils.ItemUtils.getLore
+import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.LorenzUtils.round
+import at.hannibal2.skyhanni.utils.NEUInternalName
+import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName
+import at.hannibal2.skyhanni.utils.NumberUtil.formatInt
+import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
+import at.hannibal2.skyhanni.utils.StringUtils.matches
+import at.hannibal2.skyhanni.utils.renderables.Renderable
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+
+class HoppityCollectionStats {
+
+ private val config get() = ChocolateFactoryAPI.config
+
+ private val patternGroup = ChocolateFactoryAPI.patternGroup.group("collection")
+ private val pagePattern by patternGroup.pattern(
+ "page.current",
+ "\\((?<page>\\d+)/(?<maxPage>\\d+)\\) Hoppity's Collection"
+ )
+ private val rabbitRarityPattern by patternGroup.pattern(
+ "rabbit.rarity",
+ "§.§L(?<rarity>\\w+) RABBIT"
+ )
+ private val duplicatesFoundPattern by patternGroup.pattern(
+ "duplicates.found",
+ "§7Duplicates Found: §a(?<duplicates>[\\d,]+)"
+ )
+ private val rabbitNotFoundPattern by patternGroup.pattern(
+ "rabbit.notfound",
+ "(?:§.)+You have not found this rabbit yet!"
+ )
+
+ private var display = emptyList<Renderable>()
+ private val loggedRabbits = mutableMapOf<String, RabbitCollectionInfo>()
+ private var inInventory = false
+ private var currentPage = 0
+
+ @SubscribeEvent
+ fun onInventoryOpen(event: InventoryFullyOpenedEvent) {
+ if (!isEnabled()) return
+ if (!pagePattern.matches(event.inventoryName)) return
+
+ inInventory = true
+
+ for ((_, item) in event.inventoryItems) {
+ val itemName = item.displayName ?: continue
+ val itemLore = item.getLore()
+
+ var duplicatesFound = 0
+ var rabbitRarity: RabbitCollectionRarity? = null
+ var found = true
+
+ for (line in itemLore) {
+ rabbitRarityPattern.matchMatcher(line) {
+ rabbitRarity = RabbitCollectionRarity.fromDisplayName(group("rarity"))
+ }
+ duplicatesFoundPattern.matchMatcher(line) {
+ duplicatesFound = group("duplicates").formatInt()
+ }
+ if (rabbitNotFoundPattern.matches(line)) found = false
+ }
+
+ val rarity = rabbitRarity ?: continue
+ val duplicates = duplicatesFound.coerceAtLeast(0)
+ loggedRabbits[itemName] = RabbitCollectionInfo(rarity, found, duplicates)
+ }
+
+ var totalAmountFound = 0
+ var totalRabbits = 0
+ var totalDuplicates = 0
+ var totalChocolatePerSecond = 0
+ var totalChocolateMultiplier = 0.0
+
+ val table = mutableListOf<DisplayTableEntry>()
+ for (rarity in RabbitCollectionRarity.entries) {
+ val filtered = loggedRabbits.filter { it.value.rarity == rarity }
+
+ val isTotal = rarity == RabbitCollectionRarity.TOTAL
+
+ val title = "${rarity.displayName} Rabbits"
+ val amountFound = filtered.filter { it.value.found }.size
+ val totalOfRarity = filtered.size
+ val duplicates = filtered.values.sumOf { it.duplicates }
+ val chocolatePerSecond = rarity.chocolatePerSecond * amountFound
+ val chocolateMultiplier = (rarity.chocolateMultiplier * amountFound)
+
+ if (!isTotal) {
+ totalAmountFound += amountFound
+ totalRabbits += totalOfRarity
+ totalDuplicates += duplicates
+ totalChocolatePerSecond += chocolatePerSecond
+ totalChocolateMultiplier += chocolateMultiplier
+ }
+
+ val displayFound = if (isTotal) totalAmountFound else amountFound
+ val displayTotal = if (isTotal) totalRabbits else totalOfRarity
+ val displayDuplicates = if (isTotal) totalDuplicates else duplicates
+ val displayChocolatePerSecond = if (isTotal) totalChocolatePerSecond else chocolatePerSecond
+ val displayChocolateMultiplier = if (isTotal) totalChocolateMultiplier else chocolateMultiplier
+
+ val hover = buildList {
+ add(title)
+ add("")
+ add("§7Unique Rabbits: §a$displayFound§7/§a$displayTotal")
+ add("§7Duplicate Rabbits: §a$displayDuplicates")
+ add("§7Total Rabbits Found: §a${displayFound + displayDuplicates}")
+ add("")
+ add("§7Chocolate Per Second: §a$displayChocolatePerSecond")
+ add("§7Chocolate Multiplier: §a${displayChocolateMultiplier.round(3)}")
+ }
+ table.add(
+ DisplayTableEntry(
+ title,
+ "§a$displayFound§7/§a$displayTotal",
+ displayFound.toDouble(),
+ rarity.item,
+ hover
+ )
+ )
+ }
+
+ val newList = mutableListOf<Renderable>()
+ newList.add(Renderable.string("§eHoppity Rabbit Collection§f:"))
+ newList.add(LorenzUtils.fillTable(table, padding = 5))
+ display = newList
+ }
+
+ @SubscribeEvent
+ fun onInventoryClose(event: InventoryCloseEvent) {
+ inInventory = false
+ }
+
+ @SubscribeEvent
+ fun onProfileChange(event: ProfileJoinEvent) {
+ display = emptyList()
+ loggedRabbits.clear()
+ currentPage = 0
+ inInventory = false
+ }
+
+ @SubscribeEvent
+ fun onBackgroundDraw(event: GuiRenderEvent.ChestGuiOverlayRenderEvent) {
+ if (!inInventory) return
+
+ config.hoppityStatsPosition.renderRenderables(
+ display,
+ extraSpace = 5,
+ posLabel = "Hoppity's Collection Stats"
+ )
+ }
+
+ private fun isEnabled() = LorenzUtils.inSkyBlock && config.hoppityCollectionStats
+
+ private data class RabbitCollectionInfo(
+ val rarity: RabbitCollectionRarity,
+ val found: Boolean,
+ val duplicates: Int
+ )
+
+ // todo in future make the amount and multiplier work with mythic rabbits (can't until I have some)
+ private enum class RabbitCollectionRarity(
+ val displayName: String,
+ val chocolatePerSecond: Int,
+ val chocolateMultiplier: Double,
+ val item: NEUInternalName
+ ) {
+ COMMON("§fCommon", 1, 0.002, "STAINED_GLASS".asInternalName()),
+ UNCOMMON("§aUncommon", 2, 0.003, "STAINED_GLASS-5".asInternalName()),
+ RARE("§9Rare", 4, 0.004, "STAINED_GLASS-11".asInternalName()),
+ EPIC("§5Epic", 10, 0.005, "STAINED_GLASS-10".asInternalName()),
+ LEGENDARY("§6Legendary", 0, 0.02, "STAINED_GLASS-1".asInternalName()),
+ MYTHIC("§dMythic", 0, 0.0, "STAINED_GLASS-6".asInternalName()),
+ TOTAL("§cTotal", 0, 0.0, "STAINED_GLASS-14".asInternalName()),
+ ;
+
+ companion object {
+ fun fromDisplayName(displayName: String) = entries.firstOrNull { it.name == displayName }
+ }
+ }
+}