From 9528d7296f11473854bb5407e558ad288d42a42e Mon Sep 17 00:00:00 2001 From: zhl Date: Tue, 8 Dec 2020 16:06:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=80=E4=BA=9BbattleHande?= =?UTF-8?q?r=E7=9A=84=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/global.d.ts | 4 +++- src/rooms/RoomExtMethod.ts | 8 +++++--- src/rooms/commands/EatConfirmCommand.ts | 6 ++++-- src/rooms/commands/PartResultCommand.ts | 1 + src/rooms/logic/Handler/BattleHandler.ts | 8 ++++---- src/utils/game.util.ts | 4 +++- 6 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/global.d.ts b/src/global.d.ts index ae278a7..f26cbe2 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -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; /** * 更新玩家血量 diff --git a/src/rooms/RoomExtMethod.ts b/src/rooms/RoomExtMethod.ts index 38806c0..1ae6b5a 100644 --- a/src/rooms/RoomExtMethod.ts +++ b/src/rooms/RoomExtMethod.ts @@ -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; diff --git a/src/rooms/commands/EatConfirmCommand.ts b/src/rooms/commands/EatConfirmCommand.ts index 661cd0d..dfcf7f1 100644 --- a/src/rooms/commands/EatConfirmCommand.ts +++ b/src/rooms/commands/EatConfirmCommand.ts @@ -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 { deadCount1 ++; } } + //TODO: onPlayerDead const roundNum = singleton(GameEnv).duelRoundNum; const totalRound = roundNum * singleton(GameEnv).maxDuelNum; if ((deadCount0 == 2 || deadCount1 == 2) || (this.state.round >= totalRound - 1)) { // 游戏结束 diff --git a/src/rooms/logic/Handler/BattleHandler.ts b/src/rooms/logic/Handler/BattleHandler.ts index 432f156..07e7efa 100644 --- a/src/rooms/logic/Handler/BattleHandler.ts +++ b/src/rooms/logic/Handler/BattleHandler.ts @@ -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); diff --git a/src/utils/game.util.ts b/src/utils/game.util.ts index bc1627a..dab6e4d 100644 --- a/src/utils/game.util.ts +++ b/src/utils/game.util.ts @@ -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; },