aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at
diff options
context:
space:
mode:
authorLorenz <lo.scherf@gmail.com>2022-08-22 02:08:50 +0200
committerLorenz <lo.scherf@gmail.com>2022-08-22 02:08:50 +0200
commitad946bccdb1dd666f2648434ed3653eaf0b137a1 (patch)
tree7ee383d55291c0042e6da91ff1c85433cf523509 /src/main/java/at
parente8ae72d6b76ebee6eb5f3f37315d69e5a063926c (diff)
downloadskyhanni-ad946bccdb1dd666f2648434ed3653eaf0b137a1.tar.gz
skyhanni-ad946bccdb1dd666f2648434ed3653eaf0b137a1.tar.bz2
skyhanni-ad946bccdb1dd666f2648434ed3653eaf0b137a1.zip
added support for books and essence to bazaar
Diffstat (limited to 'src/main/java/at')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarApi.kt13
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarBestSellMethod.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataGrabber.kt37
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt7
5 files changed, 46 insertions, 15 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarApi.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarApi.kt
index 3de78206b..5ae100ac2 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarApi.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarApi.kt
@@ -1,6 +1,7 @@
package at.hannibal2.skyhanni.features.bazaar
import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.StringUtils.removeColor
class BazaarApi {
@@ -29,22 +30,18 @@ class BazaarApi {
if (name.endsWith(" Gemstone")) {
return name.substring(6)
}
- if (name.startsWith("ยง")) {
- return name.substring(2)
- }
-
- return name
+ return name.removeColor()
}
- fun getBazaarDataForName(name: String): BazaarData {
+ fun getBazaarDataForName(name: String): BazaarData? {
if (bazaarMap.containsKey(name)) {
val bazaarData = bazaarMap[name]
if (bazaarData != null) {
return bazaarData
}
- LorenzUtils.error("Bazaar data is null for item '$name'")
+ LorenzUtils.error("Bazaar data not found! '$name'")
}
- throw Error("no bz data found for name '$name'")
+ return null
}
fun isBazaarItem(name: String): Boolean {
diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarBestSellMethod.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarBestSellMethod.kt
index c4afc33fc..e97ff5817 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarBestSellMethod.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarBestSellMethod.kt
@@ -40,7 +40,7 @@ class BazaarBestSellMethod {
val bazaarItem = inv.getStackInSlot(13) ?: return ""
var name = bazaarItem.displayName
name = BazaarApi.getCleanBazaarName(name)
- val data = BazaarApi.getBazaarDataForName(name)
+ val data = BazaarApi.getBazaarDataForName(name) ?: return ""
var having = 0
for (slot in chest.inventorySlots) {
diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataGrabber.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataGrabber.kt
index eea1138fa..f8f05845b 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataGrabber.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataGrabber.kt
@@ -3,6 +3,8 @@ package at.hannibal2.skyhanni.features.bazaar
import at.hannibal2.skyhanni.utils.APIUtil
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.round
+import at.hannibal2.skyhanni.utils.NumberUtil.isInt
+import at.hannibal2.skyhanni.utils.NumberUtil.toRoman
import at.hannibal2.skyhanni.utils.StringUtils.firstLetterUppercase
import kotlin.concurrent.fixedRateTimer
@@ -114,14 +116,39 @@ internal class BazaarDataGrabber(private var bazaarMap: MutableMap<String, Bazaa
//ESSENCE_CRIMSON
return itemName ?: if (apiName.startsWith("ESSENCE_")) {
val type = apiName.split("_")[1].firstLetterUppercase()
- itemName = "$type Essence";
+ itemName = "$type Essence"
itemNames[apiName] = itemName
itemName
} else {
- //TODO need to re enable this later again
- println("unknown bazaar item: '$apiName'")
-// LorenzUtils.error("Bazaar item name is null for '$apiName'! Restart to fix this problem!")
- null
+ if (apiName.startsWith("ENCHANTMENT_ULTIMATE_")) {
+ val enchantmentName = getEnchantmentRealName(apiName.split("_ULTIMATE_")[1])
+ itemNames[apiName] = enchantmentName
+ enchantmentName
+ } else if (apiName.startsWith("ENCHANTMENT_")) {
+ val enchantmentName = getEnchantmentRealName(apiName.split("ENCHANTMENT_")[1])
+ itemNames[apiName] = enchantmentName
+ enchantmentName
+ } else {
+ null
+ }
+ }
+ }
+
+ private fun getEnchantmentRealName(rawName: String): String {
+ val builder = StringBuilder()
+ for (word in rawName.lowercase().split("_")) {
+ if (word.isInt()) {
+ builder.append(word.toInt().toRoman())
+ } else {
+ if (word in listOf("of", "the")) {
+ builder.append(word)
+ } else {
+ builder.append(word.firstLetterUppercase())
+ }
+ }
+ builder.append(" ")
}
+ val string = builder.toString()
+ return string.substring(0, string.length - 1)
}
} \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt
index ab398a5bf..893a356c4 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt
@@ -49,7 +49,7 @@ class BazaarOrderHelper {
val rawName = itemName.split(if (isBuying) "BUY " else "SELL ")[1]
val bazaarName = BazaarApi.getCleanBazaarName(rawName)
- val data = BazaarApi.getBazaarDataForName(bazaarName)
+ val data = BazaarApi.getBazaarDataForName(bazaarName) ?: return
val itemLore = stack.getLore()
for (line in itemLore) {
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt b/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt
index 891826a91..1d4701397 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt
@@ -2,6 +2,7 @@ package at.hannibal2.skyhanni.utils
import java.text.NumberFormat
import java.util.*
+import java.util.regex.Pattern
import kotlin.math.pow
import kotlin.math.roundToInt
@@ -149,4 +150,10 @@ object NumberUtil {
lastDecimal + decimal
}
}
+
+ val pattern = Pattern.compile("^[0-9]*$")
+
+ fun String.isInt(): Boolean {
+ return isNotEmpty() && pattern.matcher(this).matches()
+ }
} \ No newline at end of file