private async Task BotSendsAnswer(GameCreatedModel model, string accessToken) { Random random = new Random(); var delay = random.Next(3, 10); await Task.Delay(TimeSpan.FromSeconds(delay)); var choice = random.Next(1, 3); var randomChoice = (Enum.RockPaperScissorsType)System.Enum.ToObject(typeof(Enum.RockPaperScissorsType), choice); await _botService.SendAnswer(accessToken, new SendChoiceViewModel() { Choice = randomChoice, GameId = model.GameId, GameRoundId = model.GameRoundId, Round = model.Round }); }
public async Task SendGameCreatedMessage(GameCreatedModel model) { await _hubContext.Clients.Users(new List <string>() { model.HostUserId, model.GuestUserId }) .SendAsync("GameCreated", JsonConvert.SerializeObject(model)); if (model.IsBotActivated) { var botUser = _userService.GetUserByUserId(model.GuestUserId); var credentials = await _userService.Login(new Services.Models.LoginModel() { Username = botUser.Nickname, Password = "******" }); await BotSendsAnswer(model, credentials.AccessToken); } }