diff --git a/src/robot/Robot.ts b/src/robot/Robot.ts index 262b7be..4a51c13 100644 --- a/src/robot/Robot.ts +++ b/src/robot/Robot.ts @@ -46,7 +46,6 @@ export class Robot { addListeners() { let self = this; this.room.onMessage("*", (type, data) => { - debug("[ROBOT] received message:", type, "=>", data); switch (type) { case 'draw_card_s2c': // if (data.player == self.sessionId) { @@ -57,6 +56,7 @@ export class Robot { break; case 'eat_card_s2c': if (data.errcode == 0 && data.player == self.sessionId) { + debug(`eat_success: ${self.sessionId}`); self.selectPet(); } break; @@ -64,7 +64,7 @@ export class Robot { }); this.room.onLeave(function () { - debug("[ROBOT] LEFT ROOM", arguments); + debug("LEFT ROOM", arguments); self.room.removeAllListeners(); self.room.leave(); }); @@ -165,6 +165,7 @@ export class Robot { return; } let cardIds = cards.map(o => o.id); + log(`discard: ${self.sessionId} ${cardIds}`); self.reply('discard_card_c2s', { cards: cardIds }); @@ -200,7 +201,7 @@ export class Robot { * @private */ private eatCard(cardIds: number[], target: number) { - log(`${this.sessionId} 吃牌 ${cardIds} -> ${target}`); + log(`eta_card: ${this.sessionId} ${cardIds} -> ${target}`); this.reply('eat_card_c2s', { cards: cardIds, target diff --git a/src/robot/RobotClient.ts b/src/robot/RobotClient.ts index b268ab3..bda767b 100644 --- a/src/robot/RobotClient.ts +++ b/src/robot/RobotClient.ts @@ -100,7 +100,7 @@ export class RobotClient implements Client { } public send(messageOrType: any, messageOrOptions?: any | ISendOptions, options?: ISendOptions) { - log(`receive server msg: ${messageOrType}, ${messageOrOptions}`); + // log(`receive server msg: ${messageOrType}, ${messageOrOptions}`); let self = this; if (!this.active) { return; @@ -142,6 +142,7 @@ export class RobotClient implements Client { return; } let cardIds = cards.map(o => o.id); + log(`discard: ${self.sessionId} ${cardIds}`); self.reply('discard_card_c2s', { cards: cardIds }); diff --git a/src/rooms/RoomExtMethod.ts b/src/rooms/RoomExtMethod.ts index bbe16f7..3c0f262 100644 --- a/src/rooms/RoomExtMethod.ts +++ b/src/rooms/RoomExtMethod.ts @@ -113,6 +113,7 @@ Object.defineProperties(Room.prototype, { return 0; } else { let dstHp = player.hp + (hp | 0); + debugRoom(`更新血量: ${player.id} ${player.hp} -> ${hp}`); if (dstHp <= 0) { dstHp = 0; this.dispatcher.dispatch(new PlayDeadCommand(), {player: player}); diff --git a/src/rooms/commands/BeginGameCommand.ts b/src/rooms/commands/BeginGameCommand.ts index b067897..8f637c2 100644 --- a/src/rooms/commands/BeginGameCommand.ts +++ b/src/rooms/commands/BeginGameCommand.ts @@ -20,7 +20,7 @@ export class BeginGameCommand extends Command { let cardAll = card0.concat(card1); cardAll.randomSort(); this.state.cardQueue = cardAll; - let i = 1; + let i = 0; for (let [id] of this.state.players) { this.room.addCard(id, new GameEnv().playerInitNums[i++], 0); } diff --git a/src/utils/assistant.util.ts b/src/utils/assistant.util.ts index 85b8c9a..5d900ab 100644 --- a/src/utils/assistant.util.ts +++ b/src/utils/assistant.util.ts @@ -10,6 +10,7 @@ import {HeroCfg} from "../cfg/parsers/HeroCfg"; import {EffectType} from "../cfg/enums/EffectType"; import {CardType} from "../cfg/enums/CardType"; import {GameEnv} from "../cfg/GameEnv"; +import {error, robotLog} from "../common/Debug"; let assistantUtil = { @@ -151,28 +152,44 @@ let assistantUtil = { let result: Card; let effectMap: Map = global.$cfg.get(BaseConst.EFFECTCARD); let spellCards: Card[] = []; + let petCards: Card[] = []; + // 优先取随从 - let petCount = 1; + let petCount = 0; for (let [,pet] of dstPlayer.pets) { - if (pet.state == 1) petCount ++; + if (pet.state == 1 && !pet.isHero) petCount ++; } let noMorePet = petCount >= new GameEnv().maxPlayerPetCount; + + let noPet = Math.random2(0, 100) > 70; + for (let card of cards) { - let effect = effectMap.get(card.effect); - // if (effect.type_id == EffectType.unit && dstPlayer.unitCfgs.has(card.effect + '')) { - if (effect.type_id == EffectType.unit && !noMorePet) { - result = card; - break; - } else if (effect.type_id == EffectType.skill) { + if (card.type == CardType.variable_unit) { + petCards.push(card); + } else if (card.type == CardType.general) { spellCards.push(card); } } - if (!result) { + if (!noMorePet && !noPet && petCards.length > 0) { + result = petCards.randomOne(); + } + + if (!result && spellCards.length > 0) { result = spellCards.randomOne(); } + let oldpos = -1; + if (!result && petCards.length > 0) { + result = petCards.randomOne(); + if (noMorePet) { + oldpos = 1; + } + } + if (!result) { + error(`无法选择随从或法术, 随从数: ${petCount}, 法术牌数量: ${spellCards.length}`); return null; } + robotLog(`select_pet ${dstPlayer.id}: ${result.effect} 类型: ${effectMap.get(result.effect).type_id == EffectType.skill ? '法术' : '随从'}`) let targetType: SkillTargetType = CfgMan.getTargetByCard(result.effect); let targetPlayer; let targetPos; @@ -224,7 +241,8 @@ let assistantUtil = { card: result.id, player: targetPlayer?.id, pos: targetPos, - effCards + effCards, + oldpos } },