diff --git a/src/global.d.ts b/src/global.d.ts index e608bd3..15021d0 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -329,6 +329,11 @@ declare module 'colyseus' { * @return {Player} */ getPlayerByIdx(idx: number): Player; + + /** + * 获取下一个玩家 + */ + nextPlayer(): string; } } diff --git a/src/rooms/GeneralRoom.ts b/src/rooms/GeneralRoom.ts index 16ed0f6..7d5dc67 100644 --- a/src/rooms/GeneralRoom.ts +++ b/src/rooms/GeneralRoom.ts @@ -421,4 +421,13 @@ export class GeneralRoom extends Room { } return results } + + nextPlayer(): string { + const players = [...this.state.players.values()]; + players.sort((a, b) => a.idx - b.idx); + const sessionIds = players.map(p => p.id); + return (this.state.currentTurn) + ? sessionIds[(sessionIds.indexOf(this.state.currentTurn) + 1) % sessionIds.length] + : sessionIds[0] + } } diff --git a/src/rooms/commands/TurnEndCommand.ts b/src/rooms/commands/TurnEndCommand.ts index ebd6c10..84b9de9 100644 --- a/src/rooms/commands/TurnEndCommand.ts +++ b/src/rooms/commands/TurnEndCommand.ts @@ -40,6 +40,16 @@ export class TurnEndCommand extends Command { player.statData.set(StateTypeEnum.MAXAP, maxAp); player.statData.set(StateTypeEnum.MAXSAP, maxsAp); } + // 如果state.cards中有卡, 且卡的owner是下一轮的玩家, 那么清空cards + // 20200316 添加 + if (this.state.cards.size > 0) { + const nextPid = this.room.nextPlayer() + const targetCard = [...this.state.cards.values()][0] + if (targetCard.owner == nextPid) { + this.state.cards.clear() + } + } + // 判断是否胜利 let result = gameUtil.checkGameEnd(this.state); if (result) {