aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/ledger/modules
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-12-07 00:50:33 +0100
committerLinnea Gräf <nea@nea.moe>2024-12-07 00:50:33 +0100
commitd708dca108dcbfe3d67dfe90c27de9cdb41184a6 (patch)
tree2b4b0c1d12396abbbaba7b6653616f6391988bbf /src/main/kotlin/moe/nea/ledger/modules
parent6bdc91b4bda1497e785af695769acae91e8e7064 (diff)
downloadLocalTransactionLedger-d708dca108dcbfe3d67dfe90c27de9cdb41184a6.tar.gz
LocalTransactionLedger-d708dca108dcbfe3d67dfe90c27de9cdb41184a6.tar.bz2
LocalTransactionLedger-d708dca108dcbfe3d67dfe90c27de9cdb41184a6.zip
feat: Add SQLITE database entry logging
Diffstat (limited to 'src/main/kotlin/moe/nea/ledger/modules')
-rw-r--r--src/main/kotlin/moe/nea/ledger/modules/AuctionHouseDetection.kt152
-rw-r--r--src/main/kotlin/moe/nea/ledger/modules/BankDetection.kt15
-rw-r--r--src/main/kotlin/moe/nea/ledger/modules/BazaarDetection.kt71
-rw-r--r--src/main/kotlin/moe/nea/ledger/modules/BazaarOrderDetection.kt133
-rw-r--r--src/main/kotlin/moe/nea/ledger/modules/BitsDetection.kt21
-rw-r--r--src/main/kotlin/moe/nea/ledger/modules/BitsShopDetection.kt18
-rw-r--r--src/main/kotlin/moe/nea/ledger/modules/DungeonChestDetection.kt189
-rw-r--r--src/main/kotlin/moe/nea/ledger/modules/MinionDetection.kt21
-rw-r--r--src/main/kotlin/moe/nea/ledger/modules/NpcDetection.kt31
9 files changed, 364 insertions, 287 deletions
diff --git a/src/main/kotlin/moe/nea/ledger/modules/AuctionHouseDetection.kt b/src/main/kotlin/moe/nea/ledger/modules/AuctionHouseDetection.kt
index cbbff12..0d9b0cb 100644
--- a/src/main/kotlin/moe/nea/ledger/modules/AuctionHouseDetection.kt
+++ b/src/main/kotlin/moe/nea/ledger/modules/AuctionHouseDetection.kt
@@ -1,11 +1,14 @@
package moe.nea.ledger.modules
-import moe.nea.ledger.events.BeforeGuiAction
-import moe.nea.ledger.events.ChatReceived
+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.SHORT_NUMBER_PATTERN
+import moe.nea.ledger.TransactionType
+import moe.nea.ledger.events.BeforeGuiAction
+import moe.nea.ledger.events.ChatReceived
import moe.nea.ledger.getInternalId
import moe.nea.ledger.getLore
import moe.nea.ledger.parseShortNumber
@@ -18,83 +21,88 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.util.regex.Pattern
class AuctionHouseDetection @Inject constructor(val ledger: LedgerLogger, val ids: ItemIdProvider) {
- data class LastViewedItem(
- val count: Int,
- val id: String,
- )
- /*
- You collected 8,712,000 coins from selling Ultimate Carrot Candy Upgrade to [VIP] kodokush in an auction!
- You collected 60,000 coins from selling Walnut to [MVP++] Alea1337 in an auction!
- You purchased 2x Walnut for 69 coins!
- You purchased ◆ Ice Rune I for 4,000 coins!
- */
+ data class LastViewedItem(
+ val count: Int,
+ val id: ItemId,
+ )
+ /*
+ You collected 8,712,000 coins from selling Ultimate Carrot Candy Upgrade to [VIP] kodokush in an auction!
+ You collected 60,000 coins from selling Walnut to [MVP++] Alea1337 in an auction!
+ You purchased 2x Walnut for 69 coins!
+ You purchased ◆ Ice Rune I for 4,000 coins!
+ */
- val collectSold =
- Pattern.compile("You collected (?<coins>$SHORT_NUMBER_PATTERN) coins? from selling (?<what>.*) to (?<buyer>.*) in an auction!")
- val purchased =
- Pattern.compile("You purchased (?:(?<amount>[0-9]+)x )?(?<what>.*) for (?<coins>$SHORT_NUMBER_PATTERN) coins!")
- var lastViewedItems: MutableList<LastViewedItem> = mutableListOf()
+ val collectSold =
+ Pattern.compile("You collected (?<coins>$SHORT_NUMBER_PATTERN) coins? from selling (?<what>.*) to (?<buyer>.*) in an auction!")
+ val purchased =
+ Pattern.compile("You purchased (?:(?<amount>[0-9]+)x )?(?<what>.*) for (?<coins>$SHORT_NUMBER_PATTERN) coins!")
+ var lastViewedItems: MutableList<LastViewedItem> = mutableListOf()
- @SubscribeEvent
- fun onEvent(event: ChatReceived) {
- collectSold.useMatcher(event.message) {
- val lastViewedItem = lastViewedItems.removeLastOrNull()
- ledger.logEntry(
- LedgerEntry(
- "AUCTION_SOLD",
- event.timestamp,
- parseShortNumber(group("coins")),
- lastViewedItem?.id,
- lastViewedItem?.count
- )
- )
- }
- purchased.useMatcher(event.message) {
- ledger.logEntry(
- LedgerEntry(
- "AUCTION_BOUGHT",
- event.timestamp,
- parseShortNumber(group("coins")),
- ids.findForName(group("what")),
- group("amount")?.toInt() ?: 1
- )
- )
- }
- }
+ @SubscribeEvent
+ fun onEvent(event: ChatReceived) {
+ collectSold.useMatcher(event.message) {
+ val lastViewedItem = lastViewedItems.removeLastOrNull()
+ ledger.logEntry(
+ LedgerEntry(
+ TransactionType.AUCTION_SOLD,
+ event.timestamp,
+ listOfNotNull(
+ ItemChange.gainCoins(parseShortNumber(group("coins"))),
+ lastViewedItem?.let { ItemChange.lose(it.id, it.count) }
+ ),
+ )
+ )
+ }
+ purchased.useMatcher(event.message) {
+ ledger.logEntry(
+ LedgerEntry(
+ TransactionType.AUCTION_BOUGHT,
+ event.timestamp,
+ listOf(
+ ItemChange.loseCoins(parseShortNumber(group("coins"))),
+ ItemChange.gain(
+ ids.findForName(group("what")) ?: ItemId.NIL,
+ group("amount")?.toInt() ?: 1
+ )
+ )
+ )
+ )
+ }
+ }
- @SubscribeEvent
- fun onBeforeAuctionCollected(event: BeforeGuiAction) {
- val chest = (event.gui as? GuiChest) ?: return
- val slots = chest.inventorySlots as ContainerChest
- val name = slots.lowerChestInventory.displayName.unformattedText.unformattedString()
+ @SubscribeEvent
+ fun onBeforeAuctionCollected(event: BeforeGuiAction) {
+ val chest = (event.gui as? GuiChest) ?: return
+ val slots = chest.inventorySlots as ContainerChest
+ val name = slots.lowerChestInventory.displayName.unformattedText.unformattedString()
- if (name == "BIN Auction View" || name == "Auction View") {
- handleCollectSingleAuctionView(slots)
- }
- if (name == "Manage Auctions") {
- handleCollectMultipleAuctionsView(slots)
- }
- }
+ if (name == "BIN Auction View" || name == "Auction View") {
+ handleCollectSingleAuctionView(slots)
+ }
+ if (name == "Manage Auctions") {
+ handleCollectMultipleAuctionsView(slots)
+ }
+ }
- private fun handleCollectMultipleAuctionsView(slots: ContainerChest) {
- lastViewedItems =
- (0 until slots.lowerChestInventory.sizeInventory)
- .mapNotNull { slots.lowerChestInventory.getStackInSlot(it) }
- .filter {
- it.getLore().contains("§7Status: §aSold!") // BINs
- || it.getLore().contains("§7Status: §aEnded!") // Auctions
- }
- .mapNotNull { LastViewedItem(it.stackSize, it.getInternalId() ?: return@mapNotNull null) }
- .toMutableList()
- }
+ private fun handleCollectMultipleAuctionsView(slots: ContainerChest) {
+ lastViewedItems =
+ (0 until slots.lowerChestInventory.sizeInventory)
+ .mapNotNull { slots.lowerChestInventory.getStackInSlot(it) }
+ .filter {
+ it.getLore().contains("§7Status: §aSold!") // BINs
+ || it.getLore().contains("§7Status: §aEnded!") // Auctions
+ }
+ .mapNotNull { LastViewedItem(it.stackSize, it.getInternalId() ?: return@mapNotNull null) }
+ .toMutableList()
+ }
- fun handleCollectSingleAuctionView(slots: ContainerChest) {
- val soldItem = slots.lowerChestInventory.getStackInSlot(9 + 4) ?: return
- val id = soldItem.getInternalId() ?: return
- val count = soldItem.stackSize
- lastViewedItems = mutableListOf(LastViewedItem(count, id))
- }
+ fun handleCollectSingleAuctionView(slots: ContainerChest) {
+ val soldItem = slots.lowerChestInventory.getStackInSlot(9 + 4) ?: return
+ val id = soldItem.getInternalId() ?: return
+ val count = soldItem.stackSize
+ lastViewedItems = mutableListOf(LastViewedItem(count, id))
+ }
} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/modules/BankDetection.kt b/src/main/kotlin/moe/nea/ledger/modules/BankDetection.kt
index 8d0fd81..e9a6c26 100644
--- a/src/main/kotlin/moe/nea/ledger/modules/BankDetection.kt
+++ b/src/main/kotlin/moe/nea/ledger/modules/BankDetection.kt
@@ -1,8 +1,11 @@
package moe.nea.ledger.modules
+import moe.nea.ledger.ItemChange
+import moe.nea.ledger.ItemId
import moe.nea.ledger.LedgerEntry
import moe.nea.ledger.LedgerLogger
import moe.nea.ledger.SHORT_NUMBER_PATTERN
+import moe.nea.ledger.TransactionType
import moe.nea.ledger.events.ChatReceived
import moe.nea.ledger.parseShortNumber
import moe.nea.ledger.useMatcher
@@ -22,18 +25,22 @@ class BankDetection @Inject constructor(val ledger: LedgerLogger) {
withdrawPattern.useMatcher(event.message) {
ledger.logEntry(
LedgerEntry(
- "BANK_WITHDRAW",
+ TransactionType.BANK_WITHDRAW,
event.timestamp,
- parseShortNumber(group("amount")),
+ listOf(ItemChange(ItemId.COINS,
+ parseShortNumber(group("amount")),
+ ItemChange.ChangeDirection.TRANSFORM)),
)
)
}
depositPattern.useMatcher(event.message) {
ledger.logEntry(
LedgerEntry(
- "BANK_DEPOSIT",
+ TransactionType.BANK_DEPOSIT,
event.timestamp,
- parseShortNumber(group("amount")),
+ listOf(ItemChange(ItemId.COINS,
+ parseShortNumber(group("amount")),
+ ItemChange.ChangeDirection.TRANSFORM)),
)
)
}
diff --git a/src/main/kotlin/moe/nea/ledger/modules/BazaarDetection.kt b/src/main/kotlin/moe/nea/ledger/modules/BazaarDetection.kt
index 01c8bbc..522beed 100644
--- a/src/main/kotlin/moe/nea/ledger/modules/BazaarDetection.kt
+++ b/src/main/kotlin/moe/nea/ledger/modules/BazaarDetection.kt
@@ -1,10 +1,13 @@
package moe.nea.ledger.modules
-import moe.nea.ledger.events.ChatReceived
+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.SHORT_NUMBER_PATTERN
+import moe.nea.ledger.TransactionType
+import moe.nea.ledger.events.ChatReceived
import moe.nea.ledger.parseShortNumber
import moe.nea.ledger.useMatcher
import moe.nea.ledger.utils.Inject
@@ -13,35 +16,43 @@ import java.util.regex.Pattern
class BazaarDetection @Inject constructor(val ledger: LedgerLogger, val ids: ItemIdProvider) {
- val instaBuyPattern =
- Pattern.compile("\\[Bazaar\\] Bought (?<count>$SHORT_NUMBER_PATTERN)x (?<what>.*) for (?<coins>$SHORT_NUMBER_PATTERN) coins!")
- val instaSellPattern =
- Pattern.compile("\\[Bazaar\\] Sold (?<count>$SHORT_NUMBER_PATTERN)x (?<what>.*) for (?<coins>$SHORT_NUMBER_PATTERN) coins!")
+ val instaBuyPattern =
+ Pattern.compile("\\[Bazaar\\] Bought (?<count>$SHORT_NUMBER_PATTERN)x (?<what>.*) for (?<coins>$SHORT_NUMBER_PATTERN) coins!")
+ val instaSellPattern =
+ Pattern.compile("\\[Bazaar\\] Sold (?<count>$SHORT_NUMBER_PATTERN)x (?<what>.*) for (?<coins>$SHORT_NUMBER_PATTERN) coins!")
- @SubscribeEvent
- fun onInstSellChat(event: ChatReceived) {
- instaBuyPattern.useMatcher(event.message) {
- ledger.logEntry(
- LedgerEntry(
- "BAZAAR_BUY_INSTANT",
- event.timestamp,
- parseShortNumber(group("coins")),
- ids.findForName(group("what")),
- parseShortNumber(group("count")).toInt(),
- )
- )
- }
- instaSellPattern.useMatcher(event.message) {
- ledger.logEntry(
- LedgerEntry(
- "BAZAAR_SELL_INSTANT",
- event.timestamp,
- parseShortNumber(group("coins")),
- ids.findForName(group("what")),
- parseShortNumber(group("count")).toInt(),
- )
- )
- }
- }
+ @SubscribeEvent
+ fun onInstSellChat(event: ChatReceived) {
+ instaBuyPattern.useMatcher(event.message) {
+ ledger.logEntry(
+ LedgerEntry(
+ TransactionType.BAZAAR_BUY_INSTANT,
+ event.timestamp,
+ listOf(
+ ItemChange.loseCoins(parseShortNumber(group("coins"))),
+ ItemChange.gain(
+ ids.findForName(group("what")) ?: ItemId.NIL,
+ parseShortNumber(group("count"))
+ )
+ )
+ )
+ )
+ }
+ instaSellPattern.useMatcher(event.message) {
+ ledger.logEntry(
+ LedgerEntry(
+ TransactionType.BAZAAR_SELL_INSTANT,
+ event.timestamp,
+ listOf(
+ ItemChange.gainCoins(parseShortNumber(group("coins"))),
+ ItemChange.lose(
+ ids.findForName(group("what")) ?: ItemId.NIL,
+ parseShortNumber(group("count"))
+ )
+ ),
+ )
+ )
+ }
+ }
}
diff --git a/src/main/kotlin/moe/nea/ledger/modules/BazaarOrderDetection.kt b/src/main/kotlin/moe/nea/ledger/modules/BazaarOrderDetection.kt
index 7e611ac..8b33fb1 100644
--- a/src/main/kotlin/moe/nea/ledger/modules/BazaarOrderDetection.kt
+++ b/src/main/kotlin/moe/nea/ledger/modules/BazaarOrderDetection.kt
@@ -1,10 +1,13 @@
package moe.nea.ledger.modules
-import moe.nea.ledger.events.ChatReceived
+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.SHORT_NUMBER_PATTERN
+import moe.nea.ledger.TransactionType
+import moe.nea.ledger.events.ChatReceived
import moe.nea.ledger.mixin.AccessorGuiEditSign
import moe.nea.ledger.parseShortNumber
import moe.nea.ledger.useMatcher
@@ -16,63 +19,77 @@ import java.util.regex.Pattern
class BazaarOrderDetection @Inject constructor(val ledger: LedgerLogger, val ids: ItemIdProvider) {
- val buyOrderClaimed =
- Pattern.compile("\\[Bazaar] Claimed (?<amount>$SHORT_NUMBER_PATTERN)x (?<what>.*) worth (?<coins>$SHORT_NUMBER_PATTERN) coins? bought for $SHORT_NUMBER_PATTERN each!")
- val sellOrderClaimed =
- Pattern.compile("\\[Bazaar] Claimed (?<coins>$SHORT_NUMBER_PATTERN) coins? from selling (?<amount>$SHORT_NUMBER_PATTERN)x (?<what>.*) at $SHORT_NUMBER_PATTERN each!")
- val orderFlipped =
- Pattern.compile("\\[Bazaar] Order Flipped! (?<amount>$SHORT_NUMBER_PATTERN)x (?<what>.*) for (?<coins>$SHORT_NUMBER_PATTERN) coins? of total expected profit.")
- val previousPricePattern =
- Pattern.compile("(?<price>$SHORT_NUMBER_PATTERN)/u")
- var lastFlippedPreviousPrice = 0.0
+ val buyOrderClaimed =
+ Pattern.compile("\\[Bazaar] Claimed (?<amount>$SHORT_NUMBER_PATTERN)x (?<what>.*) worth (?<coins>$SHORT_NUMBER_PATTERN) coins? bought for $SHORT_NUMBER_PATTERN each!")
+ val sellOrderClaimed =
+ Pattern.compile("\\[Bazaar] Claimed (?<coins>$SHORT_NUMBER_PATTERN) coins? from selling (?<amount>$SHORT_NUMBER_PATTERN)x (?<what>.*) at $SHORT_NUMBER_PATTERN each!")
+ val orderFlipped =
+ Pattern.compile("\\[Bazaar] Order Flipped! (?<amount>$SHORT_NUMBER_PATTERN)x (?<what>.*) for (?<coins>$SHORT_NUMBER_PATTERN) coins? of total expected profit.")
+ val previousPricePattern =
+ Pattern.compile("(?<price>$SHORT_NUMBER_PATTERN)/u")
+ var lastFlippedPreviousPrice = 0.0
- @SubscribeEvent
- fun detectSignFlip(event: GuiScreenEvent.InitGuiEvent) {
- val gui = event.gui
- if (gui !is GuiEditSign) return
- gui as AccessorGuiEditSign
- val text = gui.tileEntity_ledger.signText
- if (text[2].unformattedText != "Previous price:") return
- previousPricePattern.useMatcher(text[3].unformattedText) {
- lastFlippedPreviousPrice = parseShortNumber(group("price"))
- }
- }
+ @SubscribeEvent
+ fun detectSignFlip(event: GuiScreenEvent.InitGuiEvent) {
+ val gui = event.gui
+ if (gui !is GuiEditSign) return
+ gui as AccessorGuiEditSign
+ val text = gui.tileEntity_ledger.signText
+ if (text[2].unformattedText != "Previous price:") return
+ previousPricePattern.useMatcher(text[3].unformattedText) {
+ lastFlippedPreviousPrice = parseShortNumber(group("price"))
+ }
+ }
- @SubscribeEvent
- fun detectBuyOrders(event: ChatReceived) {
- orderFlipped.useMatcher(event.message) {
- val amount = parseShortNumber(group("amount")).toInt()
- ledger.logEntry(
- LedgerEntry(
- "BAZAAR_BUY_ORDER",
- event.timestamp,
- lastFlippedPreviousPrice * amount,
- ids.findForName(group("what")),
- amount,
- )
- )
- }
- buyOrderClaimed.useMatcher(event.message) {
- ledger.logEntry(
- LedgerEntry(
- "BAZAAR_BUY_ORDER",
- event.timestamp,
- parseShortNumber(group("coins")),
- ids.findForName(group("what")),
- parseShortNumber(group("amount")).toInt(),
- )
- )
- }
- sellOrderClaimed.useMatcher(event.message) {
- ledger.logEntry(
- LedgerEntry(
- "BAZAAR_SELL_ORDER",
- event.timestamp,
- parseShortNumber(group("coins")),
- ids.findForName(group("what")),
- parseShortNumber(group("amount")).toInt(),
- )
- )
- }
- }
+ @SubscribeEvent
+ fun detectBuyOrders(event: ChatReceived) {
+ orderFlipped.useMatcher(event.message) {
+ val amount = parseShortNumber(group("amount")).toInt()
+ ledger.logEntry(
+ LedgerEntry(
+ TransactionType.BAZAAR_BUY_ORDER,
+ event.timestamp,
+ listOf(
+ ItemChange.loseCoins(lastFlippedPreviousPrice * amount),
+ ItemChange.gain(
+ ids.findForName(group("what")) ?: ItemId.NIL,
+ amount,
+ )
+ )
+ )
+ )
+ }
+ buyOrderClaimed.useMatcher(event.message) {
+ ledger.logEntry(
+ LedgerEntry(
+ TransactionType.BAZAAR_BUY_ORDER,
+ event.timestamp,
+ listOf(
+ ItemChange.loseCoins(parseShortNumber(group("coins"))),
+ ItemChange.gain(
+ ids.findForName(group("what")) ?: ItemId.NIL,
+ parseShortNumber(group("amount"))
+ )
+ ),
+ )
+ )
+ }
+ sellOrderClaimed.useMatcher(event.message) {
+ ledger.logEntry(
+ LedgerEntry(
+ TransactionType.BAZAAR_SELL_ORDER,
+ event.timestamp,
+ listOf(
+ ItemChange.gainCoins(
+ parseShortNumber(group("coins"))
+ ),
+ ItemChange.lose(
+ ids.findForName(group("what")) ?: ItemId.NIL,
+ parseShortNumber(group("amount")),
+ )
+ ),
+ )
+ )
+ }
+ }
}
diff --git a/src/main/kotlin/moe/nea/ledger/modules/BitsDetection.kt b/src/main/kotlin/moe/nea/ledger/modules/BitsDetection.kt
index 22b5392..2872f99 100644
--- a/src/main/kotlin/moe/nea/ledger/modules/BitsDetection.kt
+++ b/src/main/kotlin/moe/nea/ledger/modules/BitsDetection.kt
@@ -1,11 +1,14 @@
package moe.nea.ledger.modules
+import moe.nea.ledger.ItemChange
+import moe.nea.ledger.ItemId
import moe.nea.ledger.events.ChatReceived
import moe.nea.ledger.events.LateWorldLoadEvent
import moe.nea.ledger.LedgerEntry
import moe.nea.ledger.LedgerLogger
import moe.nea.ledger.SHORT_NUMBER_PATTERN
import moe.nea.ledger.ScoreboardUtil
+import moe.nea.ledger.TransactionType
import moe.nea.ledger.parseShortNumber
import moe.nea.ledger.unformattedString
import moe.nea.ledger.useMatcher
@@ -27,11 +30,11 @@ class BitsDetection @Inject constructor(val ledger: LedgerLogger) {
if (lastBits != bits) {
ledger.logEntry(
LedgerEntry(
- "BITS_PURSE_STATUS",
- Instant.now(),
- 0.0,
- null,
- bits
+ TransactionType.BITS_PURSE_STATUS,
+ Instant.now(),
+ listOf(
+ ItemChange(ItemId.BITS, bits.toDouble(), ItemChange.ChangeDirection.SYNC)
+ )
)
)
lastBits = bits
@@ -46,11 +49,11 @@ class BitsDetection @Inject constructor(val ledger: LedgerLogger) {
if (event.message.startsWith("You consumed a Booster Cookie!")) {
ledger.logEntry(
LedgerEntry(
- "BOOSTER_COOKIE_ATE",
+ TransactionType.BOOSTER_COOKIE_ATE,
Instant.now(),
- 0.0,
- null,
- null,
+ listOf(
+ ItemChange.lose(ItemId.BOOSTER_COOKIE, 1)
+ )
)
)
}
diff --git a/src/main/kotlin/moe/nea/ledger/modules/BitsShopDetection.kt b/src/main/kotlin/moe/nea/ledger/modules/BitsShopDetection.kt
index 2033d8d..8fd4588 100644
--- a/src/main/kotlin/moe/nea/ledger/modules/BitsShopDetection.kt
+++ b/src/main/kotlin/moe/nea/ledger/modules/BitsShopDetection.kt
@@ -1,10 +1,13 @@
package moe.nea.ledger.modules
+import moe.nea.ledger.ItemChange
+import moe.nea.ledger.ItemId
import moe.nea.ledger.events.ChatReceived
import moe.nea.ledger.events.GuiClickEvent
import moe.nea.ledger.LedgerEntry
import moe.nea.ledger.LedgerLogger
import moe.nea.ledger.SHORT_NUMBER_PATTERN
+import moe.nea.ledger.TransactionType
import moe.nea.ledger.getInternalId
import moe.nea.ledger.getLore
import moe.nea.ledger.parseShortNumber
@@ -18,7 +21,8 @@ class BitsShopDetection @Inject constructor(val ledger: LedgerLogger) {
data class BitShopEntry(
- val id: String,
+ val id: ItemId,
+ val stackSize: Int,
val bitPrice: Int,
val timestamp: Long = System.currentTimeMillis()
)
@@ -37,7 +41,7 @@ class BitsShopDetection @Inject constructor(val ledger: LedgerLogger) {
val bitPrice = stack.getLore()
.firstNotNullOfOrNull { bitCostPattern.useMatcher(it.unformattedString()) { parseShortNumber(group("cost")).toInt() } }
?: return
- lastClickedBitShopItem = BitShopEntry(id, bitPrice)
+ lastClickedBitShopItem = BitShopEntry(id, stack.stackSize, bitPrice)
}
@SubscribeEvent
@@ -47,10 +51,12 @@ class BitsShopDetection @Inject constructor(val ledger: LedgerLogger) {
if (System.currentTimeMillis() - lastBit.timestamp > 5000) return
ledger.logEntry(
LedgerEntry(
- "COMMUNITY_SHOP_BUY", Instant.now(),
- lastBit.bitPrice.toDouble(),
- lastBit.id,
- 1
+ TransactionType.COMMUNITY_SHOP_BUY,
+ Instant.now(),
+ listOf(
+ ItemChange.lose(ItemId.BITS, lastBit.bitPrice.toDouble()),
+ ItemChange.gain(lastBit.id, lastBit.stackSize)
+ )
)
)
}
diff --git a/src/main/kotlin/moe/nea/ledger/modules/DungeonChestDetection.kt b/src/main/kotlin/moe/nea/ledger/modules/DungeonChestDetection.kt
index 4bdd37c..5598174 100644
--- a/src/main/kotlin/moe/nea/ledger/modules/DungeonChestDetection.kt
+++ b/src/main/kotlin/moe/nea/ledger/modules/DungeonChestDetection.kt
@@ -1,10 +1,13 @@
package moe.nea.ledger.modules
-import moe.nea.ledger.events.ChatReceived
-import moe.nea.ledger.events.GuiClickEvent
+import moe.nea.ledger.ItemChange
+import moe.nea.ledger.ItemId
import moe.nea.ledger.LedgerEntry
import moe.nea.ledger.LedgerLogger
import moe.nea.ledger.SHORT_NUMBER_PATTERN
+import moe.nea.ledger.TransactionType
+import moe.nea.ledger.events.ChatReceived
+import moe.nea.ledger.events.GuiClickEvent
import moe.nea.ledger.getDisplayNameU
import moe.nea.ledger.getLore
import moe.nea.ledger.parseShortNumber
@@ -18,104 +21,106 @@ import java.util.regex.Pattern
class DungeonChestDetection @Inject constructor(val logger: LedgerLogger) {
- /*{
- id: "minecraft:chest",
- Count: 1b,
- tag: {
- display: {
- Lore: ["§7Purchase this chest to receive the", "§7rewards above. You can only open", "§7one chest per Dungeons run -", "§7choose wisely!", "", "§7Cost", "§625,000 Coins", "§9Dungeon Chest Key", "", "§7§cNOTE: Coins are withdrawn from your", "§cbank if you don't have enough in", "§cyour purse."],
- Name: "§aOpen Reward Chest"
- }
- },
- Damage: 0s
- }
+ /*{
+ id: "minecraft:chest",
+ Count: 1b,
+ tag: {
+ display: {
+ Lore: ["§7Purchase this chest to receive the", "§7rewards above. You can only open", "§7one chest per Dungeons run -", "§7choose wisely!", "", "§7Cost", "§625,000 Coins", "§9Dungeon Chest Key", "", "§7§cNOTE: Coins are withdrawn from your", "§cbank if you don't have enough in", "§cyour purse."],
+ Name: "§aOpen Reward Chest"
+ }
+ },
+ Damage: 0s
+ }
- {
- id: "minecraft:feather",
- Count: 1b,
- tag: {
- overrideMeta: 1b,
- ench: [],
- HideFlags: 254,
- display: {
- Lore: ["§7Consume a §9Kismet Feather §7to reroll", "§7the loot within this chest.", "", "§7You may only use a feather once", "§7per dungeon run.", "", "§eClick to reroll this chest!"],
- Name: "§aReroll Chest"
- },
- AttributeModifiers: []
- },
- Damage: 0s
+ {
+ id: "minecraft:feather",
+ Count: 1b,
+ tag: {
+ overrideMeta: 1b,
+ ench: [],
+ HideFlags: 254,
+ display: {
+ Lore: ["§7Consume a §9Kismet Feather §7to reroll", "§7the loot within this chest.", "", "§7You may only use a feather once", "§7per dungeon run.", "", "§eClick to reroll this chest!"],
+ Name: "§aReroll Chest"
+ },
+ AttributeModifiers: []
+ },
+ Damage: 0s
}
- */
- val costPattern = Pattern.compile("(?<cost>$SHORT_NUMBER_PATTERN) Coins")
+ */
+ val costPattern = Pattern.compile("(?<cost>$SHORT_NUMBER_PATTERN) Coins")
- data class ChestCost(
- val cost: Double,
- val openTimestamp: Long,
- val hasKey: Boolean,
- )
+ data class ChestCost(
+ val cost: Double,
+ val openTimestamp: Long,
+ val hasKey: Boolean,
+ )
- var lastOpenedChest: ChestCost? = null
+ var lastOpenedChest: ChestCost? = null
- @SubscribeEvent
- fun onKismetClick(event: GuiClickEvent) {
- val slot = event.slotIn ?: return
- if (!slot.inventory.displayName.unformattedText.unformattedString().endsWith(" Chest")) return
- val stack = slot.stack ?: return
- if (stack.getDisplayNameU() == "§aReroll Chest") {
- logger.logEntry(
- LedgerEntry(
- "KISMET_REROLL",
- Instant.now(),
- 0.0,
- itemId = "KISMET_FEATHER",
- itemAmount = 1
- )
- )
- }
- }
+ @SubscribeEvent
+ fun onKismetClick(event: GuiClickEvent) {
+ val slot = event.slotIn ?: return
+ if (!slot.inventory.displayName.unformattedText.unformattedString().endsWith(" Chest")) return
+ val stack = slot.stack ?: return
+ if (stack.getDisplayNameU() == "§aReroll Chest") {
+ logger.logEntry(
+ LedgerEntry(
+ TransactionType.KISMET_REROLL,
+ Instant.now(),
+ listOf(
+ ItemChange.lose(ItemId.KISMET_FEATHER, 1)
+ )
+ )
+ )
+ }
+ }
- @SubscribeEvent
- fun onRewardChestClick(event: GuiClickEvent) {
- val slot = event.slotIn ?: return
- if (!slot.inventory.displayName.unformattedText.unformattedString().endsWith(" Chest")) return
- val stack = slot.stack ?: return
- val name = stack.getDisplayNameU()
- if (name != "§aOpen Reward Chest") return
- val lore = stack.getLore()
- val costIndex = lore.indexOf("§7Cost")
- if (costIndex < 0 || costIndex + 1 !in lore.indices) return
- val cost = costPattern.useMatcher(lore[costIndex + 1].unformattedString()) {
- parseShortNumber(group("cost"))
- } ?: 0.0 // Free chest!
- val hasKey = lore.contains("§9Dungeon Chest Key")
- lastOpenedChest?.let(::completeTransaction)
- lastOpenedChest = ChestCost(cost, System.currentTimeMillis(), hasKey)
- }
+ @SubscribeEvent
+ fun onRewardChestClick(event: GuiClickEvent) {
+ val slot = event.slotIn ?: return
+ if (!slot.inventory.displayName.unformattedText.unformattedString().endsWith(" Chest")) return
+ val stack = slot.stack ?: return
+ val name = stack.getDisplayNameU()
+ if (name != "§aOpen Reward Chest") return
+ val lore = stack.getLore()
+ val costIndex = lore.indexOf("§7Cost")
+ if (costIndex < 0 || costIndex + 1 !in lore.indices) return
+ val cost = costPattern.useMatcher(lore[costIndex + 1].unformattedString()) {
+ parseShortNumber(group("cost"))
+ } ?: 0.0 // Free chest!
+ val hasKey = lore.contains("§9Dungeon Chest Key")
+ lastOpenedChest?.let(::completeTransaction)
+ lastOpenedChest = ChestCost(cost, System.currentTimeMillis(), hasKey)
+ }
- @SubscribeEvent
- fun onChatMessage(event: ChatReceived) {
- if (event.message == "You don't have that many coins in the bank!")
- lastOpenedChest = null
- }
+ @SubscribeEvent
+ fun onChatMessage(event: ChatReceived) {
+ if (event.message == "You don't have that many coins in the bank!")
+ lastOpenedChest = null
+ }
- fun completeTransaction(toOpen: ChestCost) {
- lastOpenedChest = null
- logger.logEntry(
- LedgerEntry(
- "DUNGEON_CHEST_OPEN",
- Instant.ofEpochMilli(toOpen.openTimestamp),
- toOpen.cost,
- itemId = if (toOpen.hasKey) "DUNGEON_CHEST_KEY" else null
- )
- )
- }
+ fun completeTransaction(toOpen: ChestCost) {
+ lastOpenedChest = null
+ logger.logEntry(
+ LedgerEntry(
+ TransactionType.DUNGEON_CHEST_OPEN,
+ Instant.ofEpochMilli(toOpen.openTimestamp),
+ listOfNotNull(
+ if (toOpen.hasKey) ItemChange.lose(ItemId.DUNGEON_CHEST_KEY, 1) else null,
+ ItemChange.loseCoins(toOpen.cost)
+ ),
+ )
+ )
+ }
- @SubscribeEvent
- fun onTick(event: TickEvent) {
- val toOpen = lastOpenedChest
- if (toOpen != null && toOpen.openTimestamp + 1000L < System.currentTimeMillis()) {
- completeTransaction(toOpen)
- }
- }
+ @SubscribeEvent
+ fun onTick(event: TickEvent) {
+ val toOpen = lastOpenedChest
+ if (toOpen != null && toOpen.openTimestamp + 1000L < System.currentTimeMillis()) {
+ completeTransaction(toOpen)
+ }
+ }
}
diff --git a/src/main/kotlin/moe/nea/ledger/modules/MinionDetection.kt b/src/main/kotlin/moe/nea/ledger/modules/MinionDetection.kt
index 73d06fa..1b48095 100644
--- a/src/main/kotlin/moe/nea/ledger/modules/MinionDetection.kt
+++ b/src/main/kotlin/moe/nea/ledger/modules/MinionDetection.kt
@@ -1,12 +1,15 @@
package moe.nea.ledger.modules
-import moe.nea.ledger.events.BeforeGuiAction
-import moe.nea.ledger.events.ChatReceived
import moe.nea.ledger.ExpiringValue
+import moe.nea.ledger.ItemChange
+import moe.nea.ledger.ItemId
import moe.nea.ledger.LedgerEntry
import moe.nea.ledger.LedgerLogger
import moe.nea.ledger.ROMAN_NUMBER_PATTERN
import moe.nea.ledger.SHORT_NUMBER_PATTERN
+import moe.nea.ledger.TransactionType
+import moe.nea.ledger.events.BeforeGuiAction
+import moe.nea.ledger.events.ChatReceived
import moe.nea.ledger.parseRomanNumber
import moe.nea.ledger.parseShortNumber
import moe.nea.ledger.unformattedString
@@ -23,7 +26,7 @@ class MinionDetection @Inject constructor(val ledger: LedgerLogger) {
val hopperCollectPattern = "You received (?<amount>$SHORT_NUMBER_PATTERN) coins?!".toPattern()
val minionNamePattern = "(?<name>.*) Minion (?<level>$ROMAN_NUMBER_PATTERN)".toPattern()
- var lastOpenedMinion = ExpiringValue.empty<String>()
+ var lastOpenedMinion = ExpiringValue.empty<ItemId>()
@SubscribeEvent
fun onBeforeClaim(event: BeforeGuiAction) {
@@ -33,7 +36,9 @@ class MinionDetection @Inject constructor(val ledger: LedgerLogger) {
minionNamePattern.useMatcher(invName) {
val name = group("name")
val level = parseRomanNumber(group("level"))
- lastOpenedMinion = ExpiringValue(name.uppercase().replace(" ", "_") + "_" + level)
+ lastOpenedMinion = ExpiringValue(
+ ItemId(name.uppercase().replace(" ", "_")
+ .replace("MINION", "GENERATOR") + "_" + level))
}
}
@@ -43,10 +48,12 @@ class MinionDetection @Inject constructor(val ledger: LedgerLogger) {
hopperCollectPattern.useMatcher(event.message) {
val minionName = lastOpenedMinion.consume(3.seconds)
ledger.logEntry(LedgerEntry(
- "AUTOMERCHANT_PROFIT_COLLECT",
+ TransactionType.AUTOMERCHANT_PROFIT_COLLECT,
Instant.now(),
- parseShortNumber(group("amount")),
- minionName, // TODO: switch to its own column idk
+ listOf(
+ ItemChange.gainCoins(parseShortNumber(group("amount"))),
+ ItemChange(minionName ?: ItemId.NIL, 1.0, ItemChange.ChangeDirection.CATALYST)
+ ),
))
}
}
diff --git a/src/main/kotlin/moe/nea/ledger/modules/NpcDetection.kt b/src/main/kotlin/moe/nea/ledger/modules/NpcDetection.kt
index 68f0257..341dd12 100644
--- a/src/main/kotlin/moe/nea/ledger/modules/NpcDetection.kt
+++ b/src/main/kotlin/moe/nea/ledger/modules/NpcDetection.kt
@@ -1,10 +1,13 @@
package moe.nea.ledger.modules
-import moe.nea.ledger.events.ChatReceived
+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.SHORT_NUMBER_PATTERN
+import moe.nea.ledger.TransactionType
+import moe.nea.ledger.events.ChatReceived
import moe.nea.ledger.parseShortNumber
import moe.nea.ledger.useMatcher
import moe.nea.ledger.utils.Inject
@@ -23,22 +26,32 @@ class NpcDetection @Inject constructor(val ledger: LedgerLogger, val ids: ItemId
npcBuyPattern.useMatcher(event.message) {
ledger.logEntry(
LedgerEntry(
- "NPC_BUY",
+ TransactionType.NPC_BUY,
event.timestamp,
- parseShortNumber(group("coins")),
- ids.findForName(group("what")),
- group("count")?.let(::parseShortNumber)?.toInt() ?: 1,
+ listOf(
+ ItemChange.loseCoins(
+ parseShortNumber(group("coins")),
+ ),
+ ItemChange.gain(
+ ids.findForName(group("what")) ?: ItemId.NIL,
+ group("count")?.let(::parseShortNumber) ?: 1,
+ )
+ )
)
)
}
npcSellPattern.useMatcher(event.message) {
ledger.logEntry(
LedgerEntry(
- "NPC_SELL",
+ TransactionType.NPC_SELL,
event.timestamp,
- parseShortNumber(group("coins")),
- ids.findForName(group("what")),
- group("count")?.let(::parseShortNumber)?.toInt() ?: 1,
+ listOf(
+ ItemChange.gainCoins(parseShortNumber(group("coins"))),
+ ItemChange.lose(
+ ids.findForName(group("what")) ?: ItemId.NIL,
+ group("count")?.let(::parseShortNumber)?.toInt() ?: 1,
+ )
+ )
)
)
}