Add stolen stats to Winner
Signed-off-by: James Ketrenos <james_eikona@ketrenos.com>
This commit is contained in:
parent
6e5e8f2f80
commit
a31741f069
@ -59,3 +59,24 @@
|
|||||||
padding: 0;
|
padding: 0;
|
||||||
margin: 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;
|
||||||
|
}
|
||||||
|
@ -15,34 +15,53 @@ const Winner = ({table, color}) => {
|
|||||||
return <></>;
|
return <></>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const name = getPlayerName(table.game.sessions, color),
|
const game = table.game;
|
||||||
player = table.game.players[color];
|
|
||||||
|
const name = getPlayerName(game.sessions, color),
|
||||||
|
player = game.players[color];
|
||||||
let playerCount = 0;
|
let playerCount = 0;
|
||||||
for (let key in table.game.players) {
|
for (let key in game.players) {
|
||||||
if (table.game.players[key].status !== 'Not active') {
|
if (game.players[key].status !== 'Not active') {
|
||||||
playerCount++;
|
playerCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let description = <>
|
let description = <>
|
||||||
<div>Congratulations, <b>{name}</b>!</div>
|
<div>Congratulations, <b>{name}</b>!</div>
|
||||||
<div><PlayerColor color={color}/> {name} won the game after {Math.floor(table.game.turns / playerCount)} turns. They
|
<div><PlayerColor color={color}/> {name} won the game with <b>{player.points}</b> after {Math.floor(game.turns / playerCount)} turns.
|
||||||
had <b>{player.potential}</b> unplayed Victory Point card(s).</div>
|
{ Number(player.potential) !== 0 && <>They had <b>{player.potential}</b> unplayed Victory Point card(s).</>}</div>
|
||||||
</>;
|
</>;
|
||||||
|
|
||||||
for (let key in table.game.players) {
|
for (let key in game.players) {
|
||||||
if (key === color) {
|
if (key === color) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let tmp = table.game.players[key];
|
let tmp = game.players[key];
|
||||||
if (tmp.status === 'Not active') {
|
if (tmp.status === 'Not active') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let line = <><PlayerColor color={key}/> {getPlayerName(table.game.sessions, key)} finished with {tmp.points} victory points.
|
let line = <><PlayerColor color={key}/> {getPlayerName(game.sessions, key)} finished with {tmp.points} victory points.
|
||||||
{ tmp.potential && <>They had <b>{tmp.potential}</b> unplayed Victory Point card(s).</> }</>;
|
{ Number(tmp.potential) !== 0 && <>They had <b>{tmp.potential}</b> unplayed Victory Point card(s).</> }</>;
|
||||||
description = <>{description}<div>{line}</div></>;
|
description = <>{description}<div>{line}</div></>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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}
|
||||||
|
<Resource label={true} type={type} count={resource}/>
|
||||||
|
</>;
|
||||||
|
}
|
||||||
|
description = <>{description}<div>
|
||||||
|
Throughout the game, the robber stole <b>{game.robberStole}</b> resources:
|
||||||
|
<div>{stolen}</div>
|
||||||
|
</div></>;
|
||||||
|
}
|
||||||
|
|
||||||
description = <>{description}<div>If everyone goes back to the Lobby, you can play again.</div></>;
|
description = <>{description}<div>If everyone goes back to the Lobby, you can play again.</div></>;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -353,6 +353,7 @@ const distributeResources = (session, game, roll) => {
|
|||||||
player[type] += entry[type];
|
player[type] += entry[type];
|
||||||
message.push(`${entry[type]} ${type}`);
|
message.push(`${entry[type]} ${type}`);
|
||||||
} else {
|
} else {
|
||||||
|
robberSteal(game, color, type);
|
||||||
robber.push(`${entry[type]} ${type}`);
|
robber.push(`${entry[type]} ${type}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1866,7 +1867,9 @@ router.put("/:id/:action/:value?", async (req, res) => {
|
|||||||
game.turn.actions = [];
|
game.turn.actions = [];
|
||||||
game.turn.robberInAction = false;
|
game.turn.robberInAction = false;
|
||||||
delete game.turn.limits;
|
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.`);
|
`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');
|
debugChat(game, 'Before steal');
|
||||||
|
|
||||||
if (cards.length === 0) {
|
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.actions = [];
|
||||||
game.turn.limits = {};
|
game.turn.limits = {};
|
||||||
} else {
|
} else {
|
||||||
@ -1903,7 +1908,8 @@ router.put("/:id/:action/:value?", async (req, res) => {
|
|||||||
game.turn.actions = [];
|
game.turn.actions = [];
|
||||||
game.turn.limits = {};
|
game.turn.limits = {};
|
||||||
addChatMessage(game, session,
|
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');
|
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) => {
|
const resetGame = (game) => {
|
||||||
console.log(`Reseting ${game.id}`);
|
console.log(`Reseting ${game.id}`);
|
||||||
|
|
||||||
@ -3064,7 +3088,8 @@ const resetGame = (game) => {
|
|||||||
borderOrder: game.borderOrder,
|
borderOrder: game.borderOrder,
|
||||||
tileOrder: game.tileOrder,
|
tileOrder: game.tileOrder,
|
||||||
signature: game.signature,
|
signature: game.signature,
|
||||||
players: game.players
|
players: game.players,
|
||||||
|
stolen: {}
|
||||||
});
|
});
|
||||||
|
|
||||||
delete game.longestRoad;
|
delete game.longestRoad;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user