1
0

Fix stone resources not being distributed

Signed-off-by: James Ketrenos <james_eikona@ketrenos.com>
This commit is contained in:
James Ketrenos 2022-02-08 13:41:05 -08:00
parent 40481d79fd
commit 3285b216e4

View File

@ -174,6 +174,15 @@ const playerNameFromColor = (game, color) => {
return '';
};
const playerFromColor = (game, color) => {
for (let id in game.sessions) {
if (game.sessions[id].color === color) {
return game.sessions[id].player;
}
}
return undefined;
};
const processGameOrder = (game, player, dice) => {
let message;
@ -296,10 +305,10 @@ const distributeResources = (game, roll) => {
console.log(`Matched tiles: ${tiles.join(',')}.`);
const receives = {
"O": { wood: 0, brick: 0, sheep: 0, wheat: 0 },
"R": { wood: 0, brick: 0, sheep: 0, wheat: 0 },
"W": { wood: 0, brick: 0, sheep: 0, wheat: 0 },
"B": { wood: 0, brick: 0, sheep: 0, wheat: 0 },
"O": { wood: 0, brick: 0, sheep: 0, wheat: 0, stone: 0 },
"R": { wood: 0, brick: 0, sheep: 0, wheat: 0, stone: 0 },
"W": { wood: 0, brick: 0, sheep: 0, wheat: 0, stone: 0 },
"B": { wood: 0, brick: 0, sheep: 0, wheat: 0, stone: 0 },
};
/* Find which corners are on each tile */
@ -317,11 +326,13 @@ const distributeResources = (game, roll) => {
for (let color in receives) {
const entry = receives[color];
if (!entry.wood && !entry.brick && !entry.sheep && !entry.wheat) {
if (!entry.wood && !entry.brick && !entry.sheep && !entry.wheat && !entry.stone) {
continue;
}
let message = [];
for (let type in receives[color]) {
const player = playerFromColor(game, color);
player[type] += receives[color][type];
if (receives[color][type]) {
message.push(`${receives[color][type]} ${type}`);
}
@ -339,7 +350,12 @@ const getPlayer = (game, color) => {
points: 0,
status: "Not active",
lastActive: 0,
order: 0
order: 0,
stone: 0,
wheat: 0,
sheep: 0,
wood: 0,
brick: 0
};
}
@ -899,8 +915,11 @@ router.put("/:id/:action/:value?", async (req, res) => {
/* Figure out which players received which resources */
for (let id in game.sessions) {
const session = game.sessions[id],
const session = game.sessions[id], player = session.player,
receives = {};
if (!player) {
continue;
}
if (session.initialSettlement) {
layout.tiles.forEach((tile, index) => {
if (tile.corners.indexOf(session.initialSettlement) !== -1) {
@ -913,6 +932,7 @@ router.put("/:id/:action/:value?", async (req, res) => {
});
let message = [];
for (let type in receives) {
player[type] += receives[type];
message.push(`${receives[type]} ${type}`);
}
addChatMessage(game, null, `${session.name} receives ${message.join(', ')}.`);