From 8257a9b71f7f28d71eb595bbf60724b99fe16c34 Mon Sep 17 00:00:00 2001 From: zhl Date: Fri, 18 Dec 2020 17:22:08 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E7=BB=93=E7=AE=97command?= =?UTF-8?q?,=20=E6=94=B9=E4=B8=BA=E6=AF=8F=E4=B8=AAturn=E7=BB=93=E6=9D=9F?= =?UTF-8?q?=E5=B0=B1=E5=88=A4=E6=96=AD=E4=B8=80=E6=AC=A1=E6=B8=B8=E6=88=8F?= =?UTF-8?q?=E7=BB=93=E6=9D=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/rooms/commands/TurnEndCommand.ts | 31 ++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/src/rooms/commands/TurnEndCommand.ts b/src/rooms/commands/TurnEndCommand.ts index e0385e4..5f62705 100644 --- a/src/rooms/commands/TurnEndCommand.ts +++ b/src/rooms/commands/TurnEndCommand.ts @@ -3,6 +3,9 @@ import {CardGameState} from "../schema/CardGameState"; import {GameEnv} from "../../cfg/GameEnv"; import {PartResultCommand} from "./PartResultCommand"; import {NextTurnCommand} from "./NextTurnCommand"; +import {PlayerStateConst} from "../../constants/PlayerStateConst"; +import {Wait} from "./Wait"; +import {GameResultCommand} from "./GameResultCommand"; /** * 一轮结束 @@ -17,14 +20,30 @@ export class TurnEndCommand extends Command { this.room.battleMan.onPlayerRoundEnd(player); } } - if (this.state.currentTurn - && sessionIds.indexOf(this.state.currentTurn) == (sessionIds.length - 1)) { - // 每n轮结束的时候结算一次 - const roundNum = new GameEnv().duelRoundNum; - if (this.state.round % roundNum == (roundNum - 1)) { - return [new PartResultCommand()]; + // if (this.state.currentTurn + // && sessionIds.indexOf(this.state.currentTurn) == (sessionIds.length - 1)) { + // // 每n轮结束的时候结算一次 + // const roundNum = new GameEnv().duelRoundNum; + // if (this.state.round % roundNum == (roundNum - 1)) { + // return [new PartResultCommand()]; + // } + // } + // 判断是否胜利 + + let deadCount0 = 0; + let deadCount1 = 0; + for (let [, player] of this.state.players) { + if (player.team == 0 && player.state == PlayerStateConst.PLAYER_DEAD ) { + deadCount0 ++; + } else if (player.team == 1 && player.state == PlayerStateConst.PLAYER_DEAD ){ + deadCount1 ++; } } + const roundNum = new GameEnv().duelRoundNum; + const totalRound = roundNum * new GameEnv().maxDuelNum; + if ((deadCount0 == 2 || deadCount1 == 2) || (this.state.round >= totalRound - 1)) { // 游戏结束 + return [new GameResultCommand()]; + } return [new NextTurnCommand()] } From 0078507ea40c40e8fc1b004f0413453129d7348d Mon Sep 17 00:00:00 2001 From: zhl Date: Fri, 18 Dec 2020 19:36:24 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E6=9F=A5=E6=89=BE=E5=AF=B9=E9=9D=A2=E7=8E=A9=E5=AE=B6=E7=9A=84?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/global.d.ts | 5 +++++ src/rooms/GeneralRoom.ts | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/global.d.ts b/src/global.d.ts index ee8da43..621ab06 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -260,6 +260,11 @@ declare module "colyseus" { */ getAssistClient(sessionId: string): RobotClient; + /** + * 获取对位玩家 + * @param srcPlayer + */ + getOppositePlayer(srcPlayer: string|Player): Player; } } diff --git a/src/rooms/GeneralRoom.ts b/src/rooms/GeneralRoom.ts index 76ee8b2..724dfae 100644 --- a/src/rooms/GeneralRoom.ts +++ b/src/rooms/GeneralRoom.ts @@ -282,4 +282,20 @@ export class GeneralRoom extends Room { getAssistClient(sessionId: string): RobotClient { return this.assistMap.get(sessionId); } + + getOppositePlayer(srcPlayer: string | Player): Player { + let playerId; + if (typeof srcPlayer === 'string') { + playerId = srcPlayer as string; + } else { + playerId = srcPlayer.id; + } + if (!this.state.players.has(playerId)) { + return null; + } + const sessionIds = [...this.state.players.keys()]; + let idx = sessionIds.indexOf(playerId); + let playerId2 = sessionIds[(2 + idx) % 4]; + return this.state.players.get(playerId2); + } }