83 lines
2.8 KiB
TypeScript
83 lines
2.8 KiB
TypeScript
import {Command} from "@colyseus/command";
|
|
import {CardGameState} from "../schema/CardGameState";
|
|
import {Client} from "colyseus";
|
|
import {TurnEndCommand} from "./TurnEndCommand";
|
|
import {singleton} from "../../common/Singleton";
|
|
import {GameEnv} from "../../cfg/GameEnv";
|
|
import gameUtil from "../../utils/game.util";
|
|
|
|
/**
|
|
* 选择随从或者法术
|
|
*/
|
|
export class SelectPetCommand extends Command<CardGameState, {client: Client,
|
|
cardId: number,
|
|
playerId: string,
|
|
pos: number,
|
|
effCards: number[]
|
|
}> {
|
|
async 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 effectRate = this.room.battleMan.getTransEffCardRate(player);
|
|
// 检查效果卡, 并从玩家手牌中移除
|
|
let eff_cnt = 0; // 效果卡数量
|
|
let dbpt_cnt = 0; // 点数翻倍卡数量
|
|
let transCount = 0;
|
|
for (let cardId of effCards) {
|
|
if (!player.cards.has(cardId + '')) {
|
|
continue;
|
|
}
|
|
let card = player.cards.get(cardId + '');
|
|
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 += singleton(GameEnv).baseAddScore;
|
|
} else if (count > 3) {
|
|
moreAp += singleton(GameEnv).extraAddScore;
|
|
}
|
|
if (card.id == cardId) {
|
|
targetCard = card;
|
|
}
|
|
}
|
|
if (!targetCard) {
|
|
return;
|
|
}
|
|
//停止选随从计时, 并更新player.extraTime;
|
|
let elapsedTime = this.room.stopSchedule();
|
|
if (elapsedTime >= 0) {
|
|
let count = elapsedTime - singleton(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}
|
|
let time = this.room.battleMan.useCard(data);
|
|
await this.delay(time);
|
|
return [new TurnEndCommand()];
|
|
|
|
}
|
|
}
|