aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/inventory/ItemStars.kt124
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValueCalculator.kt66
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/nether/kuudra/KuudraAPI.kt32
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt7
4 files changed, 88 insertions, 141 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemStars.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemStars.kt
index d89c2aca9..7e0ab8d7d 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemStars.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemStars.kt
@@ -2,16 +2,20 @@ package at.hannibal2.skyhanni.features.inventory
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.features.inventory.InventoryConfig.ItemNumberEntry.CRIMSON_ARMOR
-import at.hannibal2.skyhanni.data.jsonobjects.repo.ItemsJson
import at.hannibal2.skyhanni.events.LorenzToolTipEvent
import at.hannibal2.skyhanni.events.RenderItemTipEvent
-import at.hannibal2.skyhanni.events.RepositoryReloadEvent
import at.hannibal2.skyhanni.features.inventory.ItemDisplayOverlayFeatures.isSelected
+import at.hannibal2.skyhanni.features.nether.kuudra.KuudraAPI.getKuudraTier
+import at.hannibal2.skyhanni.features.nether.kuudra.KuudraAPI.isKuudraArmor
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
+import at.hannibal2.skyhanni.utils.ItemUtils.getInternalNameOrNull
import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.LorenzUtils
-import at.hannibal2.skyhanni.utils.RegexUtils.matches
+import at.hannibal2.skyhanni.utils.RegexUtils.findMatcher
+import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getDungeonStarCount
+import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getStarCount
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
+import net.minecraft.item.ItemStack
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
@@ -20,115 +24,47 @@ object ItemStars {
private val config get() = SkyHanniMod.feature.inventory
- private val starPattern by RepoPattern.pattern(
- "inventory.itemstars.stars",
- "(.*)§.✪(.*)"
- )
+ private val repoGroup = RepoPattern.group("inventory.itemstars")
- private val armorNames = mutableListOf<String>()
- private val tiers = mutableMapOf<String, Int>()
- private val armorParts = listOf("Helmet", "Chestplate", "Leggings", "Boots")
+ /**
+ * REGEX-TEST: §6Ancient Terror Leggings §d✪✪§6✪✪✪
+ * REGEX-TEST: §dRenowned Burning Crimson Helmet §6✪✪✪✪✪
+ */
+ private val starPattern by repoGroup.pattern(
+ "stars",
+ "^(?<name>.+) (?<stars>(?:(?:§.)?✪)+)"
+ )
@SubscribeEvent(priority = EventPriority.LOW)
fun onTooltip(event: LorenzToolTipEvent) {
if (!isEnabled()) return
val stack = event.itemStack
if (stack.stackSize != 1) return
-
- val itemName = stack.name
- val stars = getStars(itemName)
-
- if (stars > 0) {
- var name = itemName
- while (starPattern.matches(name)) {
- name = name.replaceFirst("§.✪".toRegex(), "")
- }
- name = name.trim()
+ val stars = stack.grabStarCount() ?: return
+ starPattern.findMatcher(stack.name) {
+ val name = group("name")
event.toolTip[0] = "$name §c$stars✪"
}
}
@SubscribeEvent
- fun onRepoReload(event: RepositoryReloadEvent) {
- val data = event.getConstant<ItemsJson>("Items")
- armorNames.clear()
- tiers.clear()
- armorNames.addAll(data.crimsonArmors)
- for (tier in data.crimsonTiers) {
- tiers[tier.key] = tier.value
- }
- }
-
- @SubscribeEvent
fun onRenderItemTip(event: RenderItemTipEvent) {
+ if (!LorenzUtils.inSkyBlock) return
if (!CRIMSON_ARMOR.isSelected()) return
val stack = event.stack
- val number = getCrimsonStars(stack.name)
- if (number != -1) {
- event.stackTip = number.toString()
- }
- }
-
- private fun getStars(name: String): Int {
- val stars = getCrimsonStars(name)
- if (stars != -1) {
- return stars
- }
-
- return getOtherStars(name)
+ if (stack.getInternalNameOrNull()?.isKuudraArmor() != true) return
+ val stars = stack.grabStarCount() ?: return
+ event.stackTip = stars.toString()
}
- private fun getCrimsonStars(name: String): Int {
- if (!armorNames.any { name.contains(it) } || !armorParts.any { name.contains(it) }) {
- return -1
+ private fun ItemStack.grabStarCount(): Int? {
+ val internalName = getInternalNameOrNull() ?: return null
+ val baseStars = getDungeonStarCount() ?: getStarCount() ?: return null
+ if (internalName.isKuudraArmor()) {
+ val tier = internalName.getKuudraTier() ?: return baseStars
+ return baseStars + tier * 10
}
- var name1 = name
- var gold = 0
- var pink = 0
- var aqua = 0
- while (name1.contains("§6✪")) {
- name1 = name1.replaceFirst("§6✪", "")
- gold++
- }
- while (name1.contains("§d✪")) {
- name1 = name1.replaceFirst("§d✪", "")
- pink++
- }
- while (name1.contains("§b✪")) {
- name1 = name1.replaceFirst("§b✪", "")
- aqua++
- }
- return (tiers.entries.find { name1.contains(it.key) }?.value ?: 0) + if (aqua > 0) {
- 10 + aqua
- } else if (pink > 0) {
- 5 + pink
- } else {
- gold
- }
- }
-
- private fun getOtherStars(originalName: String): Int {
- var name = originalName
-
- var gold = 0
- var red = 0
- while (name.contains("§6✪")) {
- name = name.replaceFirst("§6✪", "")
- gold++
- }
- while (name.contains("§c✪")) {
- name = name.replaceFirst("§c✪", "")
- red++
- }
- while (name.contains("§d✪")) {
- name = name.replaceFirst("§d✪", "")
- red++
- }
-
- if (red > 0) return 5 + red
- if (gold > 0) return gold
-
- return -1
+ return baseStars
}
private fun isEnabled() = LorenzUtils.inSkyBlock && config.itemStars
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValueCalculator.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValueCalculator.kt
index 15c55e02e..30d326750 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValueCalculator.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValueCalculator.kt
@@ -2,6 +2,10 @@ package at.hannibal2.skyhanni.features.misc.items
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.api.ReforgeAPI
+import at.hannibal2.skyhanni.features.nether.kuudra.KuudraAPI
+import at.hannibal2.skyhanni.features.nether.kuudra.KuudraAPI.getKuudraTier
+import at.hannibal2.skyhanni.features.nether.kuudra.KuudraAPI.isKuudraArmor
+import at.hannibal2.skyhanni.features.nether.kuudra.KuudraAPI.removeKuudraTier
import at.hannibal2.skyhanni.test.command.ErrorManager
import at.hannibal2.skyhanni.utils.CollectionUtils.addOrPut
import at.hannibal2.skyhanni.utils.CollectionUtils.sorted
@@ -24,6 +28,7 @@ import at.hannibal2.skyhanni.utils.NEUItems.getItemStackOrNull
import at.hannibal2.skyhanni.utils.NEUItems.getNpcPriceOrNull
import at.hannibal2.skyhanni.utils.NEUItems.getPriceOrNull
import at.hannibal2.skyhanni.utils.NEUItems.getRawCraftCostOrNull
+import at.hannibal2.skyhanni.utils.NEUItems.removePrefix
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.NumberUtil.shortFormat
import at.hannibal2.skyhanni.utils.PrimitiveIngredient
@@ -69,8 +74,6 @@ object EstimatedItemValueCalculator {
private val config get() = SkyHanniMod.feature.inventory.estimatedItemValues
- private val kuudraSets = listOf("AURORA", "CRIMSON", "TERROR", "HOLLOW", "FERVOR")
-
var starChange = 0
get() = if (SkyHanniMod.feature.dev.debug.enabled) field else 0
@@ -134,31 +137,22 @@ object EstimatedItemValueCalculator {
return Pair(totalPrice, basePrice)
}
- private fun isKuudraSet(internalName: String) = (
- kuudraSets.any { internalName.contains(it) } &&
- listOf(
- "CHESTPLATE",
- "LEGGINGS",
- "HELMET",
- "BOOTS",
- ).any { internalName.endsWith(it) }
- )
-
private fun addAttributeCost(stack: ItemStack, list: MutableList<String>): Double {
val attributes = stack.getAttributes() ?: return 0.0
- var internalName = removeKuudraArmorPrefix(stack.getInternalName().asString().removePrefix("VANQUISHED_"))
- var genericName = internalName
- if (isKuudraSet(internalName)) {
- genericName = kuudraSets.fold(internalName) { acc, part -> acc.replace(part, "GENERIC_KUUDRA") }
+ val internalName = stack.getInternalName()
+ val internalNameString = internalName.removeKuudraTier().removePrefix("VANQUISHED_").asString()
+ var genericName = internalNameString
+ if (internalName.isKuudraArmor()) {
+ genericName = KuudraAPI.kuudraSets.fold(internalNameString) { acc, part -> acc.replace(part, "GENERIC_KUUDRA") }
}
stack.getAttributeFromShard()?.let {
return 0.0
}
if (attributes.size != 2) return 0.0
- val basePrice = internalName.asInternalName().getPriceOrNull() ?: 0.0
+ val basePrice = internalName.getPriceOrNull() ?: 0.0
var subTotal = 0.0
- val combo = ("$internalName+ATTRIBUTE_${attributes[0].first}+ATTRIBUTE_${attributes[1].first}")
- var comboPrice = combo.asInternalName().getPriceOrNull()
+ val combo = ("$internalNameString+ATTRIBUTE_${attributes[0].first}+ATTRIBUTE_${attributes[1].first}")
+ val comboPrice = combo.asInternalName().getPriceOrNull()
if (comboPrice != null) {
val useless = isUselessAttribute(combo)
@@ -194,16 +188,6 @@ object EstimatedItemValueCalculator {
return subTotal + 0.1
}
- private fun removeKuudraArmorPrefix(original: String): String {
- if (!isKuudraSet(original)) return original
-
- var internalName = original
- for (prefix in kuudraUpgradeTiers) {
- internalName = internalName.removePrefix(prefix)
- }
- return internalName
- }
-
private fun addAttributePrice(attributePrice: Double, basePrice: Double): Double = if (attributePrice > basePrice) {
attributePrice - basePrice
} else {
@@ -493,14 +477,13 @@ object EstimatedItemValueCalculator {
inputStars: Int,
): Pair<EssenceItemUtils.EssenceUpgradePrice, Pair<Int, Int>>? {
var totalStars = inputStars
- val rawInternalName = internalName.asString()
- val (price, maxStars) = if (isKuudraSet(rawInternalName)) {
- val tier = getKuudraTier(internalName)
- totalStars += (tier + 1) * 10
+ val (price, maxStars) = if (internalName.isKuudraArmor()) {
+ val tier = internalName.getKuudraTier() ?: 0
+ totalStars += tier * 10
var remainingStars = totalStars
- val removed = removeKuudraArmorPrefix(rawInternalName)
+ val removed = internalName.removeKuudraTier().asString()
var maxStars = 0
var finalPrice: EssenceItemUtils.EssenceUpgradePrice? = null
@@ -508,7 +491,7 @@ object EstimatedItemValueCalculator {
for ((id, _) in EssenceItemUtils.itemPrices) {
if (!id.contains(removed)) continue
- tiers[id] = getKuudraTier(id)
+ tiers[id] = (id.getKuudraTier() ?: 0) - 1
}
for ((id, _) in tiers.sorted()) {
@@ -535,17 +518,6 @@ object EstimatedItemValueCalculator {
return price to (havingStars to maxStars)
}
- private fun getKuudraTier(internalName: NEUInternalName): Int {
- for (tier in kuudraUpgradeTiers) {
- if (internalName.asString().contains(tier)) {
- return kuudraUpgradeTiers.indexOf(tier)
- }
- }
- return -1
- }
-// private fun getKuudraTier(internalName: NEUInternalName): Int? =
-// kuudraUpgradeTiers.firstOrNull { it in internalName.toString() }?.let { kuudraUpgradeTiers.indexOf(it) }
-
private fun getPriceFor(
prices: Map<Int, EssenceItemUtils.EssenceUpgradePrice>,
totalStars: Int,
@@ -697,7 +669,7 @@ object EstimatedItemValueCalculator {
}
private fun addBaseItem(stack: ItemStack, list: MutableList<String>): Double {
- val internalName = removeKuudraArmorPrefix(stack.getInternalName().asString()).asInternalName()
+ val internalName = stack.getInternalName().removeKuudraTier()
stack.getAttributeFromShard()?.let {
val price = it.getAttributePrice()
diff --git a/src/main/java/at/hannibal2/skyhanni/features/nether/kuudra/KuudraAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/nether/kuudra/KuudraAPI.kt
index dbae485dc..f2b1557da 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/nether/kuudra/KuudraAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/nether/kuudra/KuudraAPI.kt
@@ -8,7 +8,11 @@ import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.NEUInternalName
+import at.hannibal2.skyhanni.utils.NEUItems.removePrefix
+import at.hannibal2.skyhanni.utils.RegexUtils.matchGroup
import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
+import at.hannibal2.skyhanni.utils.RegexUtils.matches
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
@@ -26,7 +30,35 @@ object KuudraAPI {
"§.\\s*(?:§.)*KUUDRA DOWN!"
)
+ /**
+ * REGEX-TEST: BURNING_AURORA_CHESTPLATE
+ * REGEX-TEST: CRIMSON_LEGGINGS
+ * REGEX-TEST: FIERY_CRIMSON_LEGGINGS
+ * REGEX-TEST: TERROR_CHESTPLATE
+ */
+ private val kuudraArmorPattern by patternGroup.pattern(
+ "internalname.armor",
+ "(?<tier>HOT|BURNING|FIERY|INFERNAL|)_?(?<type>AURORA|CRIMSON|TERROR|HOLLOW|FERVOR)_(?:HELMET|CHESTPLATE|LEGGINGS|BOOTS)"
+ )
+
+ private val kuudraTiers = listOf("", "HOT", "BURNING", "FIERY", "INFERNAL")
+ val kuudraSets = listOf("AURORA", "CRIMSON", "TERROR", "HOLLOW", "FERVOR")
+
+ fun NEUInternalName.isKuudraArmor(): Boolean = kuudraArmorPattern.matches(asString())
+
+ fun NEUInternalName.getKuudraTier(): Int? {
+ val tier = kuudraArmorPattern.matchGroup(asString(), "tier") ?: return null
+ return (kuudraTiers.indexOf(tier) + 1).takeIf { it != 0 }
+ }
+
+ fun NEUInternalName.removeKuudraTier(): NEUInternalName {
+ val prefix = kuudraArmorPattern.matchGroup(asString(), "tier") ?: return this
+ return removePrefix("${prefix}_")
+ }
+
var kuudraTier: Int? = null
+ private set
+
fun inKuudra() = kuudraTier != null
@SubscribeEvent
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
index 75c6173ba..f5db6b429 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
@@ -226,6 +226,13 @@ object NEUItems {
fun NEUInternalName.isVanillaItem(): Boolean = manager.auctionManager.isVanillaItem(this.asString())
+ fun NEUInternalName.removePrefix(prefix: String): NEUInternalName {
+ if (prefix.isEmpty()) return this
+ val string = asString()
+ if (!string.startsWith(prefix)) return this
+ return string.substring(prefix.length).asInternalName()
+ }
+
const val itemFontSize = 2.0 / 3.0
fun ItemStack.renderOnScreen(