diff options
10 files changed, 99 insertions, 83 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/SlayerAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/SlayerAPI.kt index 62e151d2f..3a3bd8b33 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/SlayerAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/SlayerAPI.kt @@ -1,7 +1,6 @@ package at.hannibal2.skyhanni.data import at.hannibal2.skyhanni.events.* -import at.hannibal2.skyhanni.features.bazaar.BazaarApi.Companion.getBazaarData import at.hannibal2.skyhanni.features.slayer.SlayerType import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.ItemUtils.nameWithEnchantment @@ -9,6 +8,7 @@ import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.nextAfter import at.hannibal2.skyhanni.utils.NEUInternalName import at.hannibal2.skyhanni.utils.NEUItems.getItemStack +import at.hannibal2.skyhanni.utils.NEUItems.getNpcPriceOrNull import at.hannibal2.skyhanni.utils.NEUItems.getPrice import at.hannibal2.skyhanni.utils.NumberUtil import at.hannibal2.skyhanni.utils.StringUtils.removeColor @@ -67,7 +67,7 @@ object SlayerAPI { val displayName = getNameWithEnchantmentFor(internalName) val price = internalName.getPrice() - val npcPrice = internalName.getBazaarData()?.npcPrice ?: 0.0 + val npcPrice = internalName.getNpcPriceOrNull() ?: 0.0 val maxPrice = npcPrice.coerceAtLeast(price) val totalPrice = maxPrice * amount diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarData.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarData.kt index 3562be68a..daed03152 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarData.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarData.kt @@ -4,5 +4,4 @@ data class BazaarData( val displayName: String, val sellPrice: Double, val buyPrice: Double, - val npcPrice: Double, )
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataHolder.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataHolder.kt index 039b57540..61f19a630 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataHolder.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataHolder.kt @@ -18,6 +18,8 @@ class BazaarDataHolder { companion object { private val bazaarData = mutableMapOf<NEUInternalName, BazaarData>() private var npcPrices = mapOf<NEUInternalName, Double>() + + fun getNpcPrice(internalName: NEUInternalName) = npcPrices[internalName] } private fun loadNpcPrices(): MutableMap<NEUInternalName, Double> { @@ -66,29 +68,9 @@ class BazaarDataHolder { val displayName = stack.name!!.removeColor() val sellPrice = internalName.getPrice(true) val buyPrice = internalName.getPrice(false) - val npcPrice = npcPrices[internalName].let { - if (it == null) { - if (!ignoreNoNpcPrice(internalName)) { - LorenzUtils.debug("NPC price not found for '$internalName'") - } - 0.0 - } else it - } - val data = BazaarData(displayName, sellPrice, buyPrice, npcPrice) + val data = BazaarData(displayName, sellPrice, buyPrice) bazaarData[internalName] = data return data } - - private fun ignoreNoNpcPrice(internalName: NEUInternalName): Boolean { - if (internalName.startsWith("TURBO_")) return true - if (internalName.equals("PURPLE_CANDY")) return true - if (internalName.equals("JACOBS_TICKET")) return true - if (internalName.equals("RAW_SOULFLOW")) return true - if (internalName.equals("DERELICT_ASHE")) return true - - if (internalName.contains(";")) return true - - return false - } }
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/fame/CityProjectFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/fame/CityProjectFeatures.kt index 8e2c2e13a..c27bc0740 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/fame/CityProjectFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/fame/CityProjectFeatures.kt @@ -4,7 +4,6 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.data.ProfileStorageData import at.hannibal2.skyhanni.events.* import at.hannibal2.skyhanni.features.bazaar.BazaarApi -import at.hannibal2.skyhanni.features.garden.contest.FarmingContestAPI import at.hannibal2.skyhanni.utils.* import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.name 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)") + } } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/SackDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/SackDisplay.kt index 46f28a9b0..b9cd5fdeb 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/SackDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/SackDisplay.kt @@ -5,7 +5,6 @@ import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent import at.hannibal2.skyhanni.features.bazaar.BazaarApi -import at.hannibal2.skyhanni.features.bazaar.BazaarApi.Companion.getBazaarData import at.hannibal2.skyhanni.features.fishing.trophy.TrophyFishManager import at.hannibal2.skyhanni.features.fishing.trophy.TrophyRarity import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName @@ -18,6 +17,7 @@ import at.hannibal2.skyhanni.utils.NEUInternalName import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.NEUItems.getItemStack +import at.hannibal2.skyhanni.utils.NEUItems.getNpcPriceOrNull import at.hannibal2.skyhanni.utils.NEUItems.getPrice import at.hannibal2.skyhanni.utils.NumberUtil import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators @@ -344,7 +344,7 @@ class SackDisplay { 0 -> (getPrice(true) * stored.formatNumber()).toInt().let { if (it < 0) 0 else it } 1 -> try { - val npcPrice = getBazaarData()?.npcPrice ?: 0.0 + val npcPrice = getNpcPriceOrNull() ?: 0.0 (npcPrice * stored.formatNumber()).toInt() } catch (e: Exception) { 0 diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/EnderNodeTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/EnderNodeTracker.kt index 62cc85eae..9205b0154 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/EnderNodeTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/EnderNodeTracker.kt @@ -13,6 +13,7 @@ import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList import at.hannibal2.skyhanni.utils.LorenzUtils.afterChange import at.hannibal2.skyhanni.utils.LorenzUtils.editCopy +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.NumberUtil.format @@ -119,12 +120,13 @@ class EnderNodeTracker { 10_000.0 } else { val internalName = key.internalName - val bzData = internalName.getBazaarData() - if (LorenzUtils.noTradeMode) { - bzData?.npcPrice ?: georgePrice(key) ?: 0.0 + val npcPrice = internalName.getNpcPriceOrNull() + val bazaarData = internalName.getBazaarData() + if (LorenzUtils.noTradeMode || bazaarData == null) { + npcPrice ?: georgePrice(key) ?: 0.0 } else { - bzData?.npcPrice - ?.coerceAtLeast(bzData.sellPrice) + npcPrice + ?.coerceAtLeast(bazaarData.sellPrice) ?.coerceAtLeast(georgePrice(key) ?: 0.0) ?: internalName.getPrice() } diff --git a/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerItemProfitTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerItemProfitTracker.kt index e5f846252..c402becdb 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerItemProfitTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerItemProfitTracker.kt @@ -15,6 +15,7 @@ import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList import at.hannibal2.skyhanni.utils.LorenzUtils.addSelector import at.hannibal2.skyhanni.utils.LorenzUtils.sortedDesc +import at.hannibal2.skyhanni.utils.NEUItems.getNpcPrice import at.hannibal2.skyhanni.utils.NEUItems.getPrice import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems @@ -299,13 +300,13 @@ object SlayerItemProfitTracker { } private fun getPrice(internalName: NEUInternalName) = - internalName.getBazaarData()?.let { getPrice(it) } ?: internalName.getPrice() + internalName.getBazaarData()?.let { getPrice(internalName, it) } ?: internalName.getPrice() - private fun getPrice(bazaarData: BazaarData) = when (config.priceFrom) { + private fun getPrice(internalName: NEUInternalName, bazaarData: BazaarData) = when (config.priceFrom) { 0 -> bazaarData.sellPrice 1 -> bazaarData.buyPrice - else -> bazaarData.npcPrice + else -> internalName.getNpcPrice() } @SubscribeEvent diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt index b706bfb68..bf97892bb 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt @@ -1,6 +1,7 @@ package at.hannibal2.skyhanni.utils import at.hannibal2.skyhanni.config.ConfigManager +import at.hannibal2.skyhanni.features.bazaar.BazaarDataHolder import at.hannibal2.skyhanni.test.command.CopyErrorCommand import at.hannibal2.skyhanni.utils.ItemBlink.checkBlinkItem import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName_old @@ -138,11 +139,16 @@ object NEUItems { fun NEUInternalName.getPriceOrNull(useSellingPrice: Boolean = false): Double? { val price = getPrice(useSellingPrice) if (price == -1.0) { + getNpcPrice() return null } return price } + fun NEUInternalName.getNpcPrice() = getNpcPriceOrNull() ?: -1.0 + + fun NEUInternalName.getNpcPriceOrNull() = BazaarDataHolder.getNpcPrice(this) + fun transHypixelNameToInternalName(hypixelId: String) = manager.auctionManager.transformHypixelBazaarToNEUItemId(hypixelId).asInternalName() |