Skip to content

Commit

Permalink
backup changes that hanni requested,
Browse files Browse the repository at this point in the history
  • Loading branch information
RayDeeUx committed Mar 14, 2024
1 parent 1f5e809 commit 9015a08
Showing 1 changed file with 44 additions and 34 deletions.
78 changes: 44 additions & 34 deletions src/main/java/at/hannibal2/skyhanni/features/misc/GeorgeDisplay.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.InventoryCloseEvent
import at.hannibal2.skyhanni.events.InventoryOpenEvent
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.ItemUtils.cleanName
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.LorenzRarity
Expand All @@ -22,13 +21,14 @@ import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.renderables.Renderable
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.util.regex.Matcher

class GeorgeDisplay {

private val config get() = SkyHanniMod.feature.misc.pets.george
private val useFandomWiki get() = SkyHanniMod.feature.commands.betterWiki.useFandom

private val SEPARATOR = ";"
private var isValidChest = false

private val patternGroup = RepoPattern.group("george.tamingcap")
private val neededPetPattern by patternGroup.pattern(
Expand All @@ -52,6 +52,7 @@ class GeorgeDisplay {
if (!offerPetsChestPattern.matches(event.inventoryName)) return
val stack = event.inventoryItems[41] ?: return //the slot #41 = spawn egg with the tooltip
if (!increaseCapItemPattern.matches(stack.cleanName())) return
isValidChest = true
display = drawDisplay(stack.getLore())
}

Expand All @@ -66,41 +67,50 @@ class GeorgeDisplay {
var totalCost = 0.0
for (line in lore)
neededPetPattern.matchMatcher(line) {
val origTierString = group("tier")
val origPetString = group("pet")
val pet = origPetString.convertToInternalNameString().removePrefix("FROST_")
val originalTier = LorenzRarity.getByName(origTierString.uppercase().replace(" ", "_"))?.id ?: 0
val (cheapestTier, petPrice) = findCheapestTier(pet, originalTier)
val displayPetString = "${LorenzRarity.getById(cheapestTier)?.formattedName} $origPetString"
if (petPrice != -1.0) {
totalCost += petPrice
this@buildList.add(
Renderable.clickAndHover(
text = " §7- $displayPetString§7: §6${petPrice.addSeparators()} coins",
tips = listOf(
"§aClick to run §e/ahs ] $origPetString §ato find it on the Auction House.",
"§aNotes: §eSet the rarity filter yourself. §cBooster Cookie required!"
),
onClick = { LorenzUtils.sendCommandToServer("ahs ] $origPetString") }
))
} else {
val typeOfWiki = if (useFandomWiki) "Fandom" else "Official Hypixel"
this@buildList.add(
Renderable.clickAndHover(
text = " §7- $displayPetString§7: §eNot on AH; view its $typeOfWiki article here.",
tips = listOf("§eClick to open the $typeOfWiki Wiki article for the $displayPetString §eto view how to obtain it."),
onClick = {
val urlCompliantPet = displayPetString.removeColor().replace(" ", "%20")
if (useFandomWiki) OSUtils.openBrowser("https://hypixel-skyblock.fandom.com/wiki/Special:Search?query=$urlCompliantPet&scope=internal")
else OSUtils.openBrowser("https://wiki.hypixel.net/index.php?search=$urlCompliantPet")
}
))
}
calculateCheapestPricesWithPets(this, totalCost, this@buildList)
}
this.add(Renderable.string("§dTotal cost §7(§6Lowest BIN§7): §6${totalCost.addSeparators()} coins"))
if (config.otherRarities) this.add(Renderable.string("§c§lDisclaimer:§r§c Total does not include costs to upgrade via Kat."))
}

private fun calculateCheapestPricesWithPets(
matcher: Matcher,
totalCost: Double,
renderables: MutableList<Renderable>
): Boolean {
var totalCost1 = totalCost
val origTierString = matcher.group("tier")
val origPetString = matcher.group("pet")
val pet = origPetString.convertToInternalNameString().removePrefix("FROST_")
val originalTier = LorenzRarity.getByName(origTierString.uppercase().replace(" ", "_"))?.id ?: 0
val (cheapestTier, petPrice) = findCheapestTier(pet, originalTier)
val displayPetString = "${LorenzRarity.getById(cheapestTier)?.formattedName} $origPetString"
return if (petPrice != -1.0) {
totalCost1 += petPrice
renderables.add(
Renderable.clickAndHover(
text = " §7- $displayPetString§7: §6${petPrice.addSeparators()} coins",
tips = listOf(
"§eClick to run §a/ahs ] $origPetString §eto find it on the AH.",
"§eNotes: Set the rarity filter yourself. §cBooster Cookie required!"
),
onClick = { LorenzUtils.sendCommandToServer("ahs ] $origPetString") }
))
} else {
val typeOfWiki = if (useFandomWiki) "Fandom" else "Official Hypixel"
renderables.add(
Renderable.clickAndHover(
text = " §7- $displayPetString§7: §eNot on AH; open it on $typeOfWiki.",
tips = listOf("§eView the $typeOfWiki Wiki article for $displayPetString §ehere."),
onClick = {
val urlCompliantPet = displayPetString.removeColor().replace(" ", "%20")
if (useFandomWiki) OSUtils.openBrowser("https://hypixel-skyblock.fandom.com/wiki/Special:Search?query=$urlCompliantPet&scope=internal")
else OSUtils.openBrowser("https://wiki.hypixel.net/index.php?search=$urlCompliantPet")
}
))
}
}

private fun findCheapestTier(pet: String, originalTier: Int) = buildList<Pair<Int, Double>> {
this.add(originalTier to petInternalName(pet, originalTier).getPetPrice())
if (config.otherRarities) {
Expand All @@ -116,7 +126,7 @@ class GeorgeDisplay {
@SubscribeEvent
fun onRenderOverlay(event: GuiRenderEvent.ChestGuiOverlayRenderEvent) {
if (!isEnabled()) return
if (!offerPetsChestPattern.matches(InventoryUtils.openInventoryName())) return
if (!isValidChest) return
config.position.renderRenderables(display, posLabel = "George Display")
}

Expand All @@ -127,6 +137,6 @@ class GeorgeDisplay {
}

private fun String.getPetPrice(otherRarity: Boolean = false): Double = this.asInternalName().getPriceOrNull() ?: if (otherRarity) Double.MAX_VALUE else -1.0
private fun petInternalName(pet: String, originalTier: Int) = "$pet$SEPARATOR$originalTier"
private fun petInternalName(pet: String, originalTier: Int) = "$pet;$originalTier"
private fun isEnabled() = LorenzUtils.inSkyBlock && config.enabled
}

0 comments on commit 9015a08

Please sign in to comment.