Ejemplo n.º 1
0
            public async Task <ISuccessOrErrors <Common.BoardState> > JoinGame(SeatI seat, Guid playerId)
            {
                seat.State.PlayerId = playerId;
                seat.State.ETag     = Guid.NewGuid().ToString();
                await seat.WriteStateAsync();

                var game       = seat.GrainFactory.GetGrain <IGame> (seat.GetPrimaryKey());
                var boardState = await game.GetBoardState();

                var provider = seat.GetStreamProvider(seat.PlayerSeatStreamProvider);
                var stream   = provider.GetStream <PlayerTookSeatI> (seat.GetPrimaryKey(), nameof(PlayerTookSeatI));
                await stream.OnNextAsync(new PlayerTookSeatI (playerId));

                var result = new Success <Common.BoardState> (new Common.BoardState(boardState));

                return(result);
            }
Ejemplo n.º 2
0
            public async Task <ISuccessOrErrors <Common.BoardState> > LeaveGame(SeatI seat)
            {
                var playerId = seat.State.PlayerId.GetValueOrDefault();

                seat.State.PlayerId = null;
                seat.State.ETag     = Guid.NewGuid().ToString();
                await seat.WriteStateAsync();

                var game       = seat.GrainFactory.GetGrain <IGame> (seat.GetPrimaryKey());
                var boardState = await game.GetBoardState();

                var provider = seat.GetStreamProvider(seat.PlayerSeatStreamProvider);
                var stream   = provider.GetStream <PlayerLeftSeatI> (seat.GetPrimaryKey(), nameof(PlayerLeftSeatI));
                await stream.OnNextAsync(new PlayerLeftSeatI (playerId));

                return(new Success <Common.BoardState> (new Common.BoardState(boardState)));
            }