Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return function*() {
const sagaState = {
evolutionLocked: false
};
yield all([
yield takeLatest(
[ LOCK_EVOLUTIONS, UNLOCK_EVOLUTIONS ],
function*(action) {
sagaState.evolutionLocked = (action.type === LOCK_EVOLUTIONS);
}
),
yield takeLatest(
BenchActionTypes.BENCH_PIECE_ADDED,
function*(action) {
const piece = action.payload.piece;
// if evolution is locked, wait for it to be unlocked
if (sagaState.evolutionLocked) {
yield take(UNLOCK_EVOLUTIONS);
yield delay(500);
}
const { bench, board }: TState = yield select(s => ({ bench: s.bench, board: s.board }));
const { stages } = definitionProvider.get(piece.definitionId);
const nextStageIndex = piece.stage + 1;
const nextStage = stages[nextStageIndex];
return function*() {
const sagaState = {
evolutionLocked: false
};
yield all([
yield takeLatest(
[ LOCK_EVOLUTIONS, UNLOCK_EVOLUTIONS ],
function*(action) {
sagaState.evolutionLocked = (action.type === LOCK_EVOLUTIONS);
}
),
yield takeLatest(
BenchActionTypes.BENCH_PIECE_ADDED,
function*(action) {
const piece = action.payload.piece;
// if evolution is locked, wait for it to be unlocked
if (sagaState.evolutionLocked) {
yield take(UNLOCK_EVOLUTIONS);
yield delay(500);
}
function* fetchErc20Balances (api: IApi, action: IFetchErc20BalancesAction): SagaIterator {
const accounts: AddressMap[] = yield select(allAsArray);
for (const acc of accounts) {
const address = acc.get('id');
const chain = acc.get('blockchain').toLowerCase();
// Look up all known tokens for current blockchain
const _tokens = registry.all()[chain as BlockchainCode];
// Request balance for each token for current address
for (const t of _tokens) {
yield put(requestTokenBalance(chain, t, address));
}
}
}
function*(action) {
if (isGamePhaseUpdate(GamePhase.PREPARING, action) || isGamePhaseUpdate(GamePhase.READY, action)) {
// don't do anything, just cancel the old one
const pieces = (action.payload as any).payload.pieces;
yield put(BoardActions.piecesUpdated(pieces));
return;
}
const state: AppState = yield select();
const battleChannel = yield call(startBattle, turnSimulator, state.board, Constants.TURNS_IN_BATTLE);
yield takeEvery(battleChannel, function*(battleAction: BattleAction) {
switch (battleAction.type) {
case BATTLE_TURN:
yield put(BoardActions.piecesUpdated(battleAction.payload.pieces));
case BATTLE_FINISHED:
yield put(battleAction);
default:
return;
}
});
}
);
function*(action) {
const state: AppState = yield select();
const gamePhase = state.game.phase;
// not in correct phase
if (gamePhase === GamePhase.WAITING || gamePhase === GamePhase.DEAD) {
return;
}
const card = state.cards[action.payload.index];
const money = state.game.money;
// card doesn't exist or player can't afford
if (!card || money < card.cost) {
return;
}
function*() {
const state: AppState = yield select();
// if player not connected yet, don't try to reconnect
if (state.localPlayer.id === null) {
yield put(updateConnectionStatus(ConnectionStatus.DISCONNECTED_FINAL));
return;
}
const packet: ReconnectAuthenticatePacket = {
gameId: state.game.gameId,
playerId: state.localPlayer.id,
reconnectSecret: state.localPlayer.reconnectionSecret
};
yield put(sendPacket(ClientToServerPacketOpcodes.RECONNECT_AUTHENTICATE, packet));
}
)
function* fetchErc20Balances (api: IApi, action: IFetchErc20BalancesAction): SagaIterator {
const accounts: AddressMap[] = yield select(allAsArray);
for (const acc of accounts) {
const address = acc.get('id');
const chain = acc.get('blockchain').toLowerCase();
// Look up all known tokens for current blockchain
const _tokens = registry.all()[chain as BlockchainCode];
// Request balance for each token for current address
for (const t of _tokens) {
yield put(requestTokenBalance(chain, t, address));
}
}
}
function*(action) {
if (isGamePhaseUpdate(GamePhase.PREPARING, action) || isGamePhaseUpdate(GamePhase.READY, action)) {
// don't do anything, just cancel the old one
const pieces = (action.payload as any).payload.pieces;
yield put(BoardActions.piecesUpdated(pieces));
return;
}
const state: AppState = yield select();
const battleChannel = yield call(startBattle, turnSimulator, state.board, Constants.TURNS_IN_BATTLE);
yield takeEvery(battleChannel, function*(battleAction: BattleAction) {
switch (battleAction.type) {
case BATTLE_TURN:
yield put(BoardActions.piecesUpdated(battleAction.payload.pieces));
case BATTLE_FINISHED:
yield put(battleAction);
default:
return;
}
});
}
);
function*(action) {
const piece = action.payload.piece;
// if evolution is locked, wait for it to be unlocked
if (sagaState.evolutionLocked) {
yield take(UNLOCK_EVOLUTIONS);
yield delay(500);
}
const { bench, board }: TState = yield select(s => ({ bench: s.bench, board: s.board }));
const { stages } = definitionProvider.get(piece.definitionId);
const nextStageIndex = piece.stage + 1;
const nextStage = stages[nextStageIndex];
if (!nextStage) {
return;
}
const pieceIsMatching = (p: Piece) => p.definitionId === piece.definitionId && p.stage === piece.stage;
const getMatchingPieces = (pieces: Piece[]) => pieces.filter(p => p.id !== piece.id && pieceIsMatching(p));
export const preventAccidentalClose = function*() {
yield take(JOIN_COMPLETE);
// display an "Are you sure you want to leave this page?" dialog
window.onbeforeunload = () => "Are you sure you want to leave this page? There is currently no way to rejoin a game";
};