Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Experiments Profit Tracker #3066

Merged
merged 1 commit into from
Dec 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading