修改队伍设置方式和一些相关的计算方式
This commit is contained in:
parent
ff5cce11da
commit
03ac546548
@ -25,7 +25,7 @@ import { Service } from '../service/Service'
|
|||||||
|
|
||||||
export class GeneralRoom extends Room {
|
export class GeneralRoom extends Room {
|
||||||
dispatcher = new Dispatcher(this);
|
dispatcher = new Dispatcher(this);
|
||||||
maxClients = 4;
|
maxClients = 2;
|
||||||
score = 0;
|
score = 0;
|
||||||
battleMan = new BattleHandler();
|
battleMan = new BattleHandler();
|
||||||
// 用于游戏过程中各种计时器, 使用该计时器的前提是, 只针对当前操作玩家
|
// 用于游戏过程中各种计时器, 使用该计时器的前提是, 只针对当前操作玩家
|
||||||
@ -44,6 +44,9 @@ export class GeneralRoom extends Room {
|
|||||||
}
|
}
|
||||||
onCreate (options: any) {
|
onCreate (options: any) {
|
||||||
let cs = new CardGameState();
|
let cs = new CardGameState();
|
||||||
|
if (options.clients) {
|
||||||
|
this.maxClients = options.clients
|
||||||
|
}
|
||||||
this.setState(cs);
|
this.setState(cs);
|
||||||
this.setPrivate(true);
|
this.setPrivate(true);
|
||||||
if (options.count) {
|
if (options.count) {
|
||||||
@ -300,7 +303,7 @@ export class GeneralRoom extends Room {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
let idx = this.state.players.get(playerId).idx;
|
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);
|
return this.getPlayerByIdx(opposIdx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,12 @@ export class OnJoinCommand extends Command<CardGameState, {
|
|||||||
} else {
|
} else {
|
||||||
idx = seatSet.values().next().value
|
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
|
// end of set seat and team
|
||||||
let player = new Player(client.sessionId, idx, team);
|
let player = new Player(client.sessionId, idx, team);
|
||||||
this.state.players.set(client.sessionId, player);
|
this.state.players.set(client.sessionId, player);
|
||||||
|
@ -341,20 +341,24 @@ let gameUtil = {
|
|||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* 判断游戏结束
|
||||||
|
* 1. 只有1个有活人的队伍
|
||||||
|
* 2. 游戏轮数达到配置
|
||||||
|
* @param {CardGameState} state
|
||||||
|
* @return {boolean}
|
||||||
|
*/
|
||||||
checkGameEnd(state: CardGameState) {
|
checkGameEnd(state: CardGameState) {
|
||||||
let deadCount0 = 0
|
let teamMap: Map<number, number> = new Map()
|
||||||
let deadCount1 = 0
|
|
||||||
for (let [, player] of state.players) {
|
for (let [, player] of state.players) {
|
||||||
if (player.team == 0 && player.state == PlayerStateConst.PLAYER_DEAD) {
|
if (player.state != PlayerStateConst.PLAYER_DEAD) {
|
||||||
deadCount0++
|
teamMap.inc(player.team, 1)
|
||||||
} else if (player.team == 1 && player.state == PlayerStateConst.PLAYER_DEAD) {
|
|
||||||
deadCount1++
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const roundNum = new GameEnv().duelRoundNum
|
const roundNum = new GameEnv().duelRoundNum
|
||||||
const totalRound = roundNum * new GameEnv().maxDuelNum
|
const totalRound = roundNum * new GameEnv().maxDuelNum
|
||||||
return (deadCount0 == 2 || deadCount1 == 2) || (state.round >= totalRound - 1)
|
return (teamMap.size <= 1) || (state.round >= totalRound - 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user