summaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features/fame
diff options
context:
space:
mode:
authorappable <enzospiacitelli@gmail.com>2023-08-15 03:17:04 -0700
committerGitHub <noreply@github.com>2023-08-15 12:17:04 +0200
commit75a80664c2034fc4a68a115a1b686676a53949d5 (patch)
tree76e90f7330ac156272575b6f4b6c1683ab801196 /src/main/java/at/hannibal2/skyhanni/features/fame
parentd4ef6a6e3e1bee596ccbb38fef8abcce7290615e (diff)
downloadskyhanni-75a80664c2034fc4a68a115a1b686676a53949d5.tar.gz
skyhanni-75a80664c2034fc4a68a115a1b686676a53949d5.tar.bz2
skyhanni-75a80664c2034fc4a68a115a1b686676a53949d5.zip
Merge pull request #380
* account upgrade reminder
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/fame')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/fame/AccountUpgradeReminder.kt99
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/fame/CityProjectFeatures.kt194
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/fame/ReminderUtils.kt9
3 files changed, 302 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/fame/AccountUpgradeReminder.kt b/src/main/java/at/hannibal2/skyhanni/features/fame/AccountUpgradeReminder.kt
new file mode 100644
index 000000000..91efb365e
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/fame/AccountUpgradeReminder.kt
@@ -0,0 +1,99 @@
+package at.hannibal2.skyhanni.features.fame
+
+import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.data.ProfileStorageData
+import at.hannibal2.skyhanni.events.*
+import at.hannibal2.skyhanni.utils.ItemUtils.getLore
+import at.hannibal2.skyhanni.utils.LorenzUtils
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+
+class AccountUpgradeReminder {
+ private var inInventory = false
+ private var durationDays = -1
+ private var lastReminderSend = 0L
+
+ @SubscribeEvent
+ fun onTick(event: LorenzTickEvent) {
+ if (!LorenzUtils.inSkyBlock) return
+ if (event.repeatSeconds(1)) {
+ checkReminder()
+ }
+ }
+
+ // TODO: Merge this logic with CityProjectFeatures reminder to reduce duplication
+ private fun checkReminder() {
+ if (!isEnabled()) return
+ val playerSpecific = ProfileStorageData.playerSpecific ?: return
+ if (ReminderUtils.isBusy()) return
+ if (LorenzUtils.skyBlockArea == "Community Center") return
+
+ val upgrade = playerSpecific.currentAccountUpgrade ?: return
+ if (System.currentTimeMillis() <= playerSpecific.nextAccountUpgradeCompletionTime ) return
+
+ if (lastReminderSend + 30_000 > System.currentTimeMillis()) return
+ lastReminderSend = System.currentTimeMillis()
+
+ LorenzUtils.clickableChat(
+ "§e[SkyHanni] The §a$upgrade §eupgrade has completed! §c(Click to disable these reminders)",
+ "shstopaccountupgradereminder"
+ )
+ }
+
+ @SubscribeEvent
+ fun onInventoryLoad(event: InventoryFullyOpenedEvent) {
+ if (!LorenzUtils.inSkyBlock) return
+ inInventory = event.inventoryName == "Community Shop"
+ }
+
+ @SubscribeEvent
+ @Suppress("UNUSED_PARAMETER")
+ fun onInventoryClose(event: InventoryCloseEvent) {
+ inInventory = false
+ }
+
+ @SubscribeEvent
+ fun onSlotClick(event: GuiContainerEvent.SlotClickEvent) {
+ if (!inInventory) return
+ val clickedItemLore = event.slot?.stack?.getLore() ?: return
+ if (clickedItemLore.getOrNull(0) != "§8Account Upgrade") return
+ durationDays = clickedItemLore.firstNotNullOf {
+ durationRegex.matchEntire(it)
+ }.groups[1]!!.value.toInt()
+ }
+
+ @SubscribeEvent
+ fun onUpgradeStarted(event: LorenzChatEvent) {
+ if (claimedRegex.matches(event.message)) {
+ clearUpgrade()
+ } else {
+ val upgrade = startedRegex.matchEntire(event.message)?.groups?.get(1)?.value ?: return
+ startUpgrade(upgrade)
+ }
+ }
+
+ private fun startUpgrade(upgrade: String) {
+ if (durationDays == -1) return
+ val playerSpecific = ProfileStorageData.playerSpecific ?: return
+ playerSpecific.currentAccountUpgrade = upgrade
+ playerSpecific.nextAccountUpgradeCompletionTime = System.currentTimeMillis() + durationDays.toLong() * MILLIS_IN_DAY
+ }
+
+ private fun clearUpgrade() {
+ val playerSpecific = ProfileStorageData.playerSpecific ?: return
+ playerSpecific.currentAccountUpgrade = null
+ playerSpecific.nextAccountUpgradeCompletionTime = -1L
+ }
+
+ companion object {
+ private val durationRegex = "§8Duration: (\\d{1,3})d".toRegex()
+ private val startedRegex = "§eYou started the §r§a(.+) §r§eupgrade!".toRegex()
+ private val claimedRegex = "§eYou claimed the §r§a.+ §r§eupgrade!".toRegex()
+ private const val MILLIS_IN_DAY = 1000 * 60 * 60 * 24L
+
+ private fun isEnabled() = SkyHanniMod.feature.misc.accountUpgradeReminder
+
+ fun disable() {
+ SkyHanniMod.feature.misc.accountUpgradeReminder = false
+ }
+ }
+} \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/features/fame/CityProjectFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/fame/CityProjectFeatures.kt
new file mode 100644
index 000000000..8e2c2e13a
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/fame/CityProjectFeatures.kt
@@ -0,0 +1,194 @@
+package at.hannibal2.skyhanni.features.fame
+
+import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.data.ProfileStorageData
+import at.hannibal2.skyhanni.events.*
+import at.hannibal2.skyhanni.features.bazaar.BazaarApi
+import at.hannibal2.skyhanni.features.garden.contest.FarmingContestAPI
+import at.hannibal2.skyhanni.utils.*
+import at.hannibal2.skyhanni.utils.ItemUtils.getLore
+import at.hannibal2.skyhanni.utils.ItemUtils.name
+import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList
+import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
+import at.hannibal2.skyhanni.utils.RenderUtils.highlight
+import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
+import at.hannibal2.skyhanni.utils.renderables.Renderable
+import net.minecraft.client.Minecraft
+import net.minecraft.client.gui.inventory.GuiChest
+import net.minecraft.client.gui.inventory.GuiEditSign
+import net.minecraft.inventory.ContainerChest
+import net.minecraft.item.ItemStack
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+
+class CityProjectFeatures {
+ private var display = emptyList<List<Any>>()
+ private var inInventory = false
+ private var lastReminderSend = 0L
+ private val contributeAgainPattern = "§7Contribute again: §e(?<time>.*)".toPattern()
+
+ companion object {
+ private val config get() = SkyHanniMod.feature.misc.cityProject
+ fun disable() {
+ config.dailyReminder = false
+ LorenzUtils.chat("§c[SkyHanni] Disabled city project reminder messages!")
+ }
+ }
+
+ @SubscribeEvent
+ fun onTick(event: LorenzTickEvent) {
+ if (!LorenzUtils.inSkyBlock) return
+ if (event.repeatSeconds(1)) {
+ checkDailyReminder()
+ }
+ }
+
+ private fun checkDailyReminder() {
+ if (!config.dailyReminder) return
+ val playerSpecific = ProfileStorageData.playerSpecific ?: return
+ if (ReminderUtils.isBusy()) return
+
+ if (LorenzUtils.skyBlockArea == "Community Center") return
+
+ if (playerSpecific.nextCityProjectParticipationTime == 0L) return
+ if (System.currentTimeMillis() <= playerSpecific.nextCityProjectParticipationTime) return
+
+ if (lastReminderSend + 30_000 > System.currentTimeMillis()) return
+ lastReminderSend = System.currentTimeMillis()
+
+ LorenzUtils.clickableChat(
+ "§e[SkyHanni] Daily City Project Reminder! (Click here to disable this reminder)",
+ "shstopcityprojectreminder"
+ )
+ }
+
+ @SubscribeEvent
+ fun onInventoryClose(event: InventoryCloseEvent) {
+ inInventory = false
+ }
+
+ @SubscribeEvent
+ fun onInventoryOpen(event: InventoryFullyOpenedEvent) {
+ if (!LorenzUtils.inSkyBlock) return
+
+ val lore = event.inventoryItems[4]?.getLore() ?: return
+ if (lore.isEmpty()) return
+ if (lore[0] != "§8City Project") return
+ inInventory = true
+
+ if (config.showMaterials) {
+ // internal name -> amount
+ val materials = mutableMapOf<String, Int>()
+ for ((_, item) in event.inventoryItems) {
+ val itemName = item.name ?: continue
+ if (itemName != "§eContribute this component!") continue
+ fetchMaterials(item, materials)
+ }
+
+ display = buildList(materials)
+ }
+
+ if (config.showReady) {
+ var nextTime = Long.MAX_VALUE
+ for ((_, item) in event.inventoryItems) {
+ val itemName = item.name ?: continue
+
+ for (line in item.getLore()) {
+ contributeAgainPattern.matchMatcher(line) {
+ val duration = TimeUtils.getMillis(group("time"))
+ val endTime = System.currentTimeMillis() + duration
+ if (endTime < nextTime) {
+ nextTime = endTime
+ }
+ }
+ }
+ if (itemName != "§eContribute this component!") continue
+ nextTime = System.currentTimeMillis()
+ }
+ ProfileStorageData.playerSpecific?.nextCityProjectParticipationTime = nextTime
+ }
+ }
+
+ private fun buildList(materials: MutableMap<String, Int>) = buildList<List<Any>> {
+ addAsSingletonList("§7City Project Materials")
+
+ if (materials.isEmpty()) {
+ addAsSingletonList("§cNo Materials to contribute.")
+ return@buildList
+ }
+
+ for ((internalName, amount) in materials) {
+ val stack = NEUItems.getItemStack(internalName)
+ val name = stack.name ?: continue
+ val list = mutableListOf<Any>()
+ list.add(" §7- ")
+ list.add(stack)
+
+ list.add(Renderable.optionalLink("$name §ex${amount.addSeparators()}", {
+ if (Minecraft.getMinecraft().currentScreen is GuiEditSign) {
+ LorenzUtils.setTextIntoSign("$amount")
+ } else {
+ BazaarApi.searchForBazaarItem(name, amount)
+ }
+ }) { inInventory && !NEUItems.neuHasFocus() })
+
+ val price = NEUItems.getPrice(internalName) * amount
+ val format = NumberUtil.format(price)
+ list.add(" §7(§6$format§7)")
+ add(list)
+ }
+ }
+
+ private fun fetchMaterials(item: ItemStack, materials: MutableMap<String, Int>) {
+ var next = false
+ for (line in item.getLore()) {
+ if (line == "§7Cost") {
+ next = true
+ continue
+ }
+ if (!next) continue
+ if (line == "") break
+ if (line.contains("Bits")) break
+
+ val (name, amount) = ItemUtils.readItemAmount(line)
+ if (name != null) {
+ val internalName = NEUItems.getRawInternalName(name)
+ val old = materials.getOrPut(internalName) { 0 }
+ materials[internalName] = old + amount
+ }
+ }
+ }
+
+ @SubscribeEvent
+ fun onBackgroundDraw(event: GuiRenderEvent.ChestBackgroundRenderEvent) {
+ if (!LorenzUtils.inSkyBlock) return
+ if (!config.showMaterials) return
+ if (!inInventory) return
+
+ config.pos.renderStringsAndItems(display, posLabel = "City Project Materials")
+ }
+
+ @SubscribeEvent
+ fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) {
+ if (!LorenzUtils.inSkyBlock) return
+ if (!config.showReady) return
+ if (!inInventory) return
+
+
+ if (event.gui !is GuiChest) return
+ val guiChest = event.gui
+ val chest = guiChest.inventorySlots as ContainerChest
+
+ for (slot in chest.inventorySlots) {
+ if (slot == null) continue
+ if (slot.slotNumber != slot.slotIndex) continue
+ val stack = slot.stack ?: continue
+ val lore = stack.getLore()
+ if (lore.isEmpty()) continue
+ val last = lore.last()
+ if (last == "§eClick to contribute!") {
+ slot highlight LorenzColor.YELLOW
+ }
+ }
+ }
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/fame/ReminderUtils.kt b/src/main/java/at/hannibal2/skyhanni/features/fame/ReminderUtils.kt
new file mode 100644
index 000000000..6d1ab94e1
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/fame/ReminderUtils.kt
@@ -0,0 +1,9 @@
+package at.hannibal2.skyhanni.features.fame
+
+import at.hannibal2.skyhanni.features.garden.contest.FarmingContestAPI
+import at.hannibal2.skyhanni.utils.LorenzUtils
+
+object ReminderUtils {
+ fun isBusy(): Boolean =
+ LorenzUtils.inDungeons || LorenzUtils.inKuudraFight || FarmingContestAPI.inContest
+} \ No newline at end of file