|
|
@@ -34,9 +34,7 @@ Rapido.prototype.init = function(bot, chanName) {
|
|
|
this.init = false;
|
|
|
this.users = {};
|
|
|
this.wordRequest = [];
|
|
|
- const now = Date.now(),
|
|
|
- nextTick = (now / this.config.GAME_DURATION) +1;
|
|
|
-
|
|
|
+ this.resetScoresWrapper();
|
|
|
}
|
|
|
|
|
|
Rapido.prototype.onSelfJoin = function() {
|
|
|
@@ -59,7 +57,7 @@ Rapido.prototype.onRename = function(oldNick, newNick) {
|
|
|
|
|
|
Rapido.prototype.onMessage = function(user, text) {
|
|
|
if (this.config.DISABLED)
|
|
|
- return;
|
|
|
+ return;
|
|
|
this.onMessageInternal(user, this.users[user.toLowerCase()], text.trimEnd().replace(/\s+/, ' '));
|
|
|
}
|
|
|
|
|
|
@@ -77,13 +75,23 @@ Rapido.prototype.reloadDb = function() {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+Rapido.prototype.resetScoresWrapper = function() {
|
|
|
+ const now = Date.now(),
|
|
|
+ nextTick = Math.floor((now / this.config.GAME_DURATION) +1) *this.config.GAME_DURATION,
|
|
|
+ _this = this;
|
|
|
+
|
|
|
+ setTimeout(() => {
|
|
|
+ _this.resetScores();
|
|
|
+ _this.resetScoresWrapper();
|
|
|
+ }, nextTick -now);
|
|
|
+}
|
|
|
+
|
|
|
Rapido.prototype.resetScores = function() {
|
|
|
- if (this.sumScores(false) > 0) {
|
|
|
+ if (Object.keys(this.users).length > 0) {
|
|
|
this.bot.sendMsg(this.room, "Fin de la manche ! Voici les scores finaux:");
|
|
|
this.sendScore();
|
|
|
}
|
|
|
- for (var i in this.users)
|
|
|
- this.users = {};
|
|
|
+ this.users = {};
|
|
|
}
|
|
|
|
|
|
Rapido.prototype.endWord = function() {
|
|
|
@@ -132,16 +140,28 @@ Rapido.prototype.sendScore = function() {
|
|
|
scoreLines.forEach(i => this.bot.sendMsg(this.room, i));
|
|
|
}
|
|
|
|
|
|
+Rapido.prototype.computeScore = function(ellapsed, word) {
|
|
|
+ const fps = 1000 * word.length / ellapsed;
|
|
|
+ console.log({
|
|
|
+ fps: fps,
|
|
|
+ ellapsed: ellapsed,
|
|
|
+ word: word
|
|
|
+ });
|
|
|
+ for (var i =0, len = this.config.SCORE_MAP.length; i < len; ++i) {
|
|
|
+ var scoreItem = this.config.SCORE_MAP[i];
|
|
|
+ if (fps >= scoreItem[0])
|
|
|
+ return scoreItem[1];
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
Rapido.prototype.onMessageInternal = function(username, user, msg) {
|
|
|
const lmsg = msg.toLowerCase();
|
|
|
|
|
|
if (lmsg === "!next") {
|
|
|
- if (!this.currentWord
|
|
|
- // && this.wordRequest.indexOf(username) === -1
|
|
|
- ) {
|
|
|
+ if (this.wordRequest.indexOf(username) === -1)
|
|
|
this.wordRequest.push(username);
|
|
|
- }
|
|
|
- if (!this.currentWord && this.wordRequest.length > 1)
|
|
|
+ if (!this.currentWord && this.wordRequest.length >= this.config.MIN_PLAYERS)
|
|
|
this.startNextWordTimer();
|
|
|
}
|
|
|
else if (lmsg.startsWith("!score")) {
|
|
|
@@ -150,7 +170,7 @@ Rapido.prototype.onMessageInternal = function(username, user, msg) {
|
|
|
else if (this.currentWord && this.wordStart) {
|
|
|
if (lmsg === this.currentWord) {
|
|
|
const time = Date.now() -this.wordStart,
|
|
|
- pts = Math.floor((this.config.WORD_TIMEOUT -time) / 100);
|
|
|
+ pts = this.computeScore(time, this.currentWord);
|
|
|
this.bot.sendMsg(this.room, "Mot trouvé en " +time +"ms par " +username);
|
|
|
this.users[username] = this.users[username] || this.bot.createUser(username);
|
|
|
this.users[username].score += pts;
|