增加暂停计时的超时自动恢复

This commit is contained in:
zhl 2021-03-25 18:38:17 +08:00
parent 6b712babcc
commit 57a041e5b7
3 changed files with 16 additions and 0 deletions

View File

@ -34,4 +34,9 @@ export class ClockNameConst {
* @type {string}
*/
public static readonly WAITING_PREPARE = 'waiting_prepare'
/**
*
* @type {string}
*/
public static readonly CLIENT_PAUSE = 'client_pause'
}

View File

@ -1,6 +1,9 @@
import { Command } from '@colyseus/command'
import { CardGameState } from '../schema/CardGameState'
import { Client } from 'colyseus'
import { debugRoom } from '../../common/Debug'
import { TurnEndCommand } from './TurnEndCommand'
import { ClockNameConst } from '../../constants/ClockNameConst'
export class PauseCommand extends Command<CardGameState, { client: Client }> {
@ -12,6 +15,12 @@ export class PauseCommand extends Command<CardGameState, { client: Client }> {
return
}
let result = this.room.pauseAllSchedule()
let self = this
let timeOverPause = function () {
debugRoom('客户端暂停时间到, 自动恢复')
self.room.resumeAllSchedule()
}
this.room.beginSchedule(60 * 1000, timeOverPause, ClockNameConst.CLIENT_PAUSE)
client.send('pause_s2c', {})
}
}

View File

@ -1,6 +1,7 @@
import { Command } from '@colyseus/command'
import { CardGameState } from '../schema/CardGameState'
import { Client } from 'colyseus'
import { ClockNameConst } from '../../constants/ClockNameConst'
export class ResumeCommand extends Command<CardGameState, {client: Client}> {
@ -11,6 +12,7 @@ export class ResumeCommand extends Command<CardGameState, {client: Client}> {
errmsg: '当前模式不能暂停'})
return
}
this.room.stopSchedule(ClockNameConst.CLIENT_PAUSE)
this.room.resumeAllSchedule()
client.send('resume_s2c', {})
}