public async Task <string> CreateGameAsync([FromBody] CreateGameOptions options, [FromServices] StateClient state) { // TODO: Verify user owns the deck. string id = Guid.NewGuid().ToString(); var deck = DeckActorProxy.CreateProxy(options.DeckId); var deckDetails = await deck.GetDetailsAsync(); var cards = await Task.WhenAll( deckDetails.Cards.Select( async deckCard => { var card = CardActorProxy.CreateProxy(deckCard.CardId); var cardDetails = await card.GetDetailsAsync(); return(new GameCard { CardId = deckCard.CardId, Value = cardDetails.Value }); })); var game = GameActorProxy.CreateProxy(id); await game.SetDetailsAsync( new GameDetails { Players = new[] { new GamePlayer { Cards = cards, UserId = options.UserId }, CreateComputerPlayer(cards.Length) } }); var games = await state.GetStateAsync <HashSet <string> >("games"); games ??= new HashSet <string>(); games.Add(id); await state.SaveStateAsync("games", games); var user = UserActorProxy.CreateProxy(options.UserId); await user.AddGameAsync(id); return(id); }
public async Task SetCardAsync(string id, [FromBody] CardDetails details, [FromServices] StateClient state) { var proxy = CardActorProxy.CreateProxy(id); await proxy.SetDetailsAsync(details); var cards = await state.GetStateAsync <HashSet <string> >("cards"); cards ??= new HashSet <string>(); cards.Add(id); await state.SaveStateAsync("cards", cards); }