From b272503696edff5c646e5f0b893b2afc7f0d3434 Mon Sep 17 00:00:00 2001 From: Jay Thomas Date: Sat, 4 Nov 2017 22:44:00 -0400 Subject: [PATCH] Fix counter-countering --- src/deck.js | 11 +++------ src/deck.spec.js | 63 ++++++++++++++++++++++++++++++++++++++---------- src/junkyard.js | 8 ++++-- src/phrases.yml | 2 +- test.js | 15 ++++++------ 5 files changed, 67 insertions(+), 32 deletions(-) diff --git a/src/deck.js b/src/deck.js index 9d68238..ad4d8e5 100644 --- a/src/deck.js +++ b/src/deck.js @@ -384,6 +384,7 @@ const deck = [ attacker.discard = [] player.discard = cards game.announce('card:grab:counter', { attacker, player }) + game.whisperStats(attacker) }, validatePlay: (player, target, cards, game) => { if (cards.length < 2) { @@ -392,17 +393,13 @@ const deck = [ } if (cards[1].validateContact) { const [, ...tail] = cards - if (!cards[1].validateContact(target, player, tail, game)) { - return false - } + return cards[1].validateContact(target, player, tail, game) } return true }, play: (player, target, cards, game) => { - if (target.discard[0]) { - game.contact(target, player, target.discard) - } game.announce('card:grab:play', { player, target }) + game.whisperStats(target) } }, { @@ -481,8 +478,6 @@ const deck = [ game.announce('card:insurance:counter', { player }) player.afterContact.push(cards[0].afterContact) game.contact(attacker, player, attacker.discard) - // attacker.discard[0].contact(attacker, player, attacker.discard, game) - // game.discardPile.push(cards[0]) removeOnce(player.afterContact, () => cards[0].afterContact) game.incrementTurn() return cards diff --git a/src/deck.spec.js b/src/deck.spec.js index 09456db..f6dc807 100644 --- a/src/deck.spec.js +++ b/src/deck.spec.js @@ -195,20 +195,14 @@ Ava.test('Grab should counter', (t) => { game.start() const [player1, player2] = game.players - player1.hand = player1.hand.concat([ - Deck.getCard('grab'), - Deck.getCard('grab'), - Deck.getCard('gut-punch'), - Deck.getCard('gut-punch') - ]) - player2.hand = player2.hand.concat([ - Deck.getCard('grab'), - Deck.getCard('gut-punch') - ]) + const grab = Deck.getCard('grab') + const gutPunch = Deck.getCard('gut-punch') + player1.hand = [grab, grab, gutPunch, gutPunch] + player2.hand = [grab, gutPunch] - game.play(player1.id, [Deck.getCard('grab'), Deck.getCard('gut-punch')]) - game.play(player2.id, [Deck.getCard('grab'), Deck.getCard('gut-punch')]) - game.play(player1.id, [Deck.getCard('grab'), Deck.getCard('gut-punch')]) + game.play(player1.id, [grab, gutPunch]) + game.play(player2.id, [grab, gutPunch]) + game.play(player1.id, [grab, gutPunch]) game.pass(player2.id) t.is(player1.hp, 8) t.is(player2.hp, 6) @@ -216,6 +210,49 @@ Ava.test('Grab should counter', (t) => { t.is(game.discardPile.length, 6) }) +Ava.test('Grab counter should allow another counter', (t) => { + const announceCallback = Sinon.spy() + const whisperCallback = Sinon.spy() + const game = new Junkyard('player1', 'Jay', announceCallback, whisperCallback) + game.addPlayer('user2', 'Kevin') + game.start() + + const [player1, player2] = game.players + const grab = Deck.getCard('grab') + const gutPunch = Deck.getCard('gut-punch') + const block = Deck.getCard('block') + player1.hand = [block, grab, gutPunch] + player2.hand = [grab, gutPunch] + game.play(player1, [grab, gutPunch]) + game.play(player2, [grab, gutPunch]) + game.play(player1, block) + + t.true(announceCallback.calledWith('card:block:counter')) + t.is(game.turns, 1) +}) + +Ava.test('Grab should whisper stats to target when playing and countering', (t) => { + const announceCallback = Sinon.spy() + const whisperCallback = Sinon.spy() + const game = new Junkyard('user1', 'Jay', announceCallback, whisperCallback) + game.addPlayer('user2', 'Kevin') + game.start() + + const [player1, player2] = game.players + const grab = Deck.getCard('grab') + const gutPunch = Deck.getCard('gut-punch') + player1.hand = [grab, gutPunch] + player2.hand = [grab, gutPunch] + + whisperCallback.reset() + game.play(player1, [grab, gutPunch]) + t.true(whisperCallback.calledWith(player2.id, 'player:stats')) + + whisperCallback.reset() + game.play(player2, [grab, gutPunch]) + t.true(whisperCallback.calledWith(player1.id, 'player:stats')) +}) + Ava.test('Acid Coffee should make a player miss a turn', (t) => { const announceCallback = Sinon.spy() const game = new Junkyard('player1', 'Jay', announceCallback) diff --git a/src/junkyard.js b/src/junkyard.js index da2347e..f0a78d7 100644 --- a/src/junkyard.js +++ b/src/junkyard.js @@ -344,8 +344,12 @@ module.exports = class Junkyard { this.whisper(player, 'player:not-turn') return false } - // Countering the first play - if (this.target && this.target === player) { + // Countering the current-turn player + if (this.target === player) { + return playCounter(player, cards, this) + } + // Countering the target's counter + if (this.target && this.target.discard && player === this.players[0]) { return playCounter(player, cards, this) } let target = null diff --git a/src/phrases.yml b/src/phrases.yml index a796e0c..65a877a 100644 --- a/src/phrases.yml +++ b/src/phrases.yml @@ -14,7 +14,7 @@ card:armor:contact: card:avalanche: en: Avalanche card:avalanche:contact: - en: <%= player.name %> causes and avalanche to fall on <%= target.name %>. + en: <%= player.name %> causes an avalanche to fall on <%= target.name %>. card:block: en: Block card:block:counter: diff --git a/test.js b/test.js index da309ce..872c5e1 100644 --- a/test.js +++ b/test.js @@ -11,11 +11,10 @@ game.start() const [player1, player2] = game.players const grab = Deck.getCard('grab') -const uppercut = Deck.getCard('uppercut') -const insurance = Deck.getCard('insurance') -player1.hand.push(uppercut) -player1.hand.push(grab) -player2.hand.push(insurance) -player2.hp = 5 -game.play(player1.id, [grab, uppercut]) -game.play(player2.id, insurance) +const gutPunch = Deck.getCard('gut-punch') +const block = Deck.getCard('block') +player1.hand = [block, grab, gutPunch] +player2.hand = [grab, gutPunch] +game.play(player1, [grab, gutPunch]) +game.play(player2, [grab, gutPunch]) +game.play(player1, block)