diff options
Diffstat (limited to 'src/main/kotlin/repo/SBItemStack.kt')
-rw-r--r-- | src/main/kotlin/repo/SBItemStack.kt | 62 |
1 files changed, 48 insertions, 14 deletions
diff --git a/src/main/kotlin/repo/SBItemStack.kt b/src/main/kotlin/repo/SBItemStack.kt index da34707..01d1c4d 100644 --- a/src/main/kotlin/repo/SBItemStack.kt +++ b/src/main/kotlin/repo/SBItemStack.kt @@ -34,6 +34,7 @@ import moe.nea.firmament.util.modifyExtraAttributes import moe.nea.firmament.util.petData import moe.nea.firmament.util.prepend import moe.nea.firmament.util.reconstitute +import moe.nea.firmament.util.removeColorCodes import moe.nea.firmament.util.skyBlockId import moe.nea.firmament.util.skyblock.ItemType import moe.nea.firmament.util.skyblock.Rarity @@ -81,6 +82,7 @@ data class SBItemStack constructor( } val EMPTY = SBItemStack(SkyblockId.NULL, 0) + private val BREAKING_POWER_REGEX = "Breaking Power (?<power>[0-9]+)".toPattern() operator fun invoke(itemStack: ItemStack): SBItemStack { val skyblockId = itemStack.skyBlockId ?: SkyblockId.NULL return SBItemStack( @@ -223,14 +225,21 @@ data class SBItemStack constructor( Text.literal( buffKind.prefix + formattedAmount + statFormatting.postFix + - buffKind.postFix + " ") - .withColor(buffKind.color))) + buffKind.postFix + " " + ) + .withColor(buffKind.color) + ) + ) } fun formatValue() = - Text.literal(FirmFormatters.formatCommas(valueNum ?: 0.0, - 1, - includeSign = true) + statFormatting.postFix + " ") + Text.literal( + FirmFormatters.formatCommas( + valueNum ?: 0.0, + 1, + includeSign = true + ) + statFormatting.postFix + " " + ) .setStyle(Style.EMPTY.withColor(statFormatting.color)) val statFormatting = formattingOverrides[statName] ?: StatFormatting("", Formatting.GREEN) @@ -254,7 +263,7 @@ data class SBItemStack constructor( return segments.joinToString(" ") { it.replaceFirstChar { it.uppercaseChar() } } } - private fun parseStatLine(line: Text): StatLine? { + fun parseStatLine(line: Text): StatLine? { val sibs = line.siblings val stat = sibs.firstOrNull() ?: return null if (stat.style.color != TextColor.fromFormatting(Formatting.GRAY)) return null @@ -344,11 +353,20 @@ data class SBItemStack constructor( } // TODO: avoid instantiating the item stack here + @ExpensiveItemCacheApi val itemType: ItemType? get() = ItemType.fromItemStack(asImmutableItemStack()) + @ExpensiveItemCacheApi val rarity: Rarity? get() = Rarity.fromItem(asImmutableItemStack()) private var itemStack_: ItemStack? = null + val breakingPower: Int + get() = + BREAKING_POWER_REGEX.useMatch(neuItem?.lore?.firstOrNull()?.removeColorCodes()) { + group("power").toInt() + } ?: 0 + + @ExpensiveItemCacheApi private val itemStack: ItemStack get() { val itemStack = itemStack_ ?: run { @@ -405,19 +423,35 @@ data class SBItemStack constructor( .append(starString(stars)) val isDungeon = ItemType.fromItemStack(itemStack)?.isDungeon ?: true val truncatedStarCount = if (isDungeon) minOf(5, stars) else stars - appendEnhancedStats(itemStack, - baseStats - .filter { it.statFormatting.isStarAffected } - .associate { - it.statName to ((it.valueNum ?: 0.0) * (truncatedStarCount * 0.02)) - }, - BuffKind.STAR_BUFF) + appendEnhancedStats( + itemStack, + baseStats + .filter { it.statFormatting.isStarAffected } + .associate { + it.statName to ((it.valueNum ?: 0.0) * (truncatedStarCount * 0.02)) + }, + BuffKind.STAR_BUFF + ) + } + + fun isWarm(): Boolean { + if (itemStack_ != null) return true + if (ItemCache.hasCacheFor(skyblockId)) return true + return false + } + + @OptIn(ExpensiveItemCacheApi::class) + fun asLazyImmutableItemStack(): ItemStack? { + if (isWarm()) return asImmutableItemStack() + return null } - fun asImmutableItemStack(): ItemStack { + @ExpensiveItemCacheApi + fun asImmutableItemStack(): ItemStack { // TODO: add a "or fallback to painting" option to asLazyImmutableItemStack to be used in more places. return itemStack } + @ExpensiveItemCacheApi fun asCopiedItemStack(): ItemStack { return itemStack.copy() } |