diff --git a/src/cfg/GameEnv.ts b/src/cfg/GameEnv.ts index f3a5d47..711aa75 100644 --- a/src/cfg/GameEnv.ts +++ b/src/cfg/GameEnv.ts @@ -36,6 +36,10 @@ export class GameEnv { public extraAddScore: number; // 游戏结果显示时间, 也是游戏重开等待时间 public gameResultTime: number; + // 匹配等待时间, 时间结束后, 填充机器人; + public waitingPlayerTime: number; + // 匹配等待时, 每进入一个玩家, 等待时间延长n秒 + public waitingPlayerOnePlus: number; public init(data: Map) { this.initCardNum = data.get(BaseConst.INIT_CARD_NUM).value; @@ -55,5 +59,7 @@ export class GameEnv { this.baseAddScore = data.get(BaseConst.BASE_ADD_SCORE).value; this.extraAddScore = data.get(BaseConst.EXTRA_ADD_SCORE).value; this.gameResultTime = data.get(BaseConst.GAME_RESULT_TIME).value; + this.waitingPlayerTime = data.get(BaseConst.WAITING_PLAYER_TIME).value; + this.waitingPlayerOnePlus = data.get(BaseConst.WAITING_PLAYER_ONEPLUS).value; } } diff --git a/src/constants/BaseConst.ts b/src/constants/BaseConst.ts index 63a93ab..0fd9dac 100644 --- a/src/constants/BaseConst.ts +++ b/src/constants/BaseConst.ts @@ -33,6 +33,10 @@ export class BaseConst { public static readonly EXTRA_ADD_SCORE = 99016; // 游戏结果显示时间, 也是游戏重开等待时间 public static readonly GAME_RESULT_TIME = 99017; + // 匹配等待时间, 时间结束后, 填充机器人; + public static readonly WAITING_PLAYER_TIME = 99018; + // 匹配等待时, 每进入一个玩家, 等待时间延长n秒 + public static readonly WAITING_PLAYER_ONEPLUS = 99019; diff --git a/src/rooms/commands/GMCommand.ts b/src/rooms/commands/GMCommand.ts index 9a8ec91..fae21df 100644 --- a/src/rooms/commands/GMCommand.ts +++ b/src/rooms/commands/GMCommand.ts @@ -51,7 +51,8 @@ export class GMCommand extends Command { await self.room.unlock(); await self.room.setPrivate(false); + //TODO:: 开启匹配定时, 长时间没匹配到人的话, 添加机器人 + let timeOutWaitingPlayer = function () { + let count = self.room.maxClients - self.room.clients.length; + if (count > 0) { + for (let i = 0; i < count; i++) { + self.room.addRobot(); + } + } + } + let time = singleton(GameEnv).waitingPlayerTime * 1000; + self.room.beginSchedule(time, timeOutWaitingPlayer, 'waiting_player'); } else { // 如果4个人都点击了重开, 理论上不存在这种情况 error(`所有人都点击了重新开始, 为啥还没开始游戏???`); } diff --git a/src/rooms/commands/OnJoinCommand.ts b/src/rooms/commands/OnJoinCommand.ts index 4c3c89d..8e8f76c 100644 --- a/src/rooms/commands/OnJoinCommand.ts +++ b/src/rooms/commands/OnJoinCommand.ts @@ -3,6 +3,8 @@ import {CardGameState} from "../schema/CardGameState"; import {Player} from "../schema/Player"; import {Client} from "colyseus"; import {GameStateConst} from "../../constants/GameStateConst"; +import {singleton} from "../../common/Singleton"; +import {GameEnv} from "../../cfg/GameEnv"; /** * 玩家成功加入房间 @@ -15,6 +17,20 @@ export class OnJoinCommand extends Command 0) { + for (let i = 0; i < count; i++) { + self.room.addRobot(); + } + } + } + let time = singleton(GameEnv).waitingPlayerTime * 1000; + self.room.beginSchedule(time, timeOutWaitingPlayer, 'waiting_player'); + } if (this.state.players.size >= this.room.maxClients) { this.room.lock().then(() => {}); this.state.updateGameState(GameStateConst.STATE_WAIT_PREPARE); diff --git a/src/rooms/commands/PlayReadyCommand.ts b/src/rooms/commands/PlayReadyCommand.ts index ebaabab..bb0c287 100644 --- a/src/rooms/commands/PlayReadyCommand.ts +++ b/src/rooms/commands/PlayReadyCommand.ts @@ -20,12 +20,9 @@ export class PlayReadyCommand extends Command= this.room.maxClients) { + this.room.stopSchedule(); // 比大小, 确定先手 // return [new PrepareCommand()]; let i = 0;