Trying to fix BOARD disconnect in ws sync closure
Signed-off-by: James Ketrenos <james_eikona@ketrenos.com>
This commit is contained in:
parent
fd99aacfc9
commit
c433c40c07
@ -219,14 +219,14 @@ const Board = () => {
|
|||||||
}));
|
}));
|
||||||
}, [ws]);
|
}, [ws]);
|
||||||
|
|
||||||
const Road = ({road}) => {
|
const onRoadClicked = useCallback((road) => {
|
||||||
const onClick = (event) => {
|
|
||||||
console.log(`Road clicked: ${road.index}`);
|
console.log(`Road clicked: ${road.index}`);
|
||||||
sendPlacement('place-road', road.index);
|
sendPlacement('place-road', road.index);
|
||||||
};
|
}, [sendPlacement]);
|
||||||
|
|
||||||
|
const Road = ({road}) => {
|
||||||
return <div className="Road"
|
return <div className="Road"
|
||||||
onClick={onClick}
|
onClick={() => { onRoadClicked(road) }}
|
||||||
data-index={road.index}
|
data-index={road.index}
|
||||||
style={{
|
style={{
|
||||||
transform: `translate(-50%, -50%) rotate(${road.angle}deg)`,
|
transform: `translate(-50%, -50%) rotate(${road.angle}deg)`,
|
||||||
@ -236,8 +236,7 @@ const Board = () => {
|
|||||||
><div className="Road-Shape"/></div>;
|
><div className="Road-Shape"/></div>;
|
||||||
};
|
};
|
||||||
|
|
||||||
const Corner = ({corner}) => {
|
const onCornerClicked = useCallback((event, corner) => {
|
||||||
const onClick = (event) => {
|
|
||||||
let type;
|
let type;
|
||||||
if (event.currentTarget.getAttribute('data-type') === 'settlement') {
|
if (event.currentTarget.getAttribute('data-type') === 'settlement') {
|
||||||
type = 'place-city';
|
type = 'place-city';
|
||||||
@ -245,10 +244,11 @@ const Board = () => {
|
|||||||
type = 'place-settlement';
|
type = 'place-settlement';
|
||||||
}
|
}
|
||||||
sendPlacement(type, corner.index);
|
sendPlacement(type, corner.index);
|
||||||
};
|
}, [sendPlacement]);
|
||||||
|
|
||||||
|
const Corner = ({corner}) => {
|
||||||
return <div className="Corner"
|
return <div className="Corner"
|
||||||
onClick={onClick}
|
onClick={(event) => { onCornerClicked(event, corner) }}
|
||||||
data-index={corner.index}
|
data-index={corner.index}
|
||||||
style={{
|
style={{
|
||||||
top: `${corner.top}px`,
|
top: `${corner.top}px`,
|
||||||
@ -257,13 +257,13 @@ const Board = () => {
|
|||||||
><div className="Corner-Shape"/></div>;
|
><div className="Corner-Shape"/></div>;
|
||||||
};
|
};
|
||||||
|
|
||||||
const Pip = ({pip}) => {
|
const onPipClicked = useCallback((pip) => {
|
||||||
const onClick = (event) => {
|
|
||||||
sendPlacement('place-robber', pip.index);
|
sendPlacement('place-robber', pip.index);
|
||||||
};
|
}, [sendPlacement]);
|
||||||
|
|
||||||
|
const Pip = ({pip}) => {
|
||||||
return <div className="Pip"
|
return <div className="Pip"
|
||||||
onClick={onClick}
|
onClick={() => { onPipClicked(pip) }}
|
||||||
data-roll={pip.roll}
|
data-roll={pip.roll}
|
||||||
data-index={pip.index}
|
data-index={pip.index}
|
||||||
style={{
|
style={{
|
||||||
|
@ -1942,10 +1942,19 @@ const stealResource = (game, session, color) => {
|
|||||||
if (game.turn.limits.players.findIndex(item => item.color === color) === -1) {
|
if (game.turn.limits.players.findIndex(item => item.color === color) === -1) {
|
||||||
return `You can only steal a resource from a player on this terrain!`;
|
return `You can only steal a resource from a player on this terrain!`;
|
||||||
}
|
}
|
||||||
const victim = game.players[color];
|
let victim;
|
||||||
|
for (let key in game.sessions) {
|
||||||
|
if (game.sessions[key].color === color) {
|
||||||
|
victim = game.sessions[key];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!victim) {
|
||||||
|
return `You sent a wierd color for the target to steal from.`;
|
||||||
|
}
|
||||||
const cards = [];
|
const cards = [];
|
||||||
[ 'wheat', 'brick', 'sheep', 'stone', 'wood' ].forEach(field => {
|
[ 'wheat', 'brick', 'sheep', 'stone', 'wood' ].forEach(field => {
|
||||||
for (let i = 0; i < victim[field]; i++) {
|
for (let i = 0; i < victim.player[field]; i++) {
|
||||||
cards.push(field);
|
cards.push(field);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -1961,8 +1970,8 @@ const stealResource = (game, session, color) => {
|
|||||||
} else {
|
} else {
|
||||||
let index = Math.floor(Math.random() * cards.length),
|
let index = Math.floor(Math.random() * cards.length),
|
||||||
type = cards[index];
|
type = cards[index];
|
||||||
victim[type]--;
|
victim.player[type]--;
|
||||||
victim.resources--;
|
victim.player.resources--;
|
||||||
session.player[type]++;
|
session.player[type]++;
|
||||||
session.player.resources++;
|
session.player.resources++;
|
||||||
game.turn.actions = [];
|
game.turn.actions = [];
|
||||||
@ -1970,18 +1979,22 @@ const stealResource = (game, session, color) => {
|
|||||||
addChatMessage(game, session,
|
addChatMessage(game, session,
|
||||||
`${session.name} randomly stole 1 ${type} from ` +
|
`${session.name} randomly stole 1 ${type} from ` +
|
||||||
`${victim.name}.`);
|
`${victim.name}.`);
|
||||||
|
sendUpdateToPlayer(victim, {
|
||||||
|
private: victim.player
|
||||||
|
});
|
||||||
}
|
}
|
||||||
debugChat(game, 'After steal');
|
debugChat(game, 'After steal');
|
||||||
|
|
||||||
game.turn.robberInAction = false;
|
game.turn.robberInAction = false;
|
||||||
|
|
||||||
|
sendUpdateToPlayer(session, {
|
||||||
|
private: session.player
|
||||||
|
});
|
||||||
sendUpdateToPlayers(game, {
|
sendUpdateToPlayers(game, {
|
||||||
turn: game.turn,
|
turn: game.turn,
|
||||||
chat: game.chat,
|
chat: game.chat,
|
||||||
activities: game.activities
|
activities: game.activities
|
||||||
});
|
});
|
||||||
sendUpdateToPlayer(session, {
|
|
||||||
private: session.player
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const buyDevelopment = (game, session) => {
|
const buyDevelopment = (game, session) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user