Skip to content

Commit

Permalink
BP相关代码更新
Browse files Browse the repository at this point in the history
  • Loading branch information
CuteReimu committed Dec 1, 2023
1 parent b848a42 commit 1e7da3c
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/main/kotlin/message/CreateRoomCs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CreateRoomCs(
val player = Store.getPlayer(token) ?: throw HandlerException("找不到玩家")
if (player.roomId != null && Store.getRoom(player.roomId) != null) throw HandlerException("已经在房间里了")
if (Store.getRoom(rid) != null) throw HandlerException("房间已存在")
roomConfig.validate()
roomConfig.validate(false)
val room = Room(roomId = rid, roomType = type, host = if (solo == true) "" else token)
if (solo == true) room.players[0] = token
if (addRobot == true) room.players[1] = Store.robotPlayer.token
Expand Down
18 changes: 17 additions & 1 deletion src/main/kotlin/message/ResetRoomCs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,23 @@ class ResetRoomCs : Handler {
room.changeCardCount[i] = 0
room.lastGetTime[i] = 0
}
room.banPick = null
if (room.banPick != null) {
Store.notifyPlayersInRoom(
token, null, Message(
data = BanPickInfoSc(
whoFirst = 0,
phase = -1,
aPick = arrayOf(),
aBan = arrayOf(),
bPick = arrayOf(),
bBan = arrayOf(),
aOpenEx = 0,
bOpenEx = 0,
)
)
)
room.banPick = null
}
Store.putRoom(room)
Store.notifyPlayerInfo(token, protoName)
}
Expand Down
54 changes: 31 additions & 23 deletions src/main/kotlin/message/RoomConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,45 @@ package org.tfcc.bingo.message
import org.tfcc.bingo.Room

class RoomConfig(
val gameTime: Int, // 游戏总时间(不含倒计时),单位:分
val countdown: Int, // 倒计时,单位:秒
val games: Array<String>,
val gameTime: Int?, // 游戏总时间(不含倒计时),单位:分
val countdown: Int?, // 倒计时,单位:秒
val games: Array<String>?,
val ranks: Array<String>?,
val needWin: Int,
val difficulty: Int,
val needWin: Int?,
val difficulty: Int?,
val isPrivate: Boolean?,
val cdTime: Int = 30, // 选卡cd,收卡后要多少秒才能选下一张卡
val cdTime: Int?, // 选卡cd,收卡后要多少秒才能选下一张卡
) {
@Throws(HandlerException::class)
fun validate() {
if (gameTime <= 0) throw HandlerException("游戏时间必须大于0")
if (gameTime > 1440) throw HandlerException("游戏时间太长")
if (countdown < 0) throw HandlerException("倒计时不能小于0")
if (countdown > 86400) throw HandlerException("倒计时太长")
if (games.size > 99) throw HandlerException("选择的作品数太多")
fun validate(allowEmpty: Boolean) {
if (!allowEmpty) {
if (gameTime == null) throw HandlerException("游戏时长不能为空")
if (countdown == null) throw HandlerException("倒计时不能为空")
if (games == null) throw HandlerException("选择的作品不能为空")
if (ranks == null) throw HandlerException("选择的难度不能为空")
if (needWin == null) throw HandlerException("需要的胜场数不能为空")
if (cdTime == null) throw HandlerException("选卡cd不能为空")
}
if (gameTime != null && gameTime <= 0) throw HandlerException("游戏时间必须大于0")
if (gameTime != null && gameTime > 1440) throw HandlerException("游戏时间太长")
if (countdown != null && countdown < 0) throw HandlerException("倒计时不能小于0")
if (countdown != null && countdown > 86400) throw HandlerException("倒计时太长")
if (games != null && games.size > 99) throw HandlerException("选择的作品数太多")
if (ranks != null && ranks.size > 6) throw HandlerException("选择的难度数太多")
if (needWin > 99) throw HandlerException("需要胜场的数值不正确")
if (cdTime < 0) throw HandlerException("选卡cd不能小于0")
if (cdTime > 1440) throw HandlerException("选卡cd太长")
if (needWin != null && needWin > 99) throw HandlerException("需要胜场的数值不正确")
if (cdTime != null && cdTime < 0) throw HandlerException("选卡cd不能小于0")
if (cdTime != null && cdTime > 1440) throw HandlerException("选卡cd太长")
}

fun updateRoom(room: Room) {
room.gameTime = gameTime
room.countDown = countdown
room.games = games
room.ranks = ranks
room.needWin = needWin.coerceAtLeast(1)
room.difficulty = difficulty
room.isPrivate = isPrivate == true
room.cdTime = cdTime
gameTime?.let { room.gameTime = it }
countdown?.let { room.countDown = it }
games?.let { room.games = it }
ranks?.let { room.ranks = it }
needWin?.let { room.needWin = it.coerceAtLeast(1) }
difficulty?.let { room.difficulty = it }
isPrivate?.let { room.isPrivate = it }
cdTime?.let { room.cdTime = it }
}

companion object {
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/message/UpdateRoomConfigCs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class UpdateRoomConfigCs(val roomConfig: RoomConfig) : Handler {
val room = Store.getRoom(player.roomId) ?: throw HandlerException("找不到房间")
if (!room.isHost(token)) throw HandlerException("没有权限")
if (room.started) throw HandlerException("游戏已经开始")
roomConfig.validate()
roomConfig.validate(true)
roomConfig.updateRoom(room)
Store.putRoom(room)
Store.notifyPlayerInfo(token, protoName)
Expand Down

0 comments on commit 1e7da3c

Please sign in to comment.