Beispiel #1
0
        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);
        }
Beispiel #2
0
 public async Task CreateGameAsync(Guid invocationId, CreateGameOptions options)
 {
     try
     {
         var value = await _gameService.CreateGameAsync(options);
         await ResolveValueAsync(Clients.Caller, nameof(CreateGameAsync), invocationId, value);
     }
     catch (Exception ex)
     {
         await RejectAsync(Clients.Caller, nameof(CreateGameAsync), invocationId, ex.Message);
     }
 }
Beispiel #3
0
            private static void RepositionImpostorsText(CreateGameOptions createGameOptions)
            {
                var impostorsText = createGameOptions.Content.GetComponentsInChildren <TextMeshPro>()
                                    .FirstOrDefault(textMeshPro => textMeshPro.gameObject.transform.parent.name == "Impostors");

                if (!impostorsText)
                {
                    return;
                }

                var position = impostorsText.rectTransform.localPosition;

                position.x = -0.499f;
                impostorsText.rectTransform.localPosition = position;
            }
Beispiel #4
0
        public async Task <string> CreateGameRoom(CreateGameOptions gameOptions)
        {
            var gameRoom = gameRoomsService.CreateNewGameRoom();

            gameRoom.GameOptions = new GameOptions()
            {
                Player1            = null,
                Player2            = null,
                GameVarient        = gameOptions.GameVarient,
                IncrementInSeconds = gameOptions.IncrementInSeconds,
                MinutesPerSide     = gameOptions.MinutesPerSide,
                Side = gameOptions.Side
            };
            return(gameRoom.RoomKey);
        }
Beispiel #5
0
            private static void FixAirshipButtonHitBox(CreateGameOptions createGameOptions)
            {
                var mapIcon = createGameOptions.Content.transform.FindChild("Map")?.FindChild("4")
                              ?.FindChild("MapIcon4");

                if (!mapIcon)
                {
                    return;
                }

                var boxCollider = mapIcon.transform.parent.GetComponent <BoxCollider2D>();
                var size        = boxCollider.size;

                size.x           = 2.1f;
                boxCollider.size = size;
            }
 public Task <GameDto> CreateGameAsync(CreateGameOptions options) =>
 CreateInvocationAsync <GameDto>("CreateGameAsync", options);