Skip to content

Commit

Permalink
KOTH bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
stephendotgg committed Nov 24, 2023
1 parent 65d62fb commit 825c14c
Showing 1 changed file with 39 additions and 29 deletions.
68 changes: 39 additions & 29 deletions src/main/kotlin/gg/flyte/event/game/main/type/KingOfTheHillGame.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gg.flyte.event.game.main.type
import gg.flyte.event.game.GameType
import gg.flyte.event.game.main.MainGame
import gg.flyte.event.game.main.MainGameEngine
import gg.flyte.event.game.main.MainGameEngine.points
import gg.flyte.twilight.event.event
import gg.flyte.twilight.extension.*
import gg.flyte.twilight.scheduler.repeat
Expand Down Expand Up @@ -60,35 +61,9 @@ class KingOfTheHillGame : MainGame() {

private fun gameLoop() {
val onHill = mutableListOf<Player>()

val iterator = alive.iterator()
while (iterator.hasNext()) {
val player = iterator.next()
if (player.location.y <= RESPAWN_Y) {
if (player.health == 2.0) {
player.apply {
inventory.clear()
teleport(GameType.KING_OF_THE_HILL.spectatorSpawn!!)
playSound(Sound.ENTITY_PLAYER_DEATH)
world.strikeLightning(player.location)
getAttribute(Attribute.GENERIC_MAX_HEALTH)?.baseValue = 20.0;
health = 20.0
resetTitle()
clearActionBar()
}
iterator.remove()
Bukkit.broadcastMessage("${player.name} was elmimnated")

if (alive.size == 0) {
Bukkit.broadcastMessage("game ended, $player last man standing")
MainGameEngine.stop()
return
}
} else {
player.health = player.health - 2
}
} else if (GameType.KING_OF_THE_HILL.region.contains(player.location)) {
onHill.add(player)
alive.applyForEach {
if (GameType.KING_OF_THE_HILL.region.contains(location)) {
onHill.add(this)
}
}

Expand Down Expand Up @@ -137,6 +112,41 @@ class KingOfTheHillGame : MainGame() {
gameLoop()
}

tasks += repeat(4, 4) {
val iterator = alive.iterator()
while (iterator.hasNext()) {
val player = iterator.next()
if (player.location.y <= RESPAWN_Y) {
if (player.health == 2.0) {
player.apply {
inventory.clear()
teleport(GameType.KING_OF_THE_HILL.spectatorSpawn!!)
playSound(Sound.ENTITY_PLAYER_DEATH)
world.strikeLightning(player.location)
getAttribute(Attribute.GENERIC_MAX_HEALTH)?.baseValue = 20.0;
health = 20.0
resetTitle()
clearActionBar()
}
iterator.remove()
Bukkit.broadcastMessage("${player.name} was elmimnated")

if (alive.size == 0) {
Bukkit.broadcastMessage("game ended, $player last man standing")
MainGameEngine.stop()
return@repeat
}
} else {
player.apply {
health = player.health - 2
teleport(GameType.KING_OF_THE_HILL.spawns[0])
sendMessage("you fell, lost another life")
}
}
}
}
}

tasks += repeat(0, 20) {
if (GAME_SECONDS == 0) {
Bukkit.broadcastMessage("game has ended, someone won, gg")
Expand Down

0 comments on commit 825c14c

Please sign in to comment.