From 8b63debfd5b6f822a7b6fc0ac49d1ebc3d3fb3a2 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Mon, 8 May 2023 23:32:18 +0200 Subject: Added debug command /shshowcropmoneycalculation --- src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt | 2 +- .../hannibal2/skyhanni/config/commands/Commands.kt | 2 + .../features/garden/farming/CropMoneyDisplay.kt | 68 ++++++++++++++++++---- 3 files changed, 59 insertions(+), 13 deletions(-) (limited to 'src/main/java/at') diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 1d92800c7..c829b894b 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -237,7 +237,7 @@ class SkyHanniMod { loadModule(GardenLevelDisplay()) loadModule(EliteFarmingWeight()) loadModule(DicerRngDropCounter()) - loadModule(CropMoneyDisplay()) + loadModule(CropMoneyDisplay) loadModule(JacobFarmingContestsInventory()) loadModule(GardenNextJacobContest()) loadModule(WrongFungiCutterWarning()) diff --git a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt index 65390f4b2..26bb65e56 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt @@ -12,6 +12,7 @@ import at.hannibal2.skyhanni.features.event.diana.InquisitorWaypointShare import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.features.garden.GardenCropTimeCommand import at.hannibal2.skyhanni.features.garden.composter.ComposterOverlay +import at.hannibal2.skyhanni.features.garden.farming.CropMoneyDisplay import at.hannibal2.skyhanni.features.garden.farming.CropSpeedMeter import at.hannibal2.skyhanni.features.minion.MinionFeatures import at.hannibal2.skyhanni.features.misc.CollectionCounter @@ -68,6 +69,7 @@ object Commands { registerCommand("shtestgardenvisitors") { SkyHanniTestCommand.testGardenVisitors() } registerCommand("shtestcomposter") { ComposterOverlay.onCommand(it) } registerCommand("shtestinquisitor") { InquisitorWaypointShare.test() } + registerCommand("shshowcropmoneycalculation") { CropMoneyDisplay.toggleShowCalculation() } // for developers - coding help registerCommand("shreloadlocalrepo") { SkyHanniMod.repo.reloadLocalRepo() } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt index e6d0edb56..cbb34b623 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt @@ -18,6 +18,7 @@ import at.hannibal2.skyhanni.utils.LorenzUtils.moveEntryToTop import at.hannibal2.skyhanni.utils.LorenzUtils.sortedDesc import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.NumberUtil +import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getReforgeName import at.hannibal2.skyhanni.utils.StringUtils.removeColor @@ -26,9 +27,14 @@ import net.minecraft.client.Minecraft import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.common.gameevent.TickEvent -class CropMoneyDisplay { - companion object { - var multipliers = mapOf() +object CropMoneyDisplay { + var multipliers = mapOf() + var showCalculation = false + + fun toggleShowCalculation() { + showCalculation = !showCalculation + LorenzUtils.chat("§e[SkyHanni] Show crop money calculation: " + if (showCalculation) "enabled" else "disabled") + update() } private var display = listOf>() @@ -107,7 +113,7 @@ class CropMoneyDisplay { } } - val moneyPerHourData = calculateMoneyPerHour() + val moneyPerHourData = calculateMoneyPerHour(newDisplay) if (moneyPerHourData.isEmpty()) { if (!isSpeedDataEmpty()) { val message = "money/hr empty but speed data not empty, retry" @@ -126,9 +132,13 @@ class CropMoneyDisplay { val help = moneyPerHourData.mapValues { (_, value) -> value.max() } for (internalName in help.sortedDesc().keys) { number++ - val cropName = cropNames[internalName]!! - val isCurrent = cropName == GardenAPI.getCurrentlyFarmedCrop() + val crop = cropNames[internalName]!! + val isCurrent = crop == GardenAPI.getCurrentlyFarmedCrop() if (number > config.moneyPerHourShowOnlyBest && (!config.moneyPerHourShowCurrent || !isCurrent)) continue + val debug = isCurrent && showCalculation + if (debug) { + newDisplay.addAsSingletonList("final calculation for: $internalName/$crop") + } val list = mutableListOf() if (!config.moneyPerHourCompact) { @@ -152,7 +162,7 @@ class CropMoneyDisplay { if (!config.moneyPerHourCompact) { val itemName = NEUItems.getItemStack(internalName).name?.removeColor() ?: continue val currentColor = if (isCurrent) "§e" else "§7" - val contestFormat = if (GardenNextJacobContest.isNextCrop(cropName)) "§n" else "" + val contestFormat = if (GardenNextJacobContest.isNextCrop(crop)) "§n" else "" list.add("$currentColor$contestFormat$itemName§7: ") } @@ -160,7 +170,13 @@ class CropMoneyDisplay { val moneyArray = moneyPerHourData[internalName]!! for (price in moneyArray) { - val format = format(price + extraNetherWartPrices) + val finalPrice = price + extraNetherWartPrices + val format = format(finalPrice) + if (debug) { + newDisplay.addAsSingletonList(" price: ${price.addSeparators()}") + newDisplay.addAsSingletonList(" extraNetherWartPrices: ${extraNetherWartPrices.addSeparators()}") + newDisplay.addAsSingletonList(" finalPrice: ${finalPrice.addSeparators()}") + } list.add("$coinsColor$format") list.add("§7/") } @@ -204,15 +220,16 @@ class CropMoneyDisplay { LorenzUtils.formatInteger(moneyPerHour.toLong()) } - private fun calculateMoneyPerHour(): Map> { + private fun calculateMoneyPerHour(debugList: MutableList>): Map> { val moneyPerHours = mutableMapOf>() var seedsPrice: BazaarData? = null var seedsPerHour = 0.0 - val onlyNpcPrice = (!config.moneyPerHourUseCustomFormat && LorenzUtils.noTradeMode) || - (config.moneyPerHourUseCustomFormat && config.moneyPerHourCustomFormat.size == 1 - && config.moneyPerHourCustomFormat[0] == 2) + val onlyNpcPrice = + (!config.moneyPerHourUseCustomFormat && LorenzUtils.noTradeMode) || + (config.moneyPerHourUseCustomFormat && config.moneyPerHourCustomFormat.size == 1 && + config.moneyPerHourCustomFormat[0] == 2) for ((internalName, amount) in multipliers.moveEntryToTop { isSeeds(it.key) }) { val crop = cropNames[internalName]!! @@ -228,21 +245,45 @@ class CropMoneyDisplay { var speed = crop.getSpeed().toDouble() if (speed == -1.0) continue + val isCurrent = crop == GardenAPI.getCurrentlyFarmedCrop() + val debug = isCurrent && showCalculation + if (debug) { + debugList.addAsSingletonList("calculateMoneyPerHour: $internalName/$crop") + debugList.addAsSingletonList(" speed: ${speed.addSeparators()}") + } + val isSeeds = isSeeds(internalName) + if (debug) { + debugList.addAsSingletonList(" isSeeds: $isSeeds") + } if (isSeeds) speed *= 1.36 if (crop.replenish) { val blockPerSecond = crop.multiplier * 20 + if (debug) { + debugList.addAsSingletonList(" replenish blockPerSecond reduction: ${blockPerSecond.addSeparators()}") + } speed -= blockPerSecond } val speedPerHour = speed * 60 * 60 + if (debug) { + debugList.addAsSingletonList(" speedPerHour: ${speedPerHour.addSeparators()}") + } val cropsPerHour = speedPerHour / amount.toDouble() + if (debug) { + debugList.addAsSingletonList(" cropsPerHour: ${cropsPerHour.addSeparators()}") + } val bazaarData = BazaarApi.getBazaarDataByInternalName(internalName) ?: continue var npcPrice = bazaarData.npcPrice * cropsPerHour var sellOffer = bazaarData.buyPrice * cropsPerHour var instantSell = bazaarData.sellPrice * cropsPerHour + if (debug) { + debugList.addAsSingletonList(" npcPrice: ${npcPrice.addSeparators()}") + debugList.addAsSingletonList(" sellOffer: ${sellOffer.addSeparators()}") + debugList.addAsSingletonList(" instantSell: ${instantSell.addSeparators()}") + } if (crop == CropType.WHEAT && config.moneyPerHourMergeSeeds) { if (isSeeds) { @@ -251,6 +292,9 @@ class CropMoneyDisplay { continue } else { seedsPrice?.let { + if (debug) { + debugList.addAsSingletonList(" added seedsPerHour: $seedsPerHour") + } npcPrice += it.npcPrice * seedsPerHour sellOffer += it.buyPrice * seedsPerHour instantSell += it.sellPrice * seedsPerHour -- cgit