From 1f1a942ebae09f1b24a656b71b612a03c774ea5d Mon Sep 17 00:00:00 2001 From: zhl Date: Fri, 4 Dec 2020 10:07:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E7=94=9F=E6=88=90=E5=8D=A1?= =?UTF-8?q?=E7=BB=84=E6=9F=90=E4=BA=9B=E5=8D=A1=E6=97=A0=E6=B3=95=E5=8C=B9?= =?UTF-8?q?=E9=85=8D=E6=95=88=E6=9E=9C=E5=8D=A1=E7=9A=84bug,=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0vscode=E7=9A=84launch=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/launch.json | 19 ++++++++++++------- package.json | 2 +- src/rooms/MSender.ts | 6 +++--- src/utils/game.util.ts | 15 ++++++++++++--- 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 7a9dfa0..f19fcc0 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,12 +4,17 @@ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ - { - "type": "pwa-chrome", - "request": "launch", - "name": "Launch Chrome against localhost", - "url": "http://localhost:8080", - "webRoot": "${workspaceFolder}" - } + { + "address": "192.168.100.24", + "localRoot": "${workspaceFolder}", + "name": "192.168.100.24", + "port": 9229, + "remoteRoot": "Absolute path to the remote directory containing the program", + "request": "attach", + "skipFiles": [ + "/**" + ], + "type": "pwa-node" + } ] } \ No newline at end of file diff --git a/package.json b/package.json index 3ccb42d..e0014d8 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "lib/index.js", "typings": "src/global.d.ts", "scripts": { - "start": "ts-node-dev --files src/index.ts", + "start": "ts-node-dev --inspect --files src/index.ts", "loadtest": "colyseus-loadtest loadtest/example.ts --room my_room --numClients 3", "test": "echo \"Error: no test specified\" && exit 1" }, diff --git a/src/rooms/MSender.ts b/src/rooms/MSender.ts index 206c24d..1cf7687 100644 --- a/src/rooms/MSender.ts +++ b/src/rooms/MSender.ts @@ -12,7 +12,7 @@ Object.defineProperties(Room.prototype, { }, sSelectHero: { value: function (client: Client, data?: any) { - this.send(client, 'select_hero_s2c', data); + client.send('select_hero_s2c', data); }, writable: true }, @@ -24,7 +24,7 @@ Object.defineProperties(Room.prototype, { }, sDrawCard: { value: function (client: Client, data?: any) { - this.send(client, 'draw_card_s2c', data); + client.send('draw_card_s2c', data); } }, bPartResult: { @@ -41,7 +41,7 @@ Object.defineProperties(Room.prototype, { sMsgQueue: { value: function (client:Client, datas?: PetInfoMsg) { - this.broadcast("msg_queue_s2c", datas); + client.send("msg_queue_s2c", datas); } }, diff --git a/src/utils/game.util.ts b/src/utils/game.util.ts index 2784094..cc79d66 100644 --- a/src/utils/game.util.ts +++ b/src/utils/game.util.ts @@ -18,7 +18,7 @@ let gameUtil = { let countMap: Map = new Map(); let localId = 1; for (let [id, cfg] of numCfgMap) { - for (let i = 0; i <= cfg.count; i++) { + for (let i = 0; i < cfg.count; i++) { if (cfg.type_id == 1) { let effid = this.getRandomEffect(cfg.weightArr, effCfgMap, countMap); let card = new Card(localId ++, cfg.point, cfg.type_id, effid); @@ -47,18 +47,27 @@ let gameUtil = { total += data[1]; tmpArr.push([data[0], total]); } - let num = Math.random() * total; + let num = Math.random() * total; //TODO:: fix bug! 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]).count) { + if (count < effCfgMap.get(data[0]).count) { effid = effCfgMap.get(data[0]).id; countMap.set(effid, count + 1); break; } } } + if (!effid) { + for (let [id, count] of countMap) { + if (count < effCfgMap.get(id).count) { + effid = id; + countMap.set(effid, count + 1); + break + } + } + } if (!effid) { console.warn('生成卡组时, 无法匹配效果卡, 请确认效果卡的最大数量是否等于点数卡总数') }