修改队伍设置方式和一些相关的计算方式

This commit is contained in:
zhl 2021-02-24 20:17:17 +08:00
parent ff5cce11da
commit 03ac546548
3 changed files with 23 additions and 11 deletions

View File

@ -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);
}
}

View File

@ -40,7 +40,12 @@ export class OnJoinCommand extends Command<CardGameState, {
} else {
idx = seatSet.values().next().value
}
const team = (idx == 1 || idx == 2) ? 1 : 0;
let team
if (this.room.maxClients % 2 == 0 ) {
team = (idx == 1 || idx == 2) ? 1 : 0;
} else {
team = idx
}
// end of set seat and team
let player = new Player(client.sessionId, idx, team);
this.state.players.set(client.sessionId, player);

View File

@ -341,20 +341,24 @@ let gameUtil = {
}
return result
},
/**
*
* 1. 1
* 2.
* @param {CardGameState} state
* @return {boolean}
*/
checkGameEnd(state: CardGameState) {
let deadCount0 = 0
let deadCount1 = 0
let teamMap: Map<number, number> = 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)
}
}