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: reminder to open hoppity shop each year #1843

Merged
merged 8 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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 @@ -87,6 +87,12 @@ public class HoppityEggsConfig {
@FeatureToggle
public boolean highlightHoppityShop = true;

@Expose
@ConfigOption(name = "Hoppity Shop Reminder", desc = "Reminds you to open the Hoppity Shop each year.")
@ConfigEditorBoolean
@FeatureToggle
public boolean hoppityShopReminder = true;

@Expose
@ConfigOption(name = "Time in Chat", desc = "When the Egglocator can't find an egg, show the time until the next Hoppity event or egg spawn.")
@ConfigEditorBoolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ public static class PositionChange {

@Expose
public String targetName = null;

@Expose
public Integer hoppityShopYearOpened = null;
}

@Expose
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,60 @@ import at.hannibal2.skyhanni.events.InventoryCloseEvent
import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
import at.hannibal2.skyhanni.events.InventoryUpdatedEvent
import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
import at.hannibal2.skyhanni.events.SecondPassedEvent
import at.hannibal2.skyhanni.features.fame.ReminderUtils
import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactoryAPI
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.LorenzColor
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.RenderUtils.highlight
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.SkyBlockTime
import at.hannibal2.skyhanni.utils.SkyblockSeason
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.time.Duration.Companion.seconds

object HoppityNpc {

private val config get() = HoppityEggsManager.config

private var lastReminderSent = SimpleTimeMark.farPast()
private var hoppityYearOpened
get() = ChocolateFactoryAPI.profileStorage?.hoppityShopYearOpened ?: -1
set(value) {
ChocolateFactoryAPI.profileStorage?.hoppityShopYearOpened = value
}

private var slotsToHighlight = mutableSetOf<Int>()
private var inShop = false

@SubscribeEvent
fun onInventoryOpen(event: InventoryFullyOpenedEvent) {
if (!isEnabled()) return
if (event.inventoryName != "Hoppity") return
hoppityYearOpened = SkyBlockTime.now().year
appable0 marked this conversation as resolved.
Show resolved Hide resolved
inShop = true
}

private fun clear() {
inShop = false
slotsToHighlight.clear()
@SubscribeEvent
fun onSecondPassed(event: SecondPassedEvent) {
if (!isReminderEnabled()) return
if (ReminderUtils.isBusy()) return
if (hoppityYearOpened == SkyBlockTime.now().year) return
if (!ChocolateFactoryAPI.isHoppityEvent()) return
if (lastReminderSent.passedSince() <= 30.seconds) return

ChatUtils.clickableChat(
"New rabbits are available at §aHoppity's Shop§e! §c(Click to disable this reminder)",
onClick = {
disableReminder()
ChatUtils.chat("§eHoppity's Shop reminder disabled.")
},
oneTimeClick = true
)

lastReminderSent = SimpleTimeMark.now()
}

@SubscribeEvent
Expand All @@ -54,6 +84,7 @@ object HoppityNpc {

@SubscribeEvent
fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) {
if (!isHighlightEnabled()) return
if (!inShop) return
for (slot in InventoryUtils.getItemsInOpenChest()) {
if (slot.slotIndex in slotsToHighlight) {
Expand All @@ -62,5 +93,15 @@ object HoppityNpc {
}
}

fun isEnabled() = LorenzUtils.inSkyBlock && config.highlightHoppityShop
private fun isHighlightEnabled() = LorenzUtils.inSkyBlock && config.highlightHoppityShop
private fun isReminderEnabled() = LorenzUtils.inSkyBlock && config.hoppityShopReminder

private fun clear() {
inShop = false
slotsToHighlight.clear()
}

private fun disableReminder() {
config.hoppityShopReminder = false
}
}
Loading