选择英雄界面增加超时

This commit is contained in:
zhl 2020-12-14 14:06:49 +08:00
parent 18761f4c43
commit f19adf27f9
4 changed files with 35 additions and 3 deletions

View File

@ -40,6 +40,8 @@ export class GameEnv {
public waitingPlayerTime: number; public waitingPlayerTime: number;
// 匹配等待时, 每进入一个玩家, 等待时间延长n秒 // 匹配等待时, 每进入一个玩家, 等待时间延长n秒
public waitingPlayerOnePlus: number; public waitingPlayerOnePlus: number;
// 英雄选择时间
public pickHeroTime: number;
public init(data: Map<number, BaseCfg>) { public init(data: Map<number, BaseCfg>) {
this.initCardNum = data.get(BaseConst.INIT_CARD_NUM).value; this.initCardNum = data.get(BaseConst.INIT_CARD_NUM).value;
@ -61,5 +63,6 @@ export class GameEnv {
this.gameResultTime = data.get(BaseConst.GAME_RESULT_TIME).value; this.gameResultTime = data.get(BaseConst.GAME_RESULT_TIME).value;
this.waitingPlayerTime = data.get(BaseConst.WAITING_PLAYER_TIME).value; this.waitingPlayerTime = data.get(BaseConst.WAITING_PLAYER_TIME).value;
this.waitingPlayerOnePlus = data.get(BaseConst.WAITING_PLAYER_ONEPLUS).value; this.waitingPlayerOnePlus = data.get(BaseConst.WAITING_PLAYER_ONEPLUS).value;
this.pickHeroTime = data.get(BaseConst.PICK_HERO_TIME).value;
} }
} }

View File

@ -37,6 +37,8 @@ export class BaseConst {
public static readonly WAITING_PLAYER_TIME = 99018; public static readonly WAITING_PLAYER_TIME = 99018;
// 匹配等待时, 每进入一个玩家, 等待时间延长n秒 // 匹配等待时, 每进入一个玩家, 等待时间延长n秒
public static readonly WAITING_PLAYER_ONEPLUS = 99019; public static readonly WAITING_PLAYER_ONEPLUS = 99019;
// 英雄选择时间
public static readonly PICK_HERO_TIME = 99020;

View File

@ -3,6 +3,12 @@ import {CardGameState} from "../schema/CardGameState";
import {Client} from "colyseus"; import {Client} from "colyseus";
import {PlayerStateConst} from "../../constants/PlayerStateConst"; import {PlayerStateConst} from "../../constants/PlayerStateConst";
import {GameStateConst} from "../../constants/GameStateConst"; import {GameStateConst} from "../../constants/GameStateConst";
import {singleton} from "../../common/Singleton";
import {GameEnv} from "../../cfg/GameEnv";
import {SelectHeroCommand} from "./SelectHeroCommand";
import {HeroCfg} from "../../cfg/parsers/HeroCfg";
import {BaseConst} from "../../constants/BaseConst";
import arrUtil from "../../utils/array.util";
/** /**
* *
@ -32,6 +38,23 @@ export class PlayReadyCommand extends Command<CardGameState, {
} }
await this.room.setPrivate(true); await this.room.setPrivate(true);
this.room.state.updateGameState(GameStateConst.CHANGE_HERO); this.room.state.updateGameState(GameStateConst.CHANGE_HERO);
let self = this;
/**
*
*/
let pickHeroTimeOut = function () {
for (let [, curPlayer] of self.state.players) {
if (curPlayer.state == PlayerStateConst.PLAYER_READY ) {
let heroMap: Map<number, HeroCfg> = global.$cfg.get(BaseConst.HERO);
let heroArr = [...heroMap.values()];
let hero = arrUtil.randomGet(heroArr, 1);
let targetClient = self.room.getClient(curPlayer);
self.room.dispatcher.dispatch(new SelectHeroCommand(), {client: targetClient, heroId: hero[0].id});
}
}
}
let time = singleton(GameEnv).pickHeroTime * 1000;
this.room.beginSchedule(time, pickHeroTimeOut, 'pick_hero');
} }
} }

View File

@ -14,6 +14,9 @@ import {GameEnv} from "../../cfg/GameEnv";
export class SelectHeroCommand extends Command<CardGameState, { client: Client, heroId: number }> { export class SelectHeroCommand extends Command<CardGameState, { client: Client, heroId: number }> {
execute({client, heroId} = this.payload) { execute({client, heroId} = this.payload) {
let player = this.state.players.get(client.sessionId); let player = this.state.players.get(client.sessionId);
if (player.state != PlayerStateConst.PLAYER_READY) {
return;
}
const heroMap = global.$cfg.get(BaseConst.HERO); const heroMap = global.$cfg.get(BaseConst.HERO);
if (!heroMap || !heroMap.has(heroId)) { if (!heroMap || !heroMap.has(heroId)) {
this.room.sSelectHero(client, {errcode: 1, errmsg: '无法找到对应英雄的配置'}); this.room.sSelectHero(client, {errcode: 1, errmsg: '无法找到对应英雄的配置'});
@ -39,12 +42,13 @@ export class SelectHeroCommand extends Command<CardGameState, {client: Client, h
this.room.battleMan.addPlayer(player); this.room.battleMan.addPlayer(player);
this.room.bSelectHero({errocode: 0, errmsg: '', player: client.sessionId, heroId: heroId}); this.room.bSelectHero({errocode: 0, errmsg: '', player: client.sessionId, heroId: heroId});
let readyCount = 0; let readyCount = 0;
for (let [sessionId, player] of this.state.players) { for (let [, player] of this.state.players) {
if (player.state === PlayerStateConst.PLAYER_SELECT_HERO) { if (player.state === PlayerStateConst.PLAYER_SELECT_HERO) {
readyCount++; readyCount++;
} }
} }
if (readyCount >= this.room.maxClients) { if (readyCount >= this.room.maxClients) {
this.room.stopSchedule('pick_hero');
return [new BeginGameCommand()]; return [new BeginGameCommand()];
} }
} }