1
0

Track player vs robber steals and display in Winner

Signed-off-by: James Ketrenos <james_eikona@ketrenos.com>
This commit is contained in:
James Ketrenos 2022-06-05 10:05:33 -07:00
parent 8c8455263c
commit 7bf5927d99
2 changed files with 23 additions and 12 deletions

View File

@ -91,10 +91,10 @@ const Winner = ({ winnerDismissed, setWinnerDismissed }) => {
let robber; let robber;
let max = 0; let max = 0;
let playerStolen = []; let playerStolen = {};
const stats = winner.stolen; const stats = winner.stolen;
for (let player in stats) { for (let player in stats) {
if (player === 'total') { if (player === 'total' || player === 'player') {
continue; continue;
} }
if (player === 'robber') { if (player === 'robber') {
@ -109,7 +109,7 @@ const Winner = ({ winnerDismissed, setWinnerDismissed }) => {
</>; </>;
} }
robber = <div> robber = <div>
Throughout the game, the robber stole <b>{stats.robber.stole.total} Throughout the game, the robber blocked <b>{stats.robber.stole.total}
</b> resources: </b> resources:
<div className="ThiefStole">{robber}</div></div>; <div className="ThiefStole">{robber}</div></div>;
continue; continue;
@ -120,12 +120,16 @@ const Winner = ({ winnerDismissed, setWinnerDismissed }) => {
} }
if (stats[player].stolen.total > max) { if (stats[player].stolen.total > max) {
max = stats[player].stolen.total; max = stats[player].stolen.total;
playerStolen = []; playerStolen = {
robber: stats[player].stolen.robber,
player: stats[player].stolen.player,
element: <></>
};
} }
let stolen; let stolen;
for (let type in stats[player].stolen) { for (let type in stats[player].stolen) {
if (type === 'total') { if ([ 'total', 'robber', 'player' ].indexOf(type) !== -1) {
continue; continue;
} }
if (!stolen) { if (!stolen) {
@ -137,15 +141,15 @@ const Winner = ({ winnerDismissed, setWinnerDismissed }) => {
</>; </>;
} }
if (stolen) { if (stolen) {
playerStolen.push(<div key={player}> playerStolen.element = <div key={player}>
<PlayerColor color={player}/> {winner.players[player].name} <PlayerColor color={player}/> {winner.players[player].name}
<div className="PlayerStolen">{stolen}</div> <div className="PlayerStolen">{stolen}</div>
</div>); </div>;
} }
} }
if (!robber) { if (!robber) {
robber = <div>The robber never stole any resources from anyone!</div>; robber = <div>The robber never blocked any resources from anyone!</div>;
} }
const averageSeconds = Math.floor(winner.totalTime / turnCount / 1000), const averageSeconds = Math.floor(winner.totalTime / turnCount / 1000),
@ -178,10 +182,10 @@ const Winner = ({ winnerDismissed, setWinnerDismissed }) => {
<div>The game took {totalTime}.</div> <div>The game took {totalTime}.</div>
{ robber } { robber }
{ max !== 0 && <> { max !== 0 && <>
<div>The thief (and other players) stole the most resources <div>The robber stole {playerStolen.robber} and other players
from:</div> stole {playerStolen.player} resources from:</div>
<div className="PlayerStolenList"> <div className="PlayerStolenList">
{ playerStolen } { playerStolen.element }
</div> </div>
</> } </> }
</div> </div>

View File

@ -4396,7 +4396,9 @@ const trackTheft = (game, from, to, type, count) => {
total: 0 total: 0
}, },
stolen: { /* the resources stolen from this player */ stolen: { /* the resources stolen from this player */
total: 0 total: 0,
player: 0, /* by players */
robber: 0 /* by robber */
} }
}; };
} }
@ -4412,6 +4414,11 @@ const trackTheft = (game, from, to, type, count) => {
/* Update counts */ /* Update counts */
stats[from].stolen.total += count; stats[from].stolen.total += count;
if (to === 'robber') {
stats[from].stolen.robber += count;
} else {
stats[from].stolen.player += count;
}
stats[from].stolen[type] += count; stats[from].stolen[type] += count;
stats[to].stole.total += count; stats[to].stole.total += count;
stats[to].stole[type] += count; stats[to].stole[type] += count;