aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal002@users.noreply.github.com>2024-04-18 22:26:03 +0200
committerGitHub <noreply@github.com>2024-04-18 22:26:03 +0200
commit25c958f75cab5ccba7fab2312a7855230859964e (patch)
treec37c341ee9b12ae02139598b3d32ff7af3f35aab /src/main/java
parent55e2b4f3527c887bdee4bf8fc338b8404ecee4ce (diff)
downloadskyhanni-25c958f75cab5ccba7fab2312a7855230859964e.tar.gz
skyhanni-25c958f75cab5ccba7fab2312a7855230859964e.tar.bz2
skyhanni-25c958f75cab5ccba7fab2312a7855230859964e.zip
Improvelemt: RNG Meter slayer menu reading (#1479)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerRngMeterDisplay.kt42
1 files changed, 34 insertions, 8 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerRngMeterDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerRngMeterDisplay.kt
index 1327ffa33..180bd0a69 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerRngMeterDisplay.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerRngMeterDisplay.kt
@@ -13,6 +13,7 @@ import at.hannibal2.skyhanni.events.SecondPassedEvent
import at.hannibal2.skyhanni.events.SlayerChangeEvent
import at.hannibal2.skyhanni.test.command.ErrorManager
import at.hannibal2.skyhanni.utils.ChatUtils
+import at.hannibal2.skyhanni.utils.CollectionUtils.nextAfter
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.ItemUtils.itemName
@@ -22,6 +23,7 @@ import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.NumberUtil.formatLong
import at.hannibal2.skyhanni.utils.RenderUtils.renderString
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
+import at.hannibal2.skyhanni.utils.StringUtils.matches
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.StringUtils.removeWordsAtEnd
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
@@ -38,6 +40,10 @@ class SlayerRngMeterDisplay {
"inventoryname",
"(?<name>.*) RNG Meter"
)
+ private val slayerInventoryNamePattern by patternGroup.pattern(
+ "inventoryname.slayer",
+ "Slayer"
+ )
private val updatePattern by patternGroup.pattern(
"update",
" {3}§dRNG Meter §f- §d(?<exp>.*) Stored XP"
@@ -127,26 +133,46 @@ class SlayerRngMeterDisplay {
fun onInventoryOpen(event: InventoryFullyOpenedEvent) {
if (!isEnabled()) return
+ readRngmeterInventory(event)
+ readSlayerInventory(event)
+ }
+
+ private fun readRngmeterInventory(event: InventoryFullyOpenedEvent) {
val name = inventoryNamePattern.matchMatcher(event.inventoryName) {
group("name")
} ?: return
if (name != getCurrentSlayer()) return
- val storage = getStorage() ?: return
+ val internalName = event.inventoryItems.values
+ .find { item -> item.getLore().any { it.contains("§a§lSELECTED") } }
+ setNewGoal(internalName?.getInternalName())
+ }
+
+ private fun readSlayerInventory(event: InventoryFullyOpenedEvent) {
+ if (!slayerInventoryNamePattern.matches(event.inventoryName)) return
+ val item = event.inventoryItems[35] ?: return
+ val lore = item.getLore()
+ val name = lore.firstOrNull()?.removeColor() ?: return
- val selectedItem =
- event.inventoryItems.values.find { item -> item.getLore().any { it.contains("§a§lSELECTED") } }
- if (selectedItem == null) {
+ if (name != getCurrentSlayer()) return
+
+ val selectedItem = lore.nextAfter("§7Selected Drop") ?: return
+ val internalName = NEUInternalName.fromItemName(selectedItem)
+ setNewGoal(internalName)
+ }
+
+ private fun setNewGoal(internalName: NEUInternalName?) {
+ val storage = getStorage() ?: return
+ if (internalName == null) {
storage.itemGoal = ""
storage.goalNeeded = -1
} else {
- storage.itemGoal = selectedItem.itemName
- storage.goalNeeded = rngScore[getCurrentSlayer()]?.get(selectedItem.getInternalName())
+ storage.itemGoal = internalName.itemName
+ storage.goalNeeded = rngScore[getCurrentSlayer()]?.get(internalName)
?: ErrorManager.skyHanniError(
"RNG Meter goal setting failed",
- "selectedItem" to selectedItem,
- "selectedItemInternalName" to selectedItem.getInternalName(),
+ "internalName" to internalName,
"currentSlayer" to getCurrentSlayer(),
"repo" to rngScore
)