增加一些battleHander的调用

This commit is contained in:
zhl 2020-12-08 16:06:29 +08:00
parent c57b0c6430
commit 9528d7296f
6 changed files with 20 additions and 11 deletions

4
src/global.d.ts vendored
View File

@ -166,8 +166,10 @@ declare module "colyseus" {
* @param dstplayer
* @param count , max_count至少一个不为0
* @param max_count , count和max_count都不为0, Math.min(count, (max_count - ))
* @param source 0: 正常抽卡, 1: 技能
* @param fromplayer
*/
addCard(dstplayer: string, count: number, max_count: number): boolean;
addCard(dstplayer: string, count: number, max_count: number, source: number = 0, fromplayer?: string): boolean;
/**
*

View File

@ -48,7 +48,7 @@ Object.defineProperties(Room.prototype, {
}
},
addCard: {
value: function ( dstplayer: string, count: number, max_count: number) {
value: function ( dstplayer: string, count: number, max_count: number, source: number = 0, fromplayer?: string) {
let player = this.state.players.get(dstplayer);
if (count > 0) {
if (max_count > 0) {
@ -62,7 +62,8 @@ Object.defineProperties(Room.prototype, {
error("补卡方法的参数有问题, count和max_count都为0");
return false;
}
let cards = gameUtil.drawCard(this.state.cardQueue, player, count);
let player2 = fromplayer ? this.state.players.get(fromplayer) : null;
let cards = gameUtil.drawCard(this.state.cardQueue, player, count, player2);
let client = this.getClient(dstplayer);
let sData = {
player: dstplayer,
@ -72,7 +73,8 @@ Object.defineProperties(Room.prototype, {
let cardIds = cards.map(card => card.id);
let bData = {
player: dstplayer,
cards: cardIds
cards: cardIds,
source: source
};
this.bDrawCard(bData, {except: client});
return true;

View File

@ -8,6 +8,7 @@ import {debugRoom} from "../../common/Debug";
import {TurnEndCommand} from "./TurnEndCommand";
import {Player} from "../schema/Player";
import arrUtil from "../../utils/array.util";
import {Card} from "../schema/Card";
/**
* ,
@ -75,6 +76,7 @@ export class EatConfirmCommand extends Command<CardGameState, { timeUp: boolean
player.cards.delete(id + '');
player.cardSet.delete(id + '');
}
let cardArr: Card[] = [...this.state.cards.values()];
this.state.gameState = GameStateConst.STATE_PICK_PET;
let time = singleton(GameEnv).playerActTime * 1000 + player.extraTime;
let self = this;
@ -88,9 +90,9 @@ export class EatConfirmCommand extends Command<CardGameState, { timeUp: boolean
}, time);
let fromPlayer = this.state.players.get(this.state.currentTurn);
if (fromPlayer.id !== player.id) {
this.room.battleMan.onCardLinkReady(player, fromPlayer);
this.room.battleMan.onCardLinkOver(player, cardArr, fromPlayer);
} else {
this.room.battleMan.onCardLinkReady(player);
this.room.battleMan.onCardLinkOver(player, cardArr);
}
// 成功后广播吃牌成功消息
this.room.broadcast('eat_card_s2c', {player: player.id, errocode: 0, errmsg: ''});

View File

@ -127,6 +127,7 @@ export class PartResultCommand extends Command<CardGameState, {}> {
deadCount1 ++;
}
}
//TODO: onPlayerDead
const roundNum = singleton(GameEnv).duelRoundNum;
const totalRound = roundNum * singleton(GameEnv).maxDuelNum;
if ((deadCount0 == 2 || deadCount1 == 2) || (this.state.round >= totalRound - 1)) { // 游戏结束

View File

@ -230,7 +230,7 @@ export class BattleHandler {
};
/**
* / ??
* /
* @param aplayer
* @param linkcards
*/
@ -252,7 +252,7 @@ export class BattleHandler {
};
/**
* ??
* //TODO:: 弃卡实装后须调用
* @param aplayer
* @param fromplayer : 谁使玩家弃牌的
* @param dropcards : 弃掉的牌组
@ -264,7 +264,7 @@ export class BattleHandler {
};
/**
* ??
*
* @param aplayer
* @param fromplayer : 谁使玩家获得牌的
* @param dropcards : 获得的牌组
@ -295,7 +295,7 @@ export class BattleHandler {
/**
*
* @param aplayer
* @param aplayer
*/
public onPlayerDead(aplayer: Player){
let ph = this.getPlayer(aplayer);

View File

@ -94,12 +94,14 @@ let gameUtil = {
* @param cardArr
* @param player
* @param count
* @param fromplayer
*/
drawCard(cardArr: Card[], player: Player, count: number): Card[] {
drawCard(cardArr: Card[], player: Player, count: number, fromplayer?: Player): Card[] {
let cards: Card[] = [];
for (let i = 0; i < count; i++) {
cards.push(cardArr.pop());
}
//TODO:
this.addCardToPlayer(player, cards);
return cards;
},