diff --git a/src/robot/RobotClient.ts b/src/robot/RobotClient.ts index a5915d0..270bb90 100644 --- a/src/robot/RobotClient.ts +++ b/src/robot/RobotClient.ts @@ -13,6 +13,7 @@ import {EffectCardCfg} from "../cfg/parsers/EffectCardCfg"; import CfgMan from '../rooms/logic/CfgMan'; import {SkillTargetType} from "../rooms/logic/skill/SkillConst"; import {Player} from "../rooms/schema/Player"; +import gameUtil from "../utils/game.util"; export class RobotClient implements Client { id: string; @@ -143,72 +144,11 @@ export class RobotClient implements Client { } } if (result.length < 3) { - return [result[0]]; + return [cards[0]]; } else { return result; } } - // >>>>>>>>>>>>>>>>>> begin - - private discard() { - let self = this; - let next = function () { - let cardArr = [...self.cards.values()]; - // cardArr.sort((a, b) => a.number - b.number); - let cards = self.checkTriple(cardArr); - if (!cards) { - return; - } - let cardIds = cards.map(o => o.id); - self.reply('discard_card_c2s', { - cards: cardIds - }); - } - this.clock.setTimeout(next, 1500); - } - private eatOrGiveUp() { - let targetCard = [...this.svrstate.cards.values()][0]; - let cardArr = [...this.cards.values()]; - let tmpCards = this.checkTriple(cardArr, targetCard); - let next = this.giveup.bind(this); - if (tmpCards.length > 1) { - let cardIds: number[] = []; - for (let card of tmpCards) { - if (card.id !== targetCard.id) { - cardIds.push(card.id); - } - } - next = this.eatCard.bind(this, cardIds, targetCard.id); - } - - this.clock.setTimeout(next, 1500); - } - private eatCard(cardIds: number[], target: number) { - log(`${this.sessionId} 吃牌 ${cardIds} -> ${target}`); - this.reply('eat_card_c2s', { - cards: cardIds, - target - }); - } - private giveup () { - this.reply('give_up_eat_c2s', {}); - } - private selectHero() { - this.cards = this.svrstate.players.get(this.sessionId).cards; - let heroMap: Map = global.$cfg.get(BaseConst.HERO); - let heroArr = [...heroMap.values()]; - let hero = arrUtil.randomGet(heroArr, 1); - this.reply('select_hero_c2s', { - heroId: hero[0].id - }); - } - private changeCard() { - let cardIds: number[] = []; - this.reply('change_card_c2s', { - cards: cardIds - }); - } - /** * 随机获取敌对玩家 * @private @@ -232,7 +172,7 @@ export class RobotClient implements Client { let pets = []; for (let [, pet] of player.pets) { if (pet.ap > 0 && pet.state == 1) - pets.push(pet); + pets.push(pet); } let result; if (pets.length > 0) { @@ -240,6 +180,103 @@ export class RobotClient implements Client { } return result ? result.pos : -1; } + // >>>>>>>>>>>>>>>>>> begin + /** + * 出牌 + * @private + */ + private discard() { + let self = this; + let next = function () { + let cardArr = [...self.cards.values()]; + // cardArr.sort((a, b) => a.number - b.number); + let cards = self.checkTriple(cardArr); + if (!cards) { + return; + } + let cardIds = cards.map(o => o.id); + self.reply('discard_card_c2s', { + cards: cardIds + }); + } + this.clock.setTimeout(next, 1500); + } + + /** + * 吃牌或者放弃 + * @private + */ + private eatOrGiveUp() { + let targetCard = [...this.svrstate.cards.values()][0]; + let cardArr = [...this.cards.values()]; + let tmpCards = this.checkTriple(cardArr, targetCard); + let next = this.giveup.bind(this); + if (tmpCards.length > 1) { + let cardIds: number[] = []; + for (let card of tmpCards) { + if (card.id !== targetCard.id) { + cardIds.push(card.id); + } + } + next = this.eatCard.bind(this, cardIds, targetCard.id); + } + + this.clock.setTimeout(next, 1500); + } + + /** + * 吃牌 + * @param cardIds + * @param target + * @private + */ + private eatCard(cardIds: number[], target: number) { + log(`${this.sessionId} 吃牌 ${cardIds} -> ${target}`); + this.reply('eat_card_c2s', { + cards: cardIds, + target + }); + } + + /** + * 放弃吃牌 + * @private + */ + private giveup () { + this.reply('give_up_eat_c2s', {}); + } + + /** + * 开局选择英雄 + * @private + */ + private selectHero() { + this.cards = this.svrstate.players.get(this.sessionId).cards; + let heroMap: Map = global.$cfg.get(BaseConst.HERO); + let heroArr = [...heroMap.values()]; + let hero = arrUtil.randomGet(heroArr, 1); + this.reply('select_hero_c2s', { + heroId: hero[0].id + }); + } + + /** + * 开局换牌 + * @private + */ + private changeCard() { + let cardIds: number[] = []; + this.reply('change_card_c2s', { + cards: cardIds + }); + } + + + + /** + * 选择一个法术或者一个随从 + * @private + */ private selectPet() { let cards = [...this.svrstate.cards.values()]; let result;