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

Fix: Stackoverflow for getPrice #2199

Merged
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
10 changes: 2 additions & 8 deletions src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -423,15 +423,9 @@ object ItemUtils {
return neededItems
}

fun getRecipePrice(recipe: NeuRecipe): Double =
fun getRecipePrice(recipe: NeuRecipe, pastRecipes: List<NeuRecipe> = emptyList()): Double =
neededItems(recipe).map {
// prevents stack overflow errors with ENDERMAN_MONSTER
if (it.key.endsWith("_MONSTER")) {
0.0
} else {
it.key.getPrice() * it.value
}
it.key.getPrice(pastRecipes = pastRecipes) * it.value
}.sum()


}
15 changes: 9 additions & 6 deletions src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ object NEUItems {
fun getInternalNameOrNull(nbt: NBTTagCompound): NEUInternalName? =
ItemResolutionQuery(manager).withItemNBT(nbt).resolveInternalName()?.asInternalName()

fun NEUInternalName.getPrice(useSellPrice: Boolean = false) = getPriceOrNull(useSellPrice) ?: -1.0
fun NEUInternalName.getPrice(useSellPrice: Boolean = false, pastRecipes: List<NeuRecipe> = emptyList()) =
getPriceOrNull(useSellPrice, pastRecipes) ?: -1.0

fun NEUInternalName.getNpcPrice() = getNpcPriceOrNull() ?: -1.0

Expand All @@ -174,7 +175,7 @@ object NEUItems {
fun transHypixelNameToInternalName(hypixelId: String): NEUInternalName =
manager.auctionManager.transformHypixelBazaarToNEUItemId(hypixelId).asInternalName()

fun NEUInternalName.getPriceOrNull(useSellPrice: Boolean = false): Double? {
fun NEUInternalName.getPriceOrNull(useSellPrice: Boolean = false, pastRecipes: List<NeuRecipe> = emptyList()): Double? {
if (this == NEUInternalName.WISP_POTION) {
return 20_000.0
}
Expand All @@ -194,13 +195,15 @@ object NEUItems {
return 7.0 // NPC price
}

return getNpcPriceOrNull() ?: getRawCraftCostOrNull()
return getNpcPriceOrNull() ?: getRawCraftCostOrNull(pastRecipes)
}

// If NEU fails to calculate the craft costs, we calculate it ourself.
fun NEUInternalName.getRawCraftCostOrNull(): Double? = manager.auctionManager.getCraftCost(asString())?.craftCost ?: run {
getRecipes(this).map { ItemUtils.getRecipePrice(it) }.minOrNull()
}
fun NEUInternalName.getRawCraftCostOrNull(pastRecipes: List<NeuRecipe> = emptyList()): Double? =
manager.auctionManager.getCraftCost(asString())?.craftCost ?: run {
getRecipes(this).filter { it !in pastRecipes }
.map { ItemUtils.getRecipePrice(it, pastRecipes + it) }.minOrNull()
}

fun NEUInternalName.getItemStackOrNull(): ItemStack? = ItemResolutionQuery(manager)
.withKnownInternalName(asString())
Expand Down
Loading