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: Bazaar + Item Trackers #2366

Merged
merged 1 commit into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
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 @@ -127,7 +127,7 @@ object OwnInventoryData {
}
}

private fun ignoreItem(duration: Duration, condition: (NEUInternalName) -> Boolean) {
fun ignoreItem(duration: Duration, condition: (NEUInternalName) -> Boolean) {
ignoredItemsUntil.add(IgnoredItem(condition, SimpleTimeMark.now() + duration))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package at.hannibal2.skyhanni.features.inventory.bazaar

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
import at.hannibal2.skyhanni.data.OwnInventoryData
import at.hannibal2.skyhanni.data.bazaar.HypixelBazaarFetcher
import at.hannibal2.skyhanni.events.BazaarOpenedProductEvent
import at.hannibal2.skyhanni.events.GuiContainerEvent
Expand All @@ -13,8 +14,10 @@ import at.hannibal2.skyhanni.features.dungeon.DungeonAPI
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.test.command.ErrorManager
import at.hannibal2.skyhanni.utils.HypixelCommands
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.InventoryUtils.getAllItems
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalNameOrNull
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.ItemUtils.itemName
import at.hannibal2.skyhanni.utils.ItemUtils.itemNameWithoutColor
Expand All @@ -32,6 +35,7 @@ import net.minecraft.client.gui.inventory.GuiChest
import net.minecraft.inventory.ContainerChest
import net.minecraft.item.ItemStack
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.time.Duration.Companion.seconds

@SkyHanniModule
object BazaarApi {
Expand All @@ -43,13 +47,14 @@ object BazaarApi {
private var currentSearchedItem = ""

var currentlyOpenedProduct: NEUInternalName? = null
var orderOptionProduct: NEUInternalName? = null

fun NEUInternalName.getBazaarData(): BazaarData? = HypixelBazaarFetcher.latestProductInformation[this]

fun NEUInternalName.getBazaarDataOrError(): BazaarData = getBazaarData() ?: run {
ErrorManager.skyHanniError(
"Can not find bazaar data for $itemName",
"internal name" to this
"internal name" to this,
)
}

Expand Down Expand Up @@ -81,6 +86,25 @@ object BazaarApi {
}
}

@SubscribeEvent
fun onSlotClick(event: GuiContainerEvent.SlotClickEvent) {
val item = event.item ?: return
val itemName = item.name
if (isBazaarOrderInventory(InventoryUtils.openInventoryName())) {
val internalName = item.getInternalNameOrNull() ?: return
if (itemName.contains("SELL")) {
orderOptionProduct = internalName
} else if (itemName.contains("BUY")) {
// pickup items from bazaar order
OwnInventoryData.ignoreItem(1.seconds, { it == internalName })
}
}
if (InventoryUtils.openInventoryName() == "Order options" && itemName == "§cCancel Order") {
// pickup items from own bazaar order
OwnInventoryData.ignoreItem(1.seconds, { it == orderOptionProduct })
}
}

private fun getOpenedProduct(inventoryItems: Map<Int, ItemStack>): NEUInternalName? {
val buyInstantly = inventoryItems[10] ?: return null

Expand Down Expand Up @@ -161,4 +185,10 @@ object BazaarApi {
inBazaarInventory = false
currentlyOpenedProduct = null
}

fun isBazaarOrderInventory(inventoryName: String): Boolean = when (inventoryName) {
"Your Bazaar Orders" -> true
"Co-op Bazaar Orders" -> true
else -> false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,23 @@ object BazaarCancelledBuyOrderClipboard {
*/
private val lastAmountPattern by patternGroup.pattern(
"lastamount",
"(?:§6coins §7from |§6§7from |§7)§a(?<amount>.*)§7x §7missing items\\."
"(?:§6coins §7from |§6§7from |§7)§a(?<amount>.*)§7x §7missing items\\.",
)
private val cancelledMessagePattern by patternGroup.pattern(
"cancelledmessage",
"§6\\[Bazaar] §r§7§r§cCancelled! §r§7Refunded §r§6(?<coins>.*) coins §r§7from cancelling Buy Order!"
"§6\\[Bazaar] §r§7§r§cCancelled! §r§7Refunded §r§6(?<coins>.*) coins §r§7from cancelling Buy Order!",
)
private val inventoryTitlePattern by patternGroup.pattern(
"inventorytitle",
"Order options"
"Order options",
)

/**
* REGEX-TEST: §a§lBUY §5Giant Killer VII
*/
private val lastItemClickedPattern by patternGroup.pattern(
"lastitemclicked",
"§a§lBUY (?<name>.*)"
"§a§lBUY (?<name>.*)",
)

private var latestAmount: Int? = null
Expand Down Expand Up @@ -83,7 +83,7 @@ object BazaarCancelledBuyOrderClipboard {

@SubscribeEvent
fun onSlotClick(event: GuiContainerEvent.SlotClickEvent) {
if (!BazaarOrderHelper.isBazaarOrderInventory(InventoryUtils.openInventoryName())) return
if (!BazaarApi.isBazaarOrderInventory(InventoryUtils.openInventoryName())) return
val item = event.slot?.stack ?: return

val name = lastItemClickedPattern.matchMatcher(item.name) {
Expand All @@ -105,9 +105,12 @@ object BazaarCancelledBuyOrderClipboard {

val message = "Bazaar buy order cancelled. Click to reorder. " +
"(§8${latestAmount.addSeparators()}x §r${lastClicked.itemName}§e)"
ChatUtils.clickableChat(message, onClick = {
BazaarApi.searchForBazaarItem(lastClicked, latestAmount)
})
ChatUtils.clickableChat(
message,
onClick = {
BazaarApi.searchForBazaarItem(lastClicked, latestAmount)
},
)
OSUtils.copyToClipboard(latestAmount.toString())
this.latestAmount = null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,17 @@ object BazaarOrderHelper {
private val patternGroup = RepoPattern.group("bazaar.orderhelper")
private val bazaarItemNamePattern by patternGroup.pattern(
"itemname",
"§.§l(?<type>BUY|SELL) (?<name>.*)"
"§.§l(?<type>BUY|SELL) (?<name>.*)",
)
private val filledPattern by patternGroup.pattern(
"filled",
"§7Filled: §[a6].*§7/.* §a§l100%!"
"§7Filled: §[a6].*§7/.* §a§l100%!",
)
private val pricePattern by patternGroup.pattern(
"price",
"§7Price per unit: §6(?<number>.*) coins"
"§7Price per unit: §6(?<number>.*) coins",
)

fun isBazaarOrderInventory(inventoryName: String): Boolean = when (inventoryName) {
"Your Bazaar Orders" -> true
"Co-op Bazaar Orders" -> true
else -> false
}

@SubscribeEvent
fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) {
if (!LorenzUtils.inSkyBlock) return
Expand All @@ -51,7 +45,7 @@ object BazaarOrderHelper {
val guiChest = event.gui
val chest = guiChest.inventorySlots as ContainerChest
val inventoryName = chest.getInventoryName()
if (!isBazaarOrderInventory(inventoryName)) return
if (!BazaarApi.isBazaarOrderInventory(inventoryName)) return

for ((slot, stack) in chest.getUpperItems()) {
bazaarItemNamePattern.matchMatcher(stack.name) {
Expand Down
Loading