ReceiveAsync() public method

public ReceiveAsync ( ) : void
return void
Beispiel #1
0
        private void OnGameDataPacketReceived(GameDataPacket packet)
        {
            lock (receiveInProcess)
            {
                if (packet is GameResponse)
                {
                    if (CurrentQuestionState == QuestionState.None)
                    {
                        return;
                    }
                    Game.CurrentGame.HandCardSwitcher.HandleHandCardMovements();
                    var state = CurrentQuestionState;
                    switch (state)
                    {
                    case QuestionState.AskForCardUsage:
                        var response = packet as AskForCardUsageResponse;
                        if (response == null || response.Id != QuestionId)
                        {
                            Gamer.ReceiveAsync();
                            break;
                        }
                        ISkill        skill;
                        List <Card>   cards;
                        List <Player> players;
                        response.ToAnswer(out skill, out cards, out players, PlayerId);
                        CurrentQuestionState = QuestionState.None;
                        AnswerCardUsage(skill, cards, players);
                        break;

                    case QuestionState.AskForCardChoice:
                        var response2 = packet as AskForCardChoiceResponse;
                        if (response2 == null || response2.Id != QuestionId)
                        {
                            Gamer.ReceiveAsync();
                            break;
                        }
                        int opt;
                        var result = response2.ToAnswer(PlayerId, out opt);
                        if (currentChoiceOptions != null)
                        {
                            currentChoiceOptions.OptionResult = opt;
                        }
                        CurrentQuestionState = QuestionState.None;
                        AnswerCardChoice(result);
                        break;

                    case QuestionState.AskForMultipleChoice:
                        var response3 = packet as AskForMultipleChoiceResponse;
                        if (response3 == null || response3.Id != QuestionId)
                        {
                            Gamer.ReceiveAsync();
                            break;
                        }
                        CurrentQuestionState = QuestionState.None;
                        AnswerMultipleChoice(response3.ChoiceIndex);
                        break;
                    }
                }
                else if (packet is CardRearrangementNotification)
                {
                    for (int i = 0; i < Game.CurrentGame.GameServer.MaxClients; i++)
                    {
                        if (i != PlayerId)
                        {
                            Game.CurrentGame.GameServer.SendPacket(i, packet);
                        }
                    }
                }
                else if (packet is HandCardMovementNotification)
                {
                    var notif = packet as HandCardMovementNotification;
                    Game.CurrentGame.HandCardSwitcher.QueueHandCardMovement(notif);
                }
            }
        }