Skip to content

Commit

Permalink
Use chat messages to support teammate death status
Browse files Browse the repository at this point in the history
  • Loading branch information
My-Name-Is-Jeff committed Aug 5, 2023
1 parent 2472361 commit 42bf84d
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import gg.essential.universal.UChat
import gg.skytils.skytilsmod.Skytils
import gg.skytils.skytilsmod.core.TickTask
import gg.skytils.skytilsmod.core.structure.GuiElement
import gg.skytils.skytilsmod.listeners.DungeonListener
import gg.skytils.skytilsmod.utils.NumberUtil
import gg.skytils.skytilsmod.utils.NumberUtil.roundToPrecision
import gg.skytils.skytilsmod.utils.RenderUtil
Expand Down Expand Up @@ -100,6 +101,7 @@ object DungeonTimer {
)
) {
bossEntryTime = System.currentTimeMillis()
DungeonListener.markAllRevived()
if (Skytils.config.dungeonTimer && bloodClearTime != -1L) UChat.chat(
"§dPortal §btook ${diff(bossEntryTime, bloodClearTime)} seconds to enter."
)
Expand Down
84 changes: 58 additions & 26 deletions src/main/kotlin/gg/skytils/skytilsmod/listeners/DungeonListener.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,14 @@ object DungeonListener {
private val classPattern =
Regex("§r(?:§.)+(?:\\[.+] )?(?<name>\\w+?)(?:§.)* (?:§r(?:§[\\da-fklmno]){1,2}.+ )?§r§f\\(§r§d(?:(?<class>Archer|Berserk|Healer|Mage|Tank) (?<lvl>\\w+)|§r§7EMPTY)§r§f\\)§r")
private val missingPuzzlePattern = Regex("§r (?<puzzle>.+): §r§7\\[§r§6§l✦§r§7] ?§r")
private val deathRegex = Regex("§r§c ☠ §r§7(?:You were |(?:§.)+(?<username>\\w+)§r).* and became a ghost§r§7\\.§r")
private val reviveRegex = Regex("^§r§a ❣ §r§7(?:§.)+(?<username>\\w+)§r§a was revived")

@SubscribeEvent
fun onPacket(event: MainReceivePacketEvent<*, *>) {
if (!Utils.inDungeons) return
if (event.packet is S02PacketChat) {
val text = event.packet.chatComponent.formattedText
if (event.packet.chatComponent.unformattedText.startsWith("Starting in 1 second.")) {
team.clear()
deads.clear()
Expand All @@ -108,6 +111,18 @@ object DungeonListener {
if (Skytils.config.autoRepartyOnDungeonEnd) {
RepartyCommand.processCommand(mc.thePlayer, emptyArray())
}
} else if (text.startsWith("§r§c ☠ ") && text.endsWith(" and became a ghost§r§7.§r")) {
val match = deathRegex.find(text) ?: return
val username = match.groups["username"]?.value ?: mc.thePlayer.name
val teammate = team[username] ?: return
markDead(teammate)
} else if (text.startsWith("§r§a ❣ ")) {
val match = reviveRegex.find(text) ?: return
val username = match.groups["username"]!!.value
val teammate = team[username] ?: return
if (deads.remove(teammate)) {
teammate.dead = false
}
}
}
}
Expand Down Expand Up @@ -143,31 +158,7 @@ object DungeonListener {
}
teammate.dead = entry.endsWith("§r§cDEAD§r§f)§r")
if (teammate.dead) {
if (deads.add(teammate)) {
teammate.deaths++
val totalDeaths = team.values.sumOf { it.deaths }
val isFirstDeath = totalDeaths == 1

@Suppress("LocalVariableName")
val `silly~churl, billy~churl, silly~billy hilichurl` = if (isFirstDeath) {
val hutaoIsCool = hutaoFans.getIfPresent(teammate.playerName) ?: false
ScoreCalculation.firstDeathHadSpirit.set(hutaoIsCool)
hutaoIsCool
} else false
printDevMessage(isFirstDeath.toString(), "spiritpet")
printDevMessage(ScoreCalculation.firstDeathHadSpirit.toString(), "spiritpet")
if (Skytils.config.dungeonDeathCounter) {
TickTask(1) {
UChat.chat(
"§bThis is §e${teammate.playerName}§b's §e${teammate.deaths.addSuffix()}§b death out of §e${totalDeaths}§b total tracked deaths.${
" §6(SPIRIT)".toStringIfTrue(
`silly~churl, billy~churl, silly~billy hilichurl`
)
}"
)
}
}
}
markDead(teammate)
} else {
deads.remove(teammate)
}
Expand All @@ -176,6 +167,46 @@ object DungeonListener {
}
}

fun markDead(teammate: DungeonTeammate) {
if (deads.add(teammate)) {
val time = System.currentTimeMillis()
val lastDeath = teammate.lastMarkedDead
// there's no way they die twice in less than half a second
if (lastDeath != null && time - lastDeath <= 500) return
teammate.lastMarkedDead = time
teammate.deaths++
val totalDeaths = team.values.sumOf { it.deaths }
val isFirstDeath = totalDeaths == 1

@Suppress("LocalVariableName")
val `silly~churl, billy~churl, silly~billy hilichurl` = if (isFirstDeath) {
val hutaoIsCool = hutaoFans.getIfPresent(teammate.playerName) ?: false
ScoreCalculation.firstDeathHadSpirit.set(hutaoIsCool)
hutaoIsCool
} else false
printDevMessage(isFirstDeath.toString(), "spiritpet")
printDevMessage(ScoreCalculation.firstDeathHadSpirit.toString(), "spiritpet")
if (Skytils.config.dungeonDeathCounter) {
TickTask(1) {
UChat.chat(
"§bThis is §e${teammate.playerName}§b's §e${teammate.deaths.addSuffix()}§b death out of §e${totalDeaths}§b total tracked deaths.${
" §6(SPIRIT)".toStringIfTrue(
`silly~churl, billy~churl, silly~billy hilichurl`
)
}"
)
}
}
}
}

fun markAllRevived() {
deads.clear()
team.values.forEach {
it.dead = false
}
}

private fun getMembers() {
if (team.isNotEmpty() || !Utils.inDungeons) return
val tabEntries = TabListUtils.tabEntries
Expand Down Expand Up @@ -257,7 +288,7 @@ object DungeonListener {
}
}

class DungeonTeammate(
data class DungeonTeammate(
val playerName: String,
val dungeonClass: DungeonClass,
val classLevel: Int,
Expand All @@ -266,6 +297,7 @@ object DungeonListener {
var player: EntityPlayer? = null
var dead = false
var deaths = 0
var lastMarkedDead: Long? = null


fun canRender() = player != null && player!!.health > 0 && !dead
Expand Down

0 comments on commit 42bf84d

Please sign in to comment.