diff --git a/src/robot/Robot.ts b/src/robot/Robot.ts index 896c3a6..3de4af9 100644 --- a/src/robot/Robot.ts +++ b/src/robot/Robot.ts @@ -186,7 +186,13 @@ export class Robot { } let self = this let cardArr = [...self.player.cards.values()] - let result = assistantUtil.discard({cardArr, eatCard: targetCard, rate: this.cheatRate, noEatRate: this.noEatRate, noTripleRate: this.noTripleRate}) + let result = assistantUtil.discard({cardArr, + eatCard: targetCard, + rate: this.cheatRate, + noEatRate: this.noEatRate, + noTripleRate: this.noTripleRate, + playerId: this.sessionId + }) let cards = result.cards; if (!cards || cards.length == 0) { return diff --git a/src/robot/RobotClient.ts b/src/robot/RobotClient.ts index 55db5a4..3e2e0ae 100644 --- a/src/robot/RobotClient.ts +++ b/src/robot/RobotClient.ts @@ -198,7 +198,12 @@ export class RobotClient implements Client { private async eatOrGiveUp() { let targetCard = [...this.svrstate.cards.values()][0] let cardArr = [...this.selfPlayer.cards.values()] - let result = assistantUtil.discard({cardArr, eatCard: targetCard, rate: this.cheatRate, noEatRate: this.noEatRate, noTripleRate: this.noTripleRate}) + let result = assistantUtil.discard({cardArr, + eatCard: targetCard, + rate: this.cheatRate, + noEatRate: this.noEatRate, + playerId: this.sessionId, + noTripleRate: this.noTripleRate}) let tmpCards = result.cards let next = this.giveup.bind(this) if (tmpCards.length > 1 && targetCard.type === 1) { diff --git a/src/utils/assistant.util.ts b/src/utils/assistant.util.ts index e12861e..67c4f7f 100644 --- a/src/utils/assistant.util.ts +++ b/src/utils/assistant.util.ts @@ -102,11 +102,11 @@ function seekSeq(pointMap: Map, points: number[], special?: Card return result } -function parseCheat(this: any, cardArr: Card[], rate: number, eatCard?: Card) { +function parseCheat(this: any, playerId: string, cardArr: Card[], rate: number, eatCard?: Card) { let minCount = eatCard ? new GameEnv().otherEatCount : new GameEnv().selfEatCount if (cardArr.length >= minCount && rate > 0) { let random = getRandom(0, 100) - robotLog(`[discard] check cheat ^_^ random: ${random}, rate: ${rate}`) + robotLog(`(${playerId})[discard] check cheat ^_^ random: ${random}, rate: ${rate}`) if (random <= rate) { let max = Math.min(minCount+2, cardArr.length + 1) let randomCount = getRandom(minCount, max) @@ -172,7 +172,7 @@ function parseCheat(this: any, cardArr: Card[], rate: number, eatCard?: Card) { } } const oneCardArr: Card[] = cardArr.randomGet(1) - robotLog(`[discard] no cheat: ${oneCardArr[0].number}`) + robotLog(`(${playerId})[discard] no cheat: ${oneCardArr[0].number}`) return {cards: oneCardArr } } @@ -227,12 +227,14 @@ let assistantUtil = { /** * 出牌 */ - discard({cardArr, eatCard, rate, noEatRate, noTripleRate}: + discard({cardArr, eatCard, rate, noEatRate, noTripleRate, playerId}: {cardArr: Card[], eatCard?: Card, rate: number, noEatRate: number, - noTripleRate: number}): {cards: Card[], nums?: number[]} { + noTripleRate: number, + playerId?: string + }): {cards: Card[], nums?: number[]} { const pointCardArr = cardArr.filter(c => c.type == CardType.general || c.type == CardType.variable_unit) const { selfEat, @@ -242,27 +244,27 @@ let assistantUtil = { eatSecs, normalSecs } = this.checkDiscard({cardArr: pointCardArr, eatCard}) - robotLog(`[discard] check: eatself: ${selfEat}, eatother: ${otherEat}, self: ${pointCardArr.map(o=>o.number)}, target: ${eatCard?.number}`) + robotLog(`(${playerId})[discard] check: eatself: ${selfEat}, eatother: ${otherEat}, self: ${pointCardArr.map(o=>o.number)}, target: ${eatCard?.number}`) let results: Card[] = [] let random = getRandom(0, 100) if (otherEat && random <= noEatRate) { - robotLog(`[discard] cat eat, but random(${random}) <= cfg(${noEatRate})`) + robotLog(`(${playerId})[discard] cat eat, but random(${random}) <= cfg(${noEatRate})`) } else if (otherEat && random > noEatRate) { results = eatPairs.length > 0? eatPairs : eatSecs - robotLog(`[discard] eat card random(${random}) > cfg(${noEatRate}) ${results.map(o=>o.number)}`) + robotLog(`(${playerId})[discard] eat card random(${random}) > cfg(${noEatRate}) ${results.map(o=>o.number)}`) } random = getRandom(0, 100) if (selfEat && results.length == 0 && random <= noTripleRate) { - robotLog(`[discard] can hu, but random(${random}) <= cfg(${noTripleRate})`) + robotLog(`(${playerId})[discard] can hu, but random(${random}) <= cfg(${noTripleRate})`) } if (selfEat && results.length == 0 && random > noTripleRate) { results = normalPairs.length > 0 ? normalPairs : normalSecs - robotLog(`[discard] hu card random(${random}) > cfg(${noTripleRate}) ${results.map(o=>o.number)}`) + robotLog(`(${playerId})[discard] hu card random(${random}) > cfg(${noTripleRate}) ${results.map(o=>o.number)}`) } if (results.length == 0) { results = cardArr.randomGet(1) } if (!selfEat && !otherEat) { - return parseCheat(cardArr, rate, eatCard) + return parseCheat(playerId, cardArr, rate, eatCard) } return {cards: results} }, @@ -345,11 +347,11 @@ let assistantUtil = { } if (!result) { - error(`无法选择随从或法术, 随从数: ${ petCount }, 法术牌数量: ${ spellCards.length }`) + error(`(${dstPlayer.id})无法选择随从或法术, 随从数: ${ petCount }, 法术牌数量: ${ spellCards.length }`) return null } let targetType: SkillTargetType = CfgMan.getTargetByCard(result.effect) - robotLog(`select_pet ${ dstPlayer.id }: ${ result.effect } 类型: ${ effectMap.get(result.effect).type_id == EffectType.skill ? '法术' : '随从' }, targetType: ${ targetType }, oldpos: ${oldpos}`) + robotLog(`(${dstPlayer.id})select_pet ${ dstPlayer.id }: ${ result.effect } 类型: ${ effectMap.get(result.effect).type_id == EffectType.skill ? '法术' : '随从' }, targetType: ${ targetType }, oldpos: ${oldpos}`) let targetPlayer let targetPos switch (targetType) {