diff --git a/chat-plugins/uno.js b/chat-plugins/uno.js index 6809e9b999..07a435d3bf 100644 --- a/chat-plugins/uno.js +++ b/chat-plugins/uno.js @@ -144,7 +144,7 @@ class UNOgame extends Rooms.RoomGame { if (this.awaitUno) { this.unoId = Math.floor(Math.random() * 100).toString(); - this.players[this.awaitUno].sendRoom(`|raw|
`); + this.players[this.awaitUno].sendRoom(`|uhtml|uno-hand|
`); } clearTimeout(this.timer); @@ -180,6 +180,20 @@ class UNOgame extends Rooms.RoomGame { return player; } + onDraw(user) { + if (this.currentPlayer !== user.userid || this.state !== "play") return false; + if (this.players[user.userid].cardLock) return true; + + this.onCheckUno(); + + this.sendToRoom(`${user.name} has drawn a card.`); + let player = this.players[user.userid]; + + let card = this.onDrawCard(user, 1, true); + player.sendDisplay(); + player.cardLock = card[0].name; + } + onPlay(user, cardName) { if (this.currentPlayer !== user.userid || this.state !== "play") return false; let player = this.players[user.userid]; @@ -194,13 +208,7 @@ class UNOgame extends Rooms.RoomGame { clearTimeout(this.timer); // reset the autodq timer. - if (this.awaitUno) { - // if the previous player hasn't hit UNO before the next player plays something, they are forced to draw 2 cards. - this.sendToRoom(`${this.players[this.awaitUno].name} forgot to say UNO! and is forced to draw 2 cards.`); - this.onDrawCard({userid: this.awaitUno}, 2); - delete this.awaitUno; - delete this.unoId; - } + this.onCheckUno(); // update the game information. this.topCard = card; @@ -278,15 +286,14 @@ class UNOgame extends Rooms.RoomGame { this.nextTurn(); } - onDrawCard(user, count, selfDraw) { + onDrawCard(user, count) { if (!(user.userid in this.players)) return false; let drawnCards = this.drawCard(count); let player = this.players[user.userid]; player.hand.push(...drawnCards); - player.sendDisplay(); player.sendRoom(`|raw|You have drawn the following card${drawnCards.length > 1 ? "s" : ""}: ${drawnCards.map(card => `${card.name}`).join(", ")}.`); - if (selfDraw) player.cardLock = drawnCards[0].name; + return drawnCards; } drawCard(count) { @@ -311,6 +318,18 @@ class UNOgame extends Rooms.RoomGame { delete this.unoId; } + onCheckUno() { + if (this.awaitUno) { + // if the previous player hasn't hit UNO before the next player plays something, they are forced to draw 2 cards; + if (this.awaitUno !== this.currentPlayer) { + this.sendToRoom(`${this.players[this.awaitUno].name} forgot to say UNO! and is forced to draw 2 cards.`); + this.onDrawCard({userid: this.awaitUno}, 2); + } + delete this.awaitUno; + delete this.unoId; + } + } + onSendHand(user) { if (!(user.userid in this.players) || this.state === "signups") return false; @@ -368,18 +387,17 @@ class UNOgamePlayer extends Rooms.RoomGamePlayer { sendDisplay() { let hand = this.buildHand().join(""); let players = `

Players (${this.game.playerCount}):

` + this.game.getPlayers(true).join("
"); - let draw = ""; - let pass = ""; + let draw = ""; + let pass = ""; - let top = `Top Card: ${this.game.topCard.name}`; + let top = `Top Card: ${this.game.topCard.name}`; // clear previous display and show new display this.sendRoom("|uhtmlchange|uno-hand|"); this.sendRoom( - `|uhtml|uno-hand|${this.game.currentPlayer === this.userid ? `` : ""}` + - `` + - `` + - `${this.game.currentPlayer === this.userid ? `` : ""}
${top}
${hand}
${players}
${draw}${pass}
` + `|uhtml|uno-hand|${this.game.currentPlayer === this.userid ? `` : ""}` + + `` + + `${this.game.currentPlayer === this.userid ? `` : ""}
${hand}
${top}
${players}
${draw}${pass}
` ); } } @@ -489,11 +507,8 @@ exports.commands = { draw: function (target, room, user) { if (!room.game || room.game.gameid !== "uno") return false; - if (room.game.currentPlayer !== user.userid) return false; - if (room.game.players[user.userid].cardLock) return this.errorReply("You have already drawn a card this turn."); - room.add(`${user.name} has drawn a card.`).update(); - - room.game.onDrawCard(user, 1, true); + let error = room.game.onDraw(user); + if (error) return this.errorReply("You have already drawn a card this turn."); }, pass: function (target, room, user) {