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

Backend: /shdebugprice #2289

Merged
merged 2 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ import at.hannibal2.skyhanni.features.minion.MinionFeatures
import at.hannibal2.skyhanni.features.misc.CollectionTracker
import at.hannibal2.skyhanni.features.misc.LockMouseLook
import at.hannibal2.skyhanni.features.misc.MarkedPlayerManager
import at.hannibal2.skyhanni.features.misc.MiscFeatures
import at.hannibal2.skyhanni.features.misc.discordrpc.DiscordRPCManager
import at.hannibal2.skyhanni.features.misc.limbo.LimboTimeTracker
import at.hannibal2.skyhanni.features.misc.massconfiguration.DefaultConfigFeatures
Expand Down Expand Up @@ -87,6 +86,7 @@ import at.hannibal2.skyhanni.test.command.TrackSoundsCommand
import at.hannibal2.skyhanni.utils.APIUtil
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.ExtendedChatColor
import at.hannibal2.skyhanni.utils.ItemPriceUtils
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.SoundUtils
import at.hannibal2.skyhanni.utils.TabListData
Expand Down Expand Up @@ -452,6 +452,7 @@ object Commands {
"shtestisland",
"Sets the current skyblock island for testing purposes.",
) { SkyBlockIslandTest.onCommand(it) }
registerCommand("shdebugprice", "Debug different price sources for an item.") { ItemPriceUtils.debugItemPrice(it) }
}

private fun developersCodingHelp() {
Expand Down
66 changes: 66 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/utils/ItemPriceUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package at.hannibal2.skyhanni.utils

import at.hannibal2.skyhanni.features.inventory.bazaar.BazaarApi.getBazaarData
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
import at.hannibal2.skyhanni.utils.ItemUtils.itemName
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName
import at.hannibal2.skyhanni.utils.NEUItems.getItemStackOrNull
import at.hannibal2.skyhanni.utils.NEUItems.getLowestBinOrNull
import at.hannibal2.skyhanni.utils.NEUItems.getNpcPriceOrNull
import at.hannibal2.skyhanni.utils.NEUItems.getPrice
import at.hannibal2.skyhanni.utils.NEUItems.getRawCraftCostOrNull
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators

object ItemPriceUtils {

fun debugItemPrice(args: Array<String>) {
val internalName = getItemOrFromHand(args)
if (internalName == null) {
ChatUtils.userError("Hold an item in hand or do /shdebugprice <item name/id>")
return
}


val defaultPrice = internalName.getPrice().addSeparators()
ChatUtils.chat("${internalName.itemName}§f: §6$defaultPrice")

println("")
println(" Debug Item Price for $internalName ")
println("defaultPrice: $defaultPrice")

println(" #")
for (source in ItemPriceSource.values()) {
val price = internalName.getPrice(source)
println("${source.displayName} price: ${price.addSeparators()}")
}
println(" #")

println(" ")
println("getLowestBinOrNull: ${internalName.getLowestBinOrNull()?.addSeparators()}")

internalName.getBazaarData().let {
println("getBazaarData sellOfferPrice: ${it?.sellOfferPrice?.addSeparators()}")
println("getBazaarData instantBuyPrice: ${it?.instantBuyPrice?.addSeparators()}")
}

println("getNpcPriceOrNull: ${internalName.getNpcPriceOrNull()?.addSeparators()}")
println("getRawCraftCostOrNull: ${internalName.getRawCraftCostOrNull()?.addSeparators()}")
println(" ")
}

// TODO move either into inventory utils or new command utils
fun getItemOrFromHand(args: Array<String>): NEUInternalName? {
val name = args.joinToString(" ")
return if (name.isEmpty()) {
InventoryUtils.getItemInHand()?.getInternalName()
} else {
val internalName = name.asInternalName()
if (internalName.getItemStackOrNull() != null) {
internalName
} else {
NEUInternalName.fromItemNameOrNull(name)
}

}
}
}
11 changes: 9 additions & 2 deletions src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,9 @@ object NEUItems {
return if (priceSource == ItemPriceSource.BAZAAR_INSTANT_BUY) it.sellOfferPrice else it.instantBuyPrice
}

val result = manager.auctionManager.getLowestBin(asString())
if (result != -1L) return result.toDouble()
getLowestBinOrNull()?.let {
return it
}

if (equals("JACK_O_LANTERN")) {
return "PUMPKIN".asInternalName().getPrice(priceSource) + 1
Expand All @@ -208,6 +209,12 @@ object NEUItems {
return getNpcPriceOrNull() ?: getRawCraftCostOrNull(pastRecipes)
}

fun NEUInternalName.getLowestBinOrNull(): Double? {
val result = manager.auctionManager.getLowestBin(asString())
if (result == -1L) return null
return result.toDouble()
}

// If NEU fails to calculate the craft costs, we calculate it ourself.
fun NEUInternalName.getRawCraftCostOrNull(pastRecipes: List<NeuRecipe> = emptyList()): Double? =
manager.auctionManager.getCraftCost(asString())?.craftCost ?: run {
Expand Down
Loading