diff --git a/src/constants/ClockNameConst.ts b/src/constants/ClockNameConst.ts index a4ac92c..04fa09b 100644 --- a/src/constants/ClockNameConst.ts +++ b/src/constants/ClockNameConst.ts @@ -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' } diff --git a/src/rooms/commands/PauseCommand.ts b/src/rooms/commands/PauseCommand.ts index 3010245..1411ed3 100644 --- a/src/rooms/commands/PauseCommand.ts +++ b/src/rooms/commands/PauseCommand.ts @@ -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 { @@ -12,6 +15,12 @@ export class PauseCommand extends Command { 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', {}) } } diff --git a/src/rooms/commands/ResumeCommand.ts b/src/rooms/commands/ResumeCommand.ts index 7c776fd..f9d9e48 100644 --- a/src/rooms/commands/ResumeCommand.ts +++ b/src/rooms/commands/ResumeCommand.ts @@ -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 { @@ -11,6 +12,7 @@ export class ResumeCommand extends Command { errmsg: '当前模式不能暂停'}) return } + this.room.stopSchedule(ClockNameConst.CLIENT_PAUSE) this.room.resumeAllSchedule() client.send('resume_s2c', {}) }