diff options
Diffstat (limited to 'src/main/java')
2 files changed, 41 insertions, 32 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 16c0305cb..7b6fa9bc5 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 @@ -18,6 +18,7 @@ import at.hannibal2.skyhanni.features.inventory.experimentationtable.Experimenta import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.utils.CollectionUtils.addOrPut import at.hannibal2.skyhanni.utils.CollectionUtils.addSearchString +import at.hannibal2.skyhanni.utils.DelayedRun import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemPriceUtils.getNpcPriceOrNull import at.hannibal2.skyhanni.utils.ItemPriceUtils.getPrice @@ -42,6 +43,7 @@ import com.google.gson.annotations.Expose import net.minecraft.item.ItemStack import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.math.absoluteValue +import kotlin.time.Duration.Companion.milliseconds @SkyHanniModule object ExperimentsProfitTracker { @@ -98,29 +100,12 @@ object ExperimentsProfitTracker { if (!isEnabled()) return val message = event.message.removeColor() - if (claimMessagePattern.matches(message) && ExperimentMessages.DONE.isSelected()) + if (claimMessagePattern.matches(message) && ExperimentMessages.DONE.isSelected()) { event.blockedReason = "CLAIM_MESSAGE" + } experimentsDropPattern.matchMatcher(message) { - val reward = group("reward") - - event.blockedReason = when { - enchantingExpPattern.matches(reward) && ExperimentMessages.EXPERIENCE.isSelected() -> "EXPERIENCE_DROP" - experienceBottlePattern.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 -> "" - } - - enchantingExpPattern.matchMatcher(reward) { - tracker.modify { - it.xpGained += group("amount").substringBefore(",").toInt() * 1000 - } - return - } - - val internalName = NEUInternalName.fromItemNameOrNull(reward) ?: return - if (!experienceBottlePattern.matches(group("reward"))) tracker.addItem(internalName, 1, false) + event.handleDrop(group("reward")) return } @@ -132,6 +117,27 @@ 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" + listOf("Metaphysical Serum", "Experiment The Fish").contains(reward) && ExperimentMessages.MISC.isSelected() -> "MISC_DROP" + ExperimentMessages.ENCHANTMENTS.isSelected() -> "ENCHANT_DROP" + else -> "" + } + + enchantingExpPattern.matchMatcher(reward) { + tracker.modify { + it.xpGained += group("amount").substringBefore(",").toInt() * 1000 + } + return + } + + val internalName = NEUInternalName.fromItemNameOrNull(reward) ?: return + if (!experienceBottlePattern.matches(reward)) tracker.addItem(internalName, 1, false) + else DelayedRun.runDelayed(100.milliseconds) { handleExpBottles(true) } + } + @SubscribeEvent fun onItemClick(event: ItemClickEvent) { if (event.clickType == ClickType.RIGHT_CLICK) { @@ -177,9 +183,6 @@ object ExperimentsProfitTracker { it.experimentsDone++ } } - if (ExperimentationTableAPI.inTable && InventoryUtils.openInventoryName() == "Superpairs Rewards") { - handleExpBottles(true) - } } private fun drawDisplay(data: Data): List<Searchable> = buildList { @@ -230,6 +233,7 @@ object ExperimentsProfitTracker { if (internalName.asString() !in listOf("EXP_BOTTLE", "GRAND_EXP_BOTTLE", "TITANIC_EXP_BOTTLE")) continue currentBottlesInInventory.addOrPut(internalName, item.stackSize) } + for ((internalName, amount) in currentBottlesInInventory) { val lastInInv = lastBottlesInInventory.getOrDefault(internalName, 0) if (lastInInv >= amount) { @@ -237,6 +241,7 @@ object ExperimentsProfitTracker { lastBottlesInInventory[internalName] = amount continue } + if (lastInInv == 0) { currentBottlesInInventory[internalName] = 0 lastBottlesInInventory[internalName] = amount @@ -253,6 +258,5 @@ object ExperimentsProfitTracker { private fun ExperimentMessages.isSelected() = config.hideMessages.contains(this) private fun isEnabled() = - LorenzUtils.inSkyBlock && config.enabled - && ExperimentationTableAPI.inDistanceToTable(LorenzVec.getBlockBelowPlayer(), 5.0) + LorenzUtils.inSkyBlock && config.enabled && ExperimentationTableAPI.inDistanceToTable(LorenzVec.getBlockBelowPlayer(), 5.0) } diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/experimentationtable/SuperpairExperimentInformationDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/experimentationtable/SuperpairExperimentInformationDisplay.kt index 21bc6052e..86d7fca50 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/experimentationtable/SuperpairExperimentInformationDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/experimentationtable/SuperpairExperimentInformationDisplay.kt @@ -17,6 +17,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.time.Duration.Companion.milliseconds @SkyHanniModule +// TODO important: all use cases of listOf in combination with string needs to be gone. no caching, constant new list creation, and bad design. object SuperpairExperimentInformationDisplay { private val config get() = SkyHanniMod.feature.inventory.experimentationTable @@ -30,6 +31,7 @@ object SuperpairExperimentInformationDisplay { data class Item(val index: Int, val name: String) data class ItemPair(val first: Item, val second: Item) + // TODO remove string. use enum instead! maybe even create new data type instaed of map of pairs private var found = mutableMapOf<Pair<Item?, ItemPair?>, String>() private var toCheck = mutableListOf<Pair<Int, Int>>() @@ -60,7 +62,7 @@ object SuperpairExperimentInformationDisplay { @SubscribeEvent fun onChestGuiOverlayRendered(event: GuiRenderEvent.ChestGuiOverlayRenderEvent) { if (!isEnabled()) return - config.superpairDisplayPosition.renderStrings(display, posLabel = "Sperpair Experiment Information") + config.superpairDisplayPosition.renderStrings(display, posLabel = "Superpair Experiment Information") display = checkItems(toCheck) } @@ -133,6 +135,8 @@ object SuperpairExperimentInformationDisplay { ?: return else lastClicked.find { it.second == uncovered } ?: return val lastItem = InventoryUtils.getItemAtSlotIndex(lastSlotClicked.first) ?: return + val itemClicked = InventoryUtils.getItemAtSlotIndex(slot) ?: return + val lastItemName = convertToReward(lastItem) if (isWaiting(lastItemName)) return @@ -145,7 +149,7 @@ object SuperpairExperimentInformationDisplay { uncoveredAt += 1 } - hasFoundPair(slot, lastSlotClicked.first, reward, lastItemName) -> handleFoundPair( + hasFoundPair(slot, lastSlotClicked.first, reward, lastItemName) && lastItem.itemDamage == itemClicked.itemDamage -> handleFoundPair( slot, reward, lastSlotClicked.first, @@ -166,7 +170,7 @@ object SuperpairExperimentInformationDisplay { found[pair] = "Pair" found.entries.removeIf { - it.value == "Match" && right(it.key).first.name == reward + it.value == "Match" && right(it.key).first.index == slot } found.entries.removeIf { it.value == "Normal" && (left(it.key).index == slot || left(it.key).index == lastSlotClicked) @@ -177,10 +181,10 @@ object SuperpairExperimentInformationDisplay { val match = uncoveredItems.find { it.second == reward }?.first ?: return val pair = toEither(ItemPair(Item(slot, reward), Item(match, reward))) - found[pair] = "Match" - found.entries.removeIf { - it.value == "Normal" && (left(it.key).index == slot || left(it.key).index == match) - } + if (found.none { + listOf("Pair", "Match").contains(it.value) && (right(it.key).first.index == slot) + }) found[pair] = "Match" + found.entries.removeIf { it.value == "Normal" && (left(it.key).index == slot || left(it.key).index == match) } } private fun handleNormalReward(slot: Int, reward: String) { @@ -262,6 +266,7 @@ object SuperpairExperimentInformationDisplay { private fun isOutOfBounds(slot: Int, experiment: Experiment): Boolean = slot <= experiment.startSlot || slot >= experiment.endSlot || (if (experiment.sideSpace == 1) slot in sideSpaces1 else slot in sideSpaces2) + // TODO remove left and right, use custom data type instead private fun left(it: Pair<Item?, ItemPair?>): Item = it.first ?: Item(-1, "") private fun right(it: Pair<Item?, ItemPair?>): ItemPair = it.second ?: ItemPair(Item(-1, ""), Item(-1, "")) |