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

Feature: Chocolate Shop Price #1601

Merged
merged 8 commits into from
May 1, 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
2 changes: 2 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactor
import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactoryTimeTowerManager
import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactoryTooltip
import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactoryTooltipCompact
import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateShopPrice
import at.hannibal2.skyhanni.features.inventory.tiarelay.TiaRelayHelper
import at.hannibal2.skyhanni.features.inventory.tiarelay.TiaRelayWaypoints
import at.hannibal2.skyhanni.features.itemabilities.ChickenHeadTimer
Expand Down Expand Up @@ -637,6 +638,7 @@ class SkyHanniMod {
loadModule(ChocolateFactoryTooltipCompact)
loadModule(ChocolateFactoryTimeTowerManager)
loadModule(ChocolateFactoryTooltip)
loadModule(ChocolateShopPrice)
loadModule(HoppityNpc)
loadModule(HoppityEggsManager)
loadModule(HoppityEggLocator)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import at.hannibal2.skyhanni.config.FeatureToggle;
import at.hannibal2.skyhanni.config.HasLegacyId;
import at.hannibal2.skyhanni.config.features.inventory.chocolatefactory.ChocolateFactoryConfig;
import at.hannibal2.skyhanni.config.features.inventory.helper.HelperConfig;
import at.hannibal2.skyhanni.config.features.itemability.ItemAbilityConfig;
import at.hannibal2.skyhanni.config.features.misc.EstimatedItemValueConfig;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package at.hannibal2.skyhanni.config.features.inventory;
package at.hannibal2.skyhanni.config.features.inventory.chocolatefactory;

import at.hannibal2.skyhanni.config.FeatureToggle;
import at.hannibal2.skyhanni.config.core.config.Position;
import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactoryStats.ChocolateFactoryStat;
import com.google.gson.annotations.Expose;
import io.github.notenoughupdates.moulconfig.annotations.Accordion;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorDraggableList;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorSlider;
Expand Down Expand Up @@ -133,4 +134,10 @@ public class ChocolateFactoryConfig {
@ConfigEditorBoolean
@FeatureToggle
public boolean hoppityMenuShortcut = true;

@Expose
@ConfigOption(name = "Chocolate Shop Price", desc = "")
@Accordion
public ChocolateShopPriceConfig chocolateShopPrice = new ChocolateShopPriceConfig();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package at.hannibal2.skyhanni.config.features.inventory.chocolatefactory;

import at.hannibal2.skyhanni.config.FeatureToggle;
import at.hannibal2.skyhanni.config.core.config.Position;
import com.google.gson.annotations.Expose;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorSlider;
import io.github.notenoughupdates.moulconfig.annotations.ConfigLink;
import io.github.notenoughupdates.moulconfig.annotations.ConfigOption;

public class ChocolateShopPriceConfig {

@Expose
@ConfigOption(name = "Enabled", desc = "Show chocolate to coin prices inside the Chocolate Shop inventory.")
@ConfigEditorBoolean
@FeatureToggle
public boolean enabled = true;

@Expose
@ConfigLink(owner = ChocolateFactoryConfig.class, field = "chocolateShopPrice")
public Position position = new Position(200, 150, false, true);

@Expose
@ConfigOption(name = "Item Scale", desc = "Change the size of the items.")
@ConfigEditorSlider(minValue = 0.3f, maxValue = 3, minStep = 0.1f)
public double itemScale = 0.6;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)} ")
}
Expand Down Expand Up @@ -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")
Expand All @@ -141,4 +139,6 @@ class SkyMartCopperPrice {
JsonPrimitive((it.asDouble / 1.851).round(1))
}
}

private fun isEnabled() = GardenAPI.inGarden() && config.copperPrice
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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>()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
)
}
}
Expand Down Expand Up @@ -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())
}
Expand Down
Loading