|
|
@ -33,9 +33,8 @@ export { initialize, buy, roll, endTurn, loan, trade, submitTradeAccept,
|
|
|
|
nextAction, buyUncleBert, actionsFinished, skip }
|
|
|
|
nextAction, buyUncleBert, actionsFinished, skip }
|
|
|
|
|
|
|
|
|
|
|
|
let store;
|
|
|
|
let store;
|
|
|
|
|
|
|
|
let movingTimer = 0;
|
|
|
|
|
|
|
|
|
|
|
|
let spacesWithPlayers = [];
|
|
|
|
|
|
|
|
let loop = 0;
|
|
|
|
|
|
|
|
function handleMessage(evt) {
|
|
|
|
function handleMessage(evt) {
|
|
|
|
const data = JSON.parse(evt.data),
|
|
|
|
const data = JSON.parse(evt.data),
|
|
|
|
type = data.event;
|
|
|
|
type = data.event;
|
|
|
@ -69,7 +68,7 @@ function handleMessage(evt) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
store.dispatch(updatePlayer(data.player));
|
|
|
|
store.dispatch(updatePlayer(data.player));
|
|
|
|
if (data.event === 'init') {
|
|
|
|
if (data.event === 'init') {
|
|
|
|
store.dispatch(movePlayer(data.player.space, 0, data.player.color));
|
|
|
|
store.dispatch(movePlayer(data.player.space, -1, data.player.color));
|
|
|
|
store.dispatch(setHarvestTable(data.harvestTable));
|
|
|
|
store.dispatch(setHarvestTable(data.harvestTable));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// new player(s) added to game, put them on the board
|
|
|
|
// new player(s) added to game, put them on the board
|
|
|
@ -78,7 +77,7 @@ function handleMessage(evt) {
|
|
|
|
const newPlayers = data.game.otherPlayers.filter(
|
|
|
|
const newPlayers = data.game.otherPlayers.filter(
|
|
|
|
x => !otherPlayers.find(y => y.player.name === x.player.name));
|
|
|
|
x => !otherPlayers.find(y => y.player.name === x.player.name));
|
|
|
|
for (const p of newPlayers) {
|
|
|
|
for (const p of newPlayers) {
|
|
|
|
store.dispatch(movePlayer(p.player.space, 0, p.player.color));
|
|
|
|
store.dispatch(movePlayer(p.player.space, -1, p.player.color));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const oldMessages = store.getState().farm.game.messages.slice(0, 20);
|
|
|
|
const oldMessages = store.getState().farm.game.messages.slice(0, 20);
|
|
|
@ -192,7 +191,7 @@ function initialize(st, sc) {
|
|
|
|
rollMessage = '',
|
|
|
|
rollMessage = '',
|
|
|
|
rollTimer = false,
|
|
|
|
rollTimer = false,
|
|
|
|
movingAction = { from: 99, to: 99 },
|
|
|
|
movingAction = { from: 99, to: 99 },
|
|
|
|
movingTimer = 0;
|
|
|
|
handledResolveMove = true;
|
|
|
|
const unsubscribe = store.subscribe(
|
|
|
|
const unsubscribe = store.subscribe(
|
|
|
|
() => {
|
|
|
|
() => {
|
|
|
|
const state = store.getState();
|
|
|
|
const state = store.getState();
|
|
|
@ -271,6 +270,7 @@ function initialize(st, sc) {
|
|
|
|
if ((state.farm.ui.action === 'move' || state.farm.ui.action === 'goto') &&
|
|
|
|
if ((state.farm.ui.action === 'move' || state.farm.ui.action === 'goto') &&
|
|
|
|
movingAction.from !== state.farm.ui.actionValue.from &&
|
|
|
|
movingAction.from !== state.farm.ui.actionValue.from &&
|
|
|
|
movingAction.to !== state.farm.ui.actionValue.to) {
|
|
|
|
movingAction.to !== state.farm.ui.actionValue.to) {
|
|
|
|
|
|
|
|
handledResolveMove = false;
|
|
|
|
movingAction = state.farm.ui.actionValue;
|
|
|
|
movingAction = state.farm.ui.actionValue;
|
|
|
|
const movingProc = (player, from, to) => {
|
|
|
|
const movingProc = (player, from, to) => {
|
|
|
|
let currentPos = from < 0 ? from + 49 : from;
|
|
|
|
let currentPos = from < 0 ? from + 49 : from;
|
|
|
@ -298,6 +298,7 @@ function initialize(st, sc) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (currentPos !== to) {
|
|
|
|
if (currentPos !== to) {
|
|
|
|
|
|
|
|
clearInterval(movingTimer);
|
|
|
|
movingTimer = setInterval(tick, 500);
|
|
|
|
movingTimer = setInterval(tick, 500);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -305,12 +306,17 @@ function initialize(st, sc) {
|
|
|
|
state.farm.player : state.farm.game.otherPlayers
|
|
|
|
state.farm.player : state.farm.game.otherPlayers
|
|
|
|
.find(p => p.player.name === state.farm.game.currentPlayer).player,
|
|
|
|
.find(p => p.player.name === state.farm.game.currentPlayer).player,
|
|
|
|
movingAction.from, movingAction.to);
|
|
|
|
movingAction.from, movingAction.to);
|
|
|
|
} else if (state.farm.ui.action !== 'move' && state.farm.ui.action !== 'goto') {
|
|
|
|
} else if (state.farm.ui.action === 'resolve-move' && !handledResolveMove) {
|
|
|
|
if (movingTimer) {
|
|
|
|
handledResolveMove = true;
|
|
|
|
clearInterval(movingTimer);
|
|
|
|
clearInterval(movingTimer);
|
|
|
|
movingTimer = 0;
|
|
|
|
movingTimer = 0;
|
|
|
|
movingAction = { from: 99, to: 99 };
|
|
|
|
movingAction = { from: 99, to: 99 };
|
|
|
|
|
|
|
|
store.dispatch(movePlayer(state.farm.ui.actionValue.to,
|
|
|
|
|
|
|
|
state.farm.ui.playerSpaces[state.farm.ui.actionValue.color],
|
|
|
|
|
|
|
|
state.farm.ui.actionValue.color));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state.farm.ui.action === 'resolve-move' && state.farm.ui.nextAction !== 'resolve-move') {
|
|
|
|
|
|
|
|
store.dispatch(nextUIAction());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|