71 lines
2.5 KiB
TypeScript
71 lines
2.5 KiB
TypeScript
import { Command } from '@colyseus/command'
|
|
import { CardGameState } from '../schema/CardGameState'
|
|
import { NextTurnCommand } from './NextTurnCommand'
|
|
import { GameResultCommand } from './GameResultCommand'
|
|
import gameUtil from '../../utils/game.util'
|
|
import { StateTypeEnum } from '../enums/StateTypeEnum'
|
|
import { RULE_EATFLOW, RULE_EATSELF } from '../../cfg/RoomOptions'
|
|
|
|
/**
|
|
* 一轮结束
|
|
*/
|
|
export class TurnEndCommand extends Command<CardGameState, {}> {
|
|
|
|
async execute(): Promise<Command[]> {
|
|
if (this.state.currentTurn) {
|
|
let player = this.state.players.get(this.state.currentTurn)
|
|
if (player) {
|
|
let delay = this.room.battleMan.onPlayerRoundEnd(player)
|
|
await this.delay(delay)
|
|
}
|
|
}
|
|
// 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()];
|
|
// }
|
|
// }
|
|
|
|
// 记录pet的maxap(最高ap) 和 maxsap(最高单体ap)
|
|
for (let [, player] of this.state.players) {
|
|
let maxAp = player.statData.get(StateTypeEnum.MAXAP) || 0
|
|
let maxsAp = player.statData.get(StateTypeEnum.MAXSAP) || 0
|
|
let totalAp = 0
|
|
for (let [, pet] of player.pets) {
|
|
totalAp += (pet.ap || 0 + pet.extAp || 0)
|
|
maxsAp = Math.max(maxsAp, (pet.ap || 0 + pet.extAp || 0))
|
|
}
|
|
maxAp = Math.max(maxAp, totalAp)
|
|
player.statData.set(StateTypeEnum.MAXAP, maxAp)
|
|
player.statData.set(StateTypeEnum.MAXSAP, maxsAp)
|
|
}
|
|
// 20200316 添加
|
|
if (this.state.cards.size > 0 && !this.state.rules.get(RULE_EATFLOW)) {
|
|
const targetCard = [...this.state.cards.values()][0]
|
|
if (this.state.rules.get(RULE_EATSELF)) {
|
|
//如果可以吃自己出的牌, 那么等到下一轮自己出完牌再清空
|
|
if (targetCard.owner === this.state.currentTurn && targetCard.round != this.state.round) {
|
|
this.state.cards.clear()
|
|
}
|
|
} else {
|
|
// 如果不能吃自己的牌, 那么在下一回合自己轮开始前清空自己的牌
|
|
const nextPid = this.room.nextPlayer(this.state.currentTurn)
|
|
if (targetCard.owner == nextPid) {
|
|
this.state.cards.clear()
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
// 判断是否胜利
|
|
let result = gameUtil.checkGameEnd(this.state)
|
|
if (result) {
|
|
return [new GameResultCommand()]
|
|
}
|
|
return [new NextTurnCommand()]
|
|
}
|
|
|
|
}
|