lijim / monks-and-mages

Monks and Mages is a TCG-game built on React and socket.io
https://www.monksandmages.com
MIT License
17 stars 0 forks source link

Bug: Resolving effects leads to blank games #439

Closed lijim closed 1 year ago

lijim commented 1 year ago

We currently have some logic that resolves effects like this:

const newBoardState = resolveEffect(
            board,
            effectParams,
            playerName,
            true,
            sendChatMessageForRoom(socket)
        );

        if (newBoardState) {
            const gameResult = calculateGameResult(
                prevGameState,
                newBoardState
            );
            if (gameResult) {
                addGameResult(gameResult);
                recordGameResultToDatabase(gameResult);
            }
        }

        // TODO: add error handling when user tries to take an invalid action
        room.board = newBoardState; // apply state changes to in-memory storage of boards
        broadcastBoardForRoom(room.roomName);

The issue is that if newBoardState is null, we lock the board up and make it so that the game doesn't continue

I'm not sure what exact steps we need to repro, but it seems to involve auto-resolving effects within the game (e.g. summon a unit, buff the team)

const { effectQueue } = activePlayer;
    if (
        verifyEffect &&
        (!effectQueue?.length ||
            !isEqual(effectQueue[effectQueue.length - 1], effect))
    ) {
        return null;
    }

It's possible that returning the board state instead of returning null early will fix this OR we can make it so it only sets a room's board if newBoardState exists