From ff6996a65234fd08cd8e72e092566f7a2ce19133 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Sat, 14 Dec 2024 10:47:55 +0100 Subject: [PATCH] fix experiments profit tracker detecting bottles --- .../ExperimentsProfitTracker.kt | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/experimentationtable/ExperimentsProfitTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/experimentationtable/ExperimentsProfitTracker.kt index 6fb3c8624784..3b30bc14e443 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/experimentationtable/ExperimentsProfitTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/experimentationtable/ExperimentsProfitTracker.kt @@ -167,12 +167,20 @@ object ExperimentsProfitTracker { @HandleEvent fun onItemClick(event: ItemClickEvent) { - if (isEnabled() && event.clickType == ClickType.RIGHT_CLICK) { - val item = event.itemInHand ?: return - if (item.getInternalName().isExpBottle()) { - lastSplashTime = SimpleTimeMark.now() - lastSplashes.add(item) + if (!isEnabled() || event.clickType != ClickType.RIGHT_CLICK) return + val item = event.itemInHand ?: return + val internalName = item.getInternalName() + if (!internalName.isExpBottle()) return + + lastSplashTime = SimpleTimeMark.now() + + if (ExperimentationTableAPI.inDistanceToTable(LorenzVec.getBlockBelowPlayer(), 15.0)) { + tracker.modify { + it.startCost -= calculateBottlePrice(internalName) } + DelayedRun.runDelayed(100.milliseconds) { handleExpBottles(false) } + } else { + lastSplashes.add(item) } } @@ -200,8 +208,7 @@ object ExperimentsProfitTracker { private fun calculateBottlePrice(internalName: NEUInternalName): Int { val price = internalName.getPrice() val npcPrice = internalName.getNpcPriceOrNull() ?: 0.0 - val maxPrice = npcPrice.coerceAtLeast(price) - return maxPrice.toInt() + return npcPrice.coerceAtLeast(price).toInt() } @SubscribeEvent @@ -267,22 +274,20 @@ object ExperimentsProfitTracker { for ((internalName, amount) in currentBottlesInInventory) { val lastInInv = lastBottlesInInventory.getOrDefault(internalName, 0) if (lastInInv >= amount) { - currentBottlesInInventory[internalName] = 0 lastBottlesInInventory[internalName] = amount continue } if (lastInInv == 0) { - currentBottlesInInventory[internalName] = 0 lastBottlesInInventory[internalName] = amount if (addToTracker) tracker.addItem(internalName, amount, false) continue } - currentBottlesInInventory[internalName] = 0 lastBottlesInInventory[internalName] = amount if (addToTracker) tracker.addItem(internalName, amount - lastInInv, false) } + currentBottlesInInventory.clear() } private fun ExperimentMessages.isSelected() = config.hideMessages.contains(this)