Set initial Volcano values correctly
Signed-off-by: James Ketrenos <james_eikona@ketrenos.com>
This commit is contained in:
parent
68e43fa3f7
commit
3034520aae
@ -12,36 +12,26 @@ import { GlobalContext } from "./GlobalContext.js";
|
|||||||
/* Volcano based on https://www.ultraboardgames.com/catan/the-volcano.php */
|
/* Volcano based on https://www.ultraboardgames.com/catan/the-volcano.php */
|
||||||
const Volcano = ({ ws, rules, field, disabled }) => {
|
const Volcano = ({ ws, rules, field, disabled }) => {
|
||||||
const init = (Math.random() > 0.5)
|
const init = (Math.random() > 0.5)
|
||||||
? Math.floor(7 + Math.random() * 6)
|
? Math.floor(8 + Math.random() * 5) /* Do not include 7 */
|
||||||
: Math.floor(1 + Math.random() * 6);
|
: Math.floor(2 + Math.random() * 5); /* Do not include 7 */
|
||||||
const [number, setNumber] = useState(rules[field].number || init);
|
const [number, setNumber] = useState(rules[field].number || init);
|
||||||
const [gold, setGold] = useState(rules[field].gold || false);
|
const [gold, setGold] = useState(rules[field].gold || false);
|
||||||
console.log(`house-rules - ${field} - `, rules[field]);
|
console.log(`house-rules - ${field} - `, rules[field]);
|
||||||
|
|
||||||
if (!(field in rules)) {
|
if (!(field in rules)) {
|
||||||
rules[field] = {
|
rules[field] = {};
|
||||||
number: init,
|
|
||||||
gold: gold
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const update = (value) => {
|
const update = (value) => {
|
||||||
let number = (rules[field].number || init) + value;
|
let number = (rules[field].number || init) + value;
|
||||||
if (number < 1 || number > 12) {
|
if (number < 2 || number > 12) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* Number to trigger Volcano cannot be 7 */
|
/* Number to trigger Volcano cannot be 7 */
|
||||||
if (number === 7) {
|
if (number === 7) {
|
||||||
number = value > 0 ? 8 : 6;
|
number = value > 0 ? 8 : 6;
|
||||||
}
|
}
|
||||||
if (number !== rules[field].number) {
|
setNumber(number);
|
||||||
setNumber(number);
|
|
||||||
rules[field].number = number;
|
|
||||||
ws.send(JSON.stringify({
|
|
||||||
type: 'rules',
|
|
||||||
rules: rules
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -54,6 +44,16 @@ const Volcano = ({ ws, rules, field, disabled }) => {
|
|||||||
}
|
}
|
||||||
}, [ rules, ws, gold, field ]);
|
}, [ rules, ws, gold, field ]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (rules[field].number !== number) {
|
||||||
|
rules[field].number = number;
|
||||||
|
ws.send(JSON.stringify({
|
||||||
|
type: 'rules',
|
||||||
|
rules: rules
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}, [rules, ws, number, field]);
|
||||||
|
|
||||||
return <div className="Volcano">
|
return <div className="Volcano">
|
||||||
<div>
|
<div>
|
||||||
The Volcano replaces the Desert. When the Volcano erupts, roll a die to determine the direction the lava will flow. One of the six intersections on the Volcano tile will be affected. If there is a settlement on the selected intersection, it is destroyed!
|
The Volcano replaces the Desert. When the Volcano erupts, roll a die to determine the direction the lava will flow. One of the six intersections on the Volcano tile will be affected. If there is a settlement on the selected intersection, it is destroyed!
|
||||||
|
Loading…
x
Reference in New Issue
Block a user