Skip to content

Commit

Permalink
fix choc shop profit calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
catgirlseraid committed May 16, 2024
1 parent 5d4c57e commit 14016df
Showing 1 changed file with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -48,18 +50,40 @@ object ChocolateShopPrice {
update()
}

private fun ItemStack.loreCosts(): MutableList<NEUInternalName> {
var found = false
val list = mutableListOf<NEUInternalName>()
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
val table = mutableListOf<DisplayTableEntry>()
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
Expand All @@ -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 ")
Expand Down

0 comments on commit 14016df

Please sign in to comment.