diff options
author | Linnea Gräf <nea@nea.moe> | 2024-12-19 20:18:39 +0100 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-12-19 20:18:39 +0100 |
commit | eda44cb8743c709c15a7ed03381d05e43728e647 (patch) | |
tree | 557a3bd4f096584158b46921f4826208396b4baa /src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt | |
parent | a046b198645811fe1b7db129942505c379aabb03 (diff) | |
download | LocalTransactionLedger-eda44cb8743c709c15a7ed03381d05e43728e647.tar.gz LocalTransactionLedger-eda44cb8743c709c15a7ed03381d05e43728e647.tar.bz2 LocalTransactionLedger-eda44cb8743c709c15a7ed03381d05e43728e647.zip |
feat: Add corpse loot detection
Diffstat (limited to 'src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt')
-rw-r--r-- | src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt | 35 |
1 files changed, 33 insertions, 2 deletions
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 = "(?<amount>$SHORT_NUMBER_PATTERN) Coins?".toPattern() private val stackedItemRegex = "(?<name>.*) x(?<count>$SHORT_NUMBER_PATTERN)".toPattern() private val essenceRegex = "(?<essence>.*) Essence x(?<count>$SHORT_NUMBER_PATTERN)".toPattern() @@ -103,14 +107,41 @@ class ItemIdProvider { .toList() } + private val etherialRewardPattern = "\\+(?<amount>${SHORT_NUMBER_PATTERN})x? (?<what>.*)".toPattern() + fun findStackableItemByName(name: String, fallbackToGenerated: Boolean = false): Pair<ItemId, Double>? { - 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"))) |