aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/ledger/AuctionHouseDetection.kt
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-04-02 16:01:38 +0200
committerLinnea Gräf <nea@nea.moe>2024-04-02 16:01:38 +0200
commit3e0198e3a803d2dd46988ba0ac445412c7da8390 (patch)
tree6f08cebe11894769ead7ce7473b27dbdf21523d5 /src/main/kotlin/moe/nea/ledger/AuctionHouseDetection.kt
parent8d26a206297071775e88b99d4b38efcc5577af0a (diff)
downloadmoney-ledger-3e0198e3a803d2dd46988ba0ac445412c7da8390.tar.gz
money-ledger-3e0198e3a803d2dd46988ba0ac445412c7da8390.tar.bz2
money-ledger-3e0198e3a803d2dd46988ba0ac445412c7da8390.zip
Add bits stuff
Diffstat (limited to 'src/main/kotlin/moe/nea/ledger/AuctionHouseDetection.kt')
-rw-r--r--src/main/kotlin/moe/nea/ledger/AuctionHouseDetection.kt88
1 files changed, 88 insertions, 0 deletions
diff --git a/src/main/kotlin/moe/nea/ledger/AuctionHouseDetection.kt b/src/main/kotlin/moe/nea/ledger/AuctionHouseDetection.kt
new file mode 100644
index 0000000..a73d6b1
--- /dev/null
+++ b/src/main/kotlin/moe/nea/ledger/AuctionHouseDetection.kt
@@ -0,0 +1,88 @@
+package moe.nea.ledger
+
+import net.minecraft.client.gui.inventory.GuiChest
+import net.minecraft.inventory.ContainerChest
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import java.util.regex.Pattern
+
+class AuctionHouseDetection(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!
+ */
+
+ 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 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)
+ }
+ }
+
+ 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))
+ }
+
+
+}