aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt')
-rw-r--r--src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt35
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")))