diff options
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/event/lobby/waypoints/EventWaypoint.kt | 20 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/event/lobby/waypoints/christmas/PresentWaypoints.kt | 114 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/event/lobby/waypoints/halloween/Basket.kt (renamed from src/main/java/at/hannibal2/skyhanni/features/mainlobby/halloweenwaypoints/Basket.kt) | 4 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/event/lobby/waypoints/halloween/BasketEntrances.kt (renamed from src/main/java/at/hannibal2/skyhanni/features/mainlobby/halloweenwaypoints/BasketEntrances.kt) | 2 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/event/lobby/waypoints/halloween/BasketWaypoints.kt (renamed from src/main/java/at/hannibal2/skyhanni/features/mainlobby/halloweenwaypoints/BasketWaypoints.kt) | 16 |
5 files changed, 148 insertions, 8 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/lobby/waypoints/EventWaypoint.kt b/src/main/java/at/hannibal2/skyhanni/features/event/lobby/waypoints/EventWaypoint.kt new file mode 100644 index 000000000..da537d4c0 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/event/lobby/waypoints/EventWaypoint.kt @@ -0,0 +1,20 @@ +package at.hannibal2.skyhanni.features.event.lobby.waypoints + +import at.hannibal2.skyhanni.data.jsonobjects.repo.EventWaypointsJson +import at.hannibal2.skyhanni.utils.LorenzVec + +data class EventWaypoint( + val name: String, + val position: LorenzVec, + var isFound: Boolean = false +) + +fun loadEventWaypoints(waypoints: Map<String, List<EventWaypointsJson.Waypoint>>): Map<String, MutableSet<EventWaypoint>> { + return buildMap { + waypoints.forEach { lobby -> + val set = mutableSetOf<EventWaypoint>() + lobby.value.forEach { waypoint -> set.add(EventWaypoint(waypoint.name, waypoint.position)) } + this[lobby.key] = set + } + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/lobby/waypoints/christmas/PresentWaypoints.kt b/src/main/java/at/hannibal2/skyhanni/features/event/lobby/waypoints/christmas/PresentWaypoints.kt new file mode 100644 index 000000000..c400da59b --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/event/lobby/waypoints/christmas/PresentWaypoints.kt @@ -0,0 +1,114 @@ +package at.hannibal2.skyhanni.features.event.lobby.waypoints.christmas + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.HypixelData +import at.hannibal2.skyhanni.data.jsonobjects.repo.EventWaypointsJson +import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent +import at.hannibal2.skyhanni.events.LorenzTickEvent +import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent +import at.hannibal2.skyhanni.events.RepositoryReloadEvent +import at.hannibal2.skyhanni.features.event.lobby.waypoints.EventWaypoint +import at.hannibal2.skyhanni.features.event.lobby.waypoints.loadEventWaypoints +import at.hannibal2.skyhanni.test.GriffinUtils.drawWaypointFilled +import at.hannibal2.skyhanni.utils.LocationUtils.distanceSqToPlayer +import at.hannibal2.skyhanni.utils.LorenzColor +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText +import at.hannibal2.skyhanni.utils.StringUtils.matches +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +// todo: create abstract class for this and BasketWaypoints +class PresentWaypoints { + private val config get() = SkyHanniMod.feature.event.lobbyWaypoints.christmasPresent + private var presentLocations = mapOf<String, MutableSet<EventWaypoint>>() + private var presentEntranceLocations = mapOf<String, MutableSet<EventWaypoint>>() + private var closest: EventWaypoint? = null + + private val presentSet get() = presentLocations[HypixelData.lobbyType] + private val presentEntranceSet get() = presentEntranceLocations[HypixelData.lobbyType] + + private val presentAlreadyFoundPattern = "§cYou have already found this present!".toPattern() + private val presentFoundPattern = "§aYou found a.*present! §r§e\\(§r§b\\d+§r§e/§r§b\\d+§r§e\\)".toPattern() + private val allFoundPattern = "§aCongratulations! You found all the presents in every lobby!".toPattern() + + @SubscribeEvent + fun onWorldChange(event: LorenzWorldChangeEvent) { + if (!isEnabled()) return + closest = null + } + + @SubscribeEvent + fun onChat(event: LorenzChatEvent) { + if (!isEnabled()) return + processChatMessage(event.message) + } + + // <editor-fold desc = "Chat Message Processing"> + private fun processChatMessage(message: String) { + when { + presentFoundPattern.matches(message) || presentAlreadyFoundPattern.matches(message) -> handlePresentFound() + allFoundPattern.matches(message) -> handleAllPresentsFound() + } + } + + private fun handlePresentFound() { + presentSet?.minByOrNull { it.position.distanceSqToPlayer() }?.let { present -> + present.isFound = true + markEntranceAsFound(present) + if (closest == present) closest = null + } + } + + private fun markEntranceAsFound(present: EventWaypoint) { + presentEntranceSet?.find { present.name == it.name }?.let { it.isFound = true } + } + + private fun handleAllPresentsFound() { + // If all presents are found, disable the feature + LorenzUtils.chat("Congratulations! As all presents are found, we are disabling the Christmas Present Waypoints feature.") + config.allWaypoints = false + config.allEntranceWaypoints = false + } + + // </editor-fold> + + @SubscribeEvent + fun onTick(event: LorenzTickEvent) { + if (!isEnabled() && config.onlyClosest && HypixelData.locrawData != null && closest == null) return + val notFoundPresents = presentSet?.filterNot { it.isFound } + if (notFoundPresents?.isEmpty() == true) return + closest = notFoundPresents?.minByOrNull { it.position.distanceSqToPlayer() } ?: return + } + + @SubscribeEvent + fun onRenderWorld(event: LorenzRenderWorldEvent) { + if (!isEnabled()) return + presentSet?.let { event.drawWaypoints(it, config.allWaypoints, LorenzColor.GOLD, "§6") } + presentEntranceSet?.let { event.drawWaypoints(it, config.allEntranceWaypoints, LorenzColor.YELLOW, "§e") } + } + + private fun LorenzRenderWorldEvent.drawWaypoints( + waypoints: Set<EventWaypoint>, shouldDraw: Boolean, color: LorenzColor, prefix: String + ) { + if (!shouldDraw) return + waypoints.forEach { waypoint -> + if (!waypoint.shouldShow()) return@forEach + this.drawWaypointFilled(waypoint.position, color.toColor()) + this.drawDynamicText(waypoint.position, "$prefix${waypoint.name}", 1.5) + } + } + + private fun EventWaypoint.shouldShow(): Boolean = !isFound && (!config.onlyClosest || closest == this) + + @SubscribeEvent + fun onRepoReload(event: RepositoryReloadEvent) { + val data = event.getConstant<EventWaypointsJson>("EventWaypoints") + presentLocations = loadEventWaypoints(data.presents ?: error("'presents' is null in EventWaypoints!")) + presentEntranceLocations = + loadEventWaypoints(data.presents_entrances ?: error("'presents_entrances' is null in EventWaypoints!")) + } + + private fun isEnabled(): Boolean = + LorenzUtils.onHypixel && HypixelData.inLobby && (config.allWaypoints || config.allEntranceWaypoints) +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/mainlobby/halloweenwaypoints/Basket.kt b/src/main/java/at/hannibal2/skyhanni/features/event/lobby/waypoints/halloween/Basket.kt index 8b62adf4d..af36c46e7 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/mainlobby/halloweenwaypoints/Basket.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/lobby/waypoints/halloween/Basket.kt @@ -1,4 +1,4 @@ -package at.hannibal2.skyhanni.features.mainlobby.halloweenwaypoints +package at.hannibal2.skyhanni.features.event.lobby.waypoints.halloween import at.hannibal2.skyhanni.utils.LorenzVec @@ -31,4 +31,4 @@ enum class Basket(val basketName: String, val waypoint: LorenzVec) { ; var found = false -}
\ No newline at end of file +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/mainlobby/halloweenwaypoints/BasketEntrances.kt b/src/main/java/at/hannibal2/skyhanni/features/event/lobby/waypoints/halloween/BasketEntrances.kt index a923a382a..e2904f99e 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/mainlobby/halloweenwaypoints/BasketEntrances.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/lobby/waypoints/halloween/BasketEntrances.kt @@ -1,4 +1,4 @@ -package at.hannibal2.skyhanni.features.mainlobby.halloweenwaypoints +package at.hannibal2.skyhanni.features.event.lobby.waypoints.halloween import at.hannibal2.skyhanni.utils.LorenzVec diff --git a/src/main/java/at/hannibal2/skyhanni/features/mainlobby/halloweenwaypoints/BasketWaypoints.kt b/src/main/java/at/hannibal2/skyhanni/features/event/lobby/waypoints/halloween/BasketWaypoints.kt index 15902d52d..d9d90ca4a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/mainlobby/halloweenwaypoints/BasketWaypoints.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/lobby/waypoints/halloween/BasketWaypoints.kt @@ -1,6 +1,7 @@ -package at.hannibal2.skyhanni.features.mainlobby.halloweenwaypoints +package at.hannibal2.skyhanni.features.event.lobby.waypoints.halloween import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator import at.hannibal2.skyhanni.data.HypixelData import at.hannibal2.skyhanni.data.ScoreboardData import at.hannibal2.skyhanni.events.LorenzChatEvent @@ -15,7 +16,7 @@ import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class BasketWaypoints { - private val config get() = SkyHanniMod.feature.event.halloweenBasket + private val config get() = SkyHanniMod.feature.event.lobbyWaypoints.halloweenBasket private var closest: Basket? = null private var isHalloween: Boolean = false @@ -44,7 +45,7 @@ class BasketWaypoints { if (LorenzUtils.inSkyBlock) return if (event.repeatSeconds(1)) { - isHalloween = chechScoreboardHalloweenSpecific() + isHalloween = checkScoreboardHalloweenSpecific() } if (isHalloween) { @@ -92,8 +93,13 @@ class BasketWaypoints { return if (config.onlyClosest) closest == this else true } - private fun chechScoreboardHalloweenSpecific(): Boolean { + private fun checkScoreboardHalloweenSpecific(): Boolean { val list = ScoreboardData.sidebarLinesFormatted return list.anyContains("Hypixel Level") && list.anyContains("Halloween") && list.anyContains("Baskets") } -}
\ No newline at end of file + + @SubscribeEvent + fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { + event.move(13, "event.halloweenBasket", "event.lobbyWaypoints.halloweenBasket") + } +} |