diff options
author | hannibal2 <24389977+hannibal002@users.noreply.github.com> | 2024-05-01 06:50:58 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-01 14:50:58 +1000 |
commit | a2abc8845169a5bf2f729e629fee5a9c69c938fb (patch) | |
tree | 0eada21af0961ccf20cb954f159906f6dcf6d727 /src/main/java/at/hannibal2/skyhanni/features | |
parent | 4251909d9dd304410f575efa87f0bc9f4bfaf784 (diff) | |
download | skyhanni-a2abc8845169a5bf2f729e629fee5a9c69c938fb.tar.gz skyhanni-a2abc8845169a5bf2f729e629fee5a9c69c938fb.tar.bz2 skyhanni-a2abc8845169a5bf2f729e629fee5a9c69c938fb.zip |
Feature: Chocolate Shop Price (#1601)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Co-authored-by: Cal <cwolfson58@gmail.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
6 files changed, 124 insertions, 19 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt index b080e53d1..c386bb3b1 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt @@ -23,6 +23,8 @@ import at.hannibal2.skyhanni.features.garden.fortuneguide.FFGuideGUI import at.hannibal2.skyhanni.features.garden.fortuneguide.FarmingItems import at.hannibal2.skyhanni.features.garden.inventory.SkyMartCopperPrice import at.hannibal2.skyhanni.features.garden.visitor.VisitorAPI +import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactoryAPI +import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateShopPrice import at.hannibal2.skyhanni.utils.BlockUtils.isBabyCrop import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.DelayedRun @@ -167,7 +169,8 @@ object GardenAPI { addItemIcon(crop.icon.copy(), highlight, scale = scale) fun hideExtraGuis() = ComposterOverlay.inInventory || AnitaMedalProfit.inInventory || - SkyMartCopperPrice.inInventory || FarmingContestAPI.inInventory || VisitorAPI.inInventory || FFGuideGUI.isInGui() + SkyMartCopperPrice.inInventory || FarmingContestAPI.inInventory || VisitorAPI.inInventory || + FFGuideGUI.isInGui() || ChocolateShopPrice.inInventory || ChocolateFactoryAPI.inChocolateFactory fun clearCropSpeed() { storage?.cropsPerSecond?.clear() diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/SkyMartCopperPrice.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/SkyMartCopperPrice.kt index adedbb150..0d86757ea 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/SkyMartCopperPrice.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/SkyMartCopperPrice.kt @@ -76,8 +76,8 @@ class SkyMartCopperPrice { } ?: continue val internalName = item.getInternalName() - val lowestBin = internalName.getPriceOrNull() ?: continue - val profit = lowestBin - (otherItemsPrice ?: 0.0) + val itemPrice = internalName.getPriceOrNull() ?: continue + val profit = itemPrice - (otherItemsPrice ?: 0.0) val factor = profit / copper val perFormat = NumberUtil.format(factor) @@ -86,7 +86,7 @@ class SkyMartCopperPrice { val hover = buildList { add(itemName) add("") - add("§7Item price: §6${NumberUtil.format(lowestBin)} ") + add("§7Item price: §6${NumberUtil.format(itemPrice)} ") otherItemsPrice?.let { add("§7Additional cost: §6${NumberUtil.format(it)} ") } @@ -130,8 +130,6 @@ class SkyMartCopperPrice { } } - private fun isEnabled() = GardenAPI.inGarden() && config.copperPrice - @SubscribeEvent fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { event.move(3, "garden.skyMartCopperPrice", "garden.skyMart.copperPrice") @@ -141,4 +139,6 @@ class SkyMartCopperPrice { JsonPrimitive((it.asDouble / 1.851).round(1)) } } + + private fun isEnabled() = GardenAPI.inGarden() && config.copperPrice } diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryAPI.kt index 76fd47489..37ddb9a8e 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryAPI.kt @@ -2,6 +2,7 @@ package at.hannibal2.skyhanni.features.inventory.chocolatefactory import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator +import at.hannibal2.skyhanni.config.features.inventory.chocolatefactory.ChocolateFactoryConfig import at.hannibal2.skyhanni.config.storage.ProfileSpecificStorage.ChocolateFactoryStorage import at.hannibal2.skyhanni.data.ProfileStorageData import at.hannibal2.skyhanni.data.jsonobjects.repo.HoppityEggLocationsJson @@ -35,7 +36,7 @@ import net.minecraft.item.ItemStack import net.minecraftforge.fml.common.eventhandler.SubscribeEvent object ChocolateFactoryAPI { - val config get() = SkyHanniMod.feature.inventory.chocolateFactory + val config: ChocolateFactoryConfig get() = SkyHanniMod.feature.inventory.chocolateFactory val profileStorage: ChocolateFactoryStorage? get() = ProfileStorageData.profileSpecific?.chocolateFactory val patternGroup = RepoPattern.group("misc.chocolatefactory") @@ -97,7 +98,7 @@ object ChocolateFactoryAPI { ) private val chocolateFactoryInventoryNamePattern by patternGroup.pattern( "inventory.name", - "Hoppity|Chocolate Shop|Chocolate Factory Milestones" + "Hoppity|Chocolate Factory Milestones" ) var rabbitSlots = mapOf<Int, Int>() @@ -176,7 +177,7 @@ object ChocolateFactoryAPI { } val lore = item.getLore() - val upgradeCost = getChocolateUpgradeCost(lore) ?: continue + val upgradeCost = getChocolateBuyCost(lore) ?: continue val canAfford = upgradeCost <= ChocolateAmount.CURRENT.chocolate() if (canAfford) upgradeableSlots.add(slotIndex) @@ -351,7 +352,7 @@ object ChocolateFactoryAPI { event.move(44, "$old.hoppityStatsPosition", "$new.hoppityStatsPosition") } - fun getChocolateUpgradeCost(lore: List<String>): Long? { + fun getChocolateBuyCost(lore: List<String>): Long? { val nextLine = lore.nextAfter({ UtilsPatterns.costLinePattern.matches(it) }) ?: return null return chocolateAmountPattern.matchMatcher(nextLine.removeColor()) { group("amount").formatLong() diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryTooltip.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryTooltip.kt index 227ece8d9..9d556f64b 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryTooltip.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryTooltip.kt @@ -31,7 +31,7 @@ object ChocolateFactoryTooltip { if (slotIndex == ChocolateFactoryAPI.prestigeIndex) return if (slotIndex !in ChocolateFactoryAPI.otherUpgradeSlots && slotIndex !in ChocolateFactoryAPI.rabbitSlots) return - val upgradeCost = ChocolateFactoryAPI.getChocolateUpgradeCost(event.toolTip) ?: return + val upgradeCost = ChocolateFactoryAPI.getChocolateBuyCost(event.toolTip) ?: return event.toolTip.add("§8§m-----------------") val timeToUpgrade = ChocolateAmount.CURRENT.formattedTimeUntilGoal(upgradeCost) diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateShopPrice.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateShopPrice.kt new file mode 100644 index 000000000..37127d11b --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateShopPrice.kt @@ -0,0 +1,99 @@ +package at.hannibal2.skyhanni.features.inventory.chocolatefactory + +import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.events.InventoryCloseEvent +import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent +import at.hannibal2.skyhanni.utils.DisplayTableEntry +import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName +import at.hannibal2.skyhanni.utils.ItemUtils.getLore +import at.hannibal2.skyhanni.utils.ItemUtils.itemName +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.NEUItems.getPriceOrNull +import at.hannibal2.skyhanni.utils.NumberUtil +import at.hannibal2.skyhanni.utils.NumberUtil.million +import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables +import at.hannibal2.skyhanni.utils.StringUtils.matches +import at.hannibal2.skyhanni.utils.renderables.Renderable +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +object ChocolateShopPrice { + private val config get() = ChocolateFactoryAPI.config.chocolateShopPrice + + private var display = emptyList<Renderable>() + + private val menuNamePattern by ChocolateFactoryAPI.patternGroup.pattern( + "shop.title", + "Chocolate Shop" + ) + + var inInventory = false + + @SubscribeEvent + fun onInventoryOpen(event: InventoryFullyOpenedEvent) { + if (!isEnabled()) return + if (!menuNamePattern.matches(event.inventoryName)) return + + val multiplier = 1.million + + inInventory = true + // TODO merge core with SkyMartCopperPrice into a utils + val table = mutableListOf<DisplayTableEntry>() + for ((slot, item) in event.inventoryItems) { + val lore = item.getLore() + val chocolate = ChocolateFactoryAPI.getChocolateBuyCost(lore) ?: continue + val internalName = item.getInternalName() + val itemPrice = internalName.getPriceOrNull() ?: continue + + val factor = (itemPrice / chocolate) * multiplier + val perFormat = NumberUtil.format(factor) + + val itemName = item.itemName + val hover = buildList { + add(itemName) + + add("") + add("§7Item price: §6${NumberUtil.format(itemPrice)} ") + add("§7Chocolate amount: §c${NumberUtil.format(chocolate)} ") + + add("") + add("§7Profit per million chocolate: §6${perFormat} ") + } + table.add( + DisplayTableEntry( + "$itemName§f:", + "§6§l$perFormat", + factor, + internalName, + hover, + highlightsOnHoverSlots = listOf(slot) + ) + ) + } + + val newList = mutableListOf<Renderable>() + newList.add(Renderable.string("§eCoins per million chocolate§f:")) + // TODO update this value every second + // TODO add time until can afford + newList.add(Renderable.string("§eChocolate available: §6${ChocolateAmount.CURRENT.formatted}")) + newList.add(LorenzUtils.fillTable(table, padding = 5, itemScale = config.itemScale)) + display = newList + } + + @SubscribeEvent + fun onInventoryClose(event: InventoryCloseEvent) { + inInventory = false + } + + @SubscribeEvent + fun onBackgroundDraw(event: GuiRenderEvent.ChestGuiOverlayRenderEvent) { + if (inInventory) { + config.position.renderRenderables( + display, + extraSpace = 5, + posLabel = "Chocolate Shop Price" + ) + } + } + + private fun isEnabled() = LorenzUtils.inSkyBlock && config.enabled +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordRPCManager.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordRPCManager.kt index 8aa031b2d..9d9654353 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordRPCManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordRPCManager.kt @@ -84,12 +84,12 @@ object DiscordRPCManager : IPCListener { } catch (ex: Exception) { logger.warn("Failed to connect to RPC!", ex) ChatUtils.clickableChat( - "Discord Rich Presence was unable to start! " + + "Discord Rich Presence was unable to start! " + "This usually happens when you join SkyBlock when Discord is not started. " + "Please run /shrpcstart to retry once you have launched Discord.", - onClick = { - startCommand() - } + onClick = { + startCommand() + } ) } } @@ -125,10 +125,12 @@ object DiscordRPCManager : IPCListener { setLargeImage(discordIconKey, location) if (config.showSkyCryptButton.get()) { - addButton(RichPresenceButton( - "https://sky.shiiyu.moe/stats/${LorenzUtils.getPlayerName()}/${HypixelData.profileName}", - "Open SkyCrypt Profile" - )) + addButton( + RichPresenceButton( + "https://sky.shiiyu.moe/stats/${LorenzUtils.getPlayerName()}/${HypixelData.profileName}", + "Open SkyCrypt Profile" + ) + ) } }.build()) } |