aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-12-12 20:58:09 +0100
committerLinnea Gräf <nea@nea.moe>2024-12-12 20:58:09 +0100
commite9d26be68e0a094e1edd6f1bf6a9b3e28fc30007 (patch)
treec2ea27c7ef66aff00a5d2c9dfc64613d8114398a /src/main/kotlin/moe
parent92f4c6a7e4f93998ec3a2f2afe5539379ec82cd3 (diff)
downloadLocalTransactionLedger-e9d26be68e0a094e1edd6f1bf6a9b3e28fc30007.tar.gz
LocalTransactionLedger-e9d26be68e0a094e1edd6f1bf6a9b3e28fc30007.tar.bz2
LocalTransactionLedger-e9d26be68e0a094e1edd6f1bf6a9b3e28fc30007.zip
feat: Add auction charge tracker
Diffstat (limited to 'src/main/kotlin/moe')
-rw-r--r--src/main/kotlin/moe/nea/ledger/TransactionType.kt1
-rw-r--r--src/main/kotlin/moe/nea/ledger/modules/AuctionHouseDetection.kt35
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 =