如果state.cards中有卡, 且卡的owner是下一轮的玩家, 那么清空cards

This commit is contained in:
zhl 2021-03-16 14:11:37 +08:00
parent b511102887
commit 7a3ecf7c70
3 changed files with 24 additions and 0 deletions

5
src/global.d.ts vendored
View File

@ -329,6 +329,11 @@ declare module 'colyseus' {
* @return {Player}
*/
getPlayerByIdx(idx: number): Player;
/**
*
*/
nextPlayer(): string;
}
}

View File

@ -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]
}
}

View File

@ -40,6 +40,16 @@ export class TurnEndCommand extends Command<CardGameState, {}> {
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) {