Display more player stats in Winner dialog
Signed-off-by: James Ketrenos <james_eikona@ketrenos.com>
This commit is contained in:
parent
946118b036
commit
89327f0c65
@ -80,3 +80,19 @@
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
line-height: 1.5rem;
|
line-height: 1.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.Winner .ThiefStole {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.Winner .PlayerStolen {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.Winner .PlayerStolenList {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
flex-direction: row;
|
||||||
|
}
|
@ -88,24 +88,60 @@ const Winner = ({ winnerDismissed, setWinnerDismissed }) => {
|
|||||||
</div>;
|
</div>;
|
||||||
});
|
});
|
||||||
|
|
||||||
let robber = <></>;
|
let robber;
|
||||||
|
let max = 0;
|
||||||
|
|
||||||
if (winner.robberStole) {
|
let playerStolen = [];
|
||||||
let stolen = <></>;
|
const stats = winner.stolen;
|
||||||
for (let type in winner.stolen) {
|
for (let player in stats) {
|
||||||
const resource = winner.stolen[type];
|
if (player === 'robber') {
|
||||||
if (typeof resource === 'object') { /* player colors are also in 'game.stolen' */
|
robber = <></>;
|
||||||
|
for (let type in stats.robber.stole) {
|
||||||
|
if (type === 'total') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const count = stats.robber.stole[type];
|
||||||
|
robber = <>{robber}
|
||||||
|
<Resource label={true} type={type} count={count} />
|
||||||
|
</>;
|
||||||
|
}
|
||||||
|
robber = <div>
|
||||||
|
Throughout the game, the robber stole <b>{stats.robber.stole.total}
|
||||||
|
</b> resources:
|
||||||
|
<div className="ThiefStole">{robber}</div></div>;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stats[player].stolen.total < max) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (stats[player].stolen.total > max) {
|
||||||
|
max = stats[player].stolen.total;
|
||||||
|
playerStolen = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
let stolen;
|
||||||
|
for (let type in stats[player].stolen) {
|
||||||
|
if (type === 'total') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (!stolen) {
|
||||||
|
stolen = <></>;
|
||||||
|
}
|
||||||
|
const count = stats[player].stolen[type];
|
||||||
stolen = <>{stolen}
|
stolen = <>{stolen}
|
||||||
<Resource label={true} type={type} count={resource}/>
|
<Resource label={true} type={type} count={count}/>
|
||||||
</>;
|
</>;
|
||||||
}
|
}
|
||||||
robber = <div>
|
if (stolen) {
|
||||||
Throughout the game, the robber stole <b>{winner.robberStole}</b> resources:
|
playerStolen.push(<div key={player}>
|
||||||
<div>{stolen}</div>
|
<PlayerColor color={player}/> {winner.players[player].name}
|
||||||
</div>;
|
<div className="PlayerStolen">{stolen}</div>
|
||||||
} else {
|
</div>);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!robber) {
|
||||||
robber = <div>The robber never stole any resources from anyone!</div>;
|
robber = <div>The robber never stole any resources from anyone!</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,6 +174,12 @@ const Winner = ({ winnerDismissed, setWinnerDismissed }) => {
|
|||||||
{ losers }
|
{ losers }
|
||||||
<div>The game took {totalTime}.</div>
|
<div>The game took {totalTime}.</div>
|
||||||
{ robber }
|
{ robber }
|
||||||
|
{ max !== 0 && <>
|
||||||
|
<div>Player{ playerStolen.length === 1 ? '' : 's'} that had the most (<b>{max}</b>) resources stolen by the thief or other players:</div>
|
||||||
|
<div className="PlayerStolenList">
|
||||||
|
{ playerStolen }
|
||||||
|
</div>
|
||||||
|
</> }
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Button onClick={quitClicked}>Go back to Lobby</Button>
|
<Button onClick={quitClicked}>Go back to Lobby</Button>
|
||||||
|
@ -285,14 +285,15 @@ const distributeResources = (game, roll) => {
|
|||||||
tiles.forEach(tile => {
|
tiles.forEach(tile => {
|
||||||
let shuffle = game.tileOrder[tile.index];
|
let shuffle = game.tileOrder[tile.index];
|
||||||
const resource = game.tiles[shuffle];
|
const resource = game.tiles[shuffle];
|
||||||
console.log(tile.index, resource);
|
|
||||||
layout.tiles[tile.index].corners.forEach(cornerIndex => {
|
layout.tiles[tile.index].corners.forEach(cornerIndex => {
|
||||||
const active = game.placements.corners[cornerIndex];
|
const active = game.placements.corners[cornerIndex];
|
||||||
if (active && active.color) {
|
if (active && active.color) {
|
||||||
|
const count = active.type === 'settlement' ? 1 : 2;
|
||||||
if (!tile.robber) {
|
if (!tile.robber) {
|
||||||
receives[active.color][resource.type] += active.type === 'settlement' ? 1 : 2;
|
receives[active.color][resource.type] += count;
|
||||||
} else {
|
} else {
|
||||||
receives.robber[resource.type] += active.type === 'settlement' ? 1 : 2;
|
trackTheft(game, active.color, robber, resource.type, count);
|
||||||
|
receives.robber[resource.type] += count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -316,7 +317,7 @@ const distributeResources = (game, roll) => {
|
|||||||
session.player.resources += entry[type];
|
session.player.resources += entry[type];
|
||||||
message.push(`${entry[type]} ${type}`);
|
message.push(`${entry[type]} ${type}`);
|
||||||
} else {
|
} else {
|
||||||
robberSteal(game, color, type, entry[type]);
|
|
||||||
robber.push(`${entry[type]} ${type}`);
|
robber.push(`${entry[type]} ${type}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -510,6 +511,7 @@ const loadGame = async (id) => {
|
|||||||
console.log(`${info}: Creating backup of games/${id}`);
|
console.log(`${info}: Creating backup of games/${id}`);
|
||||||
await writeFile(`games/${id}.bk`, JSON.stringify(game));
|
await writeFile(`games/${id}.bk`, JSON.stringify(game));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.log(`Load or parse error from games/${id}:`, error);
|
||||||
console.log(`Attempting to load backup from games/${id}.bk`);
|
console.log(`Attempting to load backup from games/${id}.bk`);
|
||||||
game = await readFile(`games/${id}.bk`)
|
game = await readFile(`games/${id}.bk`)
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
@ -518,7 +520,7 @@ const loadGame = async (id) => {
|
|||||||
if (game) {
|
if (game) {
|
||||||
try {
|
try {
|
||||||
game = JSON.parse(game);
|
game = JSON.parse(game);
|
||||||
console.log(`Restoring backup to games/${id}`);
|
console.log(`Saving backup to games/${id}`);
|
||||||
await writeFile(`games/${id}`, JSON.stringify(game, null, 2));
|
await writeFile(`games/${id}`, JSON.stringify(game, null, 2));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
@ -2055,6 +2057,8 @@ const stealResource = (game, session, color) => {
|
|||||||
session.player.resources++;
|
session.player.resources++;
|
||||||
game.turn.actions = [];
|
game.turn.actions = [];
|
||||||
game.turn.limits = {};
|
game.turn.limits = {};
|
||||||
|
trackTheft(game, victim.color, session.color, type, 1);
|
||||||
|
|
||||||
addChatMessage(game, session,
|
addChatMessage(game, session,
|
||||||
`${session.name} randomly stole 1 ${type} from ` +
|
`${session.name} randomly stole 1 ${type} from ` +
|
||||||
`${victim.name}.`);
|
`${victim.name}.`);
|
||||||
@ -3320,7 +3324,6 @@ const calculatePoints = (game, update) => {
|
|||||||
console.log(`${info}: ${message}`);
|
console.log(`${info}: ${message}`);
|
||||||
update.winner = Object.assign({}, player, {
|
update.winner = Object.assign({}, player, {
|
||||||
state: 'winner',
|
state: 'winner',
|
||||||
robberStole: game.robberStole,
|
|
||||||
stolen: game.stolen,
|
stolen: game.stolen,
|
||||||
chat: game.chat,
|
chat: game.chat,
|
||||||
turns: game.turns,
|
turns: game.turns,
|
||||||
@ -3944,22 +3947,71 @@ const getFilteredGameForPlayer = (game, session) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const robberSteal = (game, color, type, count) => {
|
/* Example:
|
||||||
if (!game.stolen) {
|
"stolen": {
|
||||||
game.stolen = {};
|
"robber": {
|
||||||
|
"stole": {
|
||||||
|
"total": 5,
|
||||||
|
"wheat": 2,
|
||||||
|
"wood": 1,
|
||||||
|
"sheep": 2
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"O": {
|
||||||
|
"stolen": {
|
||||||
|
"total": 2,
|
||||||
|
"wheat": 2
|
||||||
|
},
|
||||||
|
"stole": {
|
||||||
|
"total": 2,
|
||||||
|
"brick": 2
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"W": {
|
||||||
|
"stolen": {
|
||||||
|
"total": 4,
|
||||||
|
"brick": 2,
|
||||||
|
"wood": 1,
|
||||||
|
"sheep": 2
|
||||||
|
},
|
||||||
|
"stole": {
|
||||||
|
"total": 3,
|
||||||
|
"brick": 2,
|
||||||
|
"wheat": 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!(color in game.stolen)) {
|
}
|
||||||
game.stolen[color] = {};
|
*/
|
||||||
|
const trackTheft = (game, from, to, type, count) => {
|
||||||
|
const stats = game.stolen;
|
||||||
|
|
||||||
|
/* Initialize the stole / stolen structures */
|
||||||
|
[ to, from ].forEach(player => {
|
||||||
|
if (!(player in stats)) {
|
||||||
|
stats[player] = {
|
||||||
|
stole: { /* the resources this player stole */
|
||||||
|
total: 0
|
||||||
|
},
|
||||||
|
stolen: { /* the resources stolen from this player */
|
||||||
|
total: 0
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/* Initialize 'type' field in structures */
|
||||||
|
if (!(type in stats[from].stole)) {
|
||||||
|
games.stolen[from].stole[type] = 0;
|
||||||
}
|
}
|
||||||
if (!(type in game.stolen)) {
|
if (!(type in stats[to].stole)) {
|
||||||
game.stolen[type] = 0;
|
games.stole[to].stolen[type] = 0;
|
||||||
}
|
}
|
||||||
if (!(type in game.stolen[color])) {
|
|
||||||
game.stolen[color][type] = 0;
|
/* Update counts */
|
||||||
}
|
stats[from].stolen.total += count;
|
||||||
game.robberStole = game.robberStole += count;
|
stats[from].stolen[type] += count;
|
||||||
game.stolen[type] += count;
|
stats[to].stole.total += count;
|
||||||
game.stolen[color][type] += count;
|
stats[to].stole[type] += count;
|
||||||
}
|
}
|
||||||
|
|
||||||
const resetGame = (game) => {
|
const resetGame = (game) => {
|
||||||
@ -3986,8 +4038,12 @@ const resetGame = (game) => {
|
|||||||
tileOrder: game.tileOrder,
|
tileOrder: game.tileOrder,
|
||||||
signature: game.signature,
|
signature: game.signature,
|
||||||
players: game.players,
|
players: game.players,
|
||||||
stolen: {},
|
stolen: {
|
||||||
robberStole: 0,
|
robber: {
|
||||||
|
stole: 0
|
||||||
|
},
|
||||||
|
total: 0
|
||||||
|
},
|
||||||
longestRoad: '',
|
longestRoad: '',
|
||||||
longestRoadLength: 0,
|
longestRoadLength: 0,
|
||||||
largestArmy: '',
|
largestArmy: '',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user