diff --git a/server.js b/server.js index 72f1ca1..295c61f 100644 --- a/server.js +++ b/server.js @@ -58,6 +58,16 @@ server.listen(process.env.PORT || 5000, function() { console.log('Starting server on port 5000'); }); +// If there are multiple dream wolves, convert them all. +function activateDreamWolvesIfNeeded(game) { + game.players.forEach((player) => { + if (!player.dead && player.card.role === "Dream Wolf") { + player.card.isTypeOfWerewolf = true; + console.log("player " + player.name + " was converted to a wolf!"); + } + }) +} + function teamWon(game) { let wolvesAlive = 0; let villagersAlive = 0; @@ -164,22 +174,28 @@ io.on('connection', function(socket) { let game = activeGames[Object.keys(activeGames).find((key) => key === code)]; if (game) { let player = game.players.find((player) => player.id === id); - player.dead = true; - player.deadAt = new Date().toJSON(); - game.killedPlayer = player.name; - game.lastKilled = player.id; - game.killedRole = player.card.role; - game.message = player.name + ", a " + player.card.role + ", was killed!"; - console.log(game.message); - const winCheck = teamWon(game); - if (winCheck === "wolf") { - console.log("wolves won the game!"); - game.winningTeam = "wolf"; - game.status = "ended"; - } if (winCheck === "village") { - console.log("village won the game!"); - game.winningTeam = "village"; - game.status = "ended"; + if (player) { + player.dead = true; + player.deadAt = new Date().toJSON(); + game.killedPlayer = player.name; + game.lastKilled = player.id; + game.killedRole = player.card.role; + game.message = player.name + ", a " + player.card.role + ", was killed!"; + console.log(game.message); + if (player.card.role === "Werewolf" && game.hasDreamWolf) { + activateDreamWolvesIfNeeded(game); + } + const winCheck = teamWon(game); + if (winCheck === "wolf") { + console.log("wolves won the game!"); + game.winningTeam = "wolf"; + game.status = "ended"; + } + if (winCheck === "village") { + console.log("village won the game!"); + game.winningTeam = "village"; + game.status = "ended"; + } } } }); diff --git a/static/cards.js b/static/cards.js index 8a3fa4d..0d9b599 100644 --- a/static/cards.js +++ b/static/cards.js @@ -15,7 +15,7 @@ export const cards = [ role: "Dream Wolf", team: "evil", description: "If a Werewolf dies, you become a Werewolf. You do not wake up with the Werewolves until this happens.", - isTypeOfWerewolf: true + isTypeOfWerewolf: false }, { role: "Minion", diff --git a/static/setup.js b/static/setup.js index d7c2ba6..54f4ac6 100644 --- a/static/setup.js +++ b/static/setup.js @@ -17,13 +17,14 @@ class Card { } class Game { - constructor(accessCode, size, deck, time) { + constructor(accessCode, size, deck, time, hasDreamWolf) { this.accessCode = accessCode; this.size = size; this.deck = deck; this.time = time; this.players = []; this.status = "lobby"; + this.hasDreamWolf = hasDreamWolf; this.endTime = null; } } @@ -230,11 +231,13 @@ function createGame() { // send a new game to the server, and then join it const playerInfo = {name: document.getElementById("name").value, code: code, id: id}; + let gameDeck = buildDeckFromQuantities(); const game = new Game( code, gameSize, - buildDeckFromQuantities(), - Math.ceil(document.getElementById("time").value) + gameDeck, + Math.ceil(document.getElementById("time").value), + gameDeck.find((card) => card.role === "Dream Wolf") !== undefined ); socket.emit('newGame', game, function() { socket.emit('joinGame', playerInfo);