From 25d79074bec71799d126406373e09901a3a72538 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Fri, 29 Dec 2023 08:52:37 +0100 Subject: Visitors don't have needs anymore, visitors go shopping --- .../skyhanni/config/ConfigUpdaterMigrator.kt | 2 +- .../features/garden/visitor/NeedsConfig.java | 46 ----------- .../garden/visitor/ShoppingListConfig.java | 48 ++++++++++++ .../features/garden/visitor/VisitorConfig.java | 4 +- .../garden/visitor/GardenVisitorFeatures.kt | 90 +++++++++++----------- .../skyhanni/features/garden/visitor/VisitorAPI.kt | 2 +- 6 files changed, 98 insertions(+), 94 deletions(-) delete mode 100644 src/main/java/at/hannibal2/skyhanni/config/features/garden/visitor/NeedsConfig.java create mode 100644 src/main/java/at/hannibal2/skyhanni/config/features/garden/visitor/ShoppingListConfig.java (limited to 'src/main/java/at/hannibal2') diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt index f98373ea3..e73f63813 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt @@ -9,7 +9,7 @@ import com.google.gson.JsonPrimitive object ConfigUpdaterMigrator { val logger = LorenzLogger("ConfigMigration") - const val CONFIG_VERSION = 17 + const val CONFIG_VERSION = 18 fun JsonElement.at(chain: List, init: Boolean): JsonElement? { if (chain.isEmpty()) return this if (this !is JsonObject) return null diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/garden/visitor/NeedsConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/garden/visitor/NeedsConfig.java deleted file mode 100644 index 002b44a16..000000000 --- a/src/main/java/at/hannibal2/skyhanni/config/features/garden/visitor/NeedsConfig.java +++ /dev/null @@ -1,46 +0,0 @@ -package at.hannibal2.skyhanni.config.features.garden.visitor; - -import at.hannibal2.skyhanni.config.FeatureToggle; -import at.hannibal2.skyhanni.config.core.config.Position; -import com.google.gson.annotations.Expose; -import io.github.moulberry.moulconfig.annotations.ConfigEditorBoolean; -import io.github.moulberry.moulconfig.annotations.ConfigOption; - -public class NeedsConfig { - @Expose - @ConfigOption(name = "Items Needed", desc = "Show all items needed for the visitors.") - @ConfigEditorBoolean - @FeatureToggle - public boolean display = true; - - @Expose - public Position pos = new Position(180, 170, false, true); - - @Expose - @ConfigOption(name = "Only when Close", desc = "Only show the needed items when close to the visitors.") - @ConfigEditorBoolean - public boolean onlyWhenClose = false; - - @Expose - @ConfigOption(name = "Bazaar Alley", desc = "Show the Visitor Items List while inside the Bazaar Alley in the Hub. " + - "This helps buying the correct amount when not having a Booster Cookie Buff active.") - @ConfigEditorBoolean - public boolean inBazaarAlley = true; - - @Expose - @ConfigOption(name = "Show Price", desc = "Show the coin price in the items needed list.") - @ConfigEditorBoolean - public boolean showPrice = true; - - @Expose - @ConfigOption(name = "Show Sack Count", desc = "Show the amount of this item that you already have in your sacks. " + - "§eOnly updates on sack change messages.") - @ConfigEditorBoolean - public boolean showSackCount = true; - - @Expose - @ConfigOption(name = "Item Preview", desc = "Show the base type for the required items next to new visitors. §cNote that some visitors may require any crop.") - @ConfigEditorBoolean - @FeatureToggle - public boolean itemPreview = true; -} diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/garden/visitor/ShoppingListConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/garden/visitor/ShoppingListConfig.java new file mode 100644 index 000000000..cbfa9e451 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/features/garden/visitor/ShoppingListConfig.java @@ -0,0 +1,48 @@ +package at.hannibal2.skyhanni.config.features.garden.visitor; + +import at.hannibal2.skyhanni.config.FeatureToggle; +import at.hannibal2.skyhanni.config.core.config.Position; +import com.google.gson.annotations.Expose; +import io.github.moulberry.moulconfig.annotations.ConfigEditorBoolean; +import io.github.moulberry.moulconfig.annotations.ConfigOption; + +public class ShoppingListConfig { + @Expose + @ConfigOption(name = "Enable", desc = "Show all items required for the visitors.") + @ConfigEditorBoolean + @FeatureToggle + // TODO rename "enabled" + public boolean display = true; + + @Expose + // TODO renmae "postion" + public Position pos = new Position(180, 170, false, true); + + @Expose + @ConfigOption(name = "Only when Close", desc = "Only show the shopping list when close to the visitors.") + @ConfigEditorBoolean + public boolean onlyWhenClose = false; + + @Expose + @ConfigOption(name = "Bazaar Alley", desc = "Show the Visitor Items List while inside the Bazaar Alley in the Hub. " + + "This helps buying the correct amount when not having a Booster Cookie Buff active.") + @ConfigEditorBoolean + public boolean inBazaarAlley = true; + + @Expose + @ConfigOption(name = "Show Price", desc = "Show the coin price in the shopping list.") + @ConfigEditorBoolean + public boolean showPrice = true; + + @Expose + @ConfigOption(name = "Show Sack Count", desc = "Show the amount of this item that you already have in your sacks. " + + "§eOnly updates on sack change messages.") + @ConfigEditorBoolean + public boolean showSackCount = true; + + @Expose + @ConfigOption(name = "Item Preview", desc = "Show the base type for the required items next to new visitors. §cNote that some visitors may require any crop.") + @ConfigEditorBoolean + @FeatureToggle + public boolean itemPreview = true; +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/garden/visitor/VisitorConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/garden/visitor/VisitorConfig.java index 7aca44b89..654dcf511 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/garden/visitor/VisitorConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/garden/visitor/VisitorConfig.java @@ -17,9 +17,9 @@ public class VisitorConfig { public TimerConfig timer = new TimerConfig(); @Expose - @ConfigOption(name = "Visitor Items Needed", desc = "") + @ConfigOption(name = "Visitor Shopping List", desc = "") @Accordion - public NeedsConfig needs = new NeedsConfig(); + public ShoppingListConfig shoppingList = new ShoppingListConfig(); @Expose @ConfigOption(name = "Visitor Inventory", desc = "") diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt index 4bcd4a079..147189257 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt @@ -95,7 +95,7 @@ class GardenVisitorFeatures { val pair = ItemUtils.readItemAmount(line) if (pair == null) { ErrorManager.logErrorStateWithData( - "Could not read items required in Visitor Inventory", "ItemUtils.readItemAmount returns null", + "Could not read Shopping List in Visitor Inventory", "ItemUtils.readItemAmount returns null", "line" to line, "offerItem" to offerItem, "lore" to lore, @@ -105,7 +105,7 @@ class GardenVisitorFeatures { } val (itemName, amount) = pair val internalName = NEUInternalName.fromItemName(itemName) - visitor.items[internalName] = amount + visitor.shoppingList[internalName] = amount } readToolTip(visitor, offerItem) @@ -128,36 +128,36 @@ class GardenVisitorFeatures { } private fun drawDisplay() = buildList { - if (!config.needs.display) return@buildList - val (requiredItems, newVisitors) = prepareDrawingData() + if (!config.shoppingList.display) return@buildList + val (shoppingList, newVisitors) = prepareDrawingData() - drawRequiredItems(requiredItems) - drawVisitors(newVisitors, requiredItems) + drawShoppingList(shoppingList) + drawVisitors(newVisitors, shoppingList) } private fun prepareDrawingData(): Pair, MutableList> { - val requiredItems = mutableMapOf() + val globalShoppingList = mutableMapOf() val newVisitors = mutableListOf() for ((visitorName, visitor) in VisitorAPI.getVisitorsMap()) { if (visitor.status == VisitorAPI.VisitorStatus.ACCEPTED || visitor.status == VisitorAPI.VisitorStatus.REFUSED) continue - val items = visitor.items - if (items.isEmpty()) { + val shoppingList = visitor.shoppingList + if (shoppingList.isEmpty()) { newVisitors.add(visitorName) } - for ((internalName, amount) in items) { - val old = requiredItems.getOrDefault(internalName, 0) - requiredItems[internalName] = old + amount + for ((internalName, amount) in shoppingList) { + val old = globalShoppingList.getOrDefault(internalName, 0) + globalShoppingList[internalName] = old + amount } } - return requiredItems to newVisitors + return globalShoppingList to newVisitors } - private fun MutableList>.drawRequiredItems(requiredItems: MutableMap) { - if (requiredItems.isNotEmpty()) { + private fun MutableList>.drawShoppingList(shoppingList: MutableMap) { + if (shoppingList.isNotEmpty()) { var totalPrice = 0.0 - addAsSingletonList("§7Visitor items needed:") - for ((internalName, amount) in requiredItems) { + addAsSingletonList("§7Visitor Shopping List:") + for ((internalName, amount) in shoppingList) { val name = internalName.getItemName() val itemStack = internalName.getItemStack() @@ -173,14 +173,14 @@ class GardenVisitorFeatures { } }) { GardenAPI.inGarden() && !NEUItems.neuHasFocus() }) - if (config.needs.showPrice) { + if (config.shoppingList.showPrice) { val price = internalName.getPrice() * amount totalPrice += price val format = NumberUtil.format(price) list.add(" §7(§6$format§7)") } - if (config.needs.showSackCount) { + if (config.shoppingList.showSackCount) { val sackItemData = SackAPI.fetchSackItem(internalName) val itemStatus = sackItemData.getStatus() val itemAmount = sackItemData.amount @@ -196,17 +196,17 @@ class GardenVisitorFeatures { } if (totalPrice > 0) { val format = NumberUtil.format(totalPrice) - this[0] = listOf("§7Visitor items needed: §7(§6$format§7)") + this[0] = listOf("§7Visitor Shopping List: §7(§6$format§7)") } } } private fun MutableList>.drawVisitors( newVisitors: MutableList, - requiredItems: MutableMap + shoppingList: MutableMap ) { if (newVisitors.isNotEmpty()) { - if (requiredItems.isNotEmpty()) { + if (shoppingList.isNotEmpty()) { addAsSingletonList("") } val amount = newVisitors.size @@ -218,7 +218,7 @@ class GardenVisitorFeatures { val list = mutableListOf() list.add(" §7- $displayName") - if (config.needs.itemPreview) { + if (config.shoppingList.itemPreview) { val items = GardenVisitorColorNames.visitorItems[visitor.removeColor()] if (items == null) { val text = "Visitor '$visitor' has no items in repo!" @@ -307,14 +307,14 @@ class GardenVisitorFeatures { private fun readToolTip(visitor: VisitorAPI.Visitor, itemStack: ItemStack?) { val stack = itemStack ?: error("Accept offer item not found for visitor ${visitor.visitorName}") var totalPrice = 0.0 - var timeRequired = -1L - var readingItemsNeeded = true + var farmingTimeRequired = -1L + var readingShoppingList = true lastFullPrice = 0.0 val foundRewards = mutableListOf() for (formattedLine in stack.getLore()) { if (formattedLine.contains("Rewards")) { - readingItemsNeeded = false + readingShoppingList = false } val (itemName, amount) = ItemUtils.readItemAmount(formattedLine) ?: continue @@ -324,7 +324,7 @@ class GardenVisitorFeatures { if (internalName.startsWith("SKYBLOCK_")) continue val price = internalName.getPrice() * amount - if (readingItemsNeeded) { + if (readingShoppingList) { totalPrice += price lastFullPrice += price } else { @@ -348,7 +348,7 @@ class GardenVisitorFeatures { } } - readingItemsNeeded = true + readingShoppingList = true val finalList = stack.getLore().toMutableList() var offset = 0 for ((i, formattedLine) in finalList.toMutableList().withIndex()) { @@ -364,17 +364,17 @@ class GardenVisitorFeatures { copperPattern.matchMatcher(formattedLine) { val copper = group("amount").replace(",", "").toInt() val pricePerCopper = NumberUtil.format((totalPrice / copper).toInt()) - val timePerCopper = TimeUtils.formatDuration((timeRequired / copper) * 1000) + val timePerCopper = TimeUtils.formatDuration((farmingTimeRequired / copper) * 1000) var copperLine = formattedLine if (config.inventory.copperPrice) copperLine += " §7(§6$pricePerCopper §7per)" if (config.inventory.copperTime) { - copperLine += if (timeRequired != -1L) " §7(§b$timePerCopper §7per)" else " §7(§cno speed data!§7)" + copperLine += if (farmingTimeRequired != -1L) " §7(§b$timePerCopper §7per)" else " §7(§cno speed data!§7)" } finalList.set(index, copperLine) } if (formattedLine.contains("Rewards")) { - readingItemsNeeded = false + readingShoppingList = false } val (itemName, amount) = ItemUtils.readItemAmount(formattedLine) ?: continue @@ -388,7 +388,7 @@ class GardenVisitorFeatures { val format = NumberUtil.format(price) finalList[index] = "$formattedLine §7(§6$format§7)" } - if (!readingItemsNeeded) continue + if (!readingShoppingList) continue val multiplier = NEUItems.getMultiplier(internalName) val rawName = multiplier.first.getItemNameOrNull()?.removeColor() ?: continue @@ -398,8 +398,8 @@ class GardenVisitorFeatures { val formattedAmount = LorenzUtils.formatInteger(cropAmount) val formattedName = "§e$formattedAmount§7x ${cropType.cropName} " val formattedSpeed = cropType.getSpeed()?.let { speed -> - timeRequired = cropAmount / speed - val duration = TimeUtils.formatDuration(timeRequired * 1000) + farmingTimeRequired = cropAmount / speed + val duration = TimeUtils.formatDuration(farmingTimeRequired * 1000) "in §b$duration" } ?: "§cno speed data!" if (config.inventory.exactAmountAndTime) { @@ -413,7 +413,7 @@ class GardenVisitorFeatures { @SubscribeEvent fun onTick(event: LorenzTickEvent) { if (!GardenAPI.inGarden()) return - if (!config.needs.display && config.highlightStatus == HighlightMode.DISABLED) return + if (!config.shoppingList.display && config.highlightStatus == HighlightMode.DISABLED) return if (!event.isMod(10)) return if (GardenAPI.onBarnPlot && config.highlightStatus != HighlightMode.DISABLED) { @@ -547,9 +547,9 @@ class GardenVisitorFeatures { private fun hasItemsInInventory(visitor: VisitorAPI.Visitor): Boolean { var ready = true - for ((internalName, need) in visitor.items) { + for ((internalName, required) in visitor.shoppingList) { val having = InventoryUtils.countItemsInLowerInventory { it.getInternalName() == internalName } - if (having < need) { + if (having < required) { ready = false } } @@ -559,14 +559,14 @@ class GardenVisitorFeatures { @SubscribeEvent fun onRenderInSigns(event: DrawScreenEvent.Post) { if (!GardenAPI.inGarden()) return - if (!config.needs.display) return + if (!config.shoppingList.display) return val gui = event.gui if (gui !is GuiEditSign) return - if (config.needs.onlyWhenClose && !GardenAPI.onBarnPlot) return + if (config.shoppingList.onlyWhenClose && !GardenAPI.onBarnPlot) return if (!hideExtraGuis()) { - config.needs.pos.renderStringsAndItems(display, posLabel = "Visitor Items Needed") + config.shoppingList.pos.renderStringsAndItems(display, posLabel = "Visitor Shopping List") } } @@ -574,22 +574,22 @@ class GardenVisitorFeatures { @SubscribeEvent fun onRenderOverlay(event: GuiRenderEvent) { - if (!config.needs.display) return + if (!config.shoppingList.display) return if (showGui()) { - config.needs.pos.renderStringsAndItems(display, posLabel = "Visitor Items Needed") + config.shoppingList.pos.renderStringsAndItems(display, posLabel = "Visitor Shopping List") } } private fun showGui(): Boolean { - if (config.needs.inBazaarAlley && IslandType.HUB.isInIsland() && LorenzUtils.skyBlockArea == "Bazaar Alley") { + if (config.shoppingList.inBazaarAlley && IslandType.HUB.isInIsland() && LorenzUtils.skyBlockArea == "Bazaar Alley") { return true } if (hideExtraGuis()) return false if (GardenAPI.inGarden()) { if (GardenAPI.onBarnPlot) return true - if (!config.needs.onlyWhenClose) return true + if (!config.shoppingList.onlyWhenClose) return true } return false } @@ -655,6 +655,8 @@ class GardenVisitorFeatures { event.transform(15, "garden.visitors.highlightStatus") { element -> ConfigUtils.migrateIntToEnum(element, HighlightMode::class.java) } + + event.move(18, "garden.visitors.needs", "garden.visitors.shoppingList") } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorAPI.kt index a74793fbe..c3c832d78 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorAPI.kt @@ -108,7 +108,7 @@ object VisitorAPI { var nameTagEntityId: Int = -1, var status: VisitorStatus, var inSacks: Boolean = false, - val items: MutableMap = mutableMapOf(), + val shoppingList: MutableMap = mutableMapOf(), var offer: VisitorOffer? = null, ) { var lore: List = emptyList() -- cgit