Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement: Descriptive Milestones in Hoppity Collection #2523

Merged
merged 10 commits into from
Sep 20, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ data class HoppityEggLocationsJson(
@Expose val maxRabbits: Int,
@Expose val maxPrestige: Int,
@Expose val chocolateMilestones: TreeSet<Long>,
@Expose val chocolateShopMilestones: List<MilestoneJson>,
@Expose val chocolateFactoryMilestones: List<MilestoneJson>,
@Expose val apiEggLocations: Map<IslandType, Map<String, LorenzVec>>,
@Expose val specialRabbits: List<String>,
)

data class MilestoneJson(
@Expose val amount: Long,
@Expose val rabbit: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ import at.hannibal2.skyhanni.utils.NEUInternalName
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.NumberUtil.formatInt
import at.hannibal2.skyhanni.utils.NumberUtil.shortFormat
import at.hannibal2.skyhanni.utils.RegexUtils.anyMatches
import at.hannibal2.skyhanni.utils.RegexUtils.findMatcher
import at.hannibal2.skyhanni.utils.RegexUtils.firstMatcher
import at.hannibal2.skyhanni.utils.RegexUtils.matches
import at.hannibal2.skyhanni.utils.RenderUtils.highlight
import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables
import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getMinecraftId
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.renderables.Renderable
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
Expand Down Expand Up @@ -187,29 +187,14 @@ object HoppityCollectionStats {
strayRabbit to HighlightRabbitTypes.STRAYS,
)

private fun missingRabbitStackNeedsFix(stack: ItemStack): Boolean =
stack.item == Items.dye && (stack.metadata == 8 || stack.getLore().any { it.lowercase().contains("milestone") })

private val replacementCache: MutableMap<String, ItemStack> = mutableMapOf()

@SubscribeEvent
fun replaceItem(event: ReplaceItemEvent) {
if (!config.rarityDyeRecolor || !pagePattern.matches(event.inventory.name)) return
val item = event.originalItem
// The "base" missing rabbits are Gray Dye (minecraft:dye with metadata 8)
if (item.getMinecraftId().toString() != "minecraft:dye" || item.metadata != 8) return

val rarity = HoppityAPI.rarityByRabbit(item.displayName)
// Add NBT for the dye color itself
val newItemStack = ItemStack(Items.dye, 1, when (rarity) {
LorenzRarity.COMMON -> 7 // Light gray dye
LorenzRarity.UNCOMMON -> 10 // Lime dye
LorenzRarity.RARE -> 4 // Lapis lazuli
LorenzRarity.EPIC -> 5 // Purple dye
LorenzRarity.LEGENDARY -> 14 // Orange dye
LorenzRarity.MYTHIC -> 13 // Magenta dye
LorenzRarity.DIVINE -> 12 // Light blue dye
LorenzRarity.SPECIAL -> 1 // Rose Red - Covering bases for future (?)
else -> return
})
newItemStack.setLore(item.getLore())
newItemStack.setStackDisplayName(item.displayName)
event.replace(newItemStack)
replacementCache[event.originalItem.displayName]?.let { event.replace(it) }
}

@SubscribeEvent
Expand All @@ -221,6 +206,29 @@ object HoppityCollectionStats {
return
}

event.inventoryItems.values.filter { it.hasDisplayName() && missingRabbitStackNeedsFix(it) }.forEach { stack ->
val rarity = HoppityAPI.rarityByRabbit(stack.displayName)
// Add NBT for the dye color itself
val newItemStack = if (config.rarityDyeRecolor) ItemStack(
Items.dye, 1,
when (rarity) {
LorenzRarity.COMMON -> 7 // Light gray dye
LorenzRarity.UNCOMMON -> 10 // Lime dye
LorenzRarity.RARE -> 4 // Lapis lazuli
LorenzRarity.EPIC -> 5 // Purple dye
LorenzRarity.LEGENDARY -> 14 // Orange dye
LorenzRarity.MYTHIC -> 13 // Magenta dye
LorenzRarity.DIVINE -> 12 // Light blue dye
LorenzRarity.SPECIAL -> 1 // Rose Red - Covering bases for future (?)
else -> return
},
) else ItemStack(Items.dye, 8)

newItemStack.setLore(buildDescriptiveMilestoneLore(stack))
newItemStack.setStackDisplayName(stack.displayName)
replacementCache[stack.displayName] = newItemStack
}

inInventory = true
if (config.hoppityCollectionStats) {
display = buildDisplay(event)
Expand All @@ -231,6 +239,38 @@ object HoppityCollectionStats {
}
}

private fun buildDescriptiveMilestoneLore(itemStack: ItemStack): List<String> {
val existingLore = itemStack.getLore().toMutableList()
var replaceIndex: Int? = null
var milestoneType: HoppityEggType = HoppityEggType.BREAKFAST

if (factoryMilestone.anyMatches(existingLore)) {
milestoneType = HoppityEggType.CHOCOLATE_FACTORY_MILESTONE
replaceIndex = existingLore.indexOfFirst { loreMatch -> factoryMilestone.matches(loreMatch) }
} else if (shopMilestone.anyMatches(existingLore)) {
milestoneType = HoppityEggType.CHOCOLATE_SHOP_MILESTONE
replaceIndex = existingLore.indexOfFirst { loreMatch -> shopMilestone.matches(loreMatch) }
}

replaceIndex?.let {
ChocolateFactoryAPI.milestoneByRabbit(itemStack.displayName)?.let {
val displayAmount = it.amount.shortFormat()
val operationFormat = when (milestoneType) {
HoppityEggType.CHOCOLATE_SHOP_MILESTONE -> "spending"
HoppityEggType.CHOCOLATE_FACTORY_MILESTONE -> "reaching"
else -> "" // Never happens
}

//List indexing is weird
existingLore[replaceIndex - 1] = "§7Obtained by $operationFormat §6$displayAmount"
existingLore[replaceIndex] = "§7all-time §6Chocolate."
return existingLore
}
}

return existingLore
}

private fun filterRabbitToHighlight(stack: ItemStack) {
val lore = stack.getLore()

Expand Down Expand Up @@ -259,6 +299,7 @@ object HoppityCollectionStats {
fun onInventoryClose(event: InventoryCloseEvent) {
inInventory = false
display = emptyList()
replacementCache.clear()
}

@SubscribeEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import at.hannibal2.skyhanni.config.features.inventory.chocolatefactory.Chocolat
import at.hannibal2.skyhanni.config.storage.ProfileSpecificStorage.ChocolateFactoryStorage
import at.hannibal2.skyhanni.data.ProfileStorageData
import at.hannibal2.skyhanni.data.jsonobjects.repo.HoppityEggLocationsJson
import at.hannibal2.skyhanni.data.jsonobjects.repo.MilestoneJson
import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
import at.hannibal2.skyhanni.events.RepositoryReloadEvent
import at.hannibal2.skyhanni.features.event.hoppity.HoppityCollectionStats
Expand Down Expand Up @@ -80,7 +81,9 @@ object ChocolateFactoryAPI {
var shrineIndex = 41
var coachRabbitIndex = 42
var maxRabbits = 395
var chocolateMilestones = TreeSet<Long>()
private var chocolateMilestones = TreeSet<Long>()
private var chocolateFactoryMilestones: MutableList<MilestoneJson> = mutableListOf()
private var chocolateShopMilestones: MutableList<MilestoneJson> = mutableListOf()
private var maxPrestige = 5

var inChocolateFactory = false
Expand Down Expand Up @@ -143,6 +146,8 @@ object ChocolateFactoryAPI {
maxRabbits = data.maxRabbits
maxPrestige = data.maxPrestige
chocolateMilestones = data.chocolateMilestones
chocolateFactoryMilestones = data.chocolateFactoryMilestones.toMutableList()
chocolateShopMilestones = data.chocolateShopMilestones.toMutableList()
specialRabbitTextures = data.specialRabbits

ChocolateFactoryUpgrade.updateIgnoredSlots()
Expand Down Expand Up @@ -226,4 +231,12 @@ object ChocolateFactoryAPI {
val basePerSecond = rawChocolatePerSecond * baseMultiplier
return (needed / basePerSecond + secondsUntilTowerExpires).seconds
}

fun milestoneByRabbit(rabbitName: String): MilestoneJson? {
return chocolateFactoryMilestones.firstOrNull {
it.rabbit.removeColor() == rabbitName.removeColor()
} ?: chocolateShopMilestones.firstOrNull {
it.rabbit.removeColor() == rabbitName.removeColor()
}
}
}
Loading