Esempio n. 1
0
        public override async Task <DialogTurnResult> BeginDialogAsync(
            DialogContext dc,
            object options = null,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (dc == null)
            {
                throw new ArgumentNullException(nameof(dc));
            }

            // We load the object and actor positions from the room state.
            var roomStates = await _roomStateAccessor.GetAsync(dc.Context, () => new Dictionary <string, RoomState>());

            // If there's no room state found, use the initial room state.
            RoomState roomState;

            if (!roomStates.TryGetValue(_roomId, out roomState))
            {
                roomState = _gameInfo.InitialRoomStates[_roomId];
                roomStates.Add(_roomId, roomState);
            }

            // When the player enters a new room, send a RoomEntered event to
            // populate the room.
            await dc.Context.SendActivityAsync(_activityFactory.RoomEntered(dc, _roomId, roomState));

            // There may be some actions that must be performed immediately after the player
            // enters the room (e.g. walk to a specific spot).
            var actions = await GetActionsAsync(dc, Command.EnterRoom);

            if (actions.Any())
            {
                // Map the actions to Bot Framework activities and send them to the client.
                if (!await ExecuteActionsAsync(dc, actions))
                {
                    // If ExecuteActionsAsync returns false, don't send anymore activities
                    // to the client. Control is handed over to a different dialog.
                    return(new DialogTurnResult(DialogTurnStatus.Waiting));
                }
            }

            // Send an Idle activity to let the GUI know that we're waiting for user interaction.
            await dc.Context.SendActivityAsync(_activityFactory.Idle(dc));

            return(new DialogTurnResult(DialogTurnStatus.Waiting));
        }