From 3d8226a3e88e2289d2b97db8eac7e214e0af9d3d Mon Sep 17 00:00:00 2001 From: James Ketrenos Date: Sun, 1 May 2022 17:31:31 -0700 Subject: [PATCH] Fix House Rules to enable/disable correctly and to only activate in server if "enabled" is set Signed-off-by: James Ketrenos --- client/src/HouseRules.js | 2 +- client/src/MediaControl.js | 2 +- server/routes/games.js | 16 +++++++++------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/client/src/HouseRules.js b/client/src/HouseRules.js index 2ef6e89..ddef926 100644 --- a/client/src/HouseRules.js +++ b/client/src/HouseRules.js @@ -155,7 +155,7 @@ const HouseRules = ({ houseRulesActive, setHouseRulesActive }) => { }, { title: `Everyone gets one re-roll`, key: `everyone-gets-one-reroll`, - description: `Each player gets one chance re - roll at any point.`, + description: `Each player gets one chance re-roll at any point.`, element: { connection.addEventListener('icecandidateerror', (event) => { if (event.errorCode === 701) { - if (connection.icegatheringstate === 'gathering') { + if (connection.iceGatheringState === 'gathering') { console.log(`media-agent - Unable to reach host: ${event.url}`); } else { console.error(`media-agent - icecandidateerror - `, event.errorCode, event.hostcandidate, event.url, event.errorText); diff --git a/server/routes/games.js b/server/routes/games.js index 8686ff1..50a48ce 100755 --- a/server/routes/games.js +++ b/server/routes/games.js @@ -292,8 +292,7 @@ const distributeResources = (game, roll) => { if (!tile.robber) { receives[active.color][resource.type] += count; } else { - if (`robin-hood-robber` in game.rules - && game.rules[`robin-hood-robber`].enabled + if (isRuleEnabled(game, `robin-hood-robber`) && game.players[active.color].points <= 2) { addChatMessage(game, null, `Robber does not steal ${count} ${resource.type} from ${game.players[active.color].name} ` + @@ -358,13 +357,17 @@ const pickRobber = (game) => { } } +const isRuleEnabled = (game, rule) => { + return rule in game.rules && game.rules[rule].enabled; +}; + const processRoll = (game, session, dice) => { addChatMessage(game, session, `${session.name} rolled ${dice[0]}, ${dice[1]}.`); game.turn.roll = dice[0] + dice[1]; if (game.turn.roll !== 7) { distributeResources(game, game.turn.roll); - if ('twelve-and-two-are-synonyms' in game.rules) { + if (isRuleEnabled(game, 'twelve-and-two-are-synonyms')) { if (dice[0] + dice[1] === 12) { addChatMessage(game, session, `House rule 'Twelve and Two are Synonyms' activated. Twelve was rolled, so two is triggered too!`); @@ -377,7 +380,7 @@ const processRoll = (game, session, dice) => { } } - if ('roll-double-roll-again' in game.rules) { + if (isRuleEnabled(game, 'roll-double-roll-again')) { if (dice[0] === dice[1]) { addChatMessage(game, session, `House rule 'Roll Double, Roll Again' activated.`); @@ -2591,9 +2594,8 @@ const placeRoad = (game, session, index) => { const getVictoryPointRule = (game) => { const minVP = 10; - if (!('victory-points' in game.rules) - || (!('points' in game.rules['victory-points'])) - || !game.rules['victory-points'].enabled) { + if (!isRuleEnabled(game, 'victory-points') + || !('points' in game.rules['victory-points'])) { return minVP; } return game.rules['victory-points'].points;