Skip to content

Commit

Permalink
added timer to hoppity egg gui and chat messages (#1625)
Browse files Browse the repository at this point in the history
Co-authored-by: hannibal2 <24389977+hannibal002@users.noreply.github.com>
  • Loading branch information
catgirlseraid and hannibal002 authored May 3, 2024
1 parent df8b39c commit 29b1129
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
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()}")
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")
}


}

0 comments on commit 29b1129

Please sign in to comment.