import { Command } from "@colyseus/command"; import { CardGameState } from "../schema/CardGameState"; import {Client} from "colyseus"; import {NextTurnCommand} from "./NextTurnCommand"; import {TurnEndCommand} from "./TurnEndCommand"; import {Player} from "../schema/Player"; import {Card} from "../schema/Card"; import {Pet} from "../schema/Pet"; import {singleton} from "../../common/Singleton"; import {GameEnv} from "../../cfg/GameEnv"; /** * 选择随从或者法术 */ export class SelectPetCommand extends Command { execute({client, cardId, playerId, pos, effCards} = 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 hasEffectSkill = this.room.battleMan.hasTransEffCardSkill(player); // 检查效果卡, 并从玩家手牌中移除 let eff_cnt = 0; // 效果卡数量 let dbpt_cnt = 0; // 点数翻倍卡数量 for (let cardId of effCards) { if (!player.cards.has(cardId + '')) { continue; } let card = player.cards.get(cardId + ''); let neetRemove = false; if (hasEffectSkill) { neetRemove = true; if (card.type === 3) { dbpt_cnt ++; } else { eff_cnt ++; } } else { if (card.type === 3) { dbpt_cnt ++; neetRemove = true; } else if (card.type === 2) { eff_cnt ++; neetRemove = true; } } if (neetRemove) { player.cards.delete(cardId + ''); player.cardSet.delete(cardId + ''); } } for (let card of this.state.cards.values()) { ap += card.number; count ++; if (count === 3) { moreAp += singleton(GameEnv).baseAddScore; } else if (count > 3) { moreAp += singleton(GameEnv).extraAddScore; } if (card.id == cardId) { targetCard = card; } } if (!targetCard) { return; } //停止选随从计时, 并更新player.extraTime; if (this.room.mainClock && this.room.mainClock.active) { let count = this.room.mainClock.elapsedTime - singleton(GameEnv).playerActTime * 1000; let newCount = player.extraTime - count; player.extraTime = Math.max(newCount, 0); this.room.mainClock.clear(); } 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} this.room.battleMan.useCard(data); return [new TurnEndCommand()]; } }