Skip to content

Commit

Permalink
Fix: Experiments Profit Tracker (#3066)
Browse files Browse the repository at this point in the history
Co-authored-by: hannibal2 <[email protected]>
  • Loading branch information
hannibal002 and hannibal002 authored Dec 15, 2024
1 parent ce0f411 commit 236c00d
Showing 1 changed file with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 236c00d

Please sign in to comment.