From 27cdcda2d4a4c12a302c391a113f5947d06c8390 Mon Sep 17 00:00:00 2001 From: James Ketrenos Date: Sun, 20 Feb 2022 12:28:25 -0800 Subject: [PATCH] Playing an Army activates robberInAction for active player to place Robber Signed-off-by: James Ketrenos --- client/src/Table.js | 10 ++++++++-- server/routes/games.js | 43 +++++++++++++++++++++++------------------- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/client/src/Table.js b/client/src/Table.js index 1cb5c9c..eb5e84d 100755 --- a/client/src/Table.js +++ b/client/src/Table.js @@ -392,8 +392,7 @@ const Action = ({ table }) => { player = game ? game.player : undefined, hasRolled = (game && game.turn && game.turn.roll) ? true : false, isTurn = (game && game.turn && game.turn.color === game.color) ? true : false, - robberActions = (game && game.turn && game.turn.roll === 7 && - !game.turn.robberDone), + robberActions = (game && game.turn && game.turn.robberInAction), haveResources = player ? player.haveResources : false; return ( @@ -1057,6 +1056,13 @@ class Table extends React.Component { table={this} /> } + { game.largestArmy && game.largestArmy === game.color && + + } assetData.developmentCards.push({ +[ 'monopoly', 'road-1', 'road-2', 'year-of-plenty'].forEach(card => assetData.developmentCards.push({ type: 'progress', card: card })); @@ -367,7 +367,7 @@ const processRoll = (game, dice) => { game.turn.roll = game.dice[0] + game.dice[1]; if (game.turn.roll === 7) { addChatMessage(game, null, `ROBBER! ${game.gender === 'female' ? 'Roberta' : 'Robert'} Robber Roberson!`); - game.turn.robberDone = false; + game.turn.robberInAction = true; delete game.turn.placedRobber; for (let id in game.sessions) { const player = game.sessions[id].player; @@ -1459,7 +1459,7 @@ router.put("/:id/:action/:value?", async (req, res) => { /* If the current turn is a robber placement, and everyone has * discarded, set the limits for where the robber can be placed */ - if (game.turn && game.turn.roll === 7 && !game.turn.robberDone) { + if (game.turn && game.turn.robberInAction) { error = `Robber is in action. Turn can not stop until all Robber tasks are resolved.`; break; } @@ -1515,7 +1515,7 @@ router.put("/:id/:action/:value?", async (req, res) => { addChatMessage(game, session, `${session.name} must select player to steal resource from.`); } else { game.turn.actions = []; - game.turn.robberDone = true; + game.turn.robberInAction = false; delete game.turn.limits; addChatMessage(game, session, `The Robber was moved to a terrain with no other players.`); } @@ -1552,7 +1552,7 @@ router.put("/:id/:action/:value?", async (req, res) => { addChatMessage(game, session, `${session.name} randomly stole ${type} from ${playerNameFromColor(game, value)}.`); } - game.turn.robberDone = true; + game.turn.robberInAction = false; break; case 'buy-development': @@ -1569,7 +1569,7 @@ router.put("/:id/:action/:value?", async (req, res) => { break; } - if (game.turn && game.turn.roll === 7 && !game.turn.robberDone) { + if (game.turn && game.turn.robberInAction) { error = `Robber is in action. You can not purchase until all Robber tasks are resolved.`; break; } @@ -1596,7 +1596,7 @@ router.put("/:id/:action/:value?", async (req, res) => { case 'play-card': if (game.state !== 'normal') { - error = `You cannot purchase a settlement unless the game is active.`; + error = `You cannot play a development card unless the game is active.`; break; } if (session.color !== game.turn.color) { @@ -1608,7 +1608,7 @@ router.put("/:id/:action/:value?", async (req, res) => { break; } - if (game.turn && game.turn.roll === 7 && !game.turn.robberDone) { + if (game.turn && game.turn.robberInAction) { error = `Robber is in action. You can not play a card until all Robber tasks are resolved.`; break; } @@ -1650,15 +1650,20 @@ router.put("/:id/:action/:value?", async (req, res) => { if (card.type === 'army') { player.army++; + + if (player.army > 2 && + (!game.largestArmy || game.players[game.largestArmy].army < player.army)) { + if (game.largestArmy !== session.color) { + game.largestArmy = session.color; + addChatMessage(game, session, `${session.name} now has the largest army (${player.army})!`) + } + } + + game.turn.robberInAction = true; + delete game.turn.placedRobber; + addChatMessage(game, session, `${session.name} must now move the robber.`); } - if (player.army > 2 && - (!game.largestArmy || game.players[game.largestArmy].army < player.army)) { - if (game.largestArmy !== session.color) { - game.largestArmy = session.color; - addChatMessage(game, session, `${session.name} now has the largest army (${player.army})!`) - } - } break; case 'buy-settlement': @@ -1675,7 +1680,7 @@ router.put("/:id/:action/:value?", async (req, res) => { break; } - if (game.turn && game.turn.roll === 7 && !game.turn.robberDone) { + if (game.turn && game.turn.robberInAction) { error = `Robber is in action. You can not purchase until all Robber tasks are resolved.`; break; } @@ -1808,7 +1813,7 @@ router.put("/:id/:action/:value?", async (req, res) => { break; } - if (game.turn && game.turn.roll === 7 && !game.turn.robberDone) { + if (game.turn && game.turn.robberInAction) { error = `Robber is in action. You can not purchase until all Robber tasks are resolved.`; break; } @@ -1888,7 +1893,7 @@ router.put("/:id/:action/:value?", async (req, res) => { break; } - if (game.turn && game.turn.roll === 7 && !game.turn.robberDone) { + if (game.turn && game.turn.robberInAction) { error = `Robber is in action. You can not purchase until all Robber tasks are resolved.`; break; } @@ -2118,7 +2123,7 @@ const sendGame = async (req, res, game, error) => { /* If the current turn is a robber placement, and everyone has * discarded, set the limits for where the robber can be placed */ - if (game.turn && game.turn.roll === 7) { + if (game.turn && game.turn.robberInAction) { let move = true; for (let color in game.players) { const discard = game.players[color].mustDiscard;