From 03ac5465486ed7c89b3a3b181677f0d9f77d639d Mon Sep 17 00:00:00 2001 From: zhl Date: Wed, 24 Feb 2021 20:17:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=98=9F=E4=BC=8D=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E6=96=B9=E5=BC=8F=E5=92=8C=E4=B8=80=E4=BA=9B=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E7=9A=84=E8=AE=A1=E7=AE=97=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/rooms/GeneralRoom.ts | 7 +++++-- src/rooms/commands/OnJoinCommand.ts | 7 ++++++- src/utils/game.util.ts | 20 ++++++++++++-------- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/rooms/GeneralRoom.ts b/src/rooms/GeneralRoom.ts index 868d4eb..4ad8e4f 100644 --- a/src/rooms/GeneralRoom.ts +++ b/src/rooms/GeneralRoom.ts @@ -25,7 +25,7 @@ import { Service } from '../service/Service' export class GeneralRoom extends Room { dispatcher = new Dispatcher(this); - maxClients = 4; + maxClients = 2; score = 0; battleMan = new BattleHandler(); // 用于游戏过程中各种计时器, 使用该计时器的前提是, 只针对当前操作玩家 @@ -44,6 +44,9 @@ export class GeneralRoom extends Room { } onCreate (options: any) { let cs = new CardGameState(); + if (options.clients) { + this.maxClients = options.clients + } this.setState(cs); this.setPrivate(true); if (options.count) { @@ -300,7 +303,7 @@ export class GeneralRoom extends Room { return null; } let idx = this.state.players.get(playerId).idx; - let opposIdx = (2 + idx) % 4; + let opposIdx = ((this.maxClients / 2 | 0) + idx) % this.maxClients; return this.getPlayerByIdx(opposIdx); } } diff --git a/src/rooms/commands/OnJoinCommand.ts b/src/rooms/commands/OnJoinCommand.ts index c338604..bc3dd21 100644 --- a/src/rooms/commands/OnJoinCommand.ts +++ b/src/rooms/commands/OnJoinCommand.ts @@ -40,7 +40,12 @@ export class OnJoinCommand extends Command = new Map() for (let [, player] of state.players) { - if (player.team == 0 && player.state == PlayerStateConst.PLAYER_DEAD) { - deadCount0++ - } else if (player.team == 1 && player.state == PlayerStateConst.PLAYER_DEAD) { - deadCount1++ + if (player.state != PlayerStateConst.PLAYER_DEAD) { + teamMap.inc(player.team, 1) } } + const roundNum = new GameEnv().duelRoundNum const totalRound = roundNum * new GameEnv().maxDuelNum - return (deadCount0 == 2 || deadCount1 == 2) || (state.round >= totalRound - 1) + return (teamMap.size <= 1) || (state.round >= totalRound - 1) } }