diff options
author | Linnea Gräf <nea@nea.moe> | 2024-12-07 21:18:21 +0100 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-12-07 21:18:21 +0100 |
commit | 6955c99b2e241cf7e4070424e8dbf29f80bb63fd (patch) | |
tree | 5abb4d0474cac2c579902e4bbf0266cdce0efaa0 /src/main/kotlin/moe/nea/ledger/modules/KatDetection.kt | |
parent | e3ace3c1b781b8d07f8eca60ba90df35da6c9d21 (diff) | |
download | LocalTransactionLedger-6955c99b2e241cf7e4070424e8dbf29f80bb63fd.tar.gz LocalTransactionLedger-6955c99b2e241cf7e4070424e8dbf29f80bb63fd.tar.bz2 LocalTransactionLedger-6955c99b2e241cf7e4070424e8dbf29f80bb63fd.zip |
feat: Add kat upgrade and flower detection
Diffstat (limited to 'src/main/kotlin/moe/nea/ledger/modules/KatDetection.kt')
-rw-r--r-- | src/main/kotlin/moe/nea/ledger/modules/KatDetection.kt | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/src/main/kotlin/moe/nea/ledger/modules/KatDetection.kt b/src/main/kotlin/moe/nea/ledger/modules/KatDetection.kt new file mode 100644 index 0000000..8a2aa19 --- /dev/null +++ b/src/main/kotlin/moe/nea/ledger/modules/KatDetection.kt @@ -0,0 +1,100 @@ +package moe.nea.ledger.modules + +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.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.unformattedString +import moe.nea.ledger.useMatcher +import moe.nea.ledger.utils.Inject +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + + +class KatDetection { + @Inject + lateinit var log: LedgerLogger + + @Inject + lateinit var itemIdProvider: ItemIdProvider + + val giftNameToIdMap = mapOf( + "flower" to ItemId("KAT_FLOWER"), + "bouquet" to ItemId("KAT_BOUQUET"), + ) + val katGift = "\\[NPC\\] Kat: A (?<gift>.*)\\? For me\\? How sweet!".toPattern() + + @SubscribeEvent + fun onChat(event: ChatReceived) { + katGift.useMatcher(event.message) { + val giftName = group("gift") + val giftId = giftNameToIdMap[giftName] + log.logEntry(LedgerEntry( + TransactionType.KAT_TIMESKIP, + event.timestamp, + listOf( + ItemChange.lose(giftId ?: ItemId.NIL, 1) + ) + )) + } + } + + val confirmSlot = 9 + 9 + 4 + val petSlot = 9 + 4 + + data class PetUpgrade( + val beforePetId: ItemId, + val cost: List<Pair<ItemId, Double>> + ) + + var lastPetUpgradeScheduled: PetUpgrade? = null + + @SubscribeEvent + fun onClick(event: BeforeGuiAction) { + val slots = event.chestSlots ?: return + val petItem = slots.lowerChestInventory.getStackInSlot(petSlot) ?: return + val beforePetId = petItem.getInternalId() ?: return + val confirmItem = slots.lowerChestInventory.getStackInSlot(confirmSlot) ?: return + val lore = confirmItem.getLore() + val cost = lore.iterator().asSequence() + .dropWhile { it.unformattedString() != "Cost" }.drop(1) + .takeWhile { it != "" } + .map { itemIdProvider.findFromLore(it) ?: Pair(ItemId.NIL, 1.0) } + .toList() + lastPetUpgradeScheduled = PetUpgrade(beforePetId, cost) + } + + val petUpgradeDialogue = "\\[NPC\\] Kat: I'll get your (?<type>.*) upgraded to (?<tier>.*) in no time!".toPattern() + fun upgradePetTier(itemId: ItemId): ItemId { + val str = itemId.string.split(";", limit = 2) + if (str.size == 2) { + val (type, tier) = str + val tierT = tier.toIntOrNull() + if (tierT != null) + return ItemId(type + ";" + (tierT + 1)) + } + return itemId + } + + @SubscribeEvent + fun onPetUpgrade(event: ChatReceived) { + petUpgradeDialogue.useMatcher(event.message) { + val upgrade = lastPetUpgradeScheduled ?: return + lastPetUpgradeScheduled = null + log.logEntry(LedgerEntry( + TransactionType.KAT_UPGRADE, + event.timestamp, + listOf( + ItemChange.lose(upgrade.beforePetId, 1), + ItemChange.gain(upgradePetTier(upgrade.beforePetId), 1), + ) + upgrade.cost.map { ItemChange.lose(it.first, it.second) }, + )) + } + } + +}
\ No newline at end of file |