Merge branch 'second' of http://git.kingsome.cn/node/card_svr into second
This commit is contained in:
commit
d4f1917639
5
src/global.d.ts
vendored
5
src/global.d.ts
vendored
@ -260,6 +260,11 @@ declare module "colyseus" {
|
||||
*/
|
||||
getAssistClient(sessionId: string): RobotClient;
|
||||
|
||||
/**
|
||||
* 获取对位玩家
|
||||
* @param srcPlayer
|
||||
*/
|
||||
getOppositePlayer(srcPlayer: string|Player): Player;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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<CardGameState, {}> {
|
||||
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()]
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user