匹配玩家超时后, 添加机器人
This commit is contained in:
parent
3649442db2
commit
682528ebc8
@ -36,6 +36,10 @@ export class GameEnv {
|
||||
public extraAddScore: number;
|
||||
// 游戏结果显示时间, 也是游戏重开等待时间
|
||||
public gameResultTime: number;
|
||||
// 匹配等待时间, 时间结束后, 填充机器人;
|
||||
public waitingPlayerTime: number;
|
||||
// 匹配等待时, 每进入一个玩家, 等待时间延长n秒
|
||||
public waitingPlayerOnePlus: number;
|
||||
|
||||
public init(data: Map<number, BaseCfg>) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
||||
|
||||
|
@ -51,7 +51,8 @@ export class GMCommand extends Command<CardGameState, {client: Client, message:
|
||||
*/
|
||||
addRobot(msg:string) {
|
||||
let count = msg ? parseInt(msg) : 1;
|
||||
for (let i = 0; i< count; i++) {
|
||||
let count2 = this.room.maxClients - this.room.clients.length;
|
||||
for (let i = 0; i< Math.min(count, count2); i++) {
|
||||
this.room.addRobot();
|
||||
}
|
||||
}
|
||||
|
@ -79,6 +79,17 @@ export class GameResultCommand extends Command<CardGameState, {}> {
|
||||
|
||||
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(`所有人都点击了重新开始, 为啥还没开始游戏???`);
|
||||
}
|
||||
|
@ -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<CardGameState, {
|
||||
// 实际的team会在PlayReadyCommand中设置
|
||||
let player = new Player(client.sessionId, 0, team);
|
||||
this.state.players.set(client.sessionId, player);
|
||||
let self = this;
|
||||
if (this.room.clients.length == 1) {
|
||||
// 正常的匹配逻辑进入的第一个玩家, 开启定时, 超过设定时间人没齐的话, 添加机器人
|
||||
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');
|
||||
}
|
||||
if (this.state.players.size >= this.room.maxClients) {
|
||||
this.room.lock().then(() => {});
|
||||
this.state.updateGameState(GameStateConst.STATE_WAIT_PREPARE);
|
||||
|
@ -20,12 +20,9 @@ export class PlayReadyCommand extends Command<CardGameState, {
|
||||
readyCount++;
|
||||
}
|
||||
}
|
||||
if (readyCount == 1) {
|
||||
// 第一个点击确认后, 开始计时, 超时就加入机器人
|
||||
|
||||
}
|
||||
// 如果所有人的状态都为已准备状态, 则开始发牌
|
||||
if (readyCount >= this.room.maxClients) {
|
||||
this.room.stopSchedule();
|
||||
// 比大小, 确定先手
|
||||
// return [new PrepareCommand()];
|
||||
let i = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user