diff --git a/src/constants/ClockNameConst.ts b/src/constants/ClockNameConst.ts new file mode 100644 index 0000000..fc0db60 --- /dev/null +++ b/src/constants/ClockNameConst.ts @@ -0,0 +1,32 @@ +export class ClockNameConst { + /** + * 抽卡计时器 + * @type {string} + */ + public static readonly DRAW_CARD = 'draw_card' + /** + * 选择随从计时器 + * @type {string} + */ + public static readonly SELECT_PET = 'select_pet' + /** + * 选择英雄计时器 + * @type {string} + */ + public static readonly PICK_HERO = 'pick_hero' + /** + * 等候玩家计时器 + * @type {string} + */ + public static readonly WAITING_PLAYER = 'waiting_player' + /** + * 重新开始游戏 + * @type {string} + */ + public static readonly RESTART_SCHEDULE = 'restart_schedule' + /** + * 吃牌轮 + * @type {string} + */ + public static readonly EAT_ROUND = 'eat_round' +} diff --git a/src/rooms/commands/DiscardCommand.ts b/src/rooms/commands/DiscardCommand.ts index e2e925b..3d44def 100644 --- a/src/rooms/commands/DiscardCommand.ts +++ b/src/rooms/commands/DiscardCommand.ts @@ -10,6 +10,7 @@ import { Card } from '../schema/Card' import { Wait } from './Wait' import { StateTypeEnum } from '../enums/StateTypeEnum' import { RoomOptions } from '../../cfg/RoomOptions' +import { ClockNameConst } from '../../constants/ClockNameConst' /** * 出牌 @@ -58,7 +59,7 @@ export class DiscardCommand extends Command= 0) { let maxTime = new GameEnv().maxDiscardTime * 1000 let count = elapsedTime - maxTime @@ -159,7 +160,7 @@ export class DiscardCommand extends Command { - async execute() { - let sessionId = this.state.currentTurn; - this.room.addCard(sessionId, new GameEnv().roundDrawNum, 0); - let maxTime = new GameEnv().maxDiscardTime * 1000; - let player = this.state.players.get(sessionId); - let self = this; - let timeOverDraw = function () { - if (sessionId == self.state.currentTurn) { - let client = self.room.getClient(sessionId); - let card = player.cards.values().next().value; - debugRoom('出牌时间到, 自动出牌: ', card.id); - player.extraTime = 0; - if (client) { - self.room.dispatcher.dispatch(new DiscardCommand(), {client, cards: [card.id], dtype: 1}); - } - } + async execute() { + let sessionId = this.state.currentTurn + this.room.addCard(sessionId, new GameEnv().roundDrawNum, 0) + let maxTime = new GameEnv().maxDiscardTime * 1000 + let player = this.state.players.get(sessionId) + let self = this + let timeOverDraw = function () { + if (sessionId == self.state.currentTurn) { + let client = self.room.getClient(sessionId) + let card = player.cards.values().next().value + debugRoom('出牌时间到, 自动出牌: ', card.id) + player.extraTime = 0 + if (client) { + self.room.dispatcher.dispatch(new DiscardCommand(), { + client, + cards: [card.id], + dtype: 1 + }) } - this.room.beginSchedule(maxTime + player.extraTime, timeOverDraw, `draw_card`); + } } + this.room.beginSchedule(maxTime + player.extraTime, timeOverDraw, ClockNameConst.DRAW_CARD) + } } diff --git a/src/rooms/commands/EatConfirmCommand.ts b/src/rooms/commands/EatConfirmCommand.ts index 87a7808..4bbb732 100644 --- a/src/rooms/commands/EatConfirmCommand.ts +++ b/src/rooms/commands/EatConfirmCommand.ts @@ -8,6 +8,7 @@ import {Player} from "../schema/Player"; import {Card} from "../schema/Card"; import gameUtil from "../../utils/game.util"; import {StateTypeEnum} from "../enums/StateTypeEnum"; +import { ClockNameConst } from '../../constants/ClockNameConst' /** * 根据条件决定吃牌玩家, 并执行吃牌逻辑 @@ -33,7 +34,7 @@ export class EatConfirmCommand extends Command= playerCount) { // 所有人都放弃了, 则取消定时, 直接进入下一轮 - this.room.stopSchedule('eat_round'); + this.room.stopSchedule(ClockNameConst.EAT_ROUND); // if (this.room.mainClock?.active) { // this.room.mainClock.clear(); // } @@ -72,7 +73,7 @@ export class EatConfirmCommand extends Command { @@ -14,7 +15,7 @@ export class GameRestartCommand extends Command this.state.restartCount ++; player.state = PlayerStateConst.PLAYER_NORMAL; if (this.state.restartCount >= this.room.maxClients) { - this.room.stopSchedule('restart_schedule'); + this.room.stopSchedule(ClockNameConst.RESTART_SCHEDULE); } } else { error(`${client.sessionId} not found!!`) diff --git a/src/rooms/commands/GameResultCommand.ts b/src/rooms/commands/GameResultCommand.ts index 7ab4a4a..5a12ed6 100644 --- a/src/rooms/commands/GameResultCommand.ts +++ b/src/rooms/commands/GameResultCommand.ts @@ -12,6 +12,7 @@ import {StateTypeEnum} from "../enums/StateTypeEnum"; import {reportGameResult} from "../../common/WebApi"; import {BaseConst} from "../../constants/BaseConst"; import {Player} from "../schema/Player"; +import { ClockNameConst } from '../../constants/ClockNameConst' class GameResult{ public id: string @@ -184,13 +185,13 @@ export class GameResultCommand extends Command { } } let time = new GameEnv().waitingPlayerTime * 1000; - self.room.beginSchedule(time, timeOutWaitingPlayer, 'waiting_player'); + self.room.beginSchedule(time, timeOutWaitingPlayer, ClockNameConst.WAITING_PLAYER); } else { // 如果4个人都点击了重开, 理论上不存在这种情况 error(`所有人都点击了重新开始, 为啥还没开始游戏???`); } } let time = new GameEnv().gameResultTime * 1000; - this.room.beginSchedule(time, resultTimeOver, 'restart_schedule'); + this.room.beginSchedule(time, resultTimeOver, ClockNameConst.RESTART_SCHEDULE); let saveData: any; try{ saveData = (await self.reportGameResult(winner, mvp.id, results.get(mvp).mvpScore, results)).data.data; diff --git a/src/rooms/commands/NextSubCommand.ts b/src/rooms/commands/NextSubCommand.ts index a691a73..f48b14a 100644 --- a/src/rooms/commands/NextSubCommand.ts +++ b/src/rooms/commands/NextSubCommand.ts @@ -5,6 +5,7 @@ import {GameEnv} from "../../cfg/GameEnv"; import {debugRoom} from "../../common/Debug"; import {EatConfirmCommand} from "./EatConfirmCommand"; import {PlayerStateConst} from "../../constants/PlayerStateConst"; +import { ClockNameConst } from '../../constants/ClockNameConst' /** * 下一个吃牌轮 @@ -27,7 +28,7 @@ export class NextSubCommand extends Command { debugRoom('吃牌时间到, 进入下一轮') self.room.dispatcher.dispatch(new EatConfirmCommand(), {timeUp: true}); } - this.room.beginSchedule(time, timeOverEat, `eat_round`); + this.room.beginSchedule(time, timeOverEat, ClockNameConst.EAT_ROUND); } } diff --git a/src/rooms/commands/OnJoinCommand.ts b/src/rooms/commands/OnJoinCommand.ts index 8178244..a6a51b0 100644 --- a/src/rooms/commands/OnJoinCommand.ts +++ b/src/rooms/commands/OnJoinCommand.ts @@ -7,6 +7,7 @@ import {GameEnv} from "../../cfg/GameEnv"; import {BaseConst} from "../../constants/BaseConst"; import {getRandom} from "../../utils/number.util"; import { getUserInfo, randomUserInfo } from '../../common/WebApi' +import { ClockNameConst } from '../../constants/ClockNameConst' /** * 玩家成功加入房间 @@ -84,13 +85,13 @@ export class OnJoinCommand extends Command 1 && this.room.clientCount() < this.room.maxClients) { let moreTime = new GameEnv().waitingPlayerOnePlus * 1000; - self.room.addScheduleTime(moreTime, 'play_join', 'waiting_player') + self.room.addScheduleTime(moreTime, 'play_join', ClockNameConst.WAITING_PLAYER) } if (this.state.players.size >= this.room.maxClients) { - this.room.stopSchedule('waiting_player'); + this.room.stopSchedule(ClockNameConst.WAITING_PLAYER); 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 2ebf482..948b53e 100644 --- a/src/rooms/commands/PlayReadyCommand.ts +++ b/src/rooms/commands/PlayReadyCommand.ts @@ -7,6 +7,7 @@ import {GameEnv} from "../../cfg/GameEnv"; import {SelectHeroCommand} from "./SelectHeroCommand"; import {HeroCfg} from "../../cfg/parsers/HeroCfg"; import {BaseConst} from "../../constants/BaseConst"; +import { ClockNameConst } from '../../constants/ClockNameConst' /** * 玩家已准备 @@ -26,8 +27,8 @@ export class PlayReadyCommand extends Command= this.room.maxClients) { - this.room.stopSchedule('restart_schedule'); - this.room.stopSchedule('waiting_player'); + this.room.stopSchedule(ClockNameConst.RESTART_SCHEDULE); + this.room.stopSchedule(ClockNameConst.WAITING_PLAYER); // 比大小, 确定先手 // return [new PrepareCommand()]; // let i = 0; @@ -59,7 +60,7 @@ export class PlayReadyCommand extends Command= this.room.maxClients) { - this.room.stopSchedule('pick_hero'); + this.room.stopSchedule(ClockNameConst.PICK_HERO); return [new BeginGameCommand()]; } } diff --git a/src/rooms/commands/SelectPetCommand.ts b/src/rooms/commands/SelectPetCommand.ts index cf801d6..a3b4975 100644 --- a/src/rooms/commands/SelectPetCommand.ts +++ b/src/rooms/commands/SelectPetCommand.ts @@ -8,6 +8,7 @@ import { RoomOptions } from '../../cfg/RoomOptions' import assistantUtil from '../../utils/assistant.util' import { GameStateConst } from '../../constants/GameStateConst' import { debugRoom } from '../../common/Debug' +import { ClockNameConst } from '../../constants/ClockNameConst' /** * 选择随从或者法术 @@ -73,7 +74,7 @@ export class SelectPetCommand extends Command= 0) { let count = elapsedTime - new GameEnv().playerActTime * 1000 let newCount = player.extraTime - Math.min(count, 0)