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 --- .../nea/ledger/modules/MineshaftCorpseDetection.kt | 74 ++++++++++++++++++++++ .../moe/nea/ledger/modules/VisitorDetection.kt | 24 +------ 2 files changed, 75 insertions(+), 23 deletions(-) create mode 100644 src/main/kotlin/moe/nea/ledger/modules/MineshaftCorpseDetection.kt (limited to 'src/main/kotlin/moe/nea/ledger/modules') diff --git a/src/main/kotlin/moe/nea/ledger/modules/MineshaftCorpseDetection.kt b/src/main/kotlin/moe/nea/ledger/modules/MineshaftCorpseDetection.kt new file mode 100644 index 0000000..85c9ad6 --- /dev/null +++ b/src/main/kotlin/moe/nea/ledger/modules/MineshaftCorpseDetection.kt @@ -0,0 +1,74 @@ +package moe.nea.ledger.modules + +import moe.nea.ledger.ItemChange +import moe.nea.ledger.ItemId +import moe.nea.ledger.ItemIdProvider +import moe.nea.ledger.LedgerEntry +import moe.nea.ledger.LedgerLogger +import moe.nea.ledger.TransactionType +import moe.nea.ledger.events.ChatReceived +import moe.nea.ledger.matches +import moe.nea.ledger.useMatcher +import moe.nea.ledger.utils.BorderedTextTracker + +class MineshaftCorpseDetection : BorderedTextTracker() { + /* +[23:39:47] [Client thread/INFO]: [CHAT] §r§a§l▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬§r +[23:39:47] [Client thread/INFO]: [CHAT] §r §r§b§l§r§9§lLAPIS §r§b§lCORPSE LOOT! §r +[23:39:47] [Client thread/INFO]: [CHAT] §r §r§a§lREWARDS§r +[23:39:47] [Client thread/INFO]: [CHAT] §r §r§5+100 HOTM Experience§r +[23:39:47] [Client thread/INFO]: [CHAT] §r §r§a§r§aGreen Goblin Egg§r +[23:39:47] [Client thread/INFO]: [CHAT] §r §r§9Enchanted Glacite §r§8x2§r +[23:39:47] [Client thread/INFO]: [CHAT] §r §r§9☠ Fine Onyx Gemstone§r +[23:39:47] [Client thread/INFO]: [CHAT] §r §r§a☠ Flawed Onyx Gemstone §r§8x20§r +[23:39:47] [Client thread/INFO]: [CHAT] §r §r§a☘ Flawed Peridot Gemstone §r§8x40§r +[23:39:47] [Client thread/INFO]: [CHAT] §r §r§bGlacite Powder §r§8x500§r +[23:39:47] [Client thread/INFO]: [CHAT] §e[SkyHanni] Profit for §9Lapis Corpse§e: §678k§r +[23:39:47] [Client thread/INFO]: [CHAT] §r§a§l▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬§r + */ + + val corpseEnterMessage = " (?.*) CORPSE LOOT!".toPattern() + + override fun shouldEnter(event: ChatReceived): Boolean { + return corpseEnterMessage.matches(event.message) + } + + override fun shouldExit(event: ChatReceived): Boolean { + return genericBorderExit.matches(event.message) + } + + override fun onBorderedTextFinished(enclosed: List) { + // TODO: test this once profile swapping has been re-enabled + val rewards = enclosed.asSequence() + .dropWhile { it.message != " REWARDS" } + .drop(1) + .mapNotNull { + itemIdProvider.findStackableItemByName(it.message, true) + } + .map { ItemChange.unpairGain(it) } + .toMutableList() + val introMessage = enclosed.first() + val corpseTyp = corpseEnterMessage.useMatcher(introMessage.message) { + group("corpseKind") + }!! + val keyTyp = corpseNameToKey[corpseTyp] + if (keyTyp == null) { + errorUtil.reportAdHoc("Unknown corpse type $corpseTyp") + } else if (keyTyp != ItemId.NIL) { + rewards.add(ItemChange.lose(keyTyp, 1)) + } + logger.logEntry( + LedgerEntry( + TransactionType.CORPSE_DESECRATED, + introMessage.timestamp, + rewards + ) + ) + } + + val corpseNameToKey = mapOf( + "LAPIS" to ItemId.NIL + ) + lateinit var logger: LedgerLogger + lateinit var itemIdProvider: ItemIdProvider +} \ No newline at end of file diff --git a/src/main/kotlin/moe/nea/ledger/modules/VisitorDetection.kt b/src/main/kotlin/moe/nea/ledger/modules/VisitorDetection.kt index 2ee581c..f457ae4 100644 --- a/src/main/kotlin/moe/nea/ledger/modules/VisitorDetection.kt +++ b/src/main/kotlin/moe/nea/ledger/modules/VisitorDetection.kt @@ -59,29 +59,7 @@ class VisitorDetection { private fun parseGardenLoreLine(rewardLine: String): Pair? { val f = rewardLine.unformattedString().trim() - return parseSpecialReward(f) - ?: idProvider.findStackableItemByName(f, true) - } - - private val specialRewardRegex = "\\+(?${SHORT_NUMBER_PATTERN})x? (?.*)".toPattern() - - private fun parseSpecialReward(specialLine: String): Pair? { - specialRewardRegex.useMatcher(specialLine) { - val id = when (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 -> ItemId.NIL - } - return Pair(id, parseShortNumber(group("amount"))) - } - return null + return idProvider.findStackableItemByName(f, true) } -- cgit