diff options
author | jani270 <69345714+jani270@users.noreply.github.com> | 2025-01-21 00:33:56 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-21 00:33:56 +0100 |
commit | aa84007823ddd16caf9ea7f2f2a039b7e95c0648 (patch) | |
tree | c913ae0a09aceccdf8660037b7fe52ac7cdec8c4 /mod | |
parent | ae6be122542f7970327fc67394115455555ae50d (diff) | |
download | LocalTransactionLedger-aa84007823ddd16caf9ea7f2f2a039b7e95c0648.tar.gz LocalTransactionLedger-aa84007823ddd16caf9ea7f2f2a039b7e95c0648.tar.bz2 LocalTransactionLedger-aa84007823ddd16caf9ea7f2f2a039b7e95c0648.zip |
feat: Basic Reforge Detection (#17)
* feat: Basic Reforge Detection
* feat: sort linesn
* ix: Build
* f
* feat: fff
---------
Co-authored-by: Linnea Gräf <nea@nea.moe>
Diffstat (limited to 'mod')
-rw-r--r-- | mod/src/main/kotlin/moe/nea/ledger/Ledger.kt | 6 | ||||
-rw-r--r-- | mod/src/main/kotlin/moe/nea/ledger/modules/BasicReforgeDetection.kt | 71 |
2 files changed, 75 insertions, 2 deletions
diff --git a/mod/src/main/kotlin/moe/nea/ledger/Ledger.kt b/mod/src/main/kotlin/moe/nea/ledger/Ledger.kt index 06ee9c9..134d519 100644 --- a/mod/src/main/kotlin/moe/nea/ledger/Ledger.kt +++ b/mod/src/main/kotlin/moe/nea/ledger/Ledger.kt @@ -17,12 +17,13 @@ import moe.nea.ledger.modules.AllowanceDetection import moe.nea.ledger.modules.AuctionHouseDetection import moe.nea.ledger.modules.BankDetection import moe.nea.ledger.modules.BankInterestDetection +import moe.nea.ledger.modules.BasicReforgeDetection import moe.nea.ledger.modules.BazaarDetection import moe.nea.ledger.modules.BazaarOrderDetection import moe.nea.ledger.modules.BitsDetection import moe.nea.ledger.modules.BitsShopDetection import moe.nea.ledger.modules.DragonEyePlacementDetection -import moe.nea.ledger.modules.`DragonSacrificeDetection` +import moe.nea.ledger.modules.DragonSacrificeDetection import moe.nea.ledger.modules.DungeonChestDetection import moe.nea.ledger.modules.ExternalDataProvider import moe.nea.ledger.modules.EyedropsDetection @@ -91,7 +92,7 @@ class Ledger { // You sold Cactus x1 for 3 Coins! // You bought back Potato x3 for 9 Coins! - TODO: TRADING, FORGE, VISITORS / COPPER, CORPSES ÖFFNEN, HIGH / LOW GAMBLES, MINION ITEMS (maybe inferno refuel) + TODO: TRADING, FORGE, MINION ITEMS (maybe inferno refuel) TODO: PET LEVELING COSTS AT FANN, SLAYER / MOB DROPS, SLAYER START COST */ companion object { @@ -129,6 +130,7 @@ class Ledger { AuctionHouseDetection::class.java, BankDetection::class.java, BankInterestDetection::class.java, + BasicReforgeDetection::class.java, BazaarDetection::class.java, BazaarOrderDetection::class.java, BitsDetection::class.java, diff --git a/mod/src/main/kotlin/moe/nea/ledger/modules/BasicReforgeDetection.kt b/mod/src/main/kotlin/moe/nea/ledger/modules/BasicReforgeDetection.kt new file mode 100644 index 0000000..17e2983 --- /dev/null +++ b/mod/src/main/kotlin/moe/nea/ledger/modules/BasicReforgeDetection.kt @@ -0,0 +1,71 @@ +package moe.nea.ledger.modules + +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.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.getInternalId +import moe.nea.ledger.getLore +import moe.nea.ledger.parseShortNumber +import moe.nea.ledger.unformattedString +import moe.nea.ledger.useMatcher +import moe.nea.ledger.utils.di.Inject +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.time.Duration.Companion.seconds + +class BasicReforgeDetection { + + var costPattern = "(?<cost>$SHORT_NUMBER_PATTERN) Coins".toPattern() + + @Inject + lateinit var logger: LedgerLogger + + data class ReforgeInstance( + val price: Double, + val item: ItemId, + ) + + var lastReforge = ExpiringValue.empty<ReforgeInstance>() + + @SubscribeEvent + fun onReforgeClick(event: GuiClickEvent) { + val slot = event.slotIn ?: return + val displayName = slot.inventory.displayName.unformattedText + if (!displayName.unformattedString().contains("Reforge Item") && + !displayName.unformattedString().startsWith("The Hex") + ) return + val stack = slot.stack ?: return + val cost = stack.getLore() + .firstNotNullOfOrNull { costPattern.useMatcher(it.unformattedString()) { parseShortNumber(group("cost")) } } + ?: return + + if (stack.getDisplayNameU() == "§aReforge Item" || stack.getDisplayNameU() == "§aRandom Basic Reforge") { + lastReforge = ExpiringValue(ReforgeInstance(cost, ItemId.NIL /*TODO: read out item stack that is being reforged to save it as a transformed item!*/)) + } + } + + val reforgeChatNotification = "You reforged your .* into a .*!".toPattern() + + @SubscribeEvent + fun onReforgeChat(event: ChatReceived) { + reforgeChatNotification.useMatcher(event.message) { + val reforge = lastReforge.get(3.seconds) ?: return + logger.logEntry( + LedgerEntry( + TransactionType.BASIC_REFORGE, + event.timestamp, + listOf( + ItemChange.loseCoins(reforge.price), + ItemChange(reforge.item, 1.0, ItemChange.ChangeDirection.TRANSFORM) + ) + ) + ) + } + } +}
\ No newline at end of file |