Fixing start game logic
This commit is contained in:
parent
1e5e2c682c
commit
f1a5946045
@ -2871,7 +2871,67 @@ const placeRoad = (game: Game, session: Session, index: number): string | undefi
|
|||||||
color: firstColor,
|
color: firstColor,
|
||||||
} as unknown as Turn;
|
} as unknown as Turn;
|
||||||
}
|
}
|
||||||
addChatMessage(game, null, `Initial placement complete. It is ${game.turn.name}'s turn.`);
|
|
||||||
|
addChatMessage(game, null, `Everyone has placed their two settlements!`);
|
||||||
|
|
||||||
|
/* Figure out which players received which resources for their
|
||||||
|
* initial (second) settlement placement. This mirrors the original
|
||||||
|
* behaviour where the player receives resources adjacent to their
|
||||||
|
* final initial settlement. */
|
||||||
|
for (const sid in game.sessions) {
|
||||||
|
const s = game.sessions[sid];
|
||||||
|
const p = s && s.player;
|
||||||
|
const receives: Record<string, number> = {} as Record<string, number>;
|
||||||
|
if (!p) continue;
|
||||||
|
if ((s as any).initialSettlement !== undefined && (s as any).initialSettlement !== null) {
|
||||||
|
layout.tiles.forEach((tile, tindex) => {
|
||||||
|
if (tile.corners.indexOf((s as any).initialSettlement) !== -1) {
|
||||||
|
const tileIdx = game.tileOrder ? game.tileOrder[tindex] : undefined;
|
||||||
|
if (tileIdx === undefined || !staticData.tiles) return;
|
||||||
|
const tileDef = staticData.tiles[tileIdx];
|
||||||
|
if (!tileDef || !tileDef.type) return;
|
||||||
|
const resource = tileDef.type as ResourceType | undefined;
|
||||||
|
if (!resource) return;
|
||||||
|
// only count known resource types
|
||||||
|
if (RESOURCE_TYPES.indexOf(resource as ResourceType) === -1) return;
|
||||||
|
if (!(resource in receives)) receives[resource] = 0;
|
||||||
|
receives[resource] = (receives[resource] || 0) + 1;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const messageParts: string[] = [];
|
||||||
|
for (const type in receives) {
|
||||||
|
const cnt = receives[type] || 0;
|
||||||
|
// update player resources
|
||||||
|
// guard against unknown resource keys
|
||||||
|
switch (type) {
|
||||||
|
case "wood":
|
||||||
|
case "brick":
|
||||||
|
case "sheep":
|
||||||
|
case "wheat":
|
||||||
|
case "stone":
|
||||||
|
(p as any)[type] = ((p as any)[type] || 0) + cnt;
|
||||||
|
p.resources = (p.resources || 0) + cnt;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// ignore unknown resource types
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
sendUpdateToPlayer(game, s, {
|
||||||
|
private: p,
|
||||||
|
});
|
||||||
|
messageParts.push(`${cnt} ${type}`);
|
||||||
|
}
|
||||||
|
if (messageParts.length) {
|
||||||
|
addChatMessage(
|
||||||
|
game,
|
||||||
|
s,
|
||||||
|
`${s.name} receives ${messageParts.join(", ")} for initial settlement placement.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
addChatMessage(game, null, `It is ${game.turn.name}'s turn.`);
|
||||||
} else {
|
} else {
|
||||||
const nextColor = order[idx - 1];
|
const nextColor = order[idx - 1];
|
||||||
if (nextColor && game.players && game.players[nextColor]) {
|
if (nextColor && game.players && game.players[nextColor]) {
|
||||||
@ -4567,6 +4627,7 @@ const getFilteredGameForPlayer = (game: any, session: any) => {
|
|||||||
order: session.color in game.players ? game.players[session.color].order : 0,
|
order: session.color in game.players ? game.players[session.color].order : 0,
|
||||||
private: player,
|
private: player,
|
||||||
sessions: reducedSessions,
|
sessions: reducedSessions,
|
||||||
|
participants: getParticipants(game),
|
||||||
layout: layout,
|
layout: layout,
|
||||||
players: getFilteredPlayers(game),
|
players: getFilteredPlayers(game),
|
||||||
// Include static asset metadata so clients can render the board immediately
|
// Include static asset metadata so clients can render the board immediately
|
||||||
|
Loading…
x
Reference in New Issue
Block a user