isundil 6 жил өмнө
parent
commit
b1b358232e
2 өөрчлөгдсөн 48 нэмэгдсэн , 18 устгасан
  1. 4 3
      config.js
  2. 44 15
      loupgarou.js

+ 4 - 3
config.js

@@ -54,10 +54,11 @@ module.exports.MODULES["#rapido"].push(new (require('./rapido.js'))({
 
 module.exports.MODULES["#rapido"].push(new (require('./loupgarou.js'))({
     DISABLED: false,
-    registrationDelay: 2 * 60, // 2 min
-    cupidonDelay: 60, // 1 min
+    registrationDelay: 2*60, // 2 min
+    cupidonDelay: 90, // 1 min 30
+    seerDelay: 90, // 1 min 30
     reminderInterval: 30, // 30 sec
-    privateChannel: "#jeux-lg"
+    privateChannel: "#test-lg"
 }));
 
 module.exports.MODULES["#voicefaible"] = new (require('./levoicefaible.js'))({

+ 44 - 15
loupgarou.js

@@ -59,11 +59,23 @@ const langMng = [
         setLoveWith: function(p1, p2) { return `Tu as planté ta flèche et choisi ${p1} et ${p2}`; },
         inLoveWith: function(other) { return `Cupidon a envoyé sa flèche sur toi et ton amoureux est ${other}`; },
         remainingPseudos: function(nicks) { return "Vous avez le choix entre : " +nicks.join(", "); },
+        seerMessage: function(players) { return "Tu vas pouvoir decouvrir le role d'un joueur. Tapes juste le pseudo du joueur qui t'interesse. Tu as le choix entre: " +players.join(", "); },
+        seerTimeout: function() { return "Il est tard et tu vas te coucher. Tu pourras reessayer demain."; },
         loverWins: function() { return "Les amoureux gagnent la partie !"; },
         wolfWins: function() { return "Les loup-garous gagnent la partie !"; },
         villagerWins: function() { return "Les villageois gagnent la partie !"; },
         congrats: function(nickList) { return nickList.length == 1 ? ("Félicitations au gagnant " +nickList[0]) : ("Félicitations aux gagnants " +nickList.join(", ")); },
         waitingCupidon: function(timeSec) { return `En attente de cupidon (${timeSec} secondes)`; },
+        waitingSeer: function(timeSec) { return `En attente de la voyante (${timeSec} secondes)`; },
+        whoiswhat: {
+            "WOLF": function(who) { return `${who} est un Loup-Garou.`; },
+            "VILLAGER": function(who) { return `${who} est un simple villageois.`; },
+            "CUPIDON": function(who) { return `${who} est un cupidon.`; },
+            "HUNTER": function(who) { return `${who} est un chasseur.`; },
+            "WITCH": function(who) { return `${who} est une sorcière.`; },
+            "SEER": function(who) { return `${who} est une voyante.`; },
+            "GIRL": function(who) { return `${who} est une petite fille.`; },
+        },
         whowaswhat: {
             "WOLF": function(who) { return `${who} était un Loup-Garou !`; },
             "VILLAGER": function(who) { return `${who} était un simple villageois !`; },
@@ -240,8 +252,6 @@ LoupGarou.prototype.setStep = function(newStep) {
     this.timeInStep = Date.now();
     this.clearReminder();
     this.currentStep = newStep;
-    console.log("Entering step", this.currentStep, STEP);
-    console.log((this.stepListeners[newStep] ? this.stepListeners[newStep].length : 0) + "found listeners");
     this.stepListeners[newStep] && this.stepListeners[newStep].some(i => i.call(this), this);
     LoupGarou.prototype.setStep.recursive = false;
 };
@@ -377,11 +387,15 @@ LoupGarou.prototype.setLovers = function(cupidon, p1, p2) {
     if (p2 !== cupidon) LoupGarou.prototype.nextStep.messageDelayed.push([p2.name, this.currentScenario.inLoveWith(p1.name)]);
 };
 
-LoupGarou.prototype.sendCupidonMsg = function (targets) {
+LoupGarou.prototype.aliveNicks = function() {
     var playerNames = [];
-    for (var i in this.players) playerNames.push(this.players[i].name);
-    var msg = this.currentScenario.cupidonMessage(playerNames);
-    console.log(targets, msg);
+    for (var i in this.players)
+        playerNames.push(this.players[i].name);
+    return playerNames;
+};
+
+LoupGarou.prototype.sendCupidonMsg = function (targets) {
+    var msg = this.currentScenario.cupidonMessage(this.aliveNicks());
     targets.forEach(i => this.bot.sendMsg(i.name, msg), this);
 };
 
@@ -413,16 +427,31 @@ LoupGarou.prototype.onCupidon = function() {
         this.nextStep();
 };
 
-LoupGarou.prototype.onSeerInternal = function(player) {
-    //FIXME ...
-    this.bot.sendMsg(this.room, "Attente voyante"); // FIXME this.currentScenario
-    this.nextStep();
+LoupGarou.prototype.onSeerInternal = function(player, msg) {
+    var req = msg.trim().toLowerCase();
+    if (this.players[req]) {
+        this.bot.sendMsg(player.name, this.currentScenario.whoiswhat[this.players[req].role](this.players[req].name));
+        player.jobDone = true;
+    } else {
+        this.bot.sendMsg(player.name, this.currentScenario.seerMessage(this.aliveNicks().filter(nick => nick !== player.name)));
+    }
 };
 
 LoupGarou.prototype.onSeer = function() {
     var players = this.withRole(ROLES.SEER);
     if (players.length) {
-        this.onSeerInternal(players[0]);
+        this.bot.sendMsg(this.room, this.currentScenario.waitingSeer(this.config.seerDelay));
+        players.forEach(i => {
+            this.bot.sendMsg(i.name, this.currentScenario.seerMessage(this.aliveNicks().filter(nick => nick !== i.name)));
+        }, this);
+        setTimeout((function() {
+            players.forEach(p => {
+                if (p.jobDone === null)
+                    this.bot.sendMsg(p.name, this.currentScenario.seerTimeout());
+                p.jobDone = null;
+            }, this);
+            this.nextStep();
+        }).bind(this), this.config.cupidonDelay * 1000);
     } else {
         this.nextStep();
     }
@@ -468,7 +497,6 @@ LoupGarou.prototype.onVillagers = function() {
     for (var i in this.players)
         if (this.players[i].dead === null)
             remainingPlayers.push(this.players[i].name);
-    this.debug();
 
     this.bot.sendMsg(this.room, this.currentScenario.startVotes());
     this.bot.sendMsg(this.room, this.currentScenario.remainingPseudos(remainingPlayers.sort()));
@@ -520,7 +548,7 @@ LoupGarou.prototype.cleanCorpses = function() {
 LoupGarou.prototype.checkEndOfGame = function() {
     var alive = [];
     for (var i in this.players) this.players[i].dead === null && alive.push(this.players[i]);
-    console.log("alive => ", alive);
+    console.log("alive => ", alive.map(i => i.name));
     if (alive.length === 2 && alive[0].lover === alive[1]) {
         this.bot.sendMsg(this.room, this.currentScenario.loverWins());
         this.bot.sendMsg(this.room, this.currentScenario.congrats(alive.map(i => i.name)));
@@ -570,9 +598,10 @@ LoupGarou.prototype.onPm = function(from, text) {
     var player = this.players[from.toLowerCase()];
     if (!player)
         return;
-    if (this.currentStep === STEP.SELECT_CUPIDON && player.role === ROLES.CUPIDON && player.jobDone === null) {
+    if (this.currentStep === STEP.SELECT_CUPIDON && player.role === ROLES.CUPIDON && player.jobDone === null)
         this.onCupidonInternal(player, text);
-    }
+    else if (this.currentStep === STEP.NIGHT_SEER && player.role === ROLES.SEER && player.jobDone === null)
+        this.onSeerInternal(player, text);
 };
 
 module.exports = LoupGarou;