diff options
Diffstat (limited to 'src/main/java/at')
2 files changed, 53 insertions, 16 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/experimentationtable/ExperimentationTableAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/experimentationtable/ExperimentationTableAPI.kt index 80433b68e..0c7fc1a73 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/experimentationtable/ExperimentationTableAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/experimentationtable/ExperimentationTableAPI.kt @@ -117,9 +117,17 @@ object ExperimentationTableAPI { /** * REGEX-TEST: Titanic Experience Bottle */ + val experienceBottleChatPattern by patternGroup.pattern( + "chat.xpbottle", + "(?:Colossal |Titanic |Grand |\\b)Experience Bottle", + ) + + /** + * REGEX-TEST: TITANIC_EXP_BOTTLE + */ val experienceBottlePattern by patternGroup.pattern( "xpbottle", - "(?:Titanic |Grand |\\b)Experience Bottle", + "(?:COLOSSAL_|TITANIC_|GRAND_|\\b)EXP_BOTTLE", ) /** 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 6e755d874..ac1e8105e 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 @@ -3,14 +3,18 @@ package at.hannibal2.skyhanni.features.inventory.experimentationtable import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.data.ClickType import at.hannibal2.skyhanni.data.IslandType +import at.hannibal2.skyhanni.data.ItemAddManager +import at.hannibal2.skyhanni.events.GuiContainerEvent import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.InventoryUpdatedEvent import at.hannibal2.skyhanni.events.IslandChangeEvent +import at.hannibal2.skyhanni.events.ItemAddEvent import at.hannibal2.skyhanni.events.ItemClickEvent import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.features.inventory.experimentationtable.ExperimentationTableAPI.claimMessagePattern import at.hannibal2.skyhanni.features.inventory.experimentationtable.ExperimentationTableAPI.enchantingExpPattern +import at.hannibal2.skyhanni.features.inventory.experimentationtable.ExperimentationTableAPI.experienceBottleChatPattern import at.hannibal2.skyhanni.features.inventory.experimentationtable.ExperimentationTableAPI.experienceBottlePattern import at.hannibal2.skyhanni.features.inventory.experimentationtable.ExperimentationTableAPI.experimentRenewPattern import at.hannibal2.skyhanni.features.inventory.experimentationtable.ExperimentationTableAPI.experimentsDropPattern @@ -28,7 +32,6 @@ import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzVec import at.hannibal2.skyhanni.utils.NEUInternalName import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators -import at.hannibal2.skyhanni.utils.NumberUtil.roundTo import at.hannibal2.skyhanni.utils.NumberUtil.shortFormat import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher import at.hannibal2.skyhanni.utils.RegexUtils.matches @@ -56,7 +59,7 @@ object ExperimentsProfitTracker { { it.experimentation.experimentsProfitTracker }, ) { drawDisplay(it) } - private var lastSplashes = mutableListOf<ItemStack>() + private val lastSplashes = mutableListOf<ItemStack>() private var lastSplashTime = SimpleTimeMark.farPast() private var lastBottlesInInventory = mutableMapOf<NEUInternalName, Int>() private var currentBottlesInInventory = mutableMapOf<NEUInternalName, Int>() @@ -96,6 +99,13 @@ object ExperimentsProfitTracker { } @SubscribeEvent + fun onItemAdd(event: ItemAddEvent) { + if (!isEnabled() || event.source != ItemAddManager.Source.COMMAND) return + + tracker.addItem(event.internalName, event.amount, command = true) + } + + @SubscribeEvent fun onChat(event: LorenzChatEvent) { if (!isEnabled()) return @@ -120,7 +130,7 @@ object ExperimentsProfitTracker { private fun LorenzChatEvent.handleDrop(reward: String) { blockedReason = when { enchantingExpPattern.matches(reward) && ExperimentMessages.EXPERIENCE.isSelected() -> "EXPERIENCE_DROP" - experienceBottlePattern.matches(reward) && ExperimentMessages.BOTTLES.isSelected() -> "BOTTLE_DROP" + experienceBottleChatPattern.matches(reward) && ExperimentMessages.BOTTLES.isSelected() -> "BOTTLE_DROP" listOf("Metaphysical Serum", "Experiment The Fish").contains(reward) && ExperimentMessages.MISC.isSelected() -> "MISC_DROP" ExperimentMessages.ENCHANTMENTS.isSelected() -> "ENCHANT_DROP" else -> "" @@ -134,37 +144,49 @@ object ExperimentsProfitTracker { } val internalName = NEUInternalName.fromItemNameOrNull(reward) ?: return - if (!experienceBottlePattern.matches(reward)) tracker.addItem(internalName, 1, false) + if (!experienceBottleChatPattern.matches(reward)) tracker.addItem(internalName, 1, false) else DelayedRun.runDelayed(100.milliseconds) { handleExpBottles(true) } } @SubscribeEvent + fun onSlotClick(event: GuiContainerEvent.SlotClickEvent) { + if (!isEnabled() || + InventoryUtils.openInventoryName() != "Bottles of Enchanting" || + !listOf(11, 12, 14, 15).contains(event.slotId) + ) return + val stack = event.slot?.stack ?: return + + val internalName = stack.getInternalName() + if (internalName.isExpBottle()) { + tracker.modify { + it.startCost -= calculateBottlePrice(internalName) + } + } + } + + @SubscribeEvent fun onItemClick(event: ItemClickEvent) { - if (event.clickType == ClickType.RIGHT_CLICK) { + if (isEnabled() && event.clickType == ClickType.RIGHT_CLICK) { val item = event.itemInHand ?: return - if (experienceBottlePattern.matches(item.displayName.removeColor())) { + if (item.getInternalName().isExpBottle()) { lastSplashTime = SimpleTimeMark.now() lastSplashes.add(item) } } } + private fun NEUInternalName.isExpBottle() = experienceBottlePattern.matches(asString()) + @SubscribeEvent fun onInventoryUpdated(event: InventoryUpdatedEvent) { if (!isEnabled()) return if (inventoriesPattern.matches(event.inventoryName)) { var startCostTemp = 0 - val iterator = lastSplashes.iterator() - while (iterator.hasNext()) { - val item = iterator.next() - val internalName = item.getInternalName() - val price = internalName.getPrice() - val npcPrice = internalName.getNpcPriceOrNull() ?: 0.0 - val maxPrice = npcPrice.coerceAtLeast(price) - startCostTemp += maxPrice.roundTo(0).toInt() - iterator.remove() + for (item in lastSplashes) { + startCostTemp += calculateBottlePrice(item.getInternalName()) } + lastSplashes.clear() tracker.modify { it.startCost -= startCostTemp } @@ -174,6 +196,13 @@ object ExperimentsProfitTracker { handleExpBottles(false) } + private fun calculateBottlePrice(internalName: NEUInternalName): Int { + val price = internalName.getPrice() + val npcPrice = internalName.getNpcPriceOrNull() ?: 0.0 + val maxPrice = npcPrice.coerceAtLeast(price) + return maxPrice.toInt() + } + @SubscribeEvent fun onInventoryClose(event: InventoryCloseEvent) { if (!isEnabled()) return |