113 lines
3.4 KiB
TypeScript
113 lines
3.4 KiB
TypeScript
import { Command } from '@colyseus/command'
|
|
import { CardGameState } from '../schema/CardGameState'
|
|
import { Client } from 'colyseus'
|
|
import { TurnEndCommand } from './TurnEndCommand'
|
|
import { GameEnv } from '../../cfg/GameEnv'
|
|
import gameUtil from '../../utils/game.util'
|
|
import { RoomOptions } from '../../cfg/RoomOptions'
|
|
import assistantUtil from '../../utils/assistant.util'
|
|
import { GameStateConst } from '../../constants/GameStateConst'
|
|
import { debugRoom } from '../../common/Debug'
|
|
import { ClockNameConst } from '../../constants/ClockNameConst'
|
|
import { addDrawCardClock } from '../../utils/clock.util'
|
|
|
|
/**
|
|
* 选择随从或者法术
|
|
*/
|
|
export class SelectPetCommand extends Command<CardGameState, {
|
|
client: Client,
|
|
cardId: number,
|
|
playerId: string,
|
|
pos: number,
|
|
effCards: number[],
|
|
oldpos: number
|
|
}> {
|
|
async execute({
|
|
client,
|
|
cardId,
|
|
playerId,
|
|
pos,
|
|
effCards,
|
|
oldpos
|
|
} = this.payload) {
|
|
let sessionId = client.sessionId
|
|
let player = this.state.players.get(sessionId)
|
|
let ap = 0
|
|
let moreAp = 0
|
|
let count = 0
|
|
let targetCard
|
|
let effectRate = this.room.battleMan.getTransEffCardRate(player)
|
|
// 检查效果卡, 并从玩家手牌中移除
|
|
let eff_cnt = 0 // 效果卡数量
|
|
let dbpt_cnt = 0 // 点数翻倍卡数量
|
|
let transCount = 0
|
|
for (let eCardId of effCards) {
|
|
if (!player.cards.has(eCardId + '')) {
|
|
continue
|
|
}
|
|
let card = player.cards.get(eCardId + '').clone()
|
|
player.cardQueue.push(card)
|
|
if (card.type === 3) {
|
|
dbpt_cnt++
|
|
} else if (card.type === 2) {
|
|
eff_cnt++
|
|
} else {
|
|
transCount++
|
|
}
|
|
}
|
|
gameUtil.deleteCardFromPlayer(player, effCards)
|
|
if (effectRate && transCount) {
|
|
eff_cnt += (transCount / effectRate | 0)
|
|
}
|
|
for (let card of this.state.cards.values()) {
|
|
ap += card.number
|
|
count++
|
|
if (count === 3) {
|
|
moreAp += new GameEnv().baseAddScore
|
|
} else if (count > 3) {
|
|
moreAp += new GameEnv().extraAddScore
|
|
}
|
|
if (card.id == cardId) {
|
|
targetCard = card
|
|
}
|
|
}
|
|
if (!targetCard) {
|
|
return
|
|
}
|
|
//停止选随从计时, 并更新player.extraTime;
|
|
let elapsedTime = this.room.stopSchedule(ClockNameConst.SELECT_PET)
|
|
if (elapsedTime >= 0) {
|
|
let count = elapsedTime - new GameEnv().playerActTime * 1000
|
|
let newCount = player.extraTime - Math.max(count, 0)
|
|
player.extraTime = Math.max(newCount, 0)
|
|
}
|
|
|
|
let dstplayer = this.state.players.get(playerId)
|
|
let dstpet
|
|
if (dstplayer && pos != undefined) {
|
|
dstpet = dstplayer.pets.get(pos + '')
|
|
}
|
|
let cardpoint = moreAp + ap
|
|
let data = {
|
|
srcplayer: player,
|
|
card: targetCard.effect,
|
|
cardpoint,
|
|
eff_cnt,
|
|
dstplayer,
|
|
dstpet,
|
|
dbpt_cnt,
|
|
oldpos
|
|
}
|
|
let time = this.room.battleMan.useCard(data)
|
|
await this.delay(time)
|
|
if (new RoomOptions().multipleEat() && assistantUtil.checkDiscard([...player.cards.values()]).length > 1) {
|
|
this.state.updateGameState(GameStateConst.STATE_BEGIN_DRAW)
|
|
this.state.updateGameTurn(player.id, this.state.eatCount + 1)
|
|
debugRoom(`more eatcount for player ${player.id}, ${this.state.eatCount}`)
|
|
addDrawCardClock(this.room)
|
|
} else {
|
|
return [new TurnEndCommand()]
|
|
}
|
|
}
|
|
}
|