diff --git a/src/global.d.ts b/src/global.d.ts index e5a6b18..7f74aae 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -167,7 +167,7 @@ declare module "colyseus" { * @param source 0: 正常抽卡, 1: 技能 * @param fromplayer */ - addCard(dstplayer: string, count: number, max_count: number, source?: number, fromplayer?: string): boolean; + addCard(dstplayer: string, count: number, max_count: number, source?: number, fromplayer?: string): number; /** * 更新玩家血量 diff --git a/src/rooms/RoomExtMethod.ts b/src/rooms/RoomExtMethod.ts index 02d44b6..f9e5dfb 100644 --- a/src/rooms/RoomExtMethod.ts +++ b/src/rooms/RoomExtMethod.ts @@ -4,6 +4,8 @@ import {error} from "../common/Debug"; import {PlayerStateConst} from "../constants/PlayerStateConst"; import {PetInfo} from "../message/PetInfo"; import {PlayDeadCommand} from "./commands/PlayDeadCommand"; +import {singleton} from "../common/Singleton"; +import {GameEnv} from "../cfg/GameEnv"; /** * 一些常用的方法 @@ -12,8 +14,16 @@ Object.defineProperties(Room.prototype, { drawCardFromPlayer: { value: function (srcplayer: string, dstplayer: string, count: number): number { let player1 = this.state.players.get(dstplayer); - let tmpCards = gameUtil.removeCard(player1, count); let player0 = this.state.players.get(srcplayer); + /** + * 首先取目标玩家手牌数和偷牌数量的最小值 + * 然后取目标玩家的手牌数和配置中玩家手牌数的差值 + * 取以上2值的最小值为实际偷牌数量 + */ + let realCount = Math.min(player1.cards.size, count); + let maxCount = singleton(GameEnv).maxCardNum; + realCount = Math.min(realCount, maxCount - player0.cards.size); + let tmpCards = gameUtil.removeCard(player1, realCount); gameUtil.addCardToPlayer(this, player0, tmpCards, player1); let cardIds = tmpCards.map(card => card.id); let client = this.getClient(player0); @@ -46,20 +56,31 @@ Object.defineProperties(Room.prototype, { return true; } }, + /** + * 补卡, 并广播消息 + * @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: { - value: function ( dstplayer: string, count: number, max_count: number, source: number = 0, fromplayer?: string) { + value: function ( dstplayer: string, count: number, max_count: number, source: number = 0, fromplayer?: string): number { + let maxCountCfg = singleton(GameEnv).maxCardNum; + let maxCount = Math.min(maxCountCfg, max_count); let player = this.state.players.get(dstplayer); + let curCount = player.cards.size; if (count > 0) { - if (max_count > 0) { - let curCount = player.cards.size; - count = Math.min(count, max_count - curCount); + if (maxCount > 0) { + count = Math.min(count, maxCount - curCount); + } else { + count = Math.min(count, maxCountCfg - curCount); } - } else if (max_count > 0){ - let curCount = player.cards.size; - count = max_count - curCount; + } else if (maxCount > 0){ + count = maxCount - curCount; } else { error("补卡方法的参数有问题, count和max_count都为0"); - return false; + return 0; } let player2 = fromplayer ? this.state.players.get(fromplayer) : null; let cards = gameUtil.drawCard(this, this.state.cardQueue, player, count, player2); @@ -77,7 +98,7 @@ Object.defineProperties(Room.prototype, { source: source }; this.bDrawCard(bData, {except: client}); - return true; + return cardIds.length; } }, updateHp: { diff --git a/src/rooms/commands/DrawCommand.ts b/src/rooms/commands/DrawCommand.ts index a52a0d5..4943b9f 100644 --- a/src/rooms/commands/DrawCommand.ts +++ b/src/rooms/commands/DrawCommand.ts @@ -25,16 +25,5 @@ export class DrawCommand extends Command { } } this.room.beginSchedule(maxTime + player.extraTime, timeOverDraw, `draw_card_${sessionId}`); - // this.room.mainClock = this.clock.setTimeout(function () { - // self.room.mainClock.clear(); - // if (sessionId == self.state.currentTurn) { - // let client = self.room.getClient(sessionId); - // let card = player.cards.values().next().value; - // debugRoom('出牌时间到, 自动出牌: ', card.id); - // player.extraTime = 0; - // self.room.dispatcher.dispatch(new DiscardCommand(), {client, cards: [card.id], dtype: 1}); - // } - // }, maxTime + player.extraTime) - } }