Esempio n. 1
0
        public async Task OnTurnAsync(ITurnContext context, CancellationToken cancellationToken)
        {
            if (context.Activity.Type is ActivityTypes.ConversationUpdate)
            {
                foreach (var newMember in context.Activity?.MembersAdded)
                {
                    if (newMember.Id == context.Activity.Recipient.Id)
                    {
                        var gameList = _gameCatalog.GetGameNames().ToList();
                        await context.SendActivityAsync(MessageFactory.SuggestedActions(gameList, "Which game do you want to play?"));

                        return;
                    }
                }
            }
            else if (context.Activity.Type is ActivityTypes.Message)
            {
                // Load the current game state from conversation state.
                // If no game state is found, start a new game from the user's input.
                var gameState = await _stateAccessors.GameStateAccessor.GetAsync(context, () => new GameState
                {
                    GameName  = context.Activity.Text,
                    GameFlags = new GameFlags()
                });

                // Load the metadata for the selected game.
                var gameInfo = _gameCatalog.GetGameInfo(gameState.GameName);

                // Establish dialog context from the loaded game.
                var dialogSet = new GameDialogSet(gameInfo, gameState.GameFlags, _stateAccessors.DialogStateAccessor);
                var dc        = await dialogSet.CreateContextAsync(context, cancellationToken);

                if (dc.ActiveDialog == null)
                {
                    // Start the game's first room.
                    var rootDialog = gameInfo.InitialRoom;
                    await dc.BeginDialogAsync(rootDialog);
                }
                else
                {
                    // get command from LUIS (if enabled)
                    if (_luisOptions.Enabled)
                    {
                        var recognizerResult = await _services.LuisServices["gameatron4000"]
                                               .RecognizeAsync <LUISModel>(context, cancellationToken);
                        string command = recognizerResult.ToCommand();
                        if (!string.IsNullOrEmpty(command))
                        {
                            context.Activity.Text = command;
                        }
                    }

                    await dc.ContinueDialogAsync();
                }

                // Save any changes back to conversation state.
                await _stateAccessors.ConversationState.SaveChangesAsync(context, false, cancellationToken);
            }
        }
Esempio n. 2
0
        public void OnGet(string game)
        {
            var gameCatalog = new GameCatalog("Games");
            var gameInfo    = gameCatalog.GetGameInfo(game);

            GameTitle    = gameInfo.Title;
            GameInfoJson = JsonConvert.SerializeObject(new
            {
                gameName    = game,
                playerActor = gameInfo.PlayerActor,
                assets      = gameInfo.Assets
                              .Select(asset => new
                {
                    key         = asset.Key,
                    url         = $"/dist/games/{game}{asset.Url}",
                    frameWidth  = asset.FrameWidth,
                    frameHeight = asset.FrameHeight
                })
            });
        }