如果state.cards中有卡, 且卡的owner是下一轮的玩家, 那么清空cards
This commit is contained in:
parent
b511102887
commit
7a3ecf7c70
5
src/global.d.ts
vendored
5
src/global.d.ts
vendored
@ -329,6 +329,11 @@ declare module 'colyseus' {
|
||||
* @return {Player}
|
||||
*/
|
||||
getPlayerByIdx(idx: number): Player;
|
||||
|
||||
/**
|
||||
* 获取下一个玩家
|
||||
*/
|
||||
nextPlayer(): string;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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]
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user