gamedigz 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/protocols/valve.js +15 -14
package/package.json CHANGED
@@ -22,7 +22,7 @@
22
22
  ],
23
23
  "main": "lib/index.js",
24
24
  "author": "GameDig Contributors",
25
- "version": "0.3.1",
25
+ "version": "0.3.2",
26
26
  "repository": {
27
27
  "type": "git",
28
28
  "url": "https://github.com/gamedig/node-gamedig.git"
@@ -427,21 +427,22 @@ class Valve extends Core {
427
427
  async cleanup(/** Results */ state) {
428
428
  // Organize players / hidden players into player / bot arrays
429
429
  const botProbability = (p) => {
430
- if (p.time === -1) return Number.MAX_VALUE;
431
- return p.time;
432
- };
433
- const sortedPlayers = state.raw.players.sort((a,b) => {
434
- return botProbability(a) - botProbability(b);
435
- });
436
-
437
- const numBots = state.raw.numbots || 0;
438
- const numPlayers = state.raw.numplayers - numBots;
439
- while(state.bots.length < numBots) {
440
- if (sortedPlayers.length) state.bots.push(sortedPlayers.pop());
441
- else state.bots.push({});
430
+ if (p.time === -1) return Number.MAX_VALUE
431
+ return p.time
442
432
  }
443
- while(state.players.length < numPlayers) {
444
- state.players.push({});
433
+
434
+ const rawPlayers = [...state.raw.players]
435
+ const sortedPlayers = rawPlayers.sort((a, b) => {
436
+ return botProbability(a) - botProbability(b)
437
+ })
438
+
439
+ const numBots = state.raw.numbots || 0
440
+
441
+ while (state.bots.length < numBots && sortedPlayers.length) {
442
+ state.bots.push(sortedPlayers.pop())
443
+ }
444
+ while ((state.players.length < state.numplayers - numBots || sortedPlayers.length) && sortedPlayers.length) {
445
+ state.players.push(sortedPlayers.pop())
445
446
  }
446
447
  }
447
448