Volcano working!
Signed-off-by: James Ketrenos <james_eikona@ketrenos.com>
This commit is contained in:
parent
af83538027
commit
9cda7c17cf
@ -166,6 +166,7 @@ const Actions = ({
|
|||||||
(turn.actions.indexOf('place-road') !== -1
|
(turn.actions.indexOf('place-road') !== -1
|
||||||
|| turn.actions.indexOf('place-city') !== -1
|
|| turn.actions.indexOf('place-city') !== -1
|
||||||
|| turn.actions.indexOf('place-settlement') !== -1);
|
|| turn.actions.indexOf('place-settlement') !== -1);
|
||||||
|
|
||||||
if (tradeActive
|
if (tradeActive
|
||||||
&& (!turn || !turn.actions || turn.actions.indexOf('trade'))) {
|
&& (!turn || !turn.actions || turn.actions.indexOf('trade'))) {
|
||||||
setTradeActive(false);
|
setTradeActive(false);
|
||||||
@ -190,6 +191,7 @@ const Actions = ({
|
|||||||
{ name && !inLobby && <>
|
{ name && !inLobby && <>
|
||||||
<Button disabled={
|
<Button disabled={
|
||||||
robberActions ||
|
robberActions ||
|
||||||
|
(turn && turn.select) ||
|
||||||
(inGame && (!isTurn || hasRolled)) ||
|
(inGame && (!isTurn || hasRolled)) ||
|
||||||
(inGameOrder && hasGameOrderRolled) ||
|
(inGameOrder && hasGameOrderRolled) ||
|
||||||
(!inGame && !inGameOrder && (!isTurn || !volcanoActive))
|
(!inGame && !inGameOrder && (!isTurn || !volcanoActive))
|
||||||
|
@ -12,9 +12,10 @@ const ChooseCard = () => {
|
|||||||
const { ws } = useContext(GlobalContext);
|
const { ws } = useContext(GlobalContext);
|
||||||
const [turn, setTurn] = useState(undefined);
|
const [turn, setTurn] = useState(undefined);
|
||||||
const [color, setColor] = useState(undefined);
|
const [color, setColor] = useState(undefined);
|
||||||
|
const [state, setState] = useState(undefined);
|
||||||
const [cards, setCards] = useState([]);
|
const [cards, setCards] = useState([]);
|
||||||
const fields = useMemo(() => [
|
const fields = useMemo(() => [
|
||||||
'turn', 'color'
|
'turn', 'color', 'state'
|
||||||
], []);
|
], []);
|
||||||
|
|
||||||
const onWsMessage = (event) => {
|
const onWsMessage = (event) => {
|
||||||
@ -28,6 +29,9 @@ const ChooseCard = () => {
|
|||||||
if ('color' in data.update && data.update.color !== color) {
|
if ('color' in data.update && data.update.color !== color) {
|
||||||
setColor(data.update.color);
|
setColor(data.update.color);
|
||||||
}
|
}
|
||||||
|
if ('state' in data.update && data.update.state !== state) {
|
||||||
|
setState(data.update.state);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -56,7 +60,19 @@ const ChooseCard = () => {
|
|||||||
}));
|
}));
|
||||||
}, [ws, cards]);
|
}, [ws, cards]);
|
||||||
|
|
||||||
const count = (turn && turn.active === 'monopoly') ? 1 : 2;
|
let count = 0;
|
||||||
|
if (turn && turn.color === color) {
|
||||||
|
count = turn.active === 'monopoly' ? 1 : 2;
|
||||||
|
}
|
||||||
|
if (state === 'volcano') {
|
||||||
|
if (!turn.select) {
|
||||||
|
count = 0;
|
||||||
|
} else if (color in turn.select) {
|
||||||
|
count = turn.select[color];
|
||||||
|
} else {
|
||||||
|
count = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const selectCard = useCallback((event) => {
|
const selectCard = useCallback((event) => {
|
||||||
event.target.classList.toggle('Selected');
|
event.target.classList.toggle('Selected');
|
||||||
@ -77,11 +93,9 @@ const ChooseCard = () => {
|
|||||||
setCards(tmp);
|
setCards(tmp);
|
||||||
}, [ setCards, count ]);
|
}, [ setCards, count ]);
|
||||||
|
|
||||||
if (!turn
|
if (!turn || !turn.active
|
||||||
|| turn.color !== color
|
|| (count === 0)
|
||||||
|| !turn.actions
|
|| !turn.actions || turn.actions.indexOf('select-resources') === -1) {
|
||||||
|| turn.actions.indexOf('select-resources') === -1
|
|
||||||
|| !turn.active) {
|
|
||||||
return <></>;
|
return <></>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,6 +117,9 @@ const ChooseCard = () => {
|
|||||||
case 'year-of-plenty':
|
case 'year-of-plenty':
|
||||||
title = <><b>Year of Plenty</b>! Tap the two resources you want to receive from the bank!</>;
|
title = <><b>Year of Plenty</b>! Tap the two resources you want to receive from the bank!</>;
|
||||||
break;
|
break;
|
||||||
|
case 'volcano':
|
||||||
|
title = <><b>Volcano has minerals</b>! Tap the {count} resources you want to receive from the bank!</>;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
title = <>Unknown card type {turn.active}.</>;
|
title = <>Unknown card type {turn.active}.</>;
|
||||||
break;
|
break;
|
||||||
|
@ -230,6 +230,7 @@ const processVolcano = (game, session, dice) => {
|
|||||||
addChatMessage(game, session, `${name} rolled ${dice[0]} for the Volcano!`);
|
addChatMessage(game, session, `${name} rolled ${dice[0]} for the Volcano!`);
|
||||||
|
|
||||||
game.state = 'normal';
|
game.state = 'normal';
|
||||||
|
|
||||||
game.turn.volcano = layout.tiles[volcano].corners[dice[0] % 6];
|
game.turn.volcano = layout.tiles[volcano].corners[dice[0] % 6];
|
||||||
const corner = game.placements.corners[game.turn.volcano];
|
const corner = game.placements.corners[game.turn.volcano];
|
||||||
if (corner.color) {
|
if (corner.color) {
|
||||||
@ -296,6 +297,9 @@ const roll = (game, session, dice) => {
|
|||||||
if (game.turn.color !== session.color) {
|
if (game.turn.color !== session.color) {
|
||||||
return `It is not your turn.`;
|
return `It is not your turn.`;
|
||||||
}
|
}
|
||||||
|
if (game.turn.select) {
|
||||||
|
return `You can not roll for the Volcano until all players have mined their resources.`;
|
||||||
|
}
|
||||||
processVolcano(game, session, dice);
|
processVolcano(game, session, dice);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -451,7 +455,40 @@ const processRoll = (game, session, dice) => {
|
|||||||
addChatMessage(game, session, `House rule 'Volcano' activated. The
|
addChatMessage(game, session, `House rule 'Volcano' activated. The
|
||||||
Volcano is erupting! You must roll the die to determine which
|
Volcano is erupting! You must roll the die to determine which
|
||||||
direciton the lava will flow!`);
|
direciton the lava will flow!`);
|
||||||
|
|
||||||
game.state = 'volcano';
|
game.state = 'volcano';
|
||||||
|
|
||||||
|
let count = 0;
|
||||||
|
console.log(game.rules['volcano']);
|
||||||
|
if (game.rules['volcano'].gold) {
|
||||||
|
game.turn.select = {};
|
||||||
|
const volcano = layout.tiles.find((tile, index) =>
|
||||||
|
staticData.tiles[game.tileOrder[index]].type === 'desert');
|
||||||
|
console.log(volcano);
|
||||||
|
volcano.corners.forEach(index => {
|
||||||
|
const corner = game.placements.corners[index];
|
||||||
|
console.log({ index, corner });
|
||||||
|
if (corner.color) {
|
||||||
|
if (!(corner.color in game.turn.select)) {
|
||||||
|
game.turn.select[corner.color] = 0;
|
||||||
|
}
|
||||||
|
game.turn.select[corner.color] +=
|
||||||
|
corner.type === 'settlement' ? 1 : 2;
|
||||||
|
count += corner.type === 'settlement' ? 1 : 2;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (count) {
|
||||||
|
game.turn.actions = [ 'select-resources' ];
|
||||||
|
if (volcano === layout.tiles[game.robber]) {
|
||||||
|
addChatMessage(game, null, `That pesky ${game.robberName} Robber Roberson blocked ${count} resources!`);
|
||||||
|
delete game.turn.selected;
|
||||||
|
} else {
|
||||||
|
addChatMessage(game, null, `House rule 'Volcanoes have minerals' activated. Players must select which resources to receive from the Volcano!`);
|
||||||
|
game.turn.active = 'volcano';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2070,7 +2107,7 @@ const pass = (game, session) => {
|
|||||||
if (game.state === 'volcano') {
|
if (game.state === 'volcano') {
|
||||||
return `You cannot not stop turn until you have finished the Volcano tasks.`;
|
return `You cannot not stop turn until you have finished the Volcano tasks.`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const next = getNextPlayerSession(game, session.name);
|
const next = getNextPlayerSession(game, session.name);
|
||||||
session.player.totalTime += Date.now() - session.player.turnStart;
|
session.player.totalTime += Date.now() - session.player.turnStart;
|
||||||
session.player.turnNotice = "";
|
session.player.turnNotice = "";
|
||||||
@ -2235,7 +2272,7 @@ const buyDevelopment = (game, session) => {
|
|||||||
const player = session.player;
|
const player = session.player;
|
||||||
|
|
||||||
if (game.state !== 'normal') {
|
if (game.state !== 'normal') {
|
||||||
return `You cannot purchase a development card unless the game is active.`;
|
return `You cannot purchase a development card unless the game is active (${game.state}).`;
|
||||||
}
|
}
|
||||||
if (session.color !== game.turn.color) {
|
if (session.color !== game.turn.color) {
|
||||||
return `It is not your turn! It is ${game.turn.name}'s turn.`;
|
return `It is not your turn! It is ${game.turn.name}'s turn.`;
|
||||||
@ -2290,7 +2327,7 @@ const playCard = (game, session, card) => {
|
|||||||
const name = session.name, player = session.player;
|
const name = session.name, player = session.player;
|
||||||
|
|
||||||
if (game.state !== 'normal') {
|
if (game.state !== 'normal') {
|
||||||
return `You cannot play a development card unless the game is active.`;
|
return `You cannot purchase a development card unless the game is active (${game.state}).`;
|
||||||
}
|
}
|
||||||
if (session.color !== game.turn.color) {
|
if (session.color !== game.turn.color) {
|
||||||
return `It is not your turn! It is ${game.turn.name}'s turn.`;
|
return `It is not your turn! It is ${game.turn.name}'s turn.`;
|
||||||
@ -2412,7 +2449,7 @@ const placeSettlement = (game, session, index) => {
|
|||||||
const player = session.player;
|
const player = session.player;
|
||||||
index = parseInt(index);
|
index = parseInt(index);
|
||||||
if (game.state !== 'initial-placement' && game.state !== 'normal') {
|
if (game.state !== 'initial-placement' && game.state !== 'normal') {
|
||||||
return `You cannot place an item unless the game is active.`;
|
return `You cannot purchase a development card unless the game is active (${game.state}).`;
|
||||||
}
|
}
|
||||||
if (session.color !== game.turn.color) {
|
if (session.color !== game.turn.color) {
|
||||||
return `It is not your turn! It is ${game.turn.name}'s turn.`;
|
return `It is not your turn! It is ${game.turn.name}'s turn.`;
|
||||||
@ -2540,7 +2577,7 @@ const placeRoad = (game, session, index) => {
|
|||||||
const player = session.player;
|
const player = session.player;
|
||||||
index = parseInt(index);
|
index = parseInt(index);
|
||||||
if (game.state !== 'initial-placement' && game.state !== 'normal') {
|
if (game.state !== 'initial-placement' && game.state !== 'normal') {
|
||||||
return `You cannot place an item unless the game is active.`;
|
return `You cannot purchase a development card unless the game is active (${game.state}).`;
|
||||||
}
|
}
|
||||||
if (session.color !== game.turn.color) {
|
if (session.color !== game.turn.color) {
|
||||||
return `It is not your turn! It is ${game.turn.name}'s turn.`;
|
return `It is not your turn! It is ${game.turn.name}'s turn.`;
|
||||||
@ -2858,7 +2895,7 @@ const buyRoad = (game, session) => {
|
|||||||
const player = session.player;
|
const player = session.player;
|
||||||
|
|
||||||
if (game.state !== 'normal') {
|
if (game.state !== 'normal') {
|
||||||
return `You cannot purchase a road unless the game is active.`;
|
return `You cannot purchase a development card unless the game is active (${game.state}).`;
|
||||||
}
|
}
|
||||||
if (session.color !== game.turn.color) {
|
if (session.color !== game.turn.color) {
|
||||||
return `It is not your turn! It is ${game.turn.name}'s turn.`;
|
return `It is not your turn! It is ${game.turn.name}'s turn.`;
|
||||||
@ -2896,11 +2933,29 @@ const selectResources = (game, session, cards) => {
|
|||||||
return `Please, let's not cheat. Ok?`;
|
return `Please, let's not cheat. Ok?`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (session.color !== game.turn.color) {
|
if ((session.color !== game.turn.color)
|
||||||
|
&& (!game.turn.select || !(session.color in game.turn.select))) {
|
||||||
|
console.log(session.color, game.turn.color, game.turn.select);
|
||||||
return `It is not your turn! It is ${game.turn.name}'s turn.`;
|
return `It is not your turn! It is ${game.turn.name}'s turn.`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const count = (game.turn.active === 'monopoly') ? 1 : 2;
|
let count = 2;
|
||||||
|
if (game.turn && game.turn.active === 'monopoly') {
|
||||||
|
count = 1;
|
||||||
|
}
|
||||||
|
if (game.state === 'volcano') {
|
||||||
|
if (!game.turn.select) {
|
||||||
|
count = 0;
|
||||||
|
} else if (session.color in game.turn.select) {
|
||||||
|
count = game.turn.select[session.color];
|
||||||
|
delete game.turn.select[session.color];
|
||||||
|
if (Object.getOwnPropertyNames(game.turn.select).length === 0) {
|
||||||
|
delete game.turn.select;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
count = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!cards || cards.length > count || cards.length === 0) {
|
if (!cards || cards.length > count || cards.length === 0) {
|
||||||
return `You have chosen the wrong number of cards!`;
|
return `You have chosen the wrong number of cards!`;
|
||||||
@ -2982,6 +3037,13 @@ const selectResources = (game, session, cards) => {
|
|||||||
addChatMessage(game, session, `${session.name} player Year of Plenty.` +
|
addChatMessage(game, session, `${session.name} player Year of Plenty.` +
|
||||||
`They chose to receive ${display.join(', ')} from the bank.`);
|
`They chose to receive ${display.join(', ')} from the bank.`);
|
||||||
break;
|
break;
|
||||||
|
case 'volcano':
|
||||||
|
cards.forEach(type => {
|
||||||
|
session.player[type]++;
|
||||||
|
session.player.resources++;
|
||||||
|
});
|
||||||
|
addChatMessage(game, session, `${session.name} player mined ${display.join(', ')} from the Volcano!`);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
delete game.turn.active;
|
delete game.turn.active;
|
||||||
game.turn.actions = [];
|
game.turn.actions = [];
|
||||||
@ -2998,7 +3060,7 @@ const selectResources = (game, session, cards) => {
|
|||||||
const buySettlement = (game, session) => {
|
const buySettlement = (game, session) => {
|
||||||
const player = session.player;
|
const player = session.player;
|
||||||
if (game.state !== 'normal') {
|
if (game.state !== 'normal') {
|
||||||
return `You cannot purchase a settlement unless the game is active.`;
|
return `You cannot purchase a development card unless the game is active (${game.state}).`;
|
||||||
}
|
}
|
||||||
if (session.color !== game.turn.color) {
|
if (session.color !== game.turn.color) {
|
||||||
return `It is not your turn! It is ${game.turn.name}'s turn.`;
|
return `It is not your turn! It is ${game.turn.name}'s turn.`;
|
||||||
@ -3034,7 +3096,7 @@ const buySettlement = (game, session) => {
|
|||||||
const buyCity = (game, session) => {
|
const buyCity = (game, session) => {
|
||||||
const player = session.player;
|
const player = session.player;
|
||||||
if (game.state !== 'normal') {
|
if (game.state !== 'normal') {
|
||||||
return `You cannot purchase a city unless the game is active.`;
|
return `You cannot purchase a development card unless the game is active (${game.state}).`;
|
||||||
}
|
}
|
||||||
if (session.color !== game.turn.color) {
|
if (session.color !== game.turn.color) {
|
||||||
return `It is not your turn! It is ${game.turn.name}'s turn.`;
|
return `It is not your turn! It is ${game.turn.name}'s turn.`;
|
||||||
@ -3070,7 +3132,7 @@ const placeCity = (game, session, index) => {
|
|||||||
const player = session.player;
|
const player = session.player;
|
||||||
index = parseInt(index);
|
index = parseInt(index);
|
||||||
if (game.state !== 'normal') {
|
if (game.state !== 'normal') {
|
||||||
return `You cannot place an item unless the game is active.`;
|
return `You cannot purchase a development card unless the game is active (${game.state}).`;
|
||||||
}
|
}
|
||||||
if (session.color !== game.turn.color) {
|
if (session.color !== game.turn.color) {
|
||||||
return `It is not your turn! It is ${game.turn.name}'s turn.`;
|
return `It is not your turn! It is ${game.turn.name}'s turn.`;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user