diff options
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt | 30 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/LorenzRarity.kt | 27 |
2 files changed, 53 insertions, 4 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt index aee09514f..25d5f9df4 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt @@ -1,5 +1,6 @@ package at.hannibal2.skyhanni.utils +import at.hannibal2.skyhanni.test.command.CopyErrorCommand import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName import at.hannibal2.skyhanni.utils.NEUItems.getItemStack import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.isRecombobulated @@ -159,7 +160,16 @@ object ItemUtils { return getPetRarity(this) } - return when (this.getLore().lastOrNull()?.take(4)) { + val lore = getLore() + var lastLine = lore.lastOrNull() ?: return null + if (lastLine == "§eClick to inspect!") { + // Assuming inside ah browser + val index = lore.indexOfFirst { it.startsWith("§7Seller: ") } - 2 + if (index > 0) { + lastLine = lore[index] + } + } + return when (lastLine.take(4)) { "§f§l" -> LorenzRarity.COMMON "§a§l" -> LorenzRarity.UNCOMMON "§9§l" -> LorenzRarity.RARE @@ -169,7 +179,13 @@ object ItemUtils { "§b§l" -> LorenzRarity.DIVINE "§4§l" -> LorenzRarity.SUPREME "§c§l" -> LorenzRarity.SPECIAL - else -> null + else -> { + CopyErrorCommand.logErrorState( + "Could not read rarity for item $name", + "getItemRarityOrNull not found for: ${getInternalName()}, name:'$name', lastLine:'$lastLine'" + ) + return null + } } } @@ -248,6 +264,14 @@ object ItemUtils { private fun getPetRarity(pet: ItemStack): LorenzRarity? { val rarityId = pet.getInternalName().asString().split(";").last().toInt() - return LorenzRarity.getById(rarityId) + val rarity = LorenzRarity.getById(rarityId) + val name = pet.name + if (rarity == null) { + CopyErrorCommand.logErrorState( + "Could not read rarity for pet $name", + "getPetRarity not found for: ${pet.getInternalName()}, name:'$name'" + ) + } + return rarity } }
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzRarity.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzRarity.kt index f21d5e32e..4af8f7e2f 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzRarity.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzRarity.kt @@ -1,5 +1,7 @@ package at.hannibal2.skyhanni.utils
+import at.hannibal2.skyhanni.test.command.CopyErrorCommand
+
// TODO: replace id with ordinal
enum class LorenzRarity(val color: LorenzColor, val id: Int) {
@@ -12,10 +14,33 @@ enum class LorenzRarity(val color: LorenzColor, val id: Int) { DIVINE(LorenzColor.AQUA, 6),
SUPREME(LorenzColor.DARK_RED, 7),
SPECIAL(LorenzColor.RED, 8),
+ VERY_SPECIAL(LorenzColor.RED, 9),
;
+ fun oneBelow(logError: Boolean = true): LorenzRarity? {
+ val rarityBelow = getById(ordinal - 1)
+ if (rarityBelow == null && logError) {
+ CopyErrorCommand.logErrorState(
+ "Problem with item rarity detected.",
+ "Trying to get an item rarity below common"
+ )
+ }
+ return rarityBelow
+ }
+
+ fun oneAbove(logError: Boolean = true): LorenzRarity? {
+ val rarityBelow = getById(ordinal + 1)
+ if (rarityBelow == null && logError) {
+ CopyErrorCommand.logErrorState(
+ "Problem with item rarity detected.",
+ "Trying to get an item rarity above special"
+ )
+ }
+ return rarityBelow
+ }
+
companion object {
- fun getById(id: Int) = entries.firstOrNull { it.id == id }
+ fun getById(id: Int) = entries.firstOrNull { it.ordinal == id }
}
}
\ No newline at end of file |