コード例 #1
0
        public async Task <IActionResult> Get(int gameID)
        {
            var game = await dbContext.Games
                       .Include(g => g.Characters).AsNoTracking()
                       .Include(g => g.Stages).AsNoTracking()
                       .FirstOrDefaultAsync(g => g.ID == gameID);

            if (game == null)
            {
                return(CodeResultAndLog(HttpStatusCode.NotFound, $"Could not find Game with ID '{gameID}'."));
            }

            var dto = GameDto.Create(game, cdnService);

            return(CodeResult(HttpStatusCode.OK, dto));
        }
コード例 #2
0
        public async Task SelectRole(GameCommand <SelectRole> cmd)
        {
            var game = _inProgressGameStore.FindById(cmd.GameId);

            try {
                await _gameService.ExecuteSelectRole(game, GetUserId(), cmd.Action);
            }
            catch (Exception e) {
                await Clients.Caller.Error(new GameErrorEvent { ErrorMessage = e.Message });
            }

            var changedEvent = new GameChangedEvent {
                Game = GameDto.Create(game)
            };
            await Clients.Group(cmd.GameId).GameChanged(changedEvent);

            await BroadcastAvailableActionTypes(game);
        }
コード例 #3
0
        public override async Task OnConnectedAsync()
        {
            if (Context.GetHttpContext().Request.Query.TryGetValue("gameId", out var gameId))
            {
                var game = _inProgressGameStore.FindById(gameId);
                await Groups.AddToGroupAsync(Context.ConnectionId, gameId);

                var changedEvent = new GameChangedEvent {
                    Game = GameDto.Create(game)
                };
                await Clients.Caller.GameChanged(changedEvent);
                await SendAvailableActionTypes(game, GetUserId());
            }
            else
            {
                await Clients.Caller.Error(new GameErrorEvent {
                    ErrorMessage = "Not found gameId query param"
                });
            }
        }
コード例 #4
0
        private async Task ExecuteRoleAction(string gameId, IAction build)
        {
            var game = _inProgressGameStore.FindById(gameId);

            try {
                await _gameService.ExecuteRoleAction(game, GetUserId(), build);
            }
            catch (Exception e) {
                await Clients.Caller.Error(new GameErrorEvent { ErrorMessage = e.Message });
            }

            await Clients.Groups(gameId).GameChanged(new GameChangedEvent {
                Game = GameDto.Create(game)
            });

            await BroadcastAvailableActionTypes(game);

            if (game.Status == GameStatus.ENDED)
            {
                await AfterGameEnded(game);
            }
        }