修改机器人逻辑, 默认出点数最小的牌
This commit is contained in:
parent
e2b42c1ad6
commit
54591b6de4
@ -13,6 +13,7 @@ import {EffectCardCfg} from "../cfg/parsers/EffectCardCfg";
|
|||||||
import CfgMan from '../rooms/logic/CfgMan';
|
import CfgMan from '../rooms/logic/CfgMan';
|
||||||
import {SkillTargetType} from "../rooms/logic/skill/SkillConst";
|
import {SkillTargetType} from "../rooms/logic/skill/SkillConst";
|
||||||
import {Player} from "../rooms/schema/Player";
|
import {Player} from "../rooms/schema/Player";
|
||||||
|
import gameUtil from "../utils/game.util";
|
||||||
|
|
||||||
export class RobotClient implements Client {
|
export class RobotClient implements Client {
|
||||||
id: string;
|
id: string;
|
||||||
@ -143,72 +144,11 @@ export class RobotClient implements Client {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (result.length < 3) {
|
if (result.length < 3) {
|
||||||
return [result[0]];
|
return [cards[0]];
|
||||||
} else {
|
} else {
|
||||||
return result;
|
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<number, HeroCfg> = 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
|
* @private
|
||||||
@ -232,7 +172,7 @@ export class RobotClient implements Client {
|
|||||||
let pets = [];
|
let pets = [];
|
||||||
for (let [, pet] of player.pets) {
|
for (let [, pet] of player.pets) {
|
||||||
if (pet.ap > 0 && pet.state == 1)
|
if (pet.ap > 0 && pet.state == 1)
|
||||||
pets.push(pet);
|
pets.push(pet);
|
||||||
}
|
}
|
||||||
let result;
|
let result;
|
||||||
if (pets.length > 0) {
|
if (pets.length > 0) {
|
||||||
@ -240,6 +180,103 @@ export class RobotClient implements Client {
|
|||||||
}
|
}
|
||||||
return result ? result.pos : -1;
|
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<number, HeroCfg> = 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() {
|
private selectPet() {
|
||||||
let cards = [...this.svrstate.cards.values()];
|
let cards = [...this.svrstate.cards.values()];
|
||||||
let result;
|
let result;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user