aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/ledger/modules/KuudraChestDetection.kt
blob: 8d0dc7bfd4e30a1a019bf7e2e2a2bfd7e3c45f70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package moe.nea.ledger.modules

import moe.nea.ledger.ItemChange
import moe.nea.ledger.ItemId
import moe.nea.ledger.LedgerEntry
import moe.nea.ledger.LedgerLogger
import moe.nea.ledger.TransactionType
import moe.nea.ledger.events.GuiClickEvent
import moe.nea.ledger.getInternalId
import moe.nea.ledger.utils.Inject
import net.minecraft.client.Minecraft
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

class KuudraChestDetection : ChestDetection() {
	// TODO: extra essence for kuudra pet (how?), item SALVAGE detection
	// TODO: save uuid along side item id

	val kuudraKeyPattern = "KUUDRA_.*_TIER_KEY".toPattern()

	@Inject
	lateinit var log: LedgerLogger

	@Inject
	lateinit var minecraft: Minecraft
	fun hasKey(keyItem: ItemId): Boolean {
		val p = minecraft.thePlayer ?: return false
		return p.inventory.mainInventory.any { it?.getInternalId() == keyItem }
	}

	@SubscribeEvent
	fun onRewardChestClick(event: GuiClickEvent) {
		val diffs = scrapeChestReward(event.slotIn ?: return) ?: return
		val requiredKey = diffs.diff.find {
			it.direction == ItemChange.ChangeDirection.LOST && kuudraKeyPattern.asPredicate().test(it.itemId.string)
		}?.itemId
		if (requiredKey != null && !hasKey(requiredKey)) {
			return
		}
		log.logEntry(LedgerEntry(
			TransactionType.KUUDRA_CHEST_OPEN,
			diffs.timestamp,
			diffs.diff,
		))
	}
}