diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateShopPrice.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateShopPrice.kt index a0b87a27cf3a..aac139ccde08 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateShopPrice.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateShopPrice.kt @@ -9,6 +9,8 @@ import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.itemName import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.NEUInternalName +import at.hannibal2.skyhanni.utils.NEUItems.getPrice import at.hannibal2.skyhanni.utils.NEUItems.getPriceOrNull import at.hannibal2.skyhanni.utils.NumberUtil import at.hannibal2.skyhanni.utils.NumberUtil.million @@ -48,6 +50,25 @@ object ChocolateShopPrice { update() } + private fun ItemStack.loreCosts(): MutableList { + var found = false + val list = mutableListOf() + for (lines in getLore()) { + if (lines == "§7Cost") { + found = true + continue + } + + if (!found) continue + if (lines.isEmpty()) return list + + NEUInternalName.fromItemNameOrNull(lines)?.let { + list.add(it) + } + } + return list + } + private fun update() { val multiplier = 1.million // TODO merge core with SkyMartCopperPrice into a utils @@ -55,11 +76,14 @@ object ChocolateShopPrice { val inventoryItems = inventoryItems for ((slot, item) in inventoryItems) { val lore = item.getLore() + val otherItemsPrice = item.loreCosts().sumOf { it.getPrice() }.takeIf { it != 0.0 } + val chocolate = ChocolateFactoryAPI.getChocolateBuyCost(lore) ?: continue val internalName = item.getInternalName() val itemPrice = internalName.getPriceOrNull() ?: continue + val profit = itemPrice - (otherItemsPrice ?: 0.0) - val factor = (itemPrice / chocolate) * multiplier + val factor = (profit / chocolate) * multiplier val perFormat = NumberUtil.format(factor) val itemName = item.itemName @@ -68,11 +92,13 @@ object ChocolateShopPrice { add("") add("§7Item price: §6${NumberUtil.format(itemPrice)} ") - add("§7Chocolate amount: §c${NumberUtil.format(chocolate)} ") - + otherItemsPrice?.let { + add("§7Additional cost: §6${NumberUtil.format(it)} ") + } + add("§7Profit per purchase: §6${NumberUtil.format(profit)} ") add("") + add("§7Chocolate amount: §c${NumberUtil.format(chocolate)} ") add("§7Profit per million chocolate: §6${perFormat} ") - add("") val formattedTimeUntilGoal = ChocolateAmount.CURRENT.formattedTimeUntilGoal(chocolate) add("§7Time until affordable: §6$formattedTimeUntilGoal ")