diff options
Diffstat (limited to 'src/main/kotlin/moe/nea/ledger')
-rw-r--r-- | src/main/kotlin/moe/nea/ledger/TransactionType.kt | 1 | ||||
-rw-r--r-- | src/main/kotlin/moe/nea/ledger/modules/AuctionHouseDetection.kt | 35 |
2 files changed, 36 insertions, 0 deletions
diff --git a/src/main/kotlin/moe/nea/ledger/TransactionType.kt b/src/main/kotlin/moe/nea/ledger/TransactionType.kt index 1c941e9..b615fcd 100644 --- a/src/main/kotlin/moe/nea/ledger/TransactionType.kt +++ b/src/main/kotlin/moe/nea/ledger/TransactionType.kt @@ -2,6 +2,7 @@ package moe.nea.ledger enum class TransactionType { AUCTION_BOUGHT, + AUCTION_LISTING_CHARGE, AUCTION_SOLD, AUTOMERCHANT_PROFIT_COLLECT, BANK_DEPOSIT, diff --git a/src/main/kotlin/moe/nea/ledger/modules/AuctionHouseDetection.kt b/src/main/kotlin/moe/nea/ledger/modules/AuctionHouseDetection.kt index 0d9b0cb..92b659d 100644 --- a/src/main/kotlin/moe/nea/ledger/modules/AuctionHouseDetection.kt +++ b/src/main/kotlin/moe/nea/ledger/modules/AuctionHouseDetection.kt @@ -1,5 +1,6 @@ package moe.nea.ledger.modules +import moe.nea.ledger.ExpiringValue import moe.nea.ledger.ItemChange import moe.nea.ledger.ItemId import moe.nea.ledger.ItemIdProvider @@ -19,6 +20,7 @@ import net.minecraft.client.gui.inventory.GuiChest import net.minecraft.inventory.ContainerChest import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import java.util.regex.Pattern +import kotlin.time.Duration.Companion.seconds class AuctionHouseDetection @Inject constructor(val ledger: LedgerLogger, val ids: ItemIdProvider) { data class LastViewedItem( @@ -32,6 +34,39 @@ class AuctionHouseDetection @Inject constructor(val ledger: LedgerLogger, val id You purchased ◆ Ice Rune I for 4,000 coins! */ + val createAuctionScreen = "Confirm( BIN)? Auction".toPattern() + val auctionCreationCostPattern = "Cost: (?<cost>$SHORT_NUMBER_PATTERN) coins?".toPattern() + + val auctionCreatedChatPattern = "(BIN )?Auction started for .*".toPattern() + + var lastCreationCost: ExpiringValue<Double> = ExpiringValue.empty() + + @SubscribeEvent + fun onCreateAuctionClick(event: BeforeGuiAction) { + val slots = event.chestSlots ?: return + if (!createAuctionScreen.asPredicate().test(slots.lowerChestInventory.name)) return + val auctionSlot = slots.lowerChestInventory.getStackInSlot(9 + 2) ?: return + val creationCost = auctionSlot.getLore().firstNotNullOfOrNull { + auctionCreationCostPattern.useMatcher(it.unformattedString()) { parseShortNumber(group("cost")) } + } + if (creationCost != null) { + lastCreationCost = ExpiringValue(creationCost) + } + } + + @SubscribeEvent + fun onCreateAuctionChat(event: ChatReceived) { + auctionCreatedChatPattern.useMatcher(event.message) { + lastCreationCost.consume(3.seconds)?.let { cost -> + ledger.logEntry(LedgerEntry( + TransactionType.AUCTION_LISTING_CHARGE, + event.timestamp, + listOf(ItemChange.loseCoins(cost)) + )) + } + } + } + val collectSold = Pattern.compile("You collected (?<coins>$SHORT_NUMBER_PATTERN) coins? from selling (?<what>.*) to (?<buyer>.*) in an auction!") val purchased = |