From df8d1f01dbe2511a766e288e8d110eb6856f0456 Mon Sep 17 00:00:00 2001 From: Phoebe <77941535+catgirlseraid@users.noreply.github.com> Date: Thu, 16 May 2024 20:36:30 +1200 Subject: Fixed choc shop profit calculations (#1805) Co-authored-by: SeRaid <77941535+SeRaid743@users.noreply.github.com> Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../garden/inventory/SkyMartCopperPrice.kt | 22 +--------------------- .../chocolatefactory/ChocolateShopPrice.kt | 15 +++++++++++---- .../java/at/hannibal2/skyhanni/utils/ItemUtils.kt | 19 +++++++++++++++++++ 3 files changed, 31 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/SkyMartCopperPrice.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/SkyMartCopperPrice.kt index 0d86757ea..f7287330d 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/SkyMartCopperPrice.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/SkyMartCopperPrice.kt @@ -9,9 +9,9 @@ import at.hannibal2.skyhanni.utils.DisplayTableEntry 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.ItemUtils.loreCosts import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.round -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 @@ -22,7 +22,6 @@ import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.renderables.Renderable import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import com.google.gson.JsonPrimitive -import net.minecraft.item.ItemStack import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class SkyMartCopperPrice { @@ -40,25 +39,6 @@ class SkyMartCopperPrice { var inInventory = false } - 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 - } - @SubscribeEvent fun onInventoryOpen(event: InventoryFullyOpenedEvent) { if (!isEnabled()) return 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 a0b87a27c..dc942cb0a 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 @@ -8,7 +8,9 @@ import at.hannibal2.skyhanni.utils.DisplayTableEntry 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.ItemUtils.loreCosts import at.hannibal2.skyhanni.utils.LorenzUtils +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 @@ -55,11 +57,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 +73,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 ") diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt index c7c70d949..3026b0c56 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt @@ -386,4 +386,23 @@ object ItemUtils { } return name } + + 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 + } } -- cgit