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"; /** * 选择随从或者法术 */ export class SelectPetCommand extends Command { 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 + ''); 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('select_pet'); if (elapsedTime >= 0) { let count = elapsedTime - new GameEnv().playerActTime * 1000; let newCount = player.extraTime - Math.min(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); return [new TurnEndCommand()]; } }