From f9b4c3699a657870014ab68d711ea6597fdf30cc Mon Sep 17 00:00:00 2001 From: James Ketrenos Date: Thu, 17 Feb 2022 14:35:32 -0800 Subject: [PATCH] Trading now lists bank offers Signed-off-by: James Ketrenos --- client/src/Table.js | 12 ++++++------ client/src/Trade.css | 12 ++++++++++-- client/src/Trade.js | 22 +++++++++++++++++----- server/routes/games.js | 40 ++++++++++++++++++++++++++++------------ 4 files changed, 61 insertions(+), 25 deletions(-) diff --git a/client/src/Table.js b/client/src/Table.js index 53b55cf..ed52df8 100755 --- a/client/src/Table.js +++ b/client/src/Table.js @@ -408,7 +408,8 @@ const Action = ({ table }) => { const inLobby = table.game.state === 'lobby', player = table.game ? table.game.player : undefined, hasRolled = (table.game && table.game.turn && table.game.turn.roll) ? true : false, - isTurn = (table.game && table.game.turn && table.game.turn.color === table.game.color) ? true : false; + isTurn = (table.game && table.game.turn && table.game.turn.color === table.game.color) ? true : false, + robberActions = (table.game && table.game.turn && table.game.turn.roll === 7 && !table.game.turn.robberDone); return ( @@ -417,13 +418,13 @@ const Action = ({ table }) => { } { table.game.state === 'normal' && <> - - - + + + { table.game.turn.roll === 7 && player && player.mustDiscard > 0 && } - + } { !inLobby && @@ -613,7 +614,6 @@ class Table extends React.Component { return this.sendAction('chat', undefined, {message: message}); } - setPlayerName(name) { return this.sendAction('player-name', name) .then(() => { diff --git a/client/src/Trade.css b/client/src/Trade.css index 624e7f3..efbb0ab 100644 --- a/client/src/Trade.css +++ b/client/src/Trade.css @@ -23,7 +23,7 @@ margin: 0.5em 0; } .Trade > * { - width: 20em; + min-width: 40em; display: inline-flex; padding: 0.5em; flex-direction: column; @@ -52,7 +52,15 @@ flex-direction: row; align-items: center; flex: 1; - justify-content: space-between; +} + +.TradeLine > div { + display: flex; + flex-grow: 1; +} + +.TradeLine > div > div { + margin-left: 0.25em; } .TradeLine *:last-child { diff --git a/client/src/Trade.js b/client/src/Trade.js index a6b087b..6efeb19 100644 --- a/client/src/Trade.js +++ b/client/src/Trade.js @@ -31,17 +31,29 @@ const Trade = ({table}) => { if (isTurn && table.game.player && table.game.player.banks) { table.game.player.banks.forEach(bank => { - players.push({ name: `Bank ${bank}`, color: undefined, gives: '1 *', gets: '2 wheat'}); + const type = (bank === 'bank') ? 'of a kind' : bank, + count = (bank === 'bank') ? 3 : 2; + players.push({ name: `Bank`, color: undefined, gives: `1 of anything`, gets: `${count} ${type}`}); }) - players.push({ name: `Bank`, color: undefined, gives: '1 *', gets: '3 *'}) + players.push({ name: `Bank`, color: undefined, gives: '1 of anything', gets: '4 of a kind'}) } - players = players.map(item => -
+ players = players.map((item, index) => +
{item.name}
-
will take
{item.gets}
for
{item.gives}
.
+
+ { item.gets && item.gives && +
will take {item.gets} for {item.gives}. +
+ } + { (!item.gets || !item.gives) && +
has not submitted a trade offer. +
+ } + +
); diff --git a/server/routes/games.js b/server/routes/games.js index abbc74d..19e8c20 100755 --- a/server/routes/games.js +++ b/server/routes/games.js @@ -81,12 +81,12 @@ const assetData = { { roll: 7, pips: 0 }, /* Robber is at the end or indexing gets off */ ], borders: [ - { left: "sheep", right: "bank" }, - { center: "sheep" }, - { left: "wheat", right: "bank" }, - { center: "wood" }, - { left: "sheep", right: "bank" }, - { center: "bank" } + [ "bank", undefined, "sheep" ], + [ undefined, "bank", undefined ], + [ "bank", undefined, "brick" ], + [ undefined, "wood", undefined ], + [ "bank", undefined, "wheat" ], + [ undefined, "stone", undefined ] ], developmentCards: [ ] @@ -362,7 +362,7 @@ const processRoll = (game, dice) => { addChatMessage(game, session, `${session.name} rolled ${game.dice[0]}, ${game.dice[1]}.`); game.turn.roll = game.dice[0] + game.dice[1]; if (game.turn.roll === 7) { - addChatMessage(game, null, `ROBBER! ROBBER! ROBBER!`); + addChatMessage(game, null, `ROBBER! Robber Roberson!`); game.turn.robberDone = false; delete game.turn.placedRobber; for (let id in game.sessions) { @@ -1217,8 +1217,15 @@ router.put("/:id/:action/:value?", async (req, res) => { corner.type = 'settlement'; if (layout.corners[index].banks.length) { layout.corners[index].banks.forEach(bank => { - if (player.banks.indexOf(bank) === -1) { - player.banks.push(bank); + const border = game.borderOrder[Math.floor(bank / 3)], + type = game.borders[border][bank % 3]; + console.log(`Bank ${bank} = ${type}`); + if (!type) { + console.log(`Bank ${bank}`) + return; + } + if (player.banks.indexOf(type) === -1) { + player.banks.push(type); } }); } @@ -1233,11 +1240,20 @@ router.put("/:id/:action/:value?", async (req, res) => { corner.type = 'settlement'; if (layout.corners[index].banks.length) { layout.corners[index].banks.forEach(bank => { - if (player.banks.indexOf(bank) === -1) { - player.banks.push(bank); + console.log(game.borderOrder); + console.log(game.borders); + const border = game.borderOrder[Math.floor(bank / 3)], + type = game.borders[border][bank % 3]; + console.log(`Bank ${bank} = ${type}`); + if (!type) { + return; + } + if (player.banks.indexOf(type) === -1) { + player.banks.push(type); } }); } + player.maritime = player.banks.map(bank => game.borders[Math.floor(bank / 3) + bank % 3]); game.turn.actions = ['place-road']; game.turn.limits = { roads: layout.corners[index].roads }; /* road placement is limited to be near this corner */ addChatMessage(game, session, `Placed a settlement. Next, they need to place a road.`); @@ -1759,7 +1775,7 @@ const shuffleBoard = (game) => { } shuffle(seq); console.log('TODO: Map borderOrder to an array of the border values; each border has 3 slots.'); - consoel.log('This is then used in generating "banks" to determine maritime trading values for each player.'); + console.log('This is then used in generating "banks" to determine maritime trading values for each player.'); game.borderOrder = seq.slice(); for (let i = 6; i < 19; i++) { seq.push(i);