Skip to content

Commit

Permalink
Improvement: CF Shop non purhcaseable (#3095)
Browse files Browse the repository at this point in the history
Co-authored-by: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com>
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 20, 2024
1 parent 0d09339 commit 92ebf2a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import at.hannibal2.skyhanni.utils.RegexUtils.groupOrNull
import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import at.hannibal2.skyhanni.utils.RegexUtils.matches
import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables
import at.hannibal2.skyhanni.utils.StringUtils.addStrikethorugh
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.UtilsPatterns
import at.hannibal2.skyhanni.utils.renderables.Renderable
Expand Down Expand Up @@ -107,8 +108,9 @@ object ChocolateShopPrice {
val internalName = item.getInternalName()
val itemPrice = internalName.getPriceOrNull() ?: continue
val otherItemsPrice = item.loreCosts().sumOf { it.getPrice() }.takeIf { it != 0.0 }
val canBeBought = lore.any { it == "§eClick to trade!" }

newProducts.add(Product(slot, item.itemName, internalName, chocolate, itemPrice, otherItemsPrice))
newProducts.add(Product(slot, item.itemName, internalName, chocolate, itemPrice, otherItemsPrice, canBeBought))
}
products = newProducts
}
Expand Down Expand Up @@ -141,10 +143,15 @@ object ChocolateShopPrice {
add("")
val formattedTimeUntilGoal = ChocolateAmount.CURRENT.formattedTimeUntilGoal(product.chocolate)
add("§7Time until affordable: §6$formattedTimeUntilGoal ")

if (!product.canBeBought) {
add("")
add("§cCannot be bought!")
}
}
table.add(
DisplayTableEntry(
"${product.name}§f:",
product.name.addStrikethorugh(!product.canBeBought),
"§6§l$perFormat",
factor,
product.item,
Expand Down Expand Up @@ -205,5 +212,6 @@ object ChocolateShopPrice {
val chocolate: Long,
val itemPrice: Double,
val otherItemPrice: Double?,
val canBeBought: Boolean,
)
}
9 changes: 9 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package at.hannibal2.skyhanni.utils
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.data.hypixel.chat.event.SystemMessageEvent
import at.hannibal2.skyhanni.mixins.transformers.AccessorChatComponentText
import at.hannibal2.skyhanni.utils.ColorUtils.getFirstColorCode
import at.hannibal2.skyhanni.utils.GuiRenderUtils.darkenColor
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.RegexUtils.findAll
Expand Down Expand Up @@ -525,4 +526,12 @@ object StringUtils {
if (string.isEmpty()) return ""
return if (string[0] in "aeiou") "an" else "a"
}

fun String.addStrikethorugh(strikethorugh: Boolean = true): String {
if (!strikethorugh) return this

val firstColor = getFirstColorCode()
val clean = removeColor()
return "§$firstColor§m$clean"
}
}

0 comments on commit 92ebf2a

Please sign in to comment.