parent
45882c8cb6
commit
ed6f40b462
|
|
@ -15,7 +15,7 @@ class Game(
|
|||
val scoreboard: GameScoreboard = GameScoreboard(this)
|
||||
val timer: GameTimer = GameTimer(this)
|
||||
val players = ArrayList<Player>()
|
||||
val rule = GamePlaceBreakRule(this)
|
||||
val placeBreakRule = GamePlaceBreakRule(this)
|
||||
var state: GameState = GameState.WAITING
|
||||
|
||||
private fun autoJoinTeam() {
|
||||
|
|
@ -48,6 +48,7 @@ class Game(
|
|||
|
||||
fun start() {
|
||||
debug("game ${map.name} started.")
|
||||
placeBreakRule.defaultRule()
|
||||
|
||||
state = GameState.START
|
||||
timer.startTimer()
|
||||
|
|
@ -57,6 +58,9 @@ class Game(
|
|||
map.wall.forBlocksInArea().forEach {
|
||||
it.block.type = Material.AIR
|
||||
}
|
||||
placeBreakRule.addRule { _, _, loc ->
|
||||
map.wall.contains(loc)
|
||||
}
|
||||
}
|
||||
}
|
||||
autoJoinTeam()
|
||||
|
|
|
|||
|
|
@ -10,10 +10,10 @@ class GamePlaceBreakRule(val game: Game) {
|
|||
BREAK
|
||||
}
|
||||
|
||||
private val rule = ArrayList<(Player, ActionType, Location) -> Boolean>()
|
||||
private val rules = ArrayList<(Player, ActionType, Location) -> Boolean>()
|
||||
fun matchRule(player: Player, actionType: ActionType, location: Location): Boolean {
|
||||
// match rules
|
||||
rule.forEach {
|
||||
rules.forEach {
|
||||
if (it(player, actionType, location)) return true
|
||||
}
|
||||
|
||||
|
|
@ -21,13 +21,13 @@ class GamePlaceBreakRule(val game: Game) {
|
|||
return false
|
||||
}
|
||||
|
||||
fun addRule(rule: (Player, Location) -> Boolean) {
|
||||
|
||||
fun addRule(rule: (player: Player, type: ActionType, loc: Location) -> Boolean) {
|
||||
rules.add(rule)
|
||||
}
|
||||
|
||||
fun defaultRule(game: Game) {
|
||||
fun defaultRule() {
|
||||
// allow mine
|
||||
rule.add { _, _, loc ->
|
||||
rules.add { _, _, loc ->
|
||||
game.map.teams.flatMap {
|
||||
it.sides + it.mine
|
||||
}.map {
|
||||
|
|
@ -36,7 +36,7 @@ class GamePlaceBreakRule(val game: Game) {
|
|||
}
|
||||
|
||||
// allow enemy wall
|
||||
rule.add { player, type, loc ->
|
||||
rules.add { player, type, loc ->
|
||||
val team = player.team ?: return@add false
|
||||
val result = game.teams.filterNot { it == team }
|
||||
.map { team.teamInfo.wall.containsBlock(loc) }
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package cc.maxmc.blastingcrisis.listener
|
||||
|
||||
import cc.maxmc.blastingcrisis.game.GamePlaceBreakRule
|
||||
import cc.maxmc.blastingcrisis.game.team
|
||||
import cc.maxmc.blastingcrisis.misc.Area
|
||||
import cc.maxmc.blastingcrisis.misc.GameManager
|
||||
import cc.maxmc.blastingcrisis.misc.debug
|
||||
|
|
@ -49,7 +48,7 @@ object GameListener {
|
|||
fun onBreak(breakEvent: BlockBreakEvent) {
|
||||
val loc = breakEvent.block.location ?: return
|
||||
val player = breakEvent.player ?: return
|
||||
if (GameManager.currentGame.rule.matchRule(player, GamePlaceBreakRule.ActionType.BREAK, loc)) return
|
||||
if (GameManager.currentGame.placeBreakRule.matchRule(player, GamePlaceBreakRule.ActionType.BREAK, loc)) return
|
||||
breakEvent.isCancelled = true
|
||||
player.sendLang("game_cant_break_block")
|
||||
}
|
||||
|
|
@ -58,7 +57,7 @@ object GameListener {
|
|||
fun onPlace(placeEvent: BlockPlaceEvent) {
|
||||
val loc = placeEvent.block.location ?: return
|
||||
val player = placeEvent.player ?: return
|
||||
if (GameManager.currentGame.rule.matchRule(player, GamePlaceBreakRule.ActionType.PLACE, loc)) return
|
||||
if (GameManager.currentGame.placeBreakRule.matchRule(player, GamePlaceBreakRule.ActionType.PLACE, loc)) return
|
||||
placeEvent.isCancelled = true
|
||||
player.sendLang("game_cant_place_block")
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue