Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Profit Per Excavation #1439

Merged
merged 4 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ import at.hannibal2.skyhanni.features.mining.eventtracker.MiningEventDisplay
import at.hannibal2.skyhanni.features.mining.eventtracker.MiningEventTracker
import at.hannibal2.skyhanni.features.mining.fossilexcavator.ExcavatorProfitTracker
import at.hannibal2.skyhanni.features.mining.fossilexcavator.FossilExcavatorAPI
import at.hannibal2.skyhanni.features.mining.fossilexcavator.ProfitPerExcavation
import at.hannibal2.skyhanni.features.mining.fossilexcavator.solver.FossilSolverDisplay
import at.hannibal2.skyhanni.features.mining.powdertracker.PowderTracker
import at.hannibal2.skyhanni.features.minion.InfernoMinionFeatures
Expand Down Expand Up @@ -668,6 +669,7 @@ class SkyHanniMod {
loadModule(ChickenHeadTimer())
loadModule(FossilSolverDisplay)
loadModule(ExcavatorProfitTracker())
loadModule(ProfitPerExcavation())
loadModule(GardenOptimalSpeed())
loadModule(GardenLevelDisplay())
loadModule(FarmingWeightDisplay())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package at.hannibal2.skyhanni.config.features.mining;

import at.hannibal2.skyhanni.config.FeatureToggle;
import com.google.gson.annotations.Expose;
import io.github.notenoughupdates.moulconfig.annotations.Accordion;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean;
import io.github.notenoughupdates.moulconfig.annotations.ConfigOption;

public class FossilExcavatorConfig {
Expand All @@ -16,4 +18,13 @@ public class FossilExcavatorConfig {
@Accordion
public ExcavatorProfitTrackerConfig profitTracker = new ExcavatorProfitTrackerConfig();

@Expose
@ConfigOption(
name = "Profit Per",
desc = "Show profit/loss in chat after each excavation. Also include breakdown information on hover."
)
@ConfigEditorBoolean
@FeatureToggle
public boolean profitPerExcavation = false;

}
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class HideNotClickableItems {
showGreenLine = true

val internalName = stack.getInternalNameOrNull() ?: return true
if (internalName == "SUSPICIOUS_SCRAP".asInternalName()) {
if (internalName == FossilExcavatorAPI.scrapItem) {
return false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<List<Any>> = buildList {
addAsSingletonList("§e§lFossil Excavation Profit Tracker")
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
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<String, Double>()
loot.forEach { (name, amount) ->
NEUInternalName.fromItemNameOrNull(name)?.let {
val profit = amount * it.getPrice()
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()
hannibal002 marked this conversation as resolved.
Show resolved Hide resolved
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)
}
}
Loading