Compare commits

...
9 Commits
Author SHA1 Message Date
tony_all 1d753801dd update automation script & test 2023-06-16 11:44:18 +08:00
tony_all 60295330de add runtime map file 2023-06-16 02:09:20 +08:00
tony_all f6e34d8efc fix placing rule 2023-06-16 02:07:14 +08:00
tony_all 6f1a727691 fix MAXMC-T-8 2023-06-16 01:56:10 +08:00
tony_all 3d09b48da8 fix MAXMC-T-6 2023-06-16 01:44:03 +08:00
tony_all 9416250e13 fix MAXMC-T-6 2023-06-16 01:41:22 +08:00
tony_all 7f4ef2a447 optimize MAXMC-T-2 2023-06-16 01:34:10 +08:00
tony_all 1053fde43f fix MAXMC-T-2 2023-06-16 01:27:30 +08:00
tony_all f1ae6d7f4c sync 2023-06-16 00:14:37 +08:00
5 changed files with 74 additions and 19 deletions
+10 -4
View File
@@ -1,10 +1,16 @@
job("Build and run tests") { job("Build and run tests") {
// run 'gradlew build' // run 'gradlew build'
gradlew("azul/zulu-openjdk:17", "build") { gradlew("azul/zulu-openjdk:17", "build", "--no-daemon") {
mountDir = "/root"
cache {
storeKey = "dot-gradle"
localPath = "/root/.gradle"
}
fileArtifacts { fileArtifacts {
localPath = "build" localPath = "build/libs"
archive = true archive = false
remotePath = "{{ run:number }}/build.zip" remotePath = "{{ run:number }}/build"
onStatus = OnStatus.SUCCESS onStatus = OnStatus.SUCCESS
} }
} }
Binary file not shown.
@@ -48,21 +48,22 @@ class Game(
fun start() { fun start() {
debug("game ${map.name} started.") debug("game ${map.name} started.")
placeBreakRule.defaultRule() placeBreakRule.loadDefaultRule()
state = GameState.START state = GameState.START
timer.startTimer() timer.startTimer()
timer.submitEvent("wall_fall", Duration.ofMinutes(1)) { timer.submitEvent("wall_fall", Duration.ofMinutes(1)) {
broadcast { it.sendLang("game_wall_fall") } broadcast { it.sendLang("game_wall_fall") }
placeBreakRule.addRule("allow_center_wall") { _, _, loc ->
map.wall.contains(loc)
}
submit { submit {
map.wall.forBlocksInArea().forEach { map.wall.forBlocksInArea().forEach {
it.block.type = Material.AIR it.block.type = Material.AIR
} }
placeBreakRule.addRule("allow_center_wall") { _, _, loc ->
map.wall.contains(loc)
}
} }
} }
autoJoinTeam() autoJoinTeam()
teams.forEach { teams.forEach {
it.start() it.start()
@@ -4,6 +4,7 @@ import cc.maxmc.blastingcrisis.game.GamePlaceBreakRule.ActionType.BREAK
import cc.maxmc.blastingcrisis.misc.debug import cc.maxmc.blastingcrisis.misc.debug
import org.bukkit.Location import org.bukkit.Location
import org.bukkit.entity.Player import org.bukkit.entity.Player
import taboolib.library.xseries.XMaterial
class GamePlaceBreakRule(val game: Game) { class GamePlaceBreakRule(val game: Game) {
enum class ActionType { enum class ActionType {
@@ -11,11 +12,11 @@ class GamePlaceBreakRule(val game: Game) {
BREAK BREAK
} }
private val rules = HashMap<String, (Player, ActionType, Location) -> Boolean>() private val rules = HashMap<String, (Player, ActionType, Location, XMaterial) -> Boolean>()
fun matchRule(player: Player, actionType: ActionType, location: Location): Boolean { fun matchRule(player: Player, actionType: ActionType, location: Location, type: XMaterial): Boolean {
// match rules // match rules
rules.forEach { (name, func) -> rules.forEach { (name, func) ->
if (func(player, actionType, location)) { if (func(player, actionType, location, type)) {
debug("Hit rule $name") debug("Hit rule $name")
return true return true
} }
@@ -25,7 +26,10 @@ class GamePlaceBreakRule(val game: Game) {
return false return false
} }
fun addRule(name: String, rule: (player: Player, type: ActionType, loc: Location) -> Boolean) { fun addRule(
name: String,
rule: (player: Player, actionType: ActionType, loc: Location, type: XMaterial) -> Boolean
) {
if (rules.containsKey(name)) { if (rules.containsKey(name)) {
throw IllegalArgumentException("Rule $name already exists.") throw IllegalArgumentException("Rule $name already exists.")
} }
@@ -33,9 +37,9 @@ class GamePlaceBreakRule(val game: Game) {
rules[name] = rule rules[name] = rule
} }
fun defaultRule() { fun loadDefaultRule() {
// allow mine // allow mine
addRule("allow_mine") { _, _, loc -> addRule("allow_mine") { _, _, loc, _ ->
game.map.teams.flatMap { game.map.teams.flatMap {
it.sides + it.mine it.sides + it.mine
}.map { }.map {
@@ -44,16 +48,31 @@ class GamePlaceBreakRule(val game: Game) {
} }
// allow enemy wall // allow enemy wall
addRule("allow_wall_conditional") { player, type, loc -> addRule("allow_wall_conditional") { player, actionType, loc, _ ->
val team = player.team ?: return@addRule false val team = player.team ?: return@addRule false
val isWall = game.teams val isWall = game.teams
.map { .map {
it.teamInfo.wall.containsBlock(loc).also { result -> debug("area ${it.teamInfo.wall} contains $loc is $result") } it.teamInfo.wall.containsBlock(loc)
.also { result -> debug("area ${it.teamInfo.wall} contains $loc is $result") }
} }
.reduce { a, b -> a || b } .reduce { a, b -> a || b }
if (!isWall) return@addRule false if (!isWall) return@addRule false
val isHome = team.teamInfo.wall.containsBlock(loc) val isHome = team.teamInfo.wall.containsBlock(loc)
(type == BREAK) xor isHome (actionType == BREAK) xor isHome
}
addRule("allow_tnt_conditional") { player, actionType, loc, type ->
if (actionType == BREAK) return@addRule false
if (type != XMaterial.TNT) return@addRule false
val team = player.team ?: return@addRule false
val isHome = game.teams
.map {
it.teamInfo.home.containsBlock(loc)
.also { result -> debug("area ${it.teamInfo.home} contains $loc is $result") }
}
.reduce { a, b -> a || b }
if (!isHome) return@addRule false
return@addRule !team.teamInfo.home.containsBlock(loc)
} }
} }
} }
@@ -1,16 +1,23 @@
package cc.maxmc.blastingcrisis.listener package cc.maxmc.blastingcrisis.listener
import cc.maxmc.blastingcrisis.game.GamePlaceBreakRule import cc.maxmc.blastingcrisis.game.GamePlaceBreakRule
import cc.maxmc.blastingcrisis.game.team
import cc.maxmc.blastingcrisis.misc.Area import cc.maxmc.blastingcrisis.misc.Area
import cc.maxmc.blastingcrisis.misc.GameManager import cc.maxmc.blastingcrisis.misc.GameManager
import cc.maxmc.blastingcrisis.misc.debug import cc.maxmc.blastingcrisis.misc.debug
import cc.maxmc.blastingcrisis.misc.toPlayerLocation
import org.bukkit.Location import org.bukkit.Location
import org.bukkit.entity.Player
import org.bukkit.event.block.BlockBreakEvent import org.bukkit.event.block.BlockBreakEvent
import org.bukkit.event.block.BlockPlaceEvent import org.bukkit.event.block.BlockPlaceEvent
import org.bukkit.event.entity.EntityDamageEvent
import org.bukkit.event.entity.EntityExplodeEvent import org.bukkit.event.entity.EntityExplodeEvent
import org.bukkit.event.entity.FoodLevelChangeEvent
import org.bukkit.event.player.PlayerInteractEvent import org.bukkit.event.player.PlayerInteractEvent
import org.bukkit.event.player.PlayerMoveEvent import org.bukkit.event.player.PlayerMoveEvent
import org.bukkit.event.player.PlayerRespawnEvent
import taboolib.common.platform.event.SubscribeEvent import taboolib.common.platform.event.SubscribeEvent
import taboolib.library.xseries.XMaterial
import taboolib.platform.util.sendLang import taboolib.platform.util.sendLang
object GameListener { object GameListener {
@@ -48,7 +55,7 @@ object GameListener {
fun onBreak(breakEvent: BlockBreakEvent) { fun onBreak(breakEvent: BlockBreakEvent) {
val loc = breakEvent.block.location ?: return val loc = breakEvent.block.location ?: return
val player = breakEvent.player ?: return val player = breakEvent.player ?: return
if (GameManager.currentGame.placeBreakRule.matchRule(player, GamePlaceBreakRule.ActionType.BREAK, loc)) return if (GameManager.currentGame.placeBreakRule.matchRule(player, GamePlaceBreakRule.ActionType.BREAK, loc, XMaterial.matchXMaterial(breakEvent.block.type))) return
breakEvent.isCancelled = true breakEvent.isCancelled = true
player.sendLang("game_cant_break_block") player.sendLang("game_cant_break_block")
} }
@@ -57,8 +64,30 @@ object GameListener {
fun onPlace(placeEvent: BlockPlaceEvent) { fun onPlace(placeEvent: BlockPlaceEvent) {
val loc = placeEvent.block.location ?: return val loc = placeEvent.block.location ?: return
val player = placeEvent.player ?: return val player = placeEvent.player ?: return
if (GameManager.currentGame.placeBreakRule.matchRule(player, GamePlaceBreakRule.ActionType.PLACE, loc)) return if (GameManager.currentGame.placeBreakRule.matchRule(player, GamePlaceBreakRule.ActionType.PLACE, loc, XMaterial.matchXMaterial(placeEvent.blockPlaced.type))) return
placeEvent.isCancelled = true placeEvent.isCancelled = true
player.sendLang("game_cant_place_block") player.sendLang("game_cant_place_block")
} }
@SubscribeEvent
fun onRespawn(respawnEvent: PlayerRespawnEvent) {
val team = respawnEvent.player.team ?: return // ignore none game player
respawnEvent.respawnLocation = team.teamInfo.spawn.toPlayerLocation()
}
@SubscribeEvent
fun protectDamageBeforeGame(damageEvent: EntityDamageEvent) {
if (damageEvent.entity !is Player) return // ignore none player entity
if (GameManager.currentGame.state.isStarted()) return
damageEvent.isCancelled = true
}
@SubscribeEvent
fun protectHunger(hungerEvent: FoodLevelChangeEvent) {
hungerEvent.isCancelled = true
(hungerEvent.entity as Player).run {
foodLevel = 20
saturation = 20f
}
}
} }