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: Show total amount of chocolate spent in chocolate shop #1921

Merged
merged 2 commits into from
May 29, 2024
Merged
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 @@ -15,8 +15,11 @@ import at.hannibal2.skyhanni.utils.NEUInternalName
import at.hannibal2.skyhanni.utils.NEUItems.getPrice
import at.hannibal2.skyhanni.utils.NEUItems.getPriceOrNull
import at.hannibal2.skyhanni.utils.NumberUtil
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.NumberUtil.formatInt
import at.hannibal2.skyhanni.utils.NumberUtil.million
import at.hannibal2.skyhanni.utils.RegexUtils.groupOrNull
import at.hannibal2.skyhanni.utils.RegexUtils.matchFirst
import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import at.hannibal2.skyhanni.utils.RegexUtils.matches
import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables
Expand All @@ -40,11 +43,18 @@ object ChocolateShopPrice {
"shop.bought",
"§aYou bought §r§.(?<item>[\\w ]+)§r(?:§8 x(?<amount>\\d+)§r)?§a!"
)
private val chocolateSpentPattern by ChocolateFactoryAPI.patternGroup.pattern(
"shop.spent",
"§7Chocolate Spent: §6(?<amount>[\\d,]+)"
)

var inInventory = false
private var callUpdate = false
var inventoryItems = emptyMap<Int, ItemStack>()

private const val MILESTONE_INDEX = 50
private var chocolateSpent = 0

@SubscribeEvent
fun onSecondPassed(event: SecondPassedEvent) {
if (inInventory) {
Expand Down Expand Up @@ -74,8 +84,14 @@ object ChocolateShopPrice {
private fun updateProducts() {
val newProducts = mutableListOf<Product>()
for ((slot, item) in inventoryItems) {

val lore = item.getLore()

if (slot == MILESTONE_INDEX) {
lore.matchFirst(chocolateSpentPattern) {
chocolateSpent = group("amount").formatInt()
}
}

val chocolate = ChocolateFactoryAPI.getChocolateBuyCost(lore) ?: continue
val internalName = item.getInternalName()
val itemPrice = internalName.getPriceOrNull() ?: continue
Expand Down Expand Up @@ -132,6 +148,8 @@ object ChocolateShopPrice {
// TODO update this value every second
// TODO add time until can afford
newList.add(Renderable.string("§eChocolate available: §6${ChocolateAmount.CURRENT.formatted}"))
// TODO add chocolate spend needed for next milestone
newList.add(Renderable.string("§eChocolate spent: §6${chocolateSpent.addSeparators()}"))
newList.add(LorenzUtils.fillTable(table, padding = 5, itemScale = config.itemScale))
display = newList
}
Expand Down
Loading