From eda44cb8743c709c15a7ed03381d05e43728e647 Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Thu, 19 Dec 2024 20:18:39 +0100 Subject: feat: Add corpse loot detection --- src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt | 35 ++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt') diff --git a/src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt b/src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt index a84aac8..c269c3d 100644 --- a/src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt +++ b/src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt @@ -86,11 +86,15 @@ class ItemIdProvider { fun findForName(name: String, fallbackToGenerated: Boolean = true): ItemId? { var id = knownNames[name] if (id == null && fallbackToGenerated) { - id = ItemId(name.uppercase().replace(" ", "_")) + id = generateName(name) } return id } + fun generateName(name: String): ItemId { + return ItemId(name.uppercase().replace(" ", "_")) + } + private val coinRegex = "(?$SHORT_NUMBER_PATTERN) Coins?".toPattern() private val stackedItemRegex = "(?.*) x(?$SHORT_NUMBER_PATTERN)".toPattern() private val essenceRegex = "(?.*) Essence x(?$SHORT_NUMBER_PATTERN)".toPattern() @@ -103,14 +107,41 @@ class ItemIdProvider { .toList() } + private val etherialRewardPattern = "\\+(?${SHORT_NUMBER_PATTERN})x? (?.*)".toPattern() + fun findStackableItemByName(name: String, fallbackToGenerated: Boolean = false): Pair? { - val properName = name.unformattedString() + val properName = name.unformattedString().trim() if (properName == "FREE" || properName == "This Chest is Free!") { return Pair(ItemId.COINS, 0.0) } coinRegex.useMatcher(properName) { return Pair(ItemId.COINS, parseShortNumber(group("amount"))) } + etherialRewardPattern.useMatcher(properName) { + val id = when (val id = group("what")) { + "Copper" -> ItemId.COPPER + "Bits" -> ItemId.BITS + "Garden Experience" -> ItemId.GARDEN + "Farming XP" -> ItemId.FARMING + "Gold Essence" -> ItemId.GOLD_ESSENCE + "Gemstone Powder" -> ItemId.GEMSTONE_POWDER + "Mithril Powder" -> ItemId.MITHRIL_POWDER + "Pelts" -> ItemId.PELT + "Fine Flour" -> ItemId.FINE_FLOUR + else -> { + id.ifDropLast(" Experience") { + ItemId.skill(generateName(it).string) + } ?: id.ifDropLast(" XP") { + ItemId.skill(generateName(it).string) + } ?: id.ifDropLast(" Powder") { + ItemId("SKYBLOCK_POWDER_${generateName(it).string}") + } ?: id.ifDropLast(" Essence") { + ItemId("ESSENCE_${generateName(it).string}") + } ?: generateName(id) + } + } + return Pair(id, parseShortNumber(group("amount"))) + } essenceRegex.useMatcher(properName) { return Pair(ItemId("ESSENCE_${group("essence").uppercase()}"), parseShortNumber(group("count"))) -- cgit