diff --git a/client/src/Winner.css b/client/src/Winner.css index c4463ba..605fa35 100644 --- a/client/src/Winner.css +++ b/client/src/Winner.css @@ -59,3 +59,24 @@ padding: 0; margin: 0; } + +.Winner .Description .Resource { + height: 3.5em; + width: 2.5em; + margin: 1rem 0.5rem 0 0.5rem; +} + +.Winner .Description .Resource > div.Right { + user-select: none; + position: absolute; + top: -0.75rem; + right: -0.75rem; + border-radius: 50%; + border: 1px solid white; + background-color: rgb(36, 148, 46); + font-size: 1rem; + width: 1.5rem; + height: 1.5rem; + text-align: center; + line-height: 1.5rem; +} diff --git a/client/src/Winner.js b/client/src/Winner.js index d682cfe..dbbe44d 100644 --- a/client/src/Winner.js +++ b/client/src/Winner.js @@ -15,34 +15,53 @@ const Winner = ({table, color}) => { return <>; } - const name = getPlayerName(table.game.sessions, color), - player = table.game.players[color]; + const game = table.game; + + const name = getPlayerName(game.sessions, color), + player = game.players[color]; let playerCount = 0; - for (let key in table.game.players) { - if (table.game.players[key].status !== 'Not active') { + for (let key in game.players) { + if (game.players[key].status !== 'Not active') { playerCount++; } } let description = <>
Congratulations, {name}!
-
{name} won the game after {Math.floor(table.game.turns / playerCount)} turns. They - had {player.potential} unplayed Victory Point card(s).
+
{name} won the game with {player.points} after {Math.floor(game.turns / playerCount)} turns. + { Number(player.potential) !== 0 && <>They had {player.potential} unplayed Victory Point card(s).}
; - for (let key in table.game.players) { + for (let key in game.players) { if (key === color) { continue; } - let tmp = table.game.players[key]; + let tmp = game.players[key]; if (tmp.status === 'Not active') { continue; } - let line = <> {getPlayerName(table.game.sessions, key)} finished with {tmp.points} victory points. - { tmp.potential && <>They had {tmp.potential} unplayed Victory Point card(s). }; + let line = <> {getPlayerName(game.sessions, key)} finished with {tmp.points} victory points. + { Number(tmp.potential) !== 0 && <>They had {tmp.potential} unplayed Victory Point card(s). }; description = <>{description}
{line}
; } + if (game.robberStole) { + let stolen = <>; + for (let type in game.stolen) { + const resource = game.stolen[type]; + if (typeof resource === 'object') { /* player colors are also in 'game.stolen' */ + continue; + } + stolen = <>{stolen} + + ; + } + description = <>{description}
+ Throughout the game, the robber stole {game.robberStole} resources: +
{stolen}
+
; + } + description = <>{description}
If everyone goes back to the Lobby, you can play again.
; return ( diff --git a/server/routes/games.js b/server/routes/games.js index 6c9b30f..0a73f2d 100755 --- a/server/routes/games.js +++ b/server/routes/games.js @@ -353,6 +353,7 @@ const distributeResources = (session, game, roll) => { player[type] += entry[type]; message.push(`${entry[type]} ${type}`); } else { + robberSteal(game, color, type); robber.push(`${entry[type]} ${type}`); } } @@ -1866,7 +1867,9 @@ router.put("/:id/:action/:value?", async (req, res) => { game.turn.actions = []; game.turn.robberInAction = false; delete game.turn.limits; - addChatMessage(game, null, `The dread robber ${game.robberName} was placed on a terrain with no other players, ` + + addChatMessage(game, null, + `The dread robber ${game.robberName} was placed on a terrain ` + + `with no other players, ` + `so ${game.turn.name} does not steal resources from anyone.`); } @@ -1892,7 +1895,9 @@ router.put("/:id/:action/:value?", async (req, res) => { debugChat(game, 'Before steal'); if (cards.length === 0) { - addActivity(game, session, `${playerNameFromColor(game, value)} did not have any cards to steal.`); + addChatMessage(game, session, + `${playerNameFromColor(game, value)} ` + + `did not have any cards for ${session.name} to steal.`); game.turn.actions = []; game.turn.limits = {}; } else { @@ -1903,7 +1908,8 @@ router.put("/:id/:action/:value?", async (req, res) => { game.turn.actions = []; game.turn.limits = {}; addChatMessage(game, session, - `${session.name} randomly stole 1 ${type} from ${playerNameFromColor(game, value)}.`); + `${session.name} randomly stole 1 ${type} from ` + + `${playerNameFromColor(game, value)}.`); } debugChat(game, 'After steal'); @@ -3040,6 +3046,24 @@ const sendGame = async (req, res, game, error, wsUpdate) => { } } +const robberSteal = (game, color, type) => { + if (!game.stolen) { + game.stolen = {}; + } + if (!(color in game.stolen)) { + game.stolen[color] = {}; + } + if (!(type in game.stolen)) { + game.stolen[type] = 0; + } + if (!(type in game.stolen[color])) { + game.stolen[color][type] = 0; + } + game.robberStole = game.robberStole ? game.robberStole++ : 1; + game.stolen[type]++; + game.stolen[color][type]++; +} + const resetGame = (game) => { console.log(`Reseting ${game.id}`); @@ -3064,7 +3088,8 @@ const resetGame = (game) => { borderOrder: game.borderOrder, tileOrder: game.tileOrder, signature: game.signature, - players: game.players + players: game.players, + stolen: {} }); delete game.longestRoad;