From 79432868dab02fce68bcd513e01c49bd07271eba Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Mon, 15 Apr 2024 18:54:33 +0200 Subject: New Feature: Profit Per Excavation (#1439) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../fossilexcavator/ExcavatorProfitTracker.kt | 5 +-- .../mining/fossilexcavator/FossilExcavatorAPI.kt | 3 ++ .../mining/fossilexcavator/ProfitPerExcavation.kt | 48 ++++++++++++++++++++++ 3 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/ProfitPerExcavation.kt (limited to 'src/main/java/at/hannibal2/skyhanni/features/mining') diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/ExcavatorProfitTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/ExcavatorProfitTracker.kt index b2bc4a910..f0a3fcaa8 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/ExcavatorProfitTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/ExcavatorProfitTracker.kt @@ -11,7 +11,6 @@ import at.hannibal2.skyhanni.utils.ItemUtils.itemName import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland import at.hannibal2.skyhanni.utils.NEUInternalName -import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName import at.hannibal2.skyhanni.utils.NEUItems.getPrice import at.hannibal2.skyhanni.utils.NumberUtil import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators @@ -63,7 +62,7 @@ class ExcavatorProfitTracker { var fossilDustGained = 0L } - private val scrapItem = "SUSPICIOUS_SCRAP".asInternalName() + private val scrapItem get() = FossilExcavatorAPI.scrapItem private fun drawDisplay(data: Data): List> = buildList { addAsSingletonList("§e§lFossil Excavation Profit Tracker") @@ -137,7 +136,7 @@ class ExcavatorProfitTracker { val name = StringUtils.pluralize(timesExcavated.toInt(), scrapItem.itemName) addAsSingletonList( Renderable.hoverTips( - "${scrapItem.itemName} §7price: §c-${NumberUtil.format(scrapPrice)}", + "$name §7price: §c-${NumberUtil.format(scrapPrice)}", listOf( "§7You paid §c${NumberUtil.format(scrapPrice)} coins §7in total", "§7for all §e$timesExcavated $name", diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/FossilExcavatorAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/FossilExcavatorAPI.kt index 40971c87e..d2e50bd1c 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/FossilExcavatorAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/FossilExcavatorAPI.kt @@ -10,6 +10,7 @@ import at.hannibal2.skyhanni.events.mining.FossilExcavationEvent import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland +import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.matches import at.hannibal2.skyhanni.utils.StringUtils.removeColor @@ -47,6 +48,8 @@ object FossilExcavatorAPI { var inInventory = false var inExcavatorMenu = false + val scrapItem = "SUSPICIOUS_SCRAP".asInternalName() + @SubscribeEvent fun onInventoryOpen(event: InventoryFullyOpenedEvent) { if (!IslandType.DWARVEN_MINES.isInIsland()) return diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/ProfitPerExcavation.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/ProfitPerExcavation.kt new file mode 100644 index 000000000..4ac8dd4ff --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/ProfitPerExcavation.kt @@ -0,0 +1,48 @@ +package at.hannibal2.skyhanni.features.mining.fossilexcavator + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.mining.FossilExcavationEvent +import at.hannibal2.skyhanni.utils.ChatUtils +import at.hannibal2.skyhanni.utils.CollectionUtils.sortedDesc +import at.hannibal2.skyhanni.utils.ItemUtils.itemName +import at.hannibal2.skyhanni.utils.NEUInternalName +import at.hannibal2.skyhanni.utils.NEUItems.getPrice +import at.hannibal2.skyhanni.utils.NumberUtil +import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class ProfitPerExcavation { + private val config get() = SkyHanniMod.feature.mining.fossilExcavator + + @SubscribeEvent + fun onFossilExcavation(event: FossilExcavationEvent) { + if (!config.profitPerExcavation) return + val loot = event.loot + + var totalProfit = 0.0 + val map = mutableMapOf() + loot.forEach { (name, amount) -> + NEUInternalName.fromItemNameOrNull(name)?.let { + val pricePer = it.getPrice() + if (pricePer == -1.0) return@forEach + val profit = amount * pricePer + val text = "Found $name §8${amount.addSeparators()}x §7(§6${NumberUtil.format(profit)}§7)" + map[text] = profit + totalProfit += profit + } + } + + val scrapItem = FossilExcavatorAPI.scrapItem + + val scrapPrice = scrapItem.getPrice() + map["${scrapItem.itemName}: §c-${NumberUtil.format(scrapPrice)}"] = -scrapPrice + totalProfit -= scrapPrice + + val hover = map.sortedDesc().keys.toMutableList() + val profitPrefix = if (totalProfit < 0) "§c" else "§6" + val totalMessage = "Profit this excavation: $profitPrefix${NumberUtil.format(totalProfit)}" + hover.add("") + hover.add("§e$totalMessage") + ChatUtils.hoverableChat(totalMessage, hover) + } +} -- cgit