aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/rift/area/westvillage/VerminTracker.kt149
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/rift/area/westvillage/kloon/KloonHacking.kt (renamed from src/main/java/at/hannibal2/skyhanni/features/rift/area/westvillage/KloonHacking.kt)2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/rift/area/westvillage/kloon/KloonTerminal.kt (renamed from src/main/java/at/hannibal2/skyhanni/features/rift/area/westvillage/KloonTerminal.kt)4
3 files changed, 152 insertions, 3 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/rift/area/westvillage/VerminTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/rift/area/westvillage/VerminTracker.kt
new file mode 100644
index 000000000..4bb2120b4
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/rift/area/westvillage/VerminTracker.kt
@@ -0,0 +1,149 @@
+package at.hannibal2.skyhanni.features.rift.area.westvillage
+
+import at.hannibal2.skyhanni.events.GuiRenderEvent
+import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
+import at.hannibal2.skyhanni.events.LorenzChatEvent
+import at.hannibal2.skyhanni.features.rift.RiftAPI
+import at.hannibal2.skyhanni.utils.InventoryUtils
+import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
+import at.hannibal2.skyhanni.utils.ItemUtils.getLore
+import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList
+import at.hannibal2.skyhanni.utils.LorenzUtils.addOrPut
+import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName
+import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
+import at.hannibal2.skyhanni.utils.StringUtils.matches
+import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
+import at.hannibal2.skyhanni.utils.tracker.SkyHanniTracker
+import at.hannibal2.skyhanni.utils.tracker.TrackerData
+import com.google.gson.annotations.Expose
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import java.util.regex.Pattern
+
+object VerminTracker {
+ private val silverfishPattern by RepoPattern.pattern(
+ "rift.area.westvillage.vermintracker.silverfish",
+ ".*§eYou vacuumed a §.*Silverfish.*"
+ )
+ private val spiderPattern by RepoPattern.pattern(
+ "rift.area.westvillage.vermintracker.spider",
+ ".*§eYou vacuumed a §.*Spider.*"
+ )
+ private val flyPattern by RepoPattern.pattern(
+ "rift.area.westvillage.vermintracker.fly",
+ ".*§eYou vacuumed a §.*Fly.*"
+ )
+ private val verminBinPattern by RepoPattern.pattern(
+ "rift.area.westvillage.vermintracker.binline",
+ "§fVermin Bin: §\\w(?<count>\\d+) (?<vermin>\\w+)"
+ )
+ private val verminBagPattern by RepoPattern.pattern(
+ "rift.area.westvillage.vermintracker.bagline",
+ "§fVacuum Bag: §\\w(?<count>\\d+) (?<vermin>\\w+)"
+ )
+
+ private val config get() = RiftAPI.config.area.westVillage.verminTracker
+
+ private val tracker = SkyHanniTracker("Vermin Tracker", { Data() }, { it.rift.verminTracker })
+ { drawDisplay(it) }
+
+ class Data : TrackerData() {
+ override fun reset() {
+ count.clear()
+ }
+
+ @Expose
+ var count: MutableMap<VerminType, Int> = mutableMapOf()
+ }
+
+ enum class VerminType(val vermin: String, val pattern: Pattern) {
+ SILVERFISH("§aSilverfish", silverfishPattern),
+ SPIDER("§aSpiders", spiderPattern),
+ FLY("§aFlies", flyPattern),
+ }
+
+ @SubscribeEvent
+ fun onChat(event: LorenzChatEvent) {
+ VerminType.entries.forEach { verminType ->
+ if (verminType.pattern.matches(event.message)) {
+ addVermin(verminType)
+ if (config.hideChat) {
+ event.blockedReason = "vermin_vacuumed"
+ }
+ }
+ }
+ }
+
+ @SubscribeEvent
+ fun onInventoryOpen(event: InventoryFullyOpenedEvent) {
+ if (!RiftAPI.inRift() || event.inventoryName != "Vermin Bin") return
+
+ val bin = event.inventoryItems[13]?.getLore() ?: return
+ val bag = InventoryUtils.getItemsInOwnInventory()
+ .firstOrNull { it.getInternalName() == "TURBOMAX_VACUUM".asInternalName() }
+ ?.getLore() ?: emptyList()
+
+ val binCounts = countVermin(bin, verminBinPattern)
+ VerminType.entries.forEach { setVermin(it, binCounts[it] ?: 0) }
+
+ if (bag.isEmpty()) return
+
+ val bagCounts = countVermin(bag, verminBagPattern)
+ VerminType.entries.forEach { addVermin(it, bagCounts[it] ?: 0) }
+ }
+
+ private fun countVermin(lore: List<String>, pattern: Pattern): MutableMap<VerminTracker.VerminType, Int> {
+ val verminCounts = mutableMapOf(
+ VerminType.SILVERFISH to 0,
+ VerminType.SPIDER to 0,
+ VerminType.FLY to 0
+ )
+ for (line in lore) {
+ pattern.matchMatcher(line) {
+ val vermin = group("vermin")?.lowercase() ?: continue
+ val verminCount = group("count")?.toInt() ?: continue
+ val verminType = getVerminType(vermin)
+ verminCounts[verminType] = verminCount
+ }
+ }
+ return verminCounts
+ }
+
+ private fun getVerminType(vermin: String): VerminType {
+ return when (vermin) {
+ "silverfish", "silverfishes" -> VerminType.SILVERFISH
+ "spider", "spiders" -> VerminType.SPIDER
+ "fly", "flies" -> VerminType.FLY
+ else -> VerminType.SILVERFISH
+ }
+ }
+
+ private fun addVermin(vermin: VerminType, count: Int = 1) {
+ tracker.modify { it.count.addOrPut(vermin, count) }
+ }
+
+ private fun setVermin(vermin: VerminType, count: Int) {
+ tracker.modify { it.count[vermin] = count }
+ }
+
+ private fun drawDisplay(data: Data): List<List<Any>> = buildList {
+ addAsSingletonList("§7Vermin Tracker:")
+ data.count.entries.sortedByDescending { it.value }.forEach { (vermin, amount) ->
+ val verminName = vermin.vermin
+ addAsSingletonList(" §7- §e${amount.addSeparators()} $verminName")
+ }
+ }
+
+ @SubscribeEvent
+ fun onRenderOverlay(event: GuiRenderEvent) {
+ if (!isEnabled()) return
+
+ tracker.renderDisplay(config.pos)
+ }
+
+ fun resetCommand(args: Array<String>) {
+ tracker.resetCommand(args, "shresetvermintracker")
+ }
+
+ private fun isEnabled() = RiftAPI.inRift() && config.enabled
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/rift/area/westvillage/KloonHacking.kt b/src/main/java/at/hannibal2/skyhanni/features/rift/area/westvillage/kloon/KloonHacking.kt
index 41c52b3f5..eb24782c6 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/rift/area/westvillage/KloonHacking.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/rift/area/westvillage/kloon/KloonHacking.kt
@@ -1,4 +1,4 @@
-package at.hannibal2.skyhanni.features.rift.area.westvillage
+package at.hannibal2.skyhanni.features.rift.area.westvillage.kloon
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
import at.hannibal2.skyhanni.data.ProfileStorageData
diff --git a/src/main/java/at/hannibal2/skyhanni/features/rift/area/westvillage/KloonTerminal.kt b/src/main/java/at/hannibal2/skyhanni/features/rift/area/westvillage/kloon/KloonTerminal.kt
index b5434d330..201bfca77 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/rift/area/westvillage/KloonTerminal.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/rift/area/westvillage/kloon/KloonTerminal.kt
@@ -1,4 +1,4 @@
-package at.hannibal2.skyhanni.features.rift.area.westvillage
+package at.hannibal2.skyhanni.features.rift.area.westvillage.kloon
import at.hannibal2.skyhanni.utils.LorenzVec
@@ -11,4 +11,4 @@ enum class KloonTerminal(val location: LorenzVec) {
BLUE(LorenzVec(-66.5, 72.0, -119.0)),
PURPLE(LorenzVec(-89.0, 73.0, -115.0)),
PINK(LorenzVec(-110.0, 73.0, -107.0))
-} \ No newline at end of file
+}