diff --git a/ecosystem.config.js b/ecosystem.config.js index ce5f720..707be4c 100644 --- a/ecosystem.config.js +++ b/ecosystem.config.js @@ -5,25 +5,28 @@ module.exports = { port : 2567, name : "card-proxy", script : "./node_modules/@colyseus/proxy/bin/proxy", - instances : 1, // scale this up if the proxy becomes the bottleneck + instances : 1, exec_mode : 'cluster', + env: { + PORT: 2567, + } }, { - port : 4000, name : "card_svr", script : "lib/index.js", // your entrypoint file watch : true, // optional instances : 2, exec_mode : 'fork', // IMPORTANT: do not use cluster mode. + increment_var : 'PORT', // increment a environment variable for each instance launched // error_file : '', // error日志路径 // out_file : '', // out日志路径 env: { + PORT: 4000, DEBUG: "colyseus:errors,colyseus:matchmaking,jc:*", NODE_ENV: "production", } }, { - port : 2500, name : "card_bot", script : "lib/robot.js", // your entrypoint file watch : true, // optional @@ -32,6 +35,7 @@ module.exports = { // error_file : '', // error日志路径 // out_file : '', // out日志路径 env: { + PORT: 2500, DEBUG: "colyseus:errors,jc:*", NODE_ENV: "production", } diff --git a/src/cfg/GameEnv.ts b/src/cfg/GameEnv.ts index a196826..196ac69 100644 --- a/src/cfg/GameEnv.ts +++ b/src/cfg/GameEnv.ts @@ -50,6 +50,12 @@ export class GameEnv { public robotActTimeMax: number; // 队友死亡后,补牌数量 public teamDeadAddNum: number; + // 胡牌张数(自摸) + public selfEatCount: number; + // 胡牌张数(吃牌) + public otherEatCount: number; + // 轮空轮的间隔时间 + public emptyRoundTime: number; public init(data: Map) { this.initCardNum = data.get(BaseConst.INIT_CARD_NUM).value; @@ -75,5 +81,8 @@ export class GameEnv { this.robotActTimeMin = data.get(BaseConst.ROBOT_ACTTIME_MIN).value; this.robotActTimeMax = data.get(BaseConst.ROBOT_ACTTIME_MAX).value; this.teamDeadAddNum = data.get(BaseConst.TEAM_DEAD_ADDNUM).value; + this.selfEatCount = data.get(BaseConst.SELF_EAT_COUNT).value; + this.otherEatCount = data.get(BaseConst.OTHER_EAT_COUNT).value; + this.emptyRoundTime = data.get(BaseConst.EMPTY_ROUND_TIME).value; } } diff --git a/src/constants/BaseConst.ts b/src/constants/BaseConst.ts index bbb67f6..e515fa0 100644 --- a/src/constants/BaseConst.ts +++ b/src/constants/BaseConst.ts @@ -45,6 +45,14 @@ export class BaseConst { public static readonly ROBOT_ACTTIME_MAX = 99022; // 队友死亡后,补牌数量 public static readonly TEAM_DEAD_ADDNUM = 99023 + // 胡牌张数(自摸) + public static readonly SELF_EAT_COUNT = 99024 + // 胡牌张数(吃牌) + public static readonly OTHER_EAT_COUNT = 99025 + // 轮空轮的间隔时间 + public static readonly EMPTY_ROUND_TIME = 99026 + + diff --git a/src/rooms/RoomExtMethod.ts b/src/rooms/RoomExtMethod.ts index 397c140..bbe16f7 100644 --- a/src/rooms/RoomExtMethod.ts +++ b/src/rooms/RoomExtMethod.ts @@ -182,7 +182,9 @@ Object.defineProperties(Room.prototype, { for (let i = 0; i < realCount; i++) { let cardId = 1000 + (this.state.maxCardId ++ ); let card = gameUtil.generateCardWithEffect(effectId, cardId, options); - tmpCards.push(card); + if (card) { + tmpCards.push(card); + } } diff --git a/src/rooms/commands/DiscardCommand.ts b/src/rooms/commands/DiscardCommand.ts index bed0169..ab6dc26 100644 --- a/src/rooms/commands/DiscardCommand.ts +++ b/src/rooms/commands/DiscardCommand.ts @@ -8,6 +8,8 @@ import {GameEnv} from "../../cfg/GameEnv"; import {debugRoom} from "../../common/Debug"; import {TurnEndCommand} from "./TurnEndCommand"; import {Card} from "../schema/Card"; +import {Wait} from "./Wait"; +import {CardType} from "../../cfg/enums/CardType"; /** * 出牌 @@ -38,7 +40,7 @@ export class DiscardCommand extends Command = new Map(); let cardIdSet: Set = new Set(); for (let c of cardArr) { @@ -40,13 +41,13 @@ let assistantUtil = { // 优先出对子 for (let [point, arr] of pointMap) { if (card) { - if (point == card.number && arr.length >= 3) { + if (point == card.number && arr.length >= maxCount) { fetched = true; result = arr; break; } } else { - if (arr.length >= 3) { + if (arr.length >= maxCount) { fetched = true; result = arr; break; @@ -71,17 +72,17 @@ let assistantUtil = { tmp.push(cur); } if (card) { - if (tmp.indexOf(card.number) >= 0 && tmp.length >= 3) { + if (tmp.indexOf(card.number) >= 0 && tmp.length >= maxCount) { break; } } else { - if (tmp.length >= 3) { + if (tmp.length >= maxCount) { break; } } } - if (tmp.length >= 3) { + if (tmp.length >= maxCount) { let subTmp = []; for (let i = tmp[0] - 1; i > 0; i--) { if (cardIdSet.has(i)) { diff --git a/src/utils/game.util.ts b/src/utils/game.util.ts index 3daf104..0bc636e 100644 --- a/src/utils/game.util.ts +++ b/src/utils/game.util.ts @@ -8,8 +8,9 @@ import {error} from "../common/Debug"; import {Room} from "colyseus"; import {PlayerStateConst} from "../constants/PlayerStateConst"; import {GameEnv} from "../cfg/GameEnv"; -import {GameResultCommand} from "../rooms/commands/GameResultCommand"; import {CardGameState} from "../rooms/schema/CardGameState"; +import {CardType} from "../cfg/enums/CardType"; +import {EffectType} from "../cfg/enums/EffectType"; let gameUtil = { /** @@ -27,8 +28,8 @@ let gameUtil = { let [effid, effType] = this.getRandomEffect(cfg.weightArr, effCfgMap, countMap); let type = cfg.type_id; // 如果效果的type_id为11, 说明是自选随从卡, 则将card的type改为11 - if (effType == 11) { - type = 11; + if (effType == EffectType.variable_unit) { + type = CardType.variable_unit; } let card = new Card(localId++, cfg.point, type, effid); cards.push(card); @@ -46,14 +47,25 @@ let gameUtil = { */ generateCardWithEffect(effectId: number, preCardId: number, options?: any): Card { let numCfgMap: Map = global.$cfg.get(BaseConst.SYSTEMCARD); + const effectMap = global.$cfg.get(BaseConst.EFFECTCARD); let cfgs = []; - for (let [, cfg] of numCfgMap) { - if (cfg.weight.indexOf(effectId + '') >= 0) { - cfgs.push(cfg); - } + const effectCfg = effectMap.get(effectId); + if (!effectCfg) { + return null; } - let cfg: SystemCardCfg = cfgs.randomOne(); - return new Card(preCardId + 1, cfg.point, cfg.type_id, effectId); + if (effectCfg.type_id == EffectType.unit) { + let point = Math.random2(1, 11) | 0; + return new Card(preCardId + 1, point, CardType.variable_unit, effectId); + } else { + for (let [, cfg] of numCfgMap) { + if (cfg.weight.indexOf(effectId + '') >= 0) { + cfgs.push(cfg); + } + } + let cfg: SystemCardCfg = cfgs.randomOne(); + return new Card(preCardId + 1, cfg.point, cfg.type_id, effectId); + } + }, /** * 获取随机的随从 @@ -200,9 +212,10 @@ let gameUtil = { * @param fromplayer */ addCardToPlayer(room: Room, player: Player, cards: Card[], fromplayer?: Player) { + const effectMap = global.$cfg.get(BaseConst.EFFECTCARD); for (let card of cards) { // 如果card的type == 11, 说明是自选随从卡, 则替换成玩家牌组中的卡 - if (card.type == 11) { + if (card.type == CardType.variable_unit && effectMap.get(card.effect).type_id == EffectType.variable_unit) { card.effect = this.getRandomServant(player); } player.cards.set(card.id + '', card); @@ -218,6 +231,7 @@ let gameUtil = { * @param targetCards */ changeCard(cardArr: Card[], player: Player, targetCards: Card[]): Card[] { + const effectMap = global.$cfg.get(BaseConst.EFFECTCARD); let cards: Card[] = []; for (let card of targetCards) { player.cards.delete(card.id + ''); @@ -227,7 +241,7 @@ let gameUtil = { let count = targetCards.length; for (let i = 0; i < count; i++) { let card = cardArr.pop(); - if (card.type == 11) { + if (card.type == CardType.variable_unit && effectMap.get(card.effect).type_id == EffectType.variable_unit) { card.effect = this.getRandomServant(player); } cards.push(card); @@ -239,8 +253,9 @@ let gameUtil = { /** * 检查出牌是否符合规则 * @param cardsLst + * @param maxCount */ - checkDiscard(cardsLst: Card[]) { + checkDiscard(cardsLst: Card[], maxCount: number) { if (cardsLst.length == 0 || cardsLst.length == 2) { return false } else if (cardsLst.length == 1) { @@ -248,14 +263,14 @@ let gameUtil = { } let numSet: number[] = []; cardsLst.forEach(function (value) { - if (value.number < 11) { + if (value.type == CardType.general || value.type == CardType.variable_unit) { numSet.push(value.number); } }); if (numSet.length === 1) { return true; } - if (numSet.length < 3) { + if (numSet.length < maxCount) { return false; } numSet.sort((a, b) => {