BlastingCrisis/src/main/kotlin/cc/maxmc/blastingcrisis/game/GameTeam.kt

60 lines
1.9 KiB
Kotlin

package cc.maxmc.blastingcrisis.game
import cc.maxmc.blastingcrisis.listener.GameListener
import cc.maxmc.blastingcrisis.map.MapTeam
import cc.maxmc.blastingcrisis.misc.debug
import cc.maxmc.blastingcrisis.misc.toPlayerLocation
import org.bukkit.entity.Player
import taboolib.platform.util.sendLang
class GameTeam(val game: Game, val teamInfo: MapTeam) {
val villager = TeamVillager(this)
val players = ArrayList<Player>()
var teamSurvive = true
private set
fun start() {
players.forEach { it.teleport(teamInfo.spawn.toPlayerLocation()) }
villager.spawn()
GameListener.interactSubscribed[teamInfo.upgrade] = {
debug("interact team ${teamInfo.name} upgrade.")
}
GameListener.moveSubscribed.add(teamInfo.teleport to {
val player = it.player ?: throw IllegalStateException("Bukkit API LOL")
debug("teleporting $player to battle field")
val team = player.team ?: throw IllegalStateException("Player ${player.name} should have a team")
player.teleport(team.teamInfo.mine.randomLocation().toPlayerLocation())
})
}
fun join(player: Player) {
players += player
if (game.state == GameState.COUNTING_DOWN || game.state == GameState.WAITING) {
player.sendLang("team_join", teamInfo.name)
}
}
fun removePlayer(player: Player) {
players -= player
if (game.state.isStarted()) {
checkTeamAlive()
}
}
fun checkTeamAlive() {
if (players.size == 0) {
teamSurvive = false
game.broadcast {
it.sendLang("team_death", teamInfo.name)
}
}
if (villager.health <= 0) {
teamSurvive = false
game.broadcast {
it.sendLang("team_death", teamInfo.name)
}
}
}
}