Example #1
0
 public int DeletePlayerAsync([Service] PlayerRepository repository, PlayerDelete input)
 {
     return(repository.DeletePlayer(input.GetId()));
 }
Example #2
0
        private static void HandlePacket(Packet packet)
        {
            Console.WriteLine(packet.Type);

            switch (packet.Type)
            {
            case PacketType.ServerTime:
                SecondsLeft = ((ServerTime)packet).Seconds;
                break;

            case PacketType.SetStatus:
            {
                SetStatus setStatus = (SetStatus)packet;
                Players[setStatus.Id].Thinking = setStatus.TurnOver;
                break;
            }

            case PacketType.GameOver:
                Game.PushState(new GameOverScreen());
                break;

            case PacketType.InitSelectionScreen:
            {
                InitSelectionScreen initSelectionScreen = (InitSelectionScreen)packet;
                Game.PushState(new SelectionScreen(initSelectionScreen.Options));
                InMatch = false;
                break;
            }

            case PacketType.SelectCardCzar:
            {
                SelectCardCzar selectCardCzar = (SelectCardCzar)packet;
                InGame         game           = (InGame)Game.PeekFirstState();

                foreach (Player p in game.Players)
                {
                    p.Czar = false;
                }

                if (Players.ContainsKey(selectCardCzar.Id))
                {
                    Players[selectCardCzar.Id].Czar = true;
                }
                else
                {
                    game.LocalPlayer.Czar = true;
                }

                foreach (Player p in game.Entities.OfType <Player>())
                {
                    p.Thinking = !p.Czar;
                }

                break;
            }

            case PacketType.WinnerPicked:
            {
                if (Game.PeekState().GetType() != typeof(GameOverScreen))
                {
                    InMatch = true;
                    Game.PopState();

                    WinnerPicked winnerPicked = (WinnerPicked)packet;
                    InGame       game         = (InGame)Game.PeekState();

                    if (winnerPicked.Id != 0)
                    {
                        Player player = Players.ContainsKey(winnerPicked.Id) ? Players[winnerPicked.Id] : game.LocalPlayer;
                        ++player.Score;

                        Game.PushState(new WinnerScreen(player.Name, CurrentBlackCard.Info.Value, winnerPicked.Cards));
                    }
                    else
                    {
                        Game.PushState(new WinnerScreen("No one", CurrentBlackCard.Info.Value, new List <string>()));
                    }
                }
                break;
            }

            case PacketType.WhiteCard:
            {
                WhiteCard whiteCards = (WhiteCard)packet;

                foreach (CardInfo c in whiteCards.Cards)
                {
                    Card card = new Card(c)
                    {
                        Position = new Vector2f(-1024.0f, -1024.0f),
                        Scale    = new Vector2f(0.643f * 0.8f, 0.643f * 0.8f)
                    };

                    Hand.Add(card);
                    Game.PeekFirstState().Entities.Add(card);
                }

                if (Hand.Any(c => c.Info.Value.Contains("brain")) && !gotBrainTumorOnce)
                {
                    Assets.PlaySound("BrainTumorCardStart.wav");
                    gotBrainTumorOnce = true;
                }
                else if (Random.Next(100) < 5)
                {
                    Assets.PlaySound("NoBrainTumorCardStart5.wav");
                }

                break;
            }

            case PacketType.BlackCard:
            {
                BlackCard blackCard = (BlackCard)packet;

                if (CurrentBlackCard != null)
                {
                    Game.PeekFirstState().Entities.Remove(CurrentBlackCard);
                }

                CurrentBlackCard = new Card(blackCard.Card)
                {
                    Position = new Vector2f(GameOptions.Width - 256.0f + 4.0f, 48.0f + 32.0f)
                };
                Game.PeekFirstState().Entities.Add(CurrentBlackCard);
                break;
            }

            case PacketType.LobbyBeginGame:
                Game.SetState(new InGame(((Lobby)Game.PeekFirstState()).Players));
                InMatch = true;
                break;

            case PacketType.PlayerDelete:
            {
                PlayerDelete playerDelete = (PlayerDelete)packet;
                Game.PeekFirstState().Entities.Remove(Players[playerDelete.Id]);
                Players.Remove(playerDelete.Id);

                break;
            }

            case PacketType.PlayerNew:
            {
                PlayerNew playerNew = (PlayerNew)packet;
                Player    player    = new Player(playerNew.Name);
                Players.Add(playerNew.Id, player);

                Game.PeekState().Entities.Add(player);
                break;
            }

            case PacketType.ChatMessage:
            {
                ChatMessage chatMessage = (ChatMessage)packet;

                // TODO Unify chatlogs...
                if (Game.PeekFirstState().GetType() == typeof(Lobby))
                {
                    ((Lobby)Game.PeekFirstState()).ChatBacklog.Add(chatMessage.Value);
                }
                else
                {
                    ((InGame)Game.PeekFirstState()).ChatBacklog.Add(chatMessage.Value);
                }

                GameUtility.PlayTaunt(chatMessage.Value);

                Assets.PlaySound("Bubble.wav");
                break;
            }

            default:
                Console.WriteLine("Unhandled packet!");
                break;
            }
        }