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: timer to hoppity egg gui and chat messages #1625

Merged
merged 2 commits into from
May 3, 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
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package at.hannibal2.skyhanni.features.event.hoppity

import at.hannibal2.skyhanni.utils.SimpleTimeMark.Companion.asTimeMark
import io.github.moulberry.notenoughupdates.util.SkyBlockTime
import kotlin.time.Duration

enum class HoppityEggType(
val mealName: String,
Expand All @@ -14,6 +16,15 @@ enum class HoppityEggType(
DINNER("Dinner", 21, "§6"),
;

fun timeUntil(): Duration {
val now = SkyBlockTime.now()
if (now.hour >= resetsAt) {
return now.copy(day = now.day + 1, hour = resetsAt, minute = 0, second = 0)
.asTimeMark().timeUntil()
}
return now.copy(hour = resetsAt, minute = 0, second = 0).asTimeMark().timeUntil()
}

fun markClaimed() {
claimed = true
}
Expand All @@ -23,7 +34,7 @@ enum class HoppityEggType(
}

fun isClaimed() = claimed
val formattedName by lazy { "$mealColour$mealName" }
val formattedName get() = "${if (isClaimed()) "§7§m" else mealColour}$mealName:$mealColour"

companion object {
fun allFound() = entries.forEach { it.markClaimed() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ import at.hannibal2.skyhanni.utils.DelayedRun
import at.hannibal2.skyhanni.utils.LocationUtils
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings
import at.hannibal2.skyhanni.utils.SimpleTimeMark.Companion.asTimeMark
import at.hannibal2.skyhanni.utils.SimpleTimeMark.Companion.fromNow
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.TimeUtils.format
import io.github.moulberry.notenoughupdates.util.SkyBlockTime
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.util.regex.Matcher
import kotlin.time.Duration.Companion.seconds
Expand All @@ -40,6 +43,10 @@ object HoppityEggsManager {
"egg.alreadycollected",
"§cYou have already collected this Chocolate (?<meal>\\w+) Egg§r§c! Try again when it respawns!"
)
private val hoppityEventNotOn by ChocolateFactoryAPI.patternGroup.pattern(
"egg.notevent",
"§cThis only works during Hoppity's Hunt!"
)

private var lastMeal: HoppityEggType? = null

Expand All @@ -57,19 +64,35 @@ object HoppityEggsManager {
val meal = getEggType(event)
meal.markClaimed()
lastMeal = meal
return
}

noEggsLeftPattern.matchMatcher(event.message) {
HoppityEggType.allFound()

val nextEgg = HoppityEggType.entries.minByOrNull { it.timeUntil() } ?: return
event.chatComponent.appendText("\n§eNext egg available in §b${nextEgg.timeUntil().format()}")
return
}

eggAlreadyCollectedPattern.matchMatcher(event.message) {
getEggType(event).markClaimed()
val nextEgg = HoppityEggType.entries.minByOrNull { it.timeUntil() } ?: return
event.chatComponent.appendText("\n§eNext egg available in §b${nextEgg.timeUntil().format()}")
return
}

eggSpawnedPattern.matchMatcher(event.message) {
getEggType(event).markSpawned()
return
}

hoppityEventNotOn.matchMatcher(event.message) {
val currentYear = SkyBlockTime.now().year
val timeUntil = SkyBlockTime(currentYear + 1).asTimeMark().timeUntil()

event.chatComponent.appendText("\n§eNext Hoppity's Hunt in §b${timeUntil.format()}")
catgirlseraid marked this conversation as resolved.
Show resolved Hide resolved
return
}
}

Expand Down Expand Up @@ -104,8 +127,7 @@ object HoppityEggsManager {
if (!ChocolateFactoryAPI.isHoppityEvent()) return

val displayList = HoppityEggType.entries
.filter { !it.isClaimed() }
.map { "§7 - ${it.formattedName}" }
.map { "§7 - ${it.formattedName} ${it.timeUntil().format()}" }
.toMutableList()
displayList.add(0, "§bUnfound Eggs:")
if (displayList.size == 1) return
Expand All @@ -127,4 +149,6 @@ object HoppityEggsManager {
)
event.move(44, "event.chocolateFactory.hoppityEggs", "event.hoppityEggs")
}


}
Loading