aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-05-08 23:32:18 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-05-08 23:32:18 +0200
commit8b63debfd5b6f822a7b6fc0ac49d1ebc3d3fb3a2 (patch)
tree9413b48452b5f7b2dd48c0a9936e6deca5f621f8 /src/main/java/at/hannibal2/skyhanni/features
parent55c2614cb69551363607cbdb7f42c38eccd3d38e (diff)
downloadskyhanni-8b63debfd5b6f822a7b6fc0ac49d1ebc3d3fb3a2.tar.gz
skyhanni-8b63debfd5b6f822a7b6fc0ac49d1ebc3d3fb3a2.tar.bz2
skyhanni-8b63debfd5b6f822a7b6fc0ac49d1ebc3d3fb3a2.zip
Added debug command /shshowcropmoneycalculation
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt68
1 files changed, 56 insertions, 12 deletions
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<String, Int>()
+object CropMoneyDisplay {
+ var multipliers = mapOf<String, Int>()
+ 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<List<Any>>()
@@ -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<Any>()
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<String, Array<Double>> {
+ private fun calculateMoneyPerHour(debugList: MutableList<List<Any>>): Map<String, Array<Double>> {
val moneyPerHours = mutableMapOf<String, Array<Double>>()
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