抽卡和偷卡判断配置中玩家手牌数量, 抽卡的方法返回抽到的卡的数量
This commit is contained in:
parent
b6b4a1ac3c
commit
3cc18f6902
2
src/global.d.ts
vendored
2
src/global.d.ts
vendored
@ -167,7 +167,7 @@ declare module "colyseus" {
|
|||||||
* @param source 0: 正常抽卡, 1: 技能
|
* @param source 0: 正常抽卡, 1: 技能
|
||||||
* @param fromplayer
|
* @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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新玩家血量
|
* 更新玩家血量
|
||||||
|
@ -4,6 +4,8 @@ import {error} from "../common/Debug";
|
|||||||
import {PlayerStateConst} from "../constants/PlayerStateConst";
|
import {PlayerStateConst} from "../constants/PlayerStateConst";
|
||||||
import {PetInfo} from "../message/PetInfo";
|
import {PetInfo} from "../message/PetInfo";
|
||||||
import {PlayDeadCommand} from "./commands/PlayDeadCommand";
|
import {PlayDeadCommand} from "./commands/PlayDeadCommand";
|
||||||
|
import {singleton} from "../common/Singleton";
|
||||||
|
import {GameEnv} from "../cfg/GameEnv";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 一些常用的方法
|
* 一些常用的方法
|
||||||
@ -12,8 +14,16 @@ Object.defineProperties(Room.prototype, {
|
|||||||
drawCardFromPlayer: {
|
drawCardFromPlayer: {
|
||||||
value: function (srcplayer: string, dstplayer: string, count: number): number {
|
value: function (srcplayer: string, dstplayer: string, count: number): number {
|
||||||
let player1 = this.state.players.get(dstplayer);
|
let player1 = this.state.players.get(dstplayer);
|
||||||
let tmpCards = gameUtil.removeCard(player1, count);
|
|
||||||
let player0 = this.state.players.get(srcplayer);
|
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);
|
gameUtil.addCardToPlayer(this, player0, tmpCards, player1);
|
||||||
let cardIds = tmpCards.map(card => card.id);
|
let cardIds = tmpCards.map(card => card.id);
|
||||||
let client = this.getClient(player0);
|
let client = this.getClient(player0);
|
||||||
@ -46,20 +56,31 @@ Object.defineProperties(Room.prototype, {
|
|||||||
return true;
|
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: {
|
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 player = this.state.players.get(dstplayer);
|
||||||
|
let curCount = player.cards.size;
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
if (max_count > 0) {
|
if (maxCount > 0) {
|
||||||
let curCount = player.cards.size;
|
count = Math.min(count, maxCount - curCount);
|
||||||
count = Math.min(count, max_count - curCount);
|
} else {
|
||||||
|
count = Math.min(count, maxCountCfg - curCount);
|
||||||
}
|
}
|
||||||
} else if (max_count > 0){
|
} else if (maxCount > 0){
|
||||||
let curCount = player.cards.size;
|
count = maxCount - curCount;
|
||||||
count = max_count - curCount;
|
|
||||||
} else {
|
} else {
|
||||||
error("补卡方法的参数有问题, count和max_count都为0");
|
error("补卡方法的参数有问题, count和max_count都为0");
|
||||||
return false;
|
return 0;
|
||||||
}
|
}
|
||||||
let player2 = fromplayer ? this.state.players.get(fromplayer) : null;
|
let player2 = fromplayer ? this.state.players.get(fromplayer) : null;
|
||||||
let cards = gameUtil.drawCard(this, this.state.cardQueue, player, count, player2);
|
let cards = gameUtil.drawCard(this, this.state.cardQueue, player, count, player2);
|
||||||
@ -77,7 +98,7 @@ Object.defineProperties(Room.prototype, {
|
|||||||
source: source
|
source: source
|
||||||
};
|
};
|
||||||
this.bDrawCard(bData, {except: client});
|
this.bDrawCard(bData, {except: client});
|
||||||
return true;
|
return cardIds.length;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
updateHp: {
|
updateHp: {
|
||||||
|
@ -25,16 +25,5 @@ export class DrawCommand extends Command<CardGameState, {}> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.room.beginSchedule(maxTime + player.extraTime, timeOverDraw, `draw_card_${sessionId}`);
|
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)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user