抽卡和偷卡判断配置中玩家手牌数量, 抽卡的方法返回抽到的卡的数量

This commit is contained in:
zhl 2020-12-09 13:58:34 +08:00
parent b6b4a1ac3c
commit 3cc18f6902
3 changed files with 32 additions and 22 deletions

2
src/global.d.ts vendored
View File

@ -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;
/**
*

View File

@ -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: {

View File

@ -25,16 +25,5 @@ export class DrawCommand extends Command<CardGameState, {}> {
}
}
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)
}
}