|
|
@@ -51,7 +51,7 @@ Rapido.prototype.onAddMode = function(user, mode) { }
|
|
|
Rapido.prototype.onRename = function(oldNick, newNick) {
|
|
|
if (this.users[oldNick.toLowerCase()]) {
|
|
|
this.users[newNick.toLowerCase()] = this.users[oldNick.toLowerCase()];
|
|
|
- delete this.activeUsers[oldNick.toLowerCase()];
|
|
|
+ delete this.users[oldNick.toLowerCase()];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -97,12 +97,34 @@ Rapido.prototype.resetScores = function() {
|
|
|
Rapido.prototype.endWord = function() {
|
|
|
clearTimeout(this.wordTimeout);
|
|
|
this.currentWord = null;
|
|
|
+ this.currentPoints = [];
|
|
|
this.wordRequest = [];
|
|
|
this.wordStart= 0;
|
|
|
}
|
|
|
|
|
|
Rapido.prototype.onWordTimeout = function() {
|
|
|
- this.bot.sendMsg(this.room, "Bah alors ? " +this.wordRequest.join(", ") +" vous fichez quoi ?");
|
|
|
+ if (this.currentPoints.length) {
|
|
|
+ this.currentPoints = this.currentPoints.map((i, index) => {
|
|
|
+ const time = i.time -this.wordStart;
|
|
|
+ return {
|
|
|
+ username: i.username,
|
|
|
+ time: time,
|
|
|
+ fps: Math.floor(100000 * this.currentWord.length / time) / 100,
|
|
|
+ pts: this.computeScore(time, this.currentWord, index)
|
|
|
+ };
|
|
|
+ });
|
|
|
+ this.currentPoints.forEach(i => {
|
|
|
+ this.bot.sendMsg(this.room, "Mot trouvé en " +i.time +"ms (" +i.fps +" touches par seconde) par " +i.username);
|
|
|
+ });
|
|
|
+ this.currentPoints.forEach(i => {
|
|
|
+ this.users[i.username] = this.users[i.username] || this.bot.createUser(i.username);
|
|
|
+ this.users[i.username].score += i.pts;
|
|
|
+ this.bot.sendMsg(this.room, i.pts +" points pour " +i.username +", qui cumule un total de " +this.users[i.username].score +" points !");
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ this.bot.sendMsg(this.room, "Bah alors ? " +this.wordRequest.join(", ") +" vous fichez quoi ?");
|
|
|
+ this.bot.sendMsg(this.room, "fin du temps réglementaire, tapez !next pour une prochaine partie.");
|
|
|
+ }
|
|
|
this.endWord();
|
|
|
}
|
|
|
|
|
|
@@ -111,6 +133,7 @@ Rapido.prototype.startNextWordTimer = function() {
|
|
|
this.currentWord = this.words[Math.floor(Math.random() * this.words.length)];
|
|
|
console.log(this.currentWord);
|
|
|
_this.bot.sendMsg(this.room, "Attention attention, prochain mot dans " +Math.floor(this.config.NEXT_WORD_DELAY / 1000) +" secondes");
|
|
|
+ _this.bot.sendMsg(this.room, "Rappel : il faut taper le plus vite possible en minuscule et sans espaces le mot proposé");
|
|
|
setTimeout(() => {
|
|
|
var wordEsc = _this.currentWord.replace(/(\w)/g, ' $1').toUpperCase().trimStart();
|
|
|
_this.bot.sendMsg(_this.room, wordEsc);
|
|
|
@@ -140,19 +163,20 @@ Rapido.prototype.sendScore = function() {
|
|
|
scoreLines.forEach(i => this.bot.sendMsg(this.room, i));
|
|
|
}
|
|
|
|
|
|
-Rapido.prototype.computeScore = function(ellapsed, word) {
|
|
|
+Rapido.prototype.computeScore = function(ellapsed, word, index) {
|
|
|
const fps = 1000 * word.length / ellapsed;
|
|
|
console.log({
|
|
|
fps: fps,
|
|
|
ellapsed: ellapsed,
|
|
|
word: word
|
|
|
});
|
|
|
+ var base = 2 +(index == 0 ? 2 : 0);
|
|
|
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 base +scoreItem[1];
|
|
|
}
|
|
|
- return 0;
|
|
|
+ return base;
|
|
|
}
|
|
|
|
|
|
Rapido.prototype.onMessageInternal = function(username, user, msg) {
|
|
|
@@ -167,16 +191,12 @@ Rapido.prototype.onMessageInternal = function(username, user, msg) {
|
|
|
else if (lmsg.startsWith("!score")) {
|
|
|
this.sendScore();
|
|
|
}
|
|
|
- else if (this.currentWord && this.wordStart) {
|
|
|
- if (lmsg === this.currentWord) {
|
|
|
- const time = Date.now() -this.wordStart,
|
|
|
- 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;
|
|
|
- this.bot.sendMsg(this.room, pts +" points pour " +username +", qui cumule un total de " +this.users[username].score +" points !");
|
|
|
- this.endWord();
|
|
|
- }
|
|
|
+ else if (this.currentWord && this.wordStart && msg === this.currentWord) {
|
|
|
+ for (var i =0, len = this.currentPoints.length; i < len; ++i)
|
|
|
+ if (this.currentPoints[i].username == username)
|
|
|
+ return;
|
|
|
+ this.currentPoints.push({ username: username, time: Date.now()});
|
|
|
+ this.bot.sendMsg(this.room, "Ok pour " +username);
|
|
|
}
|
|
|
};
|
|
|
|