aboutsummaryrefslogtreecommitdiff
path: root/player.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'player.mjs')
-rw-r--r--player.mjs37
1 files changed, 33 insertions, 4 deletions
diff --git a/player.mjs b/player.mjs
index d97ff42..4413d16 100644
--- a/player.mjs
+++ b/player.mjs
@@ -1,11 +1,11 @@
-import { Manager } from "./utils.mjs";
+import { shuffle, Manager } from "./utils.mjs";
class Player {
constructor(id, name, level, status, totalPlayed) {
this.id = id;
+ this.status = typeof status !== "undefined" ? status : false;
this.name = name;
this.level = typeof level !== "undefined" ? level : 1;
- this.status = typeof status !== "undefined" ? status : false;
this.totalPlayed = typeof totalPlayed !== "undefined" ? status : 0;
}
toggle() {
@@ -99,14 +99,43 @@ export class PlayerManager extends Manager {
this.render();
this.addToggleBehaviour();
}
- normalize(factor) {
+ active(factor) {
+ factor = typeof factor !== "undefined" ? factor : 1;
+ let data = super.active();
console.log("Normalize skill by a factor of " + factor + ".");
- let players = this.listData.map(function (p) {
+ let players = data.map(function (p) {
p.skill = Math.ceil(p.skill / factor);
return p;
});
return players;
}
+ propose(count) {
+ console.log("Required players are " + count);
+ let factor = Number(document.getElementById("skill").value);
+ console.log("Skill normalized by a factor of " + factor + ".");
+ const activePlayers = this.active(factor);
+ console.log("Active players are:");
+ console.log(
+ activePlayers
+ .map((i) => {
+ return i.name;
+ })
+ .join(",")
+ );
+ const shuffledPlayers = shuffle(activePlayers);
+ shuffledPlayers.sort((a, b) => a.totalPlayed - b.totalPlayed);
+ const selectedPlayers = shuffledPlayers.slice(0, count);
+ selectedPlayers.sort((a, b) => a.level - b.level);
+ console.log("Selected players are:");
+ console.log(
+ selectedPlayers
+ .map((i) => {
+ return i.name;
+ })
+ .join(",")
+ );
+ return selectedPlayers;
+ }
}
// Try to add this functionality inside the class to call after constructor