aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features/rift
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-07-25 03:36:16 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-07-25 03:36:16 +0200
commit4acfc5313cb68d28167c4fe4c91ad7666befc677 (patch)
treeabe83581a533a06d8063601d3142059a1c344f92 /src/main/java/at/hannibal2/skyhanni/features/rift
parente2c7746ab27d8abdfef3e93743ed243a68469192 (diff)
downloadskyhanni-4acfc5313cb68d28167c4fe4c91ad7666befc677.tar.gz
skyhanni-4acfc5313cb68d28167c4fe4c91ad7666befc677.tar.bz2
skyhanni-4acfc5313cb68d28167c4fe4c91ad7666befc677.zip
Show locations of inactive Blood Effigy
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/rift')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/rift/area/stillgorechateau/RiftBloodEffigies.kt141
1 files changed, 141 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/rift/area/stillgorechateau/RiftBloodEffigies.kt b/src/main/java/at/hannibal2/skyhanni/features/rift/area/stillgorechateau/RiftBloodEffigies.kt
new file mode 100644
index 000000000..9892be944
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/rift/area/stillgorechateau/RiftBloodEffigies.kt
@@ -0,0 +1,141 @@
+package at.hannibal2.skyhanni.features.rift.area.stillgorechateau
+
+import at.hannibal2.skyhanni.events.LorenzTickEvent
+import at.hannibal2.skyhanni.events.LorenzWorldSwitchEvent
+import at.hannibal2.skyhanni.events.RepositoryReloadEvent
+import at.hannibal2.skyhanni.events.ScoreboardRawChangeEvent
+import at.hannibal2.skyhanni.features.rift.everywhere.RiftAPI
+import at.hannibal2.skyhanni.test.GriffinUtils.drawWaypointFilled
+import at.hannibal2.skyhanni.utils.*
+import at.hannibal2.skyhanni.utils.LocationUtils.distanceToPlayer
+import at.hannibal2.skyhanni.utils.LorenzUtils.editCopy
+import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
+import at.hannibal2.skyhanni.utils.jsonobjects.RiftEffingesJson
+import net.minecraft.entity.item.EntityArmorStand
+import net.minecraftforge.client.event.RenderWorldLastEvent
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+
+class RiftBloodEffigies {
+ private val config get() = RiftAPI.config.area.stillgoreChateauConfig.bloodEffigies
+ private var locations: List<LorenzVec> = emptyList()
+ private var effingesTime = mapOf(
+ 0 to -1L,
+ 1 to -1L,
+ 2 to -1L,
+ 3 to -1L,
+ 4 to -1L,
+ 5 to -1L,
+ )
+
+ private val effigiesTimerPattern = "§eRespawn §c(?<time>.*) §7\\(or click!\\)".toPattern()
+
+ @SubscribeEvent
+ fun onWorldSwitch(event: LorenzWorldSwitchEvent) {
+ effingesTime = mapOf(
+ 0 to -1L,
+ 1 to -1L,
+ 2 to -1L,
+ 3 to -1L,
+ 4 to -1L,
+ 5 to -1L,
+ )
+ }
+
+ @SubscribeEvent
+ fun onRepoReload(event: RepositoryReloadEvent) {
+ event.getConstant<RiftEffingesJson>("RiftEffinges")?.locations?.let {
+ if (it.size != 6) {
+ error("Invalid rift effinges size: ${it.size} (expeced 6)")
+ }
+ locations = it
+ }
+ }
+
+ @SubscribeEvent
+ fun onScoreboardChange(event: ScoreboardRawChangeEvent) {
+ if (!isEnabled()) return
+
+ val line = event.newList.firstOrNull { it.startsWith("Effigies:") } ?: return
+ val hearts = "Effigies: (?<hearts>.*)".toPattern().matchMatcher(line) {
+ group("hearts")
+ } ?: return
+
+ val split = hearts.split("§").drop(1)
+ for ((index, s) in split.withIndex()) {
+ val time = effingesTime[index]!!
+ val diff = time - System.currentTimeMillis()
+ if (diff < 0L) {
+ if (s == "7") {
+ if (time != 0L) {
+ LorenzUtils.chat("§e[SkyHanni] Effigies #${index + 1} respawned!")
+ effingesTime = effingesTime.editCopy { this[index] = 0L }
+ }
+ } else {
+ if (time != -1L) {
+ LorenzUtils.chat("§e[SkyHanni] Effigies #${index + 1} got killed!")
+ val endTime = System.currentTimeMillis() + 1_000 * 60 * 10
+ effingesTime = effingesTime.editCopy { this[index] = endTime }
+ }
+ }
+ }
+ }
+ }
+
+ @SubscribeEvent
+ fun onTick(event: LorenzTickEvent) {
+ if (!event.isMod(20)) return
+ if (!isEnabled()) return
+
+ for (entity in EntityUtils.getEntitiesNearby<EntityArmorStand>(LocationUtils.playerLocation(), 6.0)) {
+ effigiesTimerPattern.matchMatcher(entity.name) {
+ val nearest = locations.sortedBy { it.distanceSq(entity.getLorenzVec()) }.firstOrNull() ?: return
+ val index = locations.indexOf(nearest)
+
+ val string = group("time")
+ val time = TimeUtils.getMillis(string)
+ effingesTime = effingesTime.editCopy { this[index] = System.currentTimeMillis() + time }
+ }
+ }
+ }
+
+ @SubscribeEvent
+ fun onRenderWorld(event: RenderWorldLastEvent) {
+ if (!isEnabled()) return
+
+ for ((index, location) in locations.withIndex()) {
+ val name = "Effigies #${index + 1}"
+ val duration = effingesTime[index]!!
+
+ if (duration == -1L) {
+ if (config.unknownTime) {
+ event.drawWaypointFilled(location, LorenzColor.GRAY.toColor(), seeThroughBlocks = true)
+ event.drawDynamicText(location, "§7Unknown Time ($name)", 1.5)
+ continue
+ }
+ } else {
+ val diff = duration - System.currentTimeMillis()
+ if (duration <= 0L) {
+ event.drawWaypointFilled(location, LorenzColor.RED.toColor(), seeThroughBlocks = true)
+ event.drawDynamicText(location, "§c$name is Alive! Break it!", 1.5)
+ continue
+ }
+
+ if (config.respawningSoon) {
+ if (diff < 60_000 * config.respwningSoonTime) {
+ val time = TimeUtils.formatDuration(diff - 999)
+ event.drawWaypointFilled(location, LorenzColor.YELLOW.toColor(), seeThroughBlocks = true)
+ event.drawDynamicText(location, "§e$name is respawning $time", 1.5)
+ continue
+ }
+ }
+ }
+
+ if (location.distanceToPlayer() < 5) {
+ event.drawDynamicText(location, "§7$name", 1.5)
+ }
+ }
+ }
+
+ fun isEnabled() = RiftAPI.inRift() && RiftAPI.inStillgoreChateau() && config.enabled
+}