From c093d7141ea5727914be6dfb2878279d5ce308a3 Mon Sep 17 00:00:00 2001 From: James Ketrenos Date: Fri, 17 Jun 2022 17:50:03 -0700 Subject: [PATCH] Working out bugs in Volcano Signed-off-by: James Ketrenos --- client/src/Actions.js | 30 ++++++++++++++++++++-------- client/src/ChooseCard.js | 31 ++++++++++++++++------------- client/src/HouseRules.js | 2 ++ server/routes/games.js | 43 ++++++++++++++++++++++++---------------- 4 files changed, 67 insertions(+), 39 deletions(-) diff --git a/client/src/Actions.js b/client/src/Actions.js index 7c9b45e..5e1510f 100644 --- a/client/src/Actions.js +++ b/client/src/Actions.js @@ -175,6 +175,26 @@ const Actions = ({ setTradeActive(true); } + let disableRoll = false; + if (robberActions) { disableRoll = true; } + if (turn && turn.select) { disableRoll = true; } + if (inGame && !isTurn) { disableRoll = true; } + if (inGame && hasRolled) { disableRoll = true; } + if (volcanoActive && (!isTurn || hasRolled)) { disableRoll = true; } + if (volcanoActive && isTurn ) { disableRoll = false; } + if (inGameOrder && hasGameOrderRolled) { disableRoll = true; } + + console.log(`actions - `, { + disableRoll, robberActions, turn, inGame, isTurn, hasRolled, volcanoActive, inGameOrder, + hasGameOrderRolled}); + + const disableDone = + volcanoActive || + placeRoad || + robberActions || + !isTurn || + !hasRolled; + return ( { edit === "" && } @@ -189,13 +209,7 @@ const Actions = ({ {name && color && inLobby && } { name && !inLobby && <> - + @@ -204,7 +218,7 @@ const Actions = ({ {name && color && } - + } { /* inLobby && diff --git a/client/src/ChooseCard.js b/client/src/ChooseCard.js index 6897933..63d33a6 100644 --- a/client/src/ChooseCard.js +++ b/client/src/ChooseCard.js @@ -61,19 +61,24 @@ const ChooseCard = () => { }, [ws, cards]); let count = 0; - if (turn && turn.color === color) { - count = turn.active === 'monopoly' ? 1 : 2; - } - if (state === 'volcano') { - if (!turn.select) { - count = 0; - } else if (color in turn.select) { - count = turn.select[color]; - } else { - count = 0; + if (turn && turn.actions && turn.actions.indexOf('select-resources') !== -1) { + if (turn.active) { + if (turn.color === color) { + count = turn.active === 'monopoly' ? 1 : 2; + } + } + + if (state === 'volcano') { + if (!turn.select) { + count = 0; + } else if (color in turn.select) { + count = turn.select[color]; + } else { + count = 0; + } } } - + const selectCard = useCallback((event) => { event.target.classList.toggle('Selected'); @@ -93,9 +98,7 @@ const ChooseCard = () => { setCards(tmp); }, [ setCards, count ]); - if (!turn || !turn.active - || (count === 0) - || !turn.actions || turn.actions.indexOf('select-resources') === -1) { + if (count === 0) { return <>; } diff --git a/client/src/HouseRules.js b/client/src/HouseRules.js index 3be9212..27d85d6 100644 --- a/client/src/HouseRules.js +++ b/client/src/HouseRules.js @@ -31,6 +31,7 @@ const Volcano = ({ ws, rules, field, disabled }) => { const toggleGold = () => { rules[field].gold = !gold; + rules[field].number = number; setGold(rules[field].gold); ws.send(JSON.stringify({ @@ -49,6 +50,7 @@ const Volcano = ({ ws, rules, field, disabled }) => { value = delta > 0 ? 8 : 6; } setNumber(value); + rules[field].gold = gold; rules[field].number = value; ws.send(JSON.stringify({ type: 'rules', diff --git a/server/routes/games.js b/server/routes/games.js index 99787ad..95cc776 100755 --- a/server/routes/games.js +++ b/server/routes/games.js @@ -420,13 +420,18 @@ const isRuleEnabled = (game, rule) => { }; const processRoll = (game, session, dice) => { + if (!dice[1]) { + console.error(`Invalid roll sequence!`); + return; + } + addChatMessage(game, session, `${session.name} rolled ` + `${dice[0]}, ${dice[1]}.`); const sum = dice[0] + dice[1]; - game.turn.roll = sum; game.dice = dice; + game.turn.roll = sum; if (game.turn.roll !== 7) { let synonym = isRuleEnabled(game, 'twelve-and-two-are-synonyms') @@ -447,27 +452,33 @@ const processRoll = (game, session, dice) => { } } + if (isRuleEnabled(game, 'roll-double-roll-again')) { + if (dice[0] === dice[1]) { + addChatMessage(game, session, `House rule 'Roll Double, Roll + Again' activated.`); + game.turn.roll = 0; + } + } + if (isRuleEnabled(game, 'volcano')) { if (sum === game.rules['volcano'].number || (synonym && (game.rules['volcano'].number === 2 || game.rules['volcano'].number === 12))) { addChatMessage(game, session, `House rule 'Volcano' activated. The - Volcano is erupting! You must roll the die to determine which - direciton the lava will flow!`); + Volcano is erupting!`); game.state = 'volcano'; let count = 0; - console.log(game.rules['volcano']); + if (game.rules['volcano'].gold) { game.turn.select = {}; const volcano = layout.tiles.find((tile, index) => staticData.tiles[game.tileOrder[index]].type === 'desert'); - console.log(volcano); + console.log({ mode: 'gold', volcano }); volcano.corners.forEach(index => { const corner = game.placements.corners[index]; - console.log({ index, corner }); if (corner.color) { if (!(corner.color in game.turn.select)) { game.turn.select[corner.color] = 0; @@ -480,27 +491,23 @@ const processRoll = (game, session, dice) => { if (count) { game.turn.actions = [ 'select-resources' ]; + /* To gain volcano resources, you need at least 3 settlements, + * so Robin Hood Robber does not apply */ if (volcano === layout.tiles[game.robber]) { - addChatMessage(game, null, `That pesky ${game.robberName} Robber Roberson blocked ${count} resources!`); - delete game.turn.selected; + addChatMessage(game, null, `That pesky ${game.robberName} Robber Roberson blocked ${count} volcanic mineral resources!`); + addChatMessage(game, null, `${game.turn.name} must roll the die to determine which direction the lava will flow!`); + delete game.turn.select; } else { addChatMessage(game, null, `House rule 'Volcanoes have minerals' activated. Players must select which resources to receive from the Volcano!`); game.turn.active = 'volcano'; } } else { + addChatMessage(game, null, `${game.turn.name} must roll the die to determine which direction the lava will flow!`); delete game.turn.select; } } } } - - if (isRuleEnabled(game, 'roll-double-roll-again')) { - if (dice[0] === dice[1]) { - addChatMessage(game, session, `House rule 'Roll Double, Roll - Again' activated.`); - game.turn.roll = 0; - } - } for (let id in game.sessions) { if (game.sessions[id].player) { @@ -863,9 +870,10 @@ const adminActions = (game, action, value, query) => { return results; case "roll": - let dice = (query.dice || '').split(','); + let dice = (query.dice || Math.ceil(Math.random() * 6)).split(','); dice = dice.map(die => parseInt(die)); + console.log({ dice }); if (!value) { return `Unable to parse roll request.`; } @@ -3003,6 +3011,7 @@ const selectResources = (game, session, cards) => { count = game.turn.select[session.color]; delete game.turn.select[session.color]; if (Object.getOwnPropertyNames(game.turn.select).length === 0) { + addChatMessage(game, null, `${game.turn.name} must roll the die to determine which direction the lava will flow!`); delete game.turn.select; } } else {