diff options
| author | Linnea Gräf <nea@nea.moe> | 2024-06-04 15:49:59 +0200 |
|---|---|---|
| committer | Linnea Gräf <nea@nea.moe> | 2024-06-04 15:49:59 +0200 |
| commit | 9b214189ee2f2e652f1b9d3405739b9a749ff4a8 (patch) | |
| tree | 56422b8c4b4e2d7c8ad8ef00ee4b13cecc7ff1ae /src/main/java/at/hannibal2 | |
| parent | efcebe42a9cc2ed20ec78c2114c69d7abdc59380 (diff) | |
| download | SkyHanni-beta.tar.gz SkyHanni-beta.tar.bz2 SkyHanni-beta.zip | |
Add location rabbit requirement trackerbeta
Diffstat (limited to 'src/main/java/at/hannibal2')
5 files changed, 143 insertions, 3 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/chocolatefactory/ChocolateFactoryConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/chocolatefactory/ChocolateFactoryConfig.java index 50230a6ae..943889642 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/chocolatefactory/ChocolateFactoryConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/chocolatefactory/ChocolateFactoryConfig.java @@ -175,6 +175,13 @@ public class ChocolateFactoryConfig { public boolean highlightRabbitsWithRequirement = false; @Expose + @ConfigOption(name = "Show missing location rabbits in overview", + desc = "Shows which in which locations you have not yet found enough egg locations to unlock the rabbit for that location") + @ConfigEditorBoolean + @FeatureToggle + public boolean showLocationRequirementsRabbitsInHoppityStats = false; + + @Expose @ConfigOption(name = "Only Requirement Not Met", desc = "Only highlight the rabbits you don't have the requirement for.") @ConfigEditorBoolean @FeatureToggle 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 d88ccb315..825686ca4 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java +++ b/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java @@ -130,10 +130,13 @@ public class ProfileSpecificStorage { public String targetName = null; @Expose - public Map<String, Integer> rabbitCounts = new HashMap(); + public Map<String, Integer> rabbitCounts = new HashMap<>(); @Expose - public Map<IslandType, Set<LorenzVec>> collectedEggLocations = new HashMap(); + public Map<String, HoppityCollectionStats.LocationRabbit> locationRabbitRequirements = new HashMap<>(); + + @Expose + public Map<IslandType, Set<LorenzVec>> collectedEggLocations = new HashMap<>(); @Expose public Integer hoppityShopYearOpened = null; diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityCollectionStats.kt b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityCollectionStats.kt index b570ae373..bb55c8b68 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityCollectionStats.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityCollectionStats.kt @@ -1,5 +1,6 @@ package at.hannibal2.skyhanni.features.event.hoppity +import at.hannibal2.skyhanni.data.IslandType import at.hannibal2.skyhanni.data.ProfileStorageData import at.hannibal2.skyhanni.events.GuiContainerEvent import at.hannibal2.skyhanni.events.GuiRenderEvent @@ -7,9 +8,12 @@ import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactoryAPI import at.hannibal2.skyhanni.utils.ChatUtils +import at.hannibal2.skyhanni.utils.CollectionUtils.collectWhile +import at.hannibal2.skyhanni.utils.CollectionUtils.consumeWhile import at.hannibal2.skyhanni.utils.DisplayTableEntry import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils.getLore +import at.hannibal2.skyhanni.utils.KSerializable import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.round @@ -19,6 +23,7 @@ import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.NumberUtil.formatInt import at.hannibal2.skyhanni.utils.RegexUtils.anyMatches import at.hannibal2.skyhanni.utils.RegexUtils.find +import at.hannibal2.skyhanni.utils.RegexUtils.findMatcher import at.hannibal2.skyhanni.utils.RegexUtils.matchFirst import at.hannibal2.skyhanni.utils.RegexUtils.matches import at.hannibal2.skyhanni.utils.RenderUtils.highlight @@ -54,6 +59,7 @@ object HoppityCollectionStats { "rabbits.found", "§.§l§m[ §a-z]+§r §.(?<current>[0-9]+)§./§.(?<total>[0-9]+)" ) + /** * REGEX-TEST: §a✔ §7Requirement */ @@ -61,6 +67,7 @@ object HoppityCollectionStats { "rabbit.requirement.met", "§a✔ §7Requirement" ) + /** * REGEX-TEST: §c✖ §7Requirement §e0§7/§a15 * REGEX-TEST: §c✖ §7Requirement §e6§7/§a20 @@ -71,10 +78,42 @@ object HoppityCollectionStats { "§c✖ §7Requirement.*", ) + /** + * REGEX-TEST: §c✖ §7Requirement §e0§7/§a15 + * REGEX-TEST: §c✖ §7Requirement §e6§7/§a20 + * REGEX-TEST: §c✖ §7Requirement §e651§7/§a1,000 + */ + private val requirementAmountNotMet by patternGroup.pattern( + "rabbit.requirement.notmet", + "§c✖ §7Requirement §e(?<acquired>[\\d,]+)§7/§a(?<required>[\\d,]+)", + ) + private var display = emptyList<Renderable>() private val loggedRabbits get() = ProfileStorageData.profileSpecific?.chocolateFactory?.rabbitCounts ?: mutableMapOf() + @KSerializable + data class LocationRabbit( + val locationName: String, + val loreFoundCount: Int, + val requiredCount: Int, + ) { + private fun getSkyhanniFoundCount(): Int { + val islandType = IslandType.getByNameOrNull(locationName) ?: return 0 + val foundLocations = HoppityEggLocations.getEggsIn(islandType) + return foundLocations.size + } + + val foundCount get() = maxOf(getSkyhanniFoundCount(), loreFoundCount) + + fun hasMetRequirements(): Boolean { + return foundCount == requiredCount + } + } + + private val locationRabbitRequirements: MutableMap<String, LocationRabbit> + get() = ProfileStorageData.profileSpecific?.chocolateFactory?.locationRabbitRequirements ?: mutableMapOf() + var inInventory = false @SubscribeEvent @@ -118,6 +157,21 @@ object HoppityCollectionStats { } } + private fun addLocationRequirementRabbitsToHud(newList: MutableList<Renderable>) { + if (!config.showLocationRequirementsRabbitsInHoppityStats) return + val missingLocationRabbits = locationRabbitRequirements.values.filter { !it.hasMetRequirements() } + newList.add(Renderable.hoverTips( + Renderable.string("§cMissing Locations: " + missingLocationRabbits.joinToString("§7, §c") { + it.locationName.substringBefore(' ') + }), + locationRabbitRequirements.map { + it.key + " §7(§e" + it.value.locationName + "§7): " + (if (it.value.hasMetRequirements()) "§a" else "§c") + + it.value.foundCount + "§7/§a" + it.value.requiredCount + } + )) + + } + private fun buildDisplay(event: InventoryFullyOpenedEvent): MutableList<Renderable> { logRabbits(event) @@ -125,6 +179,8 @@ object HoppityCollectionStats { newList.add(Renderable.string("§eHoppity Rabbit Collection§f:")) newList.add(LorenzUtils.fillTable(getRabbitStats(), padding = 5)) + addLocationRequirementRabbitsToHud(newList) + val loggedRabbitCount = loggedRabbits.size val foundRabbitCount = getFoundRabbitsFromHypixel(event) @@ -225,15 +281,61 @@ object HoppityCollectionStats { } } } + /* + * { + id: "minecraft:dye", + Count: 1b, + tag: { + display: { + Lore: ["§7Grants §6+1 Chocolate §7and §60.002x", "§6Chocolate §7per second to your", + * "§7§6Chocolate Factory§7.", + * "", "§c✖ §7Requirement §e11§7/§a15", "§7Find §a15 §7unique egg locations in the", "§7§bDeep Caverns§7.", + * "", "§7§8You cannot find this rabbit until you", "§8meet the requirement!", "", "§F§LCOMMON RABBIT"], + Name: "§fCave" + } + }, + Damage: 8s +}*/ + + /** + * REGEX-TEST: Find 15 unique egg locations in the Deep Caverns. + */ + private val locationRequirementDescription by patternGroup.pattern("rabbit.requirement.location", + "Find 15 unique egg locations in the (?<location>.*)\\..*") + + private fun saveLocationRabbit(rabbitName: String, lore: List<String>) { + val iterator = lore.iterator() + + val requirement = iterator.consumeWhile { line -> + val requirementMet = requirementMet.matches(line) + if (requirementMet) Pair(15, 15)// This is kind of hardcoded? + else requirementAmountNotMet.findMatcher(line) { + group("acquired").formatInt() to group("required").formatInt() + } + } ?: return + + val requirementDescriptionCollate = iterator.collectWhile { line -> + line.isNotEmpty() + }.joinToString(" ") { it.removeColor() } + + val location = locationRequirementDescription.findMatcher(requirementDescriptionCollate) { + group("location") + } ?: return + + locationRabbitRequirements[rabbitName] = LocationRabbit(location, requirement.first, requirement.second) + } private fun logRabbits(event: InventoryFullyOpenedEvent) { - for ((_, item) in event.inventoryItems) { + for (item in event.inventoryItems.values) { val itemName = item.displayName?.removeColor() ?: continue val isRabbit = HoppityCollectionData.isKnownRabbit(itemName) if (!isRabbit) continue val itemLore = item.getLore() + + saveLocationRabbit(itemName, itemLore) + val found = !rabbitNotFoundPattern.anyMatches(itemLore) if (!found) continue diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggLocations.kt b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggLocations.kt index 00f59cdb8..cce0aef79 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggLocations.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityEggLocations.kt @@ -38,6 +38,10 @@ object HoppityEggLocations { val islandCollectedLocations get() = collectedEggStorage[LorenzUtils.skyBlockIsland]?.toSet() ?: emptySet() + fun getEggsIn(islandType: IslandType): Set<LorenzVec> { + return collectedEggStorage[islandType] ?: emptySet() + } + fun hasCollectedEgg(location: LorenzVec): Boolean = islandCollectedLocations.contains(location) @SubscribeEvent diff --git a/src/main/java/at/hannibal2/skyhanni/utils/CollectionUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/CollectionUtils.kt index 2e1237fe8..05b99c982 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/CollectionUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/CollectionUtils.kt @@ -182,6 +182,30 @@ object CollectionUtils { } } + inline fun <T, R> Iterator<T>.consumeWhile(block: (T) -> R): R? { + while (hasNext()) { + return block(next()) ?: continue + } + return null + } + + inline fun <T> Iterator<T>.collectWhile(block: (T) -> Boolean): List<T> { + return collectWhileTo(mutableListOf(), block) + } + + inline fun <T, C : MutableCollection<T>> Iterator<T>.collectWhileTo(collection: C, block: (T) -> Boolean): C { + while (hasNext()) { + val element = next() + if (block(element)) { + collection.add(element) + } else { + break + } + } + return collection + } + + /** Updates a value if it is present in the set (equals), useful if the newValue is not reference equal with the value in the set */ inline fun <reified T> MutableSet<T>.refreshReference(newValue: T) = if (this.contains(newValue)) { this.remove(newValue) |
