增加一些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 dstplayer
* @param count , max_count至少一个不为0 * @param count , max_count至少一个不为0
* @param max_count , count和max_count都不为0, Math.min(count, (max_count - )) * @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: { 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); let player = this.state.players.get(dstplayer);
if (count > 0) { if (count > 0) {
if (max_count > 0) { if (max_count > 0) {
@ -62,7 +62,8 @@ Object.defineProperties(Room.prototype, {
error("补卡方法的参数有问题, count和max_count都为0"); error("补卡方法的参数有问题, count和max_count都为0");
return false; 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 client = this.getClient(dstplayer);
let sData = { let sData = {
player: dstplayer, player: dstplayer,
@ -72,7 +73,8 @@ Object.defineProperties(Room.prototype, {
let cardIds = cards.map(card => card.id); let cardIds = cards.map(card => card.id);
let bData = { let bData = {
player: dstplayer, player: dstplayer,
cards: cardIds cards: cardIds,
source: source
}; };
this.bDrawCard(bData, {except: client}); this.bDrawCard(bData, {except: client});
return true; return true;

View File

@ -8,6 +8,7 @@ import {debugRoom} from "../../common/Debug";
import {TurnEndCommand} from "./TurnEndCommand"; import {TurnEndCommand} from "./TurnEndCommand";
import {Player} from "../schema/Player"; import {Player} from "../schema/Player";
import arrUtil from "../../utils/array.util"; 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.cards.delete(id + '');
player.cardSet.delete(id + ''); player.cardSet.delete(id + '');
} }
let cardArr: Card[] = [...this.state.cards.values()];
this.state.gameState = GameStateConst.STATE_PICK_PET; this.state.gameState = GameStateConst.STATE_PICK_PET;
let time = singleton(GameEnv).playerActTime * 1000 + player.extraTime; let time = singleton(GameEnv).playerActTime * 1000 + player.extraTime;
let self = this; let self = this;
@ -88,9 +90,9 @@ export class EatConfirmCommand extends Command<CardGameState, { timeUp: boolean
}, time); }, time);
let fromPlayer = this.state.players.get(this.state.currentTurn); let fromPlayer = this.state.players.get(this.state.currentTurn);
if (fromPlayer.id !== player.id) { if (fromPlayer.id !== player.id) {
this.room.battleMan.onCardLinkReady(player, fromPlayer); this.room.battleMan.onCardLinkOver(player, cardArr, fromPlayer);
} else { } else {
this.room.battleMan.onCardLinkReady(player); this.room.battleMan.onCardLinkOver(player, cardArr);
} }
// 成功后广播吃牌成功消息 // 成功后广播吃牌成功消息
this.room.broadcast('eat_card_s2c', {player: player.id, errocode: 0, errmsg: ''}); 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 ++; deadCount1 ++;
} }
} }
//TODO: onPlayerDead
const roundNum = singleton(GameEnv).duelRoundNum; const roundNum = singleton(GameEnv).duelRoundNum;
const totalRound = roundNum * singleton(GameEnv).maxDuelNum; const totalRound = roundNum * singleton(GameEnv).maxDuelNum;
if ((deadCount0 == 2 || deadCount1 == 2) || (this.state.round >= totalRound - 1)) { // 游戏结束 if ((deadCount0 == 2 || deadCount1 == 2) || (this.state.round >= totalRound - 1)) { // 游戏结束

View File

@ -230,7 +230,7 @@ export class BattleHandler {
}; };
/** /**
* / ?? * /
* @param aplayer * @param aplayer
* @param linkcards * @param linkcards
*/ */
@ -252,7 +252,7 @@ export class BattleHandler {
}; };
/** /**
* ?? * //TODO:: 弃卡实装后须调用
* @param aplayer * @param aplayer
* @param fromplayer : 谁使玩家弃牌的 * @param fromplayer : 谁使玩家弃牌的
* @param dropcards : 弃掉的牌组 * @param dropcards : 弃掉的牌组
@ -264,7 +264,7 @@ export class BattleHandler {
}; };
/** /**
* ?? *
* @param aplayer * @param aplayer
* @param fromplayer : 谁使玩家获得牌的 * @param fromplayer : 谁使玩家获得牌的
* @param dropcards : 获得的牌组 * @param dropcards : 获得的牌组

View File

@ -94,12 +94,14 @@ let gameUtil = {
* @param cardArr * @param cardArr
* @param player * @param player
* @param count * @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[] = []; let cards: Card[] = [];
for (let i = 0; i < count; i++) { for (let i = 0; i < count; i++) {
cards.push(cardArr.pop()); cards.push(cardArr.pop());
} }
//TODO:
this.addCardToPlayer(player, cards); this.addCardToPlayer(player, cards);
return cards; return cards;
}, },