aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features/garden
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-08-28 19:11:40 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-08-28 19:11:40 +0200
commit7eb3e77e5ce50989af3cd4ab2b196fb0df76e168 (patch)
tree2036c9b99d2475f546481ad88ab48091ba59c249 /src/main/java/at/hannibal2/skyhanni/features/garden
parent76c81de8442ccf2726abeecb8a73c0c6cab054db (diff)
downloadskyhanni-7eb3e77e5ce50989af3cd4ab2b196fb0df76e168.tar.gz
skyhanni-7eb3e77e5ce50989af3cd4ab2b196fb0df76e168.tar.bz2
skyhanni-7eb3e77e5ce50989af3cd4ab2b196fb0df76e168.zip
Removing npc price from bazaar data and Fixed multiple bugs with garden visitor
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/garden')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt30
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt93
2 files changed, 75 insertions, 48 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 f33ae9070..53de2fa9a 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
@@ -21,6 +21,8 @@ import at.hannibal2.skyhanni.utils.LorenzUtils.moveEntryToTop
import at.hannibal2.skyhanni.utils.LorenzUtils.sortedDesc
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName
import at.hannibal2.skyhanni.utils.NEUItems.getItemStack
+import at.hannibal2.skyhanni.utils.NEUItems.getNpcPrice
+import at.hannibal2.skyhanni.utils.NEUItems.getNpcPriceOrNull
import at.hannibal2.skyhanni.utils.NEUItems.getPrice
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems
@@ -116,8 +118,8 @@ object CropMoneyDisplay {
val redMushroom = "ENCHANTED_RED_MUSHROOM".asInternalName()
val brownMushroom = "ENCHANTED_BROWN_MUSHROOM".asInternalName()
val (redPrice, brownPrice) = if (LorenzUtils.noTradeMode) {
- val redPrice = (redMushroom.getBazaarData()?.npcPrice ?: 160.0) / 160
- val brownPrice = (brownMushroom.getBazaarData()?.npcPrice ?: 160.0) / 160
+ val redPrice = (redMushroom.getNpcPriceOrNull() ?: 160.0) / 160
+ val brownPrice = (brownMushroom.getNpcPriceOrNull() ?: 160.0) / 160
redPrice to brownPrice
} else {
val redPrice = redMushroom.getPrice() / 160
@@ -132,20 +134,20 @@ object CropMoneyDisplay {
if (InventoryUtils.itemInHandId.contains("DICER") && config.moneyPerHourDicer) {
var dicerDrops = 0.0
- var bazaarData: BazaarData? = null
+ val internalName: NEUInternalName
if (it == CropType.MELON) {
dicerDrops = GardenCropSpeed.latestMelonDicer
- bazaarData = "ENCHANTED_MELON".asInternalName().getBazaarData()
- }
- if (it == CropType.PUMPKIN) {
+ internalName = "ENCHANTED_MELON".asInternalName()
+ } else if (it == CropType.PUMPKIN) {
dicerDrops = GardenCropSpeed.latestPumpkinDicer
- bazaarData = "ENCHANTED_PUMPKIN".asInternalName().getBazaarData()
- }
- if (bazaarData != null) {
- val price =
- if (LorenzUtils.noTradeMode) bazaarData.npcPrice / 160 else (bazaarData.sellPrice + bazaarData.buyPrice) / 320
- extraDicerCoins = 60 * 60 * GardenCropSpeed.getRecentBPS() * dicerDrops * price
+ internalName = "ENCHANTED_PUMPKIN".asInternalName()
+ } else {
+ error("Impossible")
}
+ val bazaarData = internalName.getBazaarData()
+ val price =
+ if (LorenzUtils.noTradeMode || bazaarData == null) internalName.getNpcPrice() / 160 else (bazaarData.sellPrice + bazaarData.buyPrice) / 320
+ extraDicerCoins = 60 * 60 * GardenCropSpeed.getRecentBPS() * dicerDrops * price
}
}
@@ -312,7 +314,7 @@ object CropMoneyDisplay {
val bazaarData = internalName.getBazaarData() ?: continue
- var npcPrice = bazaarData.npcPrice * cropsPerHour
+ var npcPrice = internalName.getNpcPrice() * cropsPerHour
var sellOffer = bazaarData.buyPrice * cropsPerHour
var instantSell = bazaarData.sellPrice * cropsPerHour
if (debug) {
@@ -331,7 +333,7 @@ object CropMoneyDisplay {
if (debug) {
debugList.addAsSingletonList(" added seedsPerHour: $seedsPerHour")
}
- npcPrice += it.npcPrice * seedsPerHour
+ npcPrice += internalName.getNpcPrice() * seedsPerHour
sellOffer += it.buyPrice * seedsPerHour
instantSell += it.sellPrice * seedsPerHour
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt
index 17a01573a..47e229355 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt
@@ -57,7 +57,7 @@ class GardenVisitorFeatures {
private val visitorChatMessagePattern = "§e\\[NPC] (§.)?(?<name>.*)§f: §r.*".toPattern()
private val logger = LorenzLogger("garden/visitors")
- private var price = 0.0
+ private var lastFullPrice = 0.0
private val offerCache = mutableListOf<String>()
companion object {
@@ -304,7 +304,7 @@ class GardenVisitorFeatures {
if (event.slot.stack?.getLore()?.any { it == "§eClick to give!" } == true) {
changeStatus(visitor, VisitorStatus.ACCEPTED, "accepted")
update()
- GardenVisitorDropStatistics.coinsSpent += round(price).toLong()
+ GardenVisitorDropStatistics.coinsSpent += round(lastFullPrice).toLong()
GardenVisitorDropStatistics.lastAccept = System.currentTimeMillis()
return
}
@@ -358,7 +358,7 @@ class GardenVisitorFeatures {
if (event.itemStack.name != "§aAccept Offer") return
if (offerCache.isEmpty()) {
- drawToolTip(event.toolTip.listIterator())
+ drawToolTip(event.toolTip)
val temp = event.toolTip.listIterator()
for (line in temp) {
offerCache.add(line)
@@ -374,42 +374,36 @@ class GardenVisitorFeatures {
}
}
- private fun drawToolTip(iterator: MutableListIterator<String>) {
+ private fun drawToolTip(list: MutableList<String>) {
+
var totalPrice = 0.0
var timeRequired = -1L
- for (line in iterator) {
+ var readingItemsNeeded = true
+ lastFullPrice = 0.0
+
+ for (line in list) {
val formattedLine = line.substring(4)
+ if (formattedLine.contains("Rewards")) {
+ readingItemsNeeded = false
+ }
+
val (itemName, amount) = ItemUtils.readItemAmount(formattedLine)
- if (itemName != null) {
- var internalName = NEUItems.getInternalNameOrNull(itemName)
- if (internalName != null) {
- internalName = internalName.replace("◆_", "")
- price = internalName.getPrice() * amount
-
- if (config.visitorShowPrice) {
- val format = NumberUtil.format(price)
- iterator.set("$formattedLine §7(§6$format§7)")
- }
- if (totalPrice == 0.0) {
- totalPrice = price
- val multiplier = NEUItems.getMultiplier(internalName)
- val rawName = multiplier.first.getItemNameOrNull()?.removeColor() ?: continue
- getByNameOrNull(rawName)?.let {
- val cropAmount = multiplier.second.toLong() * amount
- val formattedAmount = LorenzUtils.formatInteger(cropAmount)
- val formattedName = "§e$formattedAmount§7x ${it.cropName} "
- val formattedSpeed = it.getSpeed()?.let { speed ->
- timeRequired = cropAmount / speed
- val duration = TimeUtils.formatDuration(timeRequired * 1000)
- "in §b$duration"
- } ?: "§cno speed data!"
- if (config.visitorExactAmountAndTime) {
- iterator.add("§7- $formattedName($formattedSpeed§7)")
- }
- }
- }
- }
+ if (itemName == null) continue
+ val internalName = NEUItems.getInternalNameOrNull(itemName)?.replace("◆_", "") ?: continue
+ val price = internalName.getPrice() * amount
+
+ if (readingItemsNeeded) {
+ totalPrice += price
+ lastFullPrice += price
+ } else {
+ totalPrice -= price
}
+ }
+
+ readingItemsNeeded = true
+ val iterator = list.listIterator()
+ for (line in iterator) {
+ val formattedLine = line.substring(4)
if (config.visitorExperiencePrice) {
gardenExperiencePattern.matchMatcher(formattedLine) {
@@ -430,6 +424,37 @@ class GardenVisitorFeatures {
}
iterator.set(copperLine)
}
+
+ if (formattedLine.contains("Rewards")) {
+ readingItemsNeeded = false
+ }
+
+ val (itemName, amount) = ItemUtils.readItemAmount(formattedLine)
+ if (itemName == null) continue
+ val internalName = NEUItems.getInternalNameOrNull(itemName)?.replace("◆_", "") ?: continue
+ val price = internalName.getPrice() * amount
+
+ if (config.visitorShowPrice) {
+ val format = NumberUtil.format(price)
+ iterator.set("$formattedLine §7(§6$format§7)")
+ }
+ if (!readingItemsNeeded) continue
+ val multiplier = NEUItems.getMultiplier(internalName)
+
+ val rawName = multiplier.first.getItemNameOrNull()?.removeColor() ?: continue
+ val cropType = getByNameOrNull(rawName) ?: return
+
+ val cropAmount = multiplier.second.toLong() * amount
+ val formattedAmount = LorenzUtils.formatInteger(cropAmount)
+ val formattedName = "§e$formattedAmount§7x ${cropType.cropName} "
+ val formattedSpeed = cropType.getSpeed()?.let { speed ->
+ timeRequired = cropAmount / speed
+ val duration = TimeUtils.formatDuration(timeRequired * 1000)
+ "in §b$duration"
+ } ?: "§cno speed data!"
+ if (config.visitorExactAmountAndTime) {
+ iterator.add("§7- $formattedName($formattedSpeed§7)")
+ }
}
}