修正生成卡组某些卡无法匹配效果卡的bug, 增加vscode的launch配置

This commit is contained in:
zhl 2020-12-04 10:07:25 +08:00
parent 6f9082c3b2
commit 1f1a942eba
4 changed files with 28 additions and 14 deletions

19
.vscode/launch.json vendored
View File

@ -4,12 +4,17 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{ {
"type": "pwa-chrome", "address": "192.168.100.24",
"request": "launch", "localRoot": "${workspaceFolder}",
"name": "Launch Chrome against localhost", "name": "192.168.100.24",
"url": "http://localhost:8080", "port": 9229,
"webRoot": "${workspaceFolder}" "remoteRoot": "Absolute path to the remote directory containing the program",
} "request": "attach",
"skipFiles": [
"<node_internals>/**"
],
"type": "pwa-node"
}
] ]
} }

View File

@ -5,7 +5,7 @@
"main": "lib/index.js", "main": "lib/index.js",
"typings": "src/global.d.ts", "typings": "src/global.d.ts",
"scripts": { "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", "loadtest": "colyseus-loadtest loadtest/example.ts --room my_room --numClients 3",
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },

View File

@ -12,7 +12,7 @@ Object.defineProperties(Room.prototype, {
}, },
sSelectHero: { sSelectHero: {
value: function (client: Client, data?: any) { value: function (client: Client, data?: any) {
this.send(client, 'select_hero_s2c', data); client.send('select_hero_s2c', data);
}, },
writable: true writable: true
}, },
@ -24,7 +24,7 @@ Object.defineProperties(Room.prototype, {
}, },
sDrawCard: { sDrawCard: {
value: function (client: Client, data?: any) { value: function (client: Client, data?: any) {
this.send(client, 'draw_card_s2c', data); client.send('draw_card_s2c', data);
} }
}, },
bPartResult: { bPartResult: {
@ -41,7 +41,7 @@ Object.defineProperties(Room.prototype, {
sMsgQueue: { sMsgQueue: {
value: function (client:Client, datas?: PetInfoMsg) { value: function (client:Client, datas?: PetInfoMsg) {
this.broadcast("msg_queue_s2c", datas); client.send("msg_queue_s2c", datas);
} }
}, },

View File

@ -18,7 +18,7 @@ let gameUtil = {
let countMap: Map<number, number> = new Map(); let countMap: Map<number, number> = new Map();
let localId = 1; let localId = 1;
for (let [id, cfg] of numCfgMap) { 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) { if (cfg.type_id == 1) {
let effid = this.getRandomEffect(cfg.weightArr, effCfgMap, countMap); let effid = this.getRandomEffect(cfg.weightArr, effCfgMap, countMap);
let card = new Card(localId ++, cfg.point, cfg.type_id, effid); let card = new Card(localId ++, cfg.point, cfg.type_id, effid);
@ -47,18 +47,27 @@ let gameUtil = {
total += data[1]; total += data[1];
tmpArr.push([data[0], total]); tmpArr.push([data[0], total]);
} }
let num = Math.random() * total; let num = Math.random() * total; //TODO:: fix bug!
let effid; let effid;
for (let data of tmpArr) { for (let data of tmpArr) {
if (data[1] >= num ) { if (data[1] >= num ) {
let count = countMap.has(data[0]) ? countMap.get(data[0]) : 0; 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; effid = effCfgMap.get(data[0]).id;
countMap.set(effid, count + 1); countMap.set(effid, count + 1);
break; 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) { if (!effid) {
console.warn('生成卡组时, 无法匹配效果卡, 请确认效果卡的最大数量是否等于点数卡总数') console.warn('生成卡组时, 无法匹配效果卡, 请确认效果卡的最大数量是否等于点数卡总数')
} }