Skip to content

Commit

Permalink
房间配置增加reservedType字段,标准赛倒计时阶段不能抢卡
Browse files Browse the repository at this point in the history
  • Loading branch information
CuteReimu committed Mar 14, 2024
1 parent 33bdc2b commit 06a18db
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/main/kotlin/Room.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Room(
var lastOperateMs: Long = 0 // 最后一次操作的时间戳,毫秒
var banPick: BanPick? = null
var debugSpells: IntArray? = null
var reservedType: Int? = null
val type
get() = when (roomType) {
1 -> RoomTypeNormal
Expand Down
13 changes: 10 additions & 3 deletions src/main/kotlin/RoomTypeNormal.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ object RoomTypeNormal : RoomType {
throw HandlerException("暂停中,不能操作")
if (room.startMs <= now - room.gameTime.toLong() * 60000L - room.totalPauseMs && !room.isHost(token) && !room.scoreDraw())
throw HandlerException("游戏时间到")
if (room.startMs > now - room.countDown.toLong() * 1000L) {
val isCountingDown = room.startMs > now - room.countDown.toLong() * 1000L
if (isCountingDown) {
if (!status.isSelectStatus() && !(status == NONE && st.isSelectStatus()))
throw HandlerException("倒计时还没结束")
}
Expand All @@ -61,7 +62,10 @@ object RoomTypeNormal : RoomType {
if (room.lastGetTime[0] == 0L) 0 else ((room.cdTime - 1) * 1000 - now + room.startMs + room.totalPauseMs + room.lastGetTime[0])
if (remainSelectTime > 0)
throw HandlerException("还有${remainSelectTime / 1000 + 1}秒才能选卡")
if (st == RIGHT_SELECT) BOTH_SELECT else status
if (st == RIGHT_SELECT) {
!isCountingDown || throw HandlerException("倒计时阶段不能抢卡")
BOTH_SELECT
} else status
}

NONE ->
Expand All @@ -88,7 +92,10 @@ object RoomTypeNormal : RoomType {
if (room.lastGetTime[1] == 0L) 0 else ((room.cdTime - 1) * 1000 - now + room.startMs + room.totalPauseMs + room.lastGetTime[1])
if (remainSelectTime > 0)
throw HandlerException("还有${remainSelectTime / 1000 + 1}秒才能选卡")
if (st == LEFT_SELECT) BOTH_SELECT else status
if (st == LEFT_SELECT) {
!isCountingDown || throw HandlerException("倒计时阶段不能抢卡")
BOTH_SELECT
} else status
}

NONE ->
Expand Down
3 changes: 3 additions & 0 deletions src/main/kotlin/message/RoomConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class RoomConfig(
val difficulty: Int?,
val isPrivate: Boolean?,
val cdTime: Int?, // 选卡cd,收卡后要多少秒才能选下一张卡
val reservedType: Int?, // 纯客户端用的一个类型字段
) {
@Throws(HandlerException::class)
fun validate(allowEmpty: Boolean) {
Expand Down Expand Up @@ -42,6 +43,7 @@ class RoomConfig(
difficulty?.let { room.difficulty = it }
isPrivate?.let { room.isPrivate = it }
cdTime?.let { room.cdTime = it }
reservedType?.let { room.reservedType = it }
}

companion object {
Expand All @@ -54,6 +56,7 @@ class RoomConfig(
difficulty = room.difficulty,
isPrivate = room.isPrivate,
cdTime = room.cdTime,
reservedType = room.reservedType,
)
}
}

0 comments on commit 06a18db

Please sign in to comment.