diff --git a/src/cfg/parsers/EffectCardCfg.ts b/src/cfg/parsers/EffectCardCfg.ts index 8dbed4c..e1a90e1 100644 --- a/src/cfg/parsers/EffectCardCfg.ts +++ b/src/cfg/parsers/EffectCardCfg.ts @@ -3,6 +3,7 @@ import {Cfg} from "../../common/DataParser"; export class EffectCardCfg implements Cfg{ public id: number; + public maxCount: number; public typeId: number; public eff1Id: number; public eff2Id: number; @@ -18,5 +19,6 @@ export class EffectCardCfg implements Cfg{ this.eff3Id = data.eff3_id; this.eff4Id = data.eff4_id; this.eff5Id = data.eff5_id; + this.maxCount = 20; } } diff --git a/src/cfg/parsers/SystemCardCfg.ts b/src/cfg/parsers/SystemCardCfg.ts index ce444b0..f04818c 100644 --- a/src/cfg/parsers/SystemCardCfg.ts +++ b/src/cfg/parsers/SystemCardCfg.ts @@ -6,17 +6,17 @@ export class SystemCardCfg implements Cfg { public count: number; public point: number; public weight: string; - public weightArr: []; + public weightArr: number[][]; public decode(data: any) { this.id = data.id; this.typeId = data.type_id; this.point = data.point; + this.count = data.count; this.weight = data.weight; let arr = this.weight.split('|'); this.weightArr = []; for (let str of arr) { let subArr = str.split(':'); - // @ts-ignore this.weightArr.push([parseInt(subArr[0]), parseInt(subArr[1])]); } } diff --git a/src/common/DataParser.ts b/src/common/DataParser.ts index 079d375..ece5b6a 100644 --- a/src/common/DataParser.ts +++ b/src/common/DataParser.ts @@ -17,13 +17,13 @@ export var DataParser = (function (){ for (let i = 0, len = data.length; i < len; i++) { let obj = data[i]; if (!obj[idkey]) { - console.error(`配置${key}的数据有误,唯一标识 ${idkey} 值为0或者没有${idkey}`); + console.warn(`配置${key}的数据有误,唯一标识 ${idkey} 值为0或者没有${idkey}`); continue; } let to = new CfgCreator(); to.decode(obj); if (dict.has(to.id)) { - console.error(`配置${key}的数据有误,唯一标识 id 有重复值:${to.id}`) + console.warn(`配置${key}的数据有误,唯一标识 id 有重复值:${to.id}`) process.abort(); } dict.set(to.id, to); diff --git a/src/global.d.ts b/src/global.d.ts index 5bb8a8c..4bcf86d 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -1,7 +1,5 @@ export {}; -declare var console1: Console; - declare global { namespace NodeJS { interface Global { @@ -11,3 +9,12 @@ declare global { } } } + +declare module colyseus { + namespace Colyseus { + class Room { + testFun(param1: string): void; + } + } +} + diff --git a/src/rooms/GeneralRoom.ts b/src/rooms/GeneralRoom.ts index ee9b30e..0a9d3a6 100644 --- a/src/rooms/GeneralRoom.ts +++ b/src/rooms/GeneralRoom.ts @@ -12,6 +12,7 @@ import {EatCardCommand} from "./commands/EatCardCommand"; import {GiveUpCommand} from "./commands/GiveUpCommand"; import {BattleHandler} from "./logic/Handler/BattleHandler"; + export class GeneralRoom extends Room { dispatcher = new Dispatcher(this); maxClients = 4; @@ -68,7 +69,7 @@ export class GeneralRoom extends Room { onJoin (client: Client, options: any) { this.dispatcher.dispatch(new OnJoinCommand(), { client: client, - battle: this.battleMan, + battle: this.battleMan, }); this.clientMap.set(client.sessionId, client); } diff --git a/src/rooms/commands/EatCardCommand.ts b/src/rooms/commands/EatCardCommand.ts index 9f473a4..7168b3d 100644 --- a/src/rooms/commands/EatCardCommand.ts +++ b/src/rooms/commands/EatCardCommand.ts @@ -45,6 +45,7 @@ export class EatCardCommand extends Command = []; let numCfgMap: Map = global.$cfg.get(BaseConst.SYSTEMCARD); - let effCfgMap = global.$cfg.get(BaseConst.EFFECTCARD); - let nums: Array = []; - let types : Array = []; + let effCfgMap: Map = global.$cfg.get(BaseConst.EFFECTCARD); + + let countMap: Map = new Map(); + let localId = 1; for (let [id, cfg] of numCfgMap) { for (let i = 0; i < cfg.count; i++) { - nums.push(cfg.point); + if (cfg.typeId == 1) { + let effid = this.getRandomEffect(cfg.weightArr, effCfgMap, countMap); + let card = new Card(localId ++, cfg.point, cfg.typeId, effid); + cards.push(card); + } else { + let card = new Card(localId ++, cfg.point, cfg.typeId, 0); + cards.push(card); + } + } } - arrUtil.randomSort(nums); - for (let i = 0; i < 8; i ++) { - for (let j = 0; j < 24; j ++) { - types.push(i); - } - } - arrUtil.randomSort(types); - for (let i = 0; i < nums.length; i++) { - cards.push(new Card(nums[i] + 1, types[i], i, i)); - } arrUtil.randomSort(cards); return cards; }, + getRandomEffect(weightArr: number[][], effCfgMap: Map, countMap: Map) { + let total = 0; + let tmpArr:number[][] = []; + for (let data of weightArr) { + total += data[1]; + tmpArr.push([data[0], total]); + } + let num = Math.random() * total; + let effid; + for (let data of tmpArr) { + if (data[1] >= num ) { + let count = countMap.has(data[0]) ? countMap.get(data[0]) : 0; + if (count < effCfgMap.get(data[0]).maxCount) { + effid = effCfgMap.get(data[0]).id; + countMap.set(effid, count + 1); + break; + } + } + } + if (!effid) { + console.warn('生成卡组时, 无法匹配效果卡, 请确认效果卡的最大数量是否等于点数卡总数') + } + return effid; + }, /** * 检查目标数组中的卡id是否在存在 * @param cardMap