diff options
author | Phoebe <77941535+catgirlseraid@users.noreply.github.com> | 2024-05-16 20:36:30 +1200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-16 10:36:30 +0200 |
commit | df8d1f01dbe2511a766e288e8d110eb6856f0456 (patch) | |
tree | 63e8ca24154965acce6e011655989ceb6fc43fb0 /src/main | |
parent | 388a656c95c745c8cced86931e9ab30e10e3bb9e (diff) | |
download | skyhanni-df8d1f01dbe2511a766e288e8d110eb6856f0456.tar.gz skyhanni-df8d1f01dbe2511a766e288e8d110eb6856f0456.tar.bz2 skyhanni-df8d1f01dbe2511a766e288e8d110eb6856f0456.zip |
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>
Diffstat (limited to 'src/main')
3 files changed, 31 insertions, 25 deletions
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<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 - } - @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<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 + } } |