1
0

Trying to fix BOARD disconnect in ws sync closure

Signed-off-by: James Ketrenos <james_eikona@ketrenos.com>
This commit is contained in:
James Ketrenos 2022-03-13 15:33:05 -07:00
parent fd99aacfc9
commit c433c40c07
2 changed files with 43 additions and 30 deletions

View File

@ -219,14 +219,14 @@ const Board = () => {
}));
}, [ws]);
const Road = ({road}) => {
const onClick = (event) => {
console.log(`Road clicked: ${road.index}`);
sendPlacement('place-road', road.index);
};
const onRoadClicked = useCallback((road) => {
console.log(`Road clicked: ${road.index}`);
sendPlacement('place-road', road.index);
}, [sendPlacement]);
const Road = ({road}) => {
return <div className="Road"
onClick={onClick}
onClick={() => { onRoadClicked(road) }}
data-index={road.index}
style={{
transform: `translate(-50%, -50%) rotate(${road.angle}deg)`,
@ -236,19 +236,19 @@ const Board = () => {
><div className="Road-Shape"/></div>;
};
const Corner = ({corner}) => {
const onClick = (event) => {
let type;
if (event.currentTarget.getAttribute('data-type') === 'settlement') {
type = 'place-city';
} else {
type = 'place-settlement';
}
sendPlacement(type, corner.index);
};
const onCornerClicked = useCallback((event, corner) => {
let type;
if (event.currentTarget.getAttribute('data-type') === 'settlement') {
type = 'place-city';
} else {
type = 'place-settlement';
}
sendPlacement(type, corner.index);
}, [sendPlacement]);
return <div className="Corner"
onClick={onClick}
const Corner = ({corner}) => {
return <div className="Corner"
onClick={(event) => { onCornerClicked(event, corner) }}
data-index={corner.index}
style={{
top: `${corner.top}px`,
@ -257,13 +257,13 @@ const Board = () => {
><div className="Corner-Shape"/></div>;
};
const Pip = ({pip}) => {
const onClick = (event) => {
sendPlacement('place-robber', pip.index);
};
const onPipClicked = useCallback((pip) => {
sendPlacement('place-robber', pip.index);
}, [sendPlacement]);
const Pip = ({pip}) => {
return <div className="Pip"
onClick={onClick}
onClick={() => { onPipClicked(pip) }}
data-roll={pip.roll}
data-index={pip.index}
style={{

View File

@ -1942,10 +1942,19 @@ const stealResource = (game, session, color) => {
if (game.turn.limits.players.findIndex(item => item.color === color) === -1) {
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 = [];
[ '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);
}
});
@ -1961,8 +1970,8 @@ const stealResource = (game, session, color) => {
} else {
let index = Math.floor(Math.random() * cards.length),
type = cards[index];
victim[type]--;
victim.resources--;
victim.player[type]--;
victim.player.resources--;
session.player[type]++;
session.player.resources++;
game.turn.actions = [];
@ -1970,18 +1979,22 @@ const stealResource = (game, session, color) => {
addChatMessage(game, session,
`${session.name} randomly stole 1 ${type} from ` +
`${victim.name}.`);
sendUpdateToPlayer(victim, {
private: victim.player
});
}
debugChat(game, 'After steal');
game.turn.robberInAction = false;
sendUpdateToPlayer(session, {
private: session.player
});
sendUpdateToPlayers(game, {
turn: game.turn,
chat: game.chat,
activities: game.activities
});
sendUpdateToPlayer(session, {
private: session.player
});
}
const buyDevelopment = (game, session) => {