コード例 #1
0
        private void HandleProxyResponse(LcdsServiceProxyResponse Response)
        {
            Debug.WriteLine(Response.MethodName);
            if (Response.MethodName == "infoRetrievedV1")
            {
                /*
                  TODO: there is alot of info yet to be processed like available champs, skins,
                  demand info (roles/positions) and something called cpr adjustment (no f*****g idea)
                  but it can wait.
                */
                var response = JsonConvert.DeserializeObject<InfoRetrieved>(Response.Payload);
                if (response.initialSpellIds.Length > 0)
                {
                    spell1 = response.initialSpellIds[0];
                    if (response.initialSpellIds.Length > 1)
                        spell2 = response.initialSpellIds[1];

                    Dispatcher.BeginInvoke(DispatcherPriority.Input,
                        new ThreadStart(() => { RenderLegendaryClientPlayerSumSpellIcons(); }));
                }
                if (response.spellIds.Length > 0)
                    availableSpells = response.spellIds.ToList();
            }
            else if (Response.MethodName == "estimatedWaitTimeRetrievedV1")
            {
                //TODO: make use of response.estimatedWaitTime if there is any
                //ReceivedWaitTime response = JsonConvert.DeserializeObject<ReceivedWaitTime>(Response.Payload);
                Dispatcher.BeginInvoke(DispatcherPriority.Input,
                    new ThreadStart(() => { QueueButton.IsEnabled = true; }));
            }
            else if (Response.MethodName == "soloQueryCreatedV1")
            {
                Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                {
                    QueueButton.IsEnabled = false;
                    QueueButton.Content = "Searching for team";
                    TeamPlayer.Role.IsEnabled = false;
                    TeamPlayer.Position.IsEnabled = false;
                    TeamPlayer.SummonerSpell1.IsEnabled = false;
                    TeamPlayer.SummonerSpell2.IsEnabled = false;
                    TeamPlayer.MasteryPage.IsEnabled = false;
                    TeamPlayer.RunePage.IsEnabled = false;
                    TeamPlayer.SelectChampion.IsEnabled = false;
                }));
                inQueueTimer = 0;

                timer = new Timer(1000);
                timer.Elapsed += (object sender, ElapsedEventArgs e) =>
                {
                    inQueueTimer++;
                    Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        TimeSpan ts = TimeSpan.FromSeconds(inQueueTimer);
                        if (Client.inQueueTimer.Visibility == Visibility.Hidden)
                            Client.inQueueTimer.Visibility = Visibility.Visible;
                        Client.inQueueTimer.Content = string.Format("In Queue {0:D2}:{1:D2}", ts.Minutes, ts.Seconds);
                        QueueButton.Content = "Searching for team";
                    }));
                };
                timer.AutoReset = true;
                timer.Start();
            }
            else if (Response.MethodName == "acceptedByGroupV2")
            {
                Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                {
                    timer.Stop();
                    Client.inQueueTimer.Visibility = Visibility.Hidden;
                    TimeLeft = 10;
                    var m = JsonConvert.DeserializeObject<ReceivedGroupId>(Response.Payload);
                    teambuilderCandidateAutoQuitTimeout = m.candidateAutoQuitTimeout;
                    teambuilderGroupId = m.groupId;
                    teambuilderSlotId = m.slotId;
                    MatchFoundGrid.Visibility = Visibility.Visible;

                    TimeLeft = teambuilderCandidateAutoQuitTimeout;

                    CountdownTimer = new Timer(1000);
                    CountdownTimer.Elapsed += QueueElapsed;
                    CountdownTimer.AutoReset = true;
                    CountdownTimer.Start();
                    Client.FocusClient();
                }));
            }
            else if (Response.MethodName == "groupUpdatedV3")
            {
                // pre-match queue team lobby, welcome to the hell of LCDS calls ^^
                // This SHOULD be called only once per matchmade group, but in case its not...
                Debug.WriteLine("groupUpdatedV3 was called");

                CallWithArgs(Guid.NewGuid().ToString(), "cap", "pickSkinV2",
                    "{\"skinId\":" + skinId + ",\"isNewlyPurchasedSkin\":false}");
                var response = JsonConvert.DeserializeObject<GroupUpdate>(Response.Payload);
                Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() => { updateGroup(response); }));
            }
            else if (Response.MethodName == "slotPopulatedV1")
            {
                // New player joined lobby, this is fired AFTER both sides accept the invitation
                // => TODO: show players trying to join lobby (candidateFoundV2)

                // PlayerSlot will do, but this call does NOT use advertisedRole and status properties!
                var response = JsonConvert.DeserializeObject<PlayerSlot>(Response.Payload);
                Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() => { populateSlot(response); }));
            }
            else if (Response.MethodName == "soloSearchedForAnotherGroupV2")
            {
                // Someone left matchmade lobby
                var response = JsonConvert.DeserializeObject<SoloSearchedForAnotherGroupResponse>(Response.Payload);
                if (response.slotId == teambuilderSlotId)
                {
                    //we left the team
                    // TODO: get back to queue
                    Debug.WriteLine("we left/got kicked from team.");
                }
                else
                {
                    Dispatcher.BeginInvoke(DispatcherPriority.Input,
                        new ThreadStart(() => { PlayerListView.Items.RemoveAt(response.slotId); }));
                }
                // for now, need2know what reasons are there
                if (response.reason != "SOLO_INITIATED" && response.reason != "GROUP_DISBANDED")
                    Debug.WriteLine("soloSearchedForAnotherGroupV2 - reason was not SOLO_INITIATED! : " +
                                    response.reason);
            }
            else if (Response.MethodName == "readinessIndicatedV1")
            {
                var response = JsonConvert.DeserializeObject<ReadinesIndicator>(Response.Payload);
                Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                {
                    if (PlayerListView.Items.GetItemAt(response.slotId) is TeamBuilderChoose)
                    {
                        var tbc = PlayerListView.Items.GetItemAt(response.slotId) as TeamBuilderChoose;
                        if (response.ready)
                            tbc.PlayerReadyStatus.Visibility = Visibility.Visible;
                        else
                            tbc.PlayerReadyStatus.Visibility = Visibility.Hidden;
                    }
                    else if (PlayerListView.Items.GetItemAt(response.slotId) is TeamBuilderPlayer)
                    {
                        var tbc = PlayerListView.Items.GetItemAt(response.slotId) as TeamBuilderPlayer;
                        if (response.ready)
                            tbc.PlayerReadyStatus.Visibility = Visibility.Visible;
                        else
                            tbc.PlayerReadyStatus.Visibility = Visibility.Hidden;
                    }
                }));
            }
            else if (Response.MethodName == "matchmakingPhaseStartedV1")
            {
                Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                {
                    ReadyButton.IsEnabled = false;
                    ReadyButton.Content = "Searching for match";
                }));
                inQueueTimer = 0;

                timer = new Timer(1000);
                timer.Elapsed += (object sender, ElapsedEventArgs e) =>
                {
                    inQueueTimer++;
                    Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        TimeSpan ts = TimeSpan.FromSeconds(inQueueTimer);
                        if (Client.inQueueTimer.Visibility == Visibility.Hidden)
                            Client.inQueueTimer.Visibility = Visibility.Visible;
                        Client.inQueueTimer.Content = string.Format("In Queue {0:D2}:{1:D2}", ts.Minutes, ts.Seconds);
                        ReadyButton.Content = "Searching for match";
                    }));
                };
                timer.AutoReset = true;
                timer.Start();
            }
            else if (Response.MethodName == "matchMadeV1")
            {
                Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                {
                    Client.inQueueTimer.Visibility = Visibility.Hidden;
                }));
                timer.Stop();
            }
            else if (Response.MethodName == "removedFromServiceV1")
            {
                // TODO: how about we don't quit teambuilder page each time this thing is called?
                // QuitReason response = JsonConvert.DeserializeObject<QuitReason>(Response.Payload);
                // if (response.reason == "CANDIDATE_DECLINED_GROUP") else if (response.reason == "QUIT")
                Debug.WriteLine("removed from service; no longer listening to calls");

                Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                {
                    Client.inQueueTimer.Visibility = Visibility.Hidden;
                    if (Client.LastPageContent == Content) Client.LastPageContent = null;
                    if (Client.CurrentPage == this)
                    {
                        Client.CurrentPage = null;
                        Client.ReturnButton.Visibility = Visibility.Hidden;
                    }
                }));
                if (CountdownTimer != null)
                    CountdownTimer.Stop();
                if (timer != null)
                    timer.Stop();

                Client.RiotConnection.MessageReceived -= PVPNet_OnMessageReceived;
                Client.GameStatus = "outOfGame";
                Client.SetChatHover();
#pragma warning disable 4014
                RiotCalls.Leave();
#pragma warning restore 4014

                //temp, what other reasons are there?
                var response = JsonConvert.DeserializeObject<QuitReason>(Response.Payload);
                if (response.reason != "CANDIDATE_DECLINED_GROUP" && response.reason != "QUIT")
                    Debug.WriteLine("removedFromServiceV1 - new reason! : " + response.reason);
            }
            else if (Response.MethodName.StartsWith("callFailed"))
            {
                Debug.WriteLine("TeamBuilder error: " + Response.Status);
                Debug.WriteLine("TeamBuilder payload: " + Response.Payload);
            }
        }
コード例 #2
0
 private void parseLcdsMessage(LcdsServiceProxyResponse ProxyResponse)
 {
     if (ProxyResponse.MethodName == "retrieveOnlineFriendsOfFriends")
     {
         Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
         {
             FriendsOfFriendsView.Items.Clear();
             var suggestedFriends = JsonConvert.DeserializeObject<SuggestedFriend[]>(ProxyResponse.Payload);
             foreach (SuggestedFriend s in suggestedFriends)
             {
                 var invitePlayer = new SuggestedPlayerItem();
                 invitePlayer.PlayerLabel.Content = s.summonerName;
                 invitePlayer.InviteButton.Click += async (object obj, RoutedEventArgs e) =>
                 {
                     await RiotCalls.InviteFriendOfFriend(s.summonerId, s.commonFriendId);
                     foreach (SuggestedPlayerItem item in FriendsOfFriendsView.Items)
                     {
                         if ((string)item.PlayerLabel.Content == s.summonerName)
                         {
                             item.InviteButton.IsEnabled = false;
                             item.InviteButton.Content = "Invited";
                             var t = new Timer();
                             t.AutoReset = false;
                             t.Elapsed += (object source, ElapsedEventArgs args) =>
                             {
                                 Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                                 {
                                     item.InviteButton.IsEnabled = true;
                                     item.InviteButton.Content = "Invite";
                                 }));
                             };
                             t.Interval = 5000;
                             t.Start();
                         }
                     }
                 };
                 FriendsOfFriendsView.Items.Add(invitePlayer);
             }
         }));
     }
 }