Esempio n. 1
0
        private async void GetGames()
        {
            CustomGameListView.Items.Clear();
            allItems.Clear();
            PracticeGameSearchResult[] Games = await Client.PVPNet.ListAllPracticeGames();

            foreach (PracticeGameSearchResult game in Games)
            {
                GameItem item = new GameItem
                {
                    GameName   = game.Name,
                    GameOwner  = game.Owner.SummonerName,
                    Map        = BaseMap.GetMap(game.GameMapId).DisplayName,
                    Private    = game.PrivateGame.ToString().Replace("True", "Y").Replace("False", ""),
                    Slots      = (game.Team1Count + game.Team2Count) + "/" + game.MaxNumPlayers,
                    Spectators = game.SpectatorCount,
                    Type       = game.GameModeString.Replace("ODIN", "DOMINION"),
                    Id         = game.Id
                };
                if (item.GameName.ToLower().Contains("factions"))
                {
                    CustomGameListView.Items.Add(item);
                    allItems.Add(item);
                }
            }
            LimitGames();
        }
Esempio n. 2
0
        private async void GetGames()
        {
            CustomGameListView.Items.Clear();
            allItems.Clear();
            PracticeGameSearchResult[] games = await RiotCalls.ListAllPracticeGames();

            foreach (GameItem item in games.Select(game => new GameItem
            {
                GameName = game.Name,
                GameOwner = game.Owner.SummonerName,
                Map = BaseMap.GetMap(game.GameMapId).DisplayName,
                Private = game.PrivateGame.ToString().Replace("True", "Y").Replace("False", ""),
                Slots = (game.Team1Count + game.Team2Count) + "/" + game.MaxNumPlayers,
                Spectators = game.SpectatorCount,
                Type = game.GameModeString.Replace("ODIN", "DOMINION"),
                Id = game.Id
            }))
            {
                CustomGameListView.Items.Add(item);
                allItems.Add(item);
            }
            LimitGames();
        }
        public NotificationPopup(ChatSubjects subject, Message Message)
        {
            InitializeComponent();
            Subject     = subject;
            MessageData = Message;
            NotificationTypeLabel.Content = Client.TitleCaseString(Enum.GetName(typeof(ChatSubjects), subject).Replace("_", " "));

            //TODO: Get name from id
            ChatPlayerItem Player = Client.AllPlayers[Message.From.User];

            using (XmlReader reader = XmlReader.Create(new StringReader(Message.Body)))
            {
                while (reader.Read())
                {
                    if (reader.IsStartElement())
                    {
                        #region Parse Popup

                        switch (reader.Name)
                        {
                        case "inviteId":
                            reader.Read();
                            InviteId = Convert.ToInt32(reader.Value);
                            break;

                        case "profileIconId":
                            reader.Read();
                            ProfileIconId = Convert.ToInt32(reader.Value);
                            break;

                        case "gameType":
                            reader.Read();
                            GameType = reader.Value;
                            break;

                        case "mapId":
                            reader.Read();
                            MapId = Convert.ToInt32(reader.Value);
                            break;

                        case "queueId":
                            reader.Read();
                            QueueId = Convert.ToInt32(reader.Value);
                            break;

                        case "gameId":
                            reader.Read();
                            GameId = Convert.ToInt32(reader.Value);
                            break;
                        }

                        #endregion Parse Popup
                    }
                }
            }

            var uriSource = Path.Combine(Client.ExecutingDirectory, "Assets", "profileicon", ProfileIconId + ".png");
            ProfileImage.Source = Client.GetImage(uriSource);

            NotificationTextBox.Text = Player.Username + " has invited you to a game" + Environment.NewLine
                                       + "Hosted on " + BaseMap.GetMap(MapId).DisplayName + Environment.NewLine
                                       + "Game Type: " + Client.TitleCaseString(GameType).Replace("_", " ") + Environment.NewLine;
        }
Esempio n. 4
0
        private void GameLobby_OnMessageReceived(object sender, object message)
        {
            if (message.GetType() == typeof(GameDTO))
            {
                GameDTO dto = message as GameDTO;
                Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(async() =>
                {
                    if (!HasConnectedToChat)
                    {
                        //Run once
                        BaseMap map                  = BaseMap.GetMap(dto.MapId);
                        MapLabel.Content             = map.DisplayName;
                        ModeLabel.Content            = Client.TitleCaseString(dto.GameMode);
                        GameTypeConfigDTO configType = Client.LoginPacket.GameTypeConfigs.Find(x => x.Id == dto.GameTypeConfigId);
                        TypeLabel.Content            = GetGameMode(configType.Id);
                        SizeLabel.Content            = dto.MaxNumPlayers / 2 + "v" + dto.MaxNumPlayers / 2;

                        HasConnectedToChat = true;
                        try
                        {
                            string ObfuscatedName = Client.GetObfuscatedChatroomName(dto.Name.ToLower() + Convert.ToInt32(dto.Id), ChatPrefixes.Arranging_Practice);
                            string JID            = Client.GetChatroomJID(ObfuscatedName, dto.RoomPassword, false);
                            newRoom                    = Client.ConfManager.GetRoom(new jabber.JID(JID));
                            newRoom.Nickname           = Client.LoginPacket.AllSummonerData.Summoner.Name;
                            newRoom.OnRoomMessage     += newRoom_OnRoomMessage;
                            newRoom.OnParticipantJoin += newRoom_OnParticipantJoin;
                            newRoom.Join(dto.RoomPassword);
                        }
                        catch { }
                    }
                    if (dto.GameState == "TEAM_SELECT")
                    {
                        OptomisticLock     = dto.OptimisticLock;
                        LaunchedTeamSelect = false;
                        BlueTeamListView.Items.Clear();
                        PurpleTeamListView.Items.Clear();

                        List <Participant> AllParticipants = new List <Participant>(dto.TeamOne.ToArray());
                        AllParticipants.AddRange(dto.TeamTwo);

                        int i           = 0;
                        bool PurpleSide = false;

                        foreach (Participant playerTeam in AllParticipants)
                        {
                            i++;
                            CustomLobbyPlayer lobbyPlayer = new CustomLobbyPlayer();
                            BotControl botPlayer          = new BotControl();
                            if (playerTeam is PlayerParticipant)
                            {
                                PlayerParticipant player = playerTeam as PlayerParticipant;
                                lobbyPlayer = RenderPlayer(player, dto.OwnerSummary.SummonerId == player.SummonerId);
                                IsOwner     = dto.OwnerSummary.SummonerId == Client.LoginPacket.AllSummonerData.Summoner.SumId;
                                StartGameButton.IsEnabled  = IsOwner;
                                AddBotBlueTeam.IsEnabled   = IsOwner;
                                AddBotPurpleTeam.IsEnabled = IsOwner;

                                if (Client.Whitelist.Count > 0)
                                {
                                    if (!Client.Whitelist.Contains(player.SummonerName.ToLower()))
                                    {
                                        await Client.PVPNet.BanUserFromGame(Client.GameID, player.AccountId);
                                    }
                                }
                            }
                            else if (playerTeam is BotParticipant)
                            {
                                BotParticipant botParticipant = playerTeam as BotParticipant;
                                botPlayer = RenderBot(botParticipant);
                            }

                            if (i > dto.TeamOne.Count)
                            {
                                i          = 0;
                                PurpleSide = true;
                            }

                            if (!PurpleSide)
                            {
                                BlueTeamListView.Items.Add(lobbyPlayer);
                            }
                            else
                            {
                                PurpleTeamListView.Items.Add(lobbyPlayer);
                            }
                        }
                    }
                    else if (dto.GameState == "CHAMP_SELECT" || dto.GameState == "PRE_CHAMP_SELECT")
                    {
                        if (!LaunchedTeamSelect)
                        {
                            Client.ChampSelectDTO  = dto;
                            Client.LastPageContent = Client.Container.Content;
                            Client.SwitchPage(new ChampSelectPage(this));
                            Client.GameStatus = "championSelect";
                            Client.SetChatHover();
                            LaunchedTeamSelect = true;
                        }
                    }
                }));
            }
        }
Esempio n. 5
0
        private void ParseSpectatorGames()
        {
            Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
            {
                try
                {
                    if (GameList == null)
                    {
                        return;
                    }

                    if (GameList.Count <= 0)
                    {
                        return;
                    }

                    BlueBansLabel.Visibility   = Visibility.Hidden;
                    PurpleBansLabel.Visibility = Visibility.Hidden;
                    BlueBanListView.Items.Clear();
                    PurpleBanListView.Items.Clear();
                    BlueListView.Items.Clear();
                    PurpleListView.Items.Clear();
                    int gameId        = 0;
                    object objectGame = GameList[SelectedGame];
                    var spectatorGame = objectGame as Dictionary <string, object>;
                    ImageGrid.Children.Clear();
                    if (spectatorGame != null)
                    {
                        foreach (var pair in spectatorGame)
                        {
                            switch (pair.Key)
                            {
                            case "participants":
                                {
                                    var players = pair.Value as ArrayList;

                                    int i = 0;
                                    foreach (object objectPlayer in players)
                                    {
                                        var playerInfo    = objectPlayer as Dictionary <string, object>;
                                        int teamId        = 100;
                                        int championId    = 0;
                                        int spell1Id      = 0;
                                        int spell2Id      = 0;
                                        string playerName = "";
                                        foreach (var playerPair in playerInfo)
                                        {
                                            switch (playerPair.Key)
                                            {
                                            case "teamId":
                                                teamId = (int)playerPair.Value;
                                                break;

                                            case "championId":
                                                championId = (int)playerPair.Value;
                                                break;

                                            case "summonerName":
                                                playerName = playerPair.Value as string;
                                                break;

                                            case "spell1Id":
                                                spell1Id = (int)playerPair.Value;
                                                break;

                                            case "spell2Id":
                                                spell2Id = (int)playerPair.Value;
                                                break;
                                            }
                                        }
                                        var control = new ChampSelectPlayer
                                        {
                                            ChampionImage = { Source = champions.GetChampion(championId).icon }
                                        };
                                        var uriSource =
                                            new Uri(
                                                Path.Combine(Client.ExecutingDirectory, "Assets", "spell",
                                                             SummonerSpell.GetSpellImageName(spell1Id)), UriKind.Absolute);
                                        control.SummonerSpell1.Source = new BitmapImage(uriSource);
                                        uriSource =
                                            new Uri(
                                                Path.Combine(Client.ExecutingDirectory, "Assets", "spell",
                                                             SummonerSpell.GetSpellImageName(spell2Id)), UriKind.Absolute);
                                        control.SummonerSpell2.Source = new BitmapImage(uriSource);
                                        control.PlayerName.Content    = playerName;

                                        var m = new Image();
                                        Panel.SetZIndex(m, -2); //Put background behind everything
                                        m.Stretch             = Stretch.None;
                                        m.Width               = 100;
                                        m.Opacity             = 0.30;
                                        m.HorizontalAlignment = HorizontalAlignment.Left;
                                        m.VerticalAlignment   = VerticalAlignment.Stretch;
                                        m.Margin              = new Thickness(i++ *100, 0, 0, 0);
                                        var cropRect          = new Rectangle(new Point(100, 0), new Size(100, 560));
                                        var src               =
                                            System.Drawing.Image.FromFile(Path.Combine(Client.ExecutingDirectory,
                                                                                       "Assets",
                                                                                       "champions", champions.GetChampion(championId).portraitPath)) as Bitmap;
                                        var target = new Bitmap(cropRect.Width, cropRect.Height);

                                        using (Graphics g = Graphics.FromImage(target))
                                            g.DrawImage(src, new Rectangle(0, 0, target.Width, target.Height),
                                                        cropRect,
                                                        GraphicsUnit.Pixel);

                                        m.Source = Client.ToWpfBitmap(target);
                                        ImageGrid.Children.Add(m);
                                        if (teamId == 100)
                                        {
                                            BlueListView.Items.Add(control);
                                        }
                                        else
                                        {
                                            PurpleListView.Items.Add(control);
                                        }
                                    }
                                }
                                break;

                            case "gameId":
                                gameId = (int)pair.Value;
                                break;

                            case "mapId":
                                try
                                {
                                    MapLabel.Content = BaseMap.GetMap((int)pair.Value).DisplayName;
                                }
                                catch (Exception e)
                                {
                                    Client.Log(e.Source, "Error");
                                    Client.Log(e.Message, "Error");
                                }
                                break;

                            case "gameLength":
                                {
                                    var seconds = (int)pair.Value;
                                    Client.spectatorTimer.Stop();
                                    Client.spectatorTimer          = new Timer(1000);
                                    Client.spectatorTimer.Elapsed += (s, e) => // Sincerely Idk when to stop it
                                    {
                                        seconds++;
                                        Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                                        {
                                            TimeSpan ts           = TimeSpan.FromSeconds(seconds);
                                            GameTimeLabel.Content = string.Format("{0:D2}:{1:D2} min", ts.Minutes,
                                                                                  ts.Seconds);
                                        }));
                                    };
                                    Client.spectatorTimer.Start();
                                }
                                break;

                            case "bannedChampions":
                                {
                                    //ArrayList players = pair.Value as ArrayList;
                                    //Dictionary<string, object> playerInfo = objectPlayer as Dictionary<string, object>;
                                    //foreach (KeyValuePair<string, object> playerPair in playerInfo)
                                    var keyArray = pair.Value as ArrayList;
                                    if (keyArray.Count > 0)
                                    {
                                        BlueBansLabel.Visibility   = Visibility.Visible;
                                        PurpleBansLabel.Visibility = Visibility.Visible;
                                    }
                                    foreach (Dictionary <string, object> keyArrayP in keyArray)
                                    //Dictionary<string, object> keyArrayP = keyArray as Dictionary<string, object>;
                                    {
                                        int cid    = 0;
                                        int teamId = 100;
                                        foreach (var keyArrayPair in keyArrayP)
                                        {
                                            switch (keyArrayPair.Key)
                                            {
                                            case "championId":
                                                cid = (int)keyArrayPair.Value;
                                                break;

                                            case "teamId":
                                                teamId = (int)keyArrayPair.Value;
                                                break;
                                            }
                                        }
                                        var item       = new ListViewItem();
                                        var champImage = new Image
                                        {
                                            Height = 58,
                                            Width  = 58
                                        };
                                        //temp
                                        try
                                        {
                                            champImage.Source = champions.GetChampion(cid).icon;
                                        }
                                        catch
                                        {
                                        }

                                        item.Content = champImage;
                                        if (teamId == 100)
                                        {
                                            BlueBanListView.Items.Add(item);
                                        }
                                        else
                                        {
                                            PurpleBanListView.Items.Add(item);
                                        }
                                    }
                                }
                                break;
                            }
                        }
                    }

                    try
                    {
                        BaseRegion region = BaseRegion.GetRegion((string)SpectatorComboBox.SelectedValue);
                        string spectatorJson;
                        string url = region.SpectatorLink + "consumer/getGameMetaData/" + region.InternalName + "/" +
                                     gameId + "/token";
                        using (var client = new WebClient())
                            spectatorJson = client.DownloadString(url);

                        var serializer       = new JavaScriptSerializer();
                        var deserializedJson = serializer.Deserialize <Dictionary <string, object> >(spectatorJson);
                        MMRLabel.Content     = "≈" + deserializedJson["interestScore"];
                    }
                    catch
                    {
                        MMRLabel.Content = "N/A";
                    }

                    if (Client.curentlyRecording.Contains(gameId))
                    {
                        RecordButton.IsEnabled = false;
                        RecordButton.Content   = "Recording...";
                    }
                    else
                    {
                        RecordButton.IsEnabled = true;
                        RecordButton.Content   = "Record";
                    }
                }
                catch (Exception e)
                {
                    Client.Log(e.Message);
                }
            }));
        }
        public NotificationPopup(ChatSubjects subject, Message message)
        {
            InitializeComponent();
            _subject     = subject;
            _messageData = message;
            string name = Enum.GetName(typeof(ChatSubjects), subject);

            if (name != null)
            {
                NotificationTypeLabel.Content =
                    Client.TitleCaseString(name.Replace("_", " "));
            }

            //TODO: Get name from id
            if (Client.AllPlayers.ContainsKey(message.From.User))
            {
                ChatPlayerItem player = Client.AllPlayers[message.From.User];
                using (XmlReader reader = XmlReader.Create(new StringReader(message.Body)))
                {
                    while (reader.Read())
                    {
                        if (!reader.IsStartElement())
                        {
                            continue;
                        }

                        #region Parse Popup

                        switch (reader.Name)
                        {
                        case "inviteId":
                            reader.Read();
                            _inviteId = Convert.ToInt32(reader.Value);
                            break;

                        case "profileIconId":
                            reader.Read();
                            _profileIconId = Convert.ToInt32(reader.Value);
                            break;

                        case "gameType":
                            reader.Read();
                            _gameType = reader.Value;
                            break;

                        case "mapId":
                            reader.Read();
                            _mapId = Convert.ToInt32(reader.Value);
                            break;

                        case "queueId":
                            reader.Read();
                            _queueId = Convert.ToInt32(reader.Value);
                            break;

                        case "gameId":
                            reader.Read();
                            _gameId = Convert.ToInt32(reader.Value);
                            break;
                        }

                        #endregion Parse Popup
                    }
                }

                string uriSource = Path.Combine(Client.ExecutingDirectory, "Assets", "profileicon", _profileIconId + ".png");
                ProfileImage.Source = Client.GetImage(uriSource);

                NotificationTextBox.Text = player.Username + " has invited you to a game" + Environment.NewLine
                                           + "Hosted on " + BaseMap.GetMap(_mapId).DisplayName + Environment.NewLine
                                           + "Game Type: " + Client.TitleCaseString(_gameType).Replace("_", " ") +
                                           Environment.NewLine;
            }
        }
Esempio n. 7
0
        private void Lobby_OnMessageReceived(object sender, object message)
        {
            if (message.GetType() != typeof(GameDTO))
            {
                return;
            }

            var dto = message as GameDTO;

            Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(async() =>
            {
                if (!HasConnectedToChat)
                {
                    //Run once
                    BaseMap map                  = BaseMap.GetMap(dto.MapId);
                    MapLabel.Content             = map.DisplayName;
                    ModeLabel.Content            = Client.TitleCaseString(dto.GameMode);
                    GameTypeConfigDTO configType =
                        Client.LoginPacket.GameTypeConfigs.Find(x => x.Id == dto.GameTypeConfigId);
                    TypeLabel.Content = GetGameMode(configType.Id);
                    SizeLabel.Content = dto.MaxNumPlayers / 2 + "v" + dto.MaxNumPlayers / 2;

                    HasConnectedToChat    = true;
                    string obfuscatedName =
                        Client.GetObfuscatedChatroomName(dto.Name.ToLower() + Convert.ToInt64(dto.Id),
                                                         ChatPrefixes.Arranging_Practice);
                    string Jid = Client.GetChatroomJid(obfuscatedName, dto.RoomPassword, false);
                    newRoom    = new MucManager(Client.XmppConnection);
                    Client.XmppConnection.OnMessage  += XmppConnection_OnMessage;
                    Client.XmppConnection.OnPresence += XmppConnection_OnPresence;
                    jid = new Jid(dto.RoomName);
                    newRoom.AcceptDefaultConfiguration(jid);
                    newRoom.JoinRoom(jid, Client.LoginPacket.AllSummonerData.Summoner.Name, dto.RoomPassword);
                }
                switch (dto.GameState)
                {
                case "TEAM_SELECT":
                    {
                        OptomisticLock     = dto.OptimisticLock;
                        LaunchedTeamSelect = false;
                        BlueTeamListView.Items.Clear();
                        PurpleTeamListView.Items.Clear();

                        var allParticipants = new List <Participant>(dto.TeamOne.ToArray());
                        allParticipants.AddRange(dto.TeamTwo);

                        int i           = 0;
                        bool purpleSide = false;

                        foreach (Participant playerTeam in allParticipants)
                        {
                            i++;
                            var lobbyPlayer = new CustomLobbyPlayer();
                            //var botPlayer = new BotControl();
                            if (playerTeam is PlayerParticipant)
                            {
                                var player  = playerTeam as PlayerParticipant;
                                lobbyPlayer = RenderPlayer(player, dto.OwnerSummary.SummonerId == player.SummonerId);
                                ///BotParticipant botParticipant = playerTeam as BotParticipant;
                                //botPlayer = RenderBot(botParticipant);
                                IsOwner = dto.OwnerSummary.SummonerId ==
                                          Client.LoginPacket.AllSummonerData.Summoner.SumId;
                                StartGameButton.IsEnabled = IsOwner;

                                if (Client.Whitelist.Count > 0)
                                {
                                    if (!Client.Whitelist.Contains(player.SummonerName.ToLower()))
                                    {
                                        await RiotCalls.BanUserFromGame(Client.GameID, player.AccountId);
                                    }
                                }
                            }

                            if (i > dto.TeamOne.Count)
                            {
                                i          = 0;
                                purpleSide = true;
                            }

                            if (!purpleSide)
                            {
                                BlueTeamListView.Items.Add(lobbyPlayer);
                            }
                            else
                            {
                                PurpleTeamListView.Items.Add(lobbyPlayer);
                            }
                        }
                    }
                    break;

                case "PRE_CHAMP_SELECT":
                case "CHAMP_SELECT":
                    if (!LaunchedTeamSelect)
                    {
                        Client.ChampSelectDTO  = dto;
                        Client.LastPageContent = Client.Container.Content;
                        Client.SwitchPage(new ChampSelectPage(dto.RoomName, dto.RoomPassword).Load(this));
                        LaunchedTeamSelect = true;
                    }
                    break;
                }
            }));
        }
Esempio n. 8
0
        public NotificationPopup(ChatSubjects subject, agsXMPP.protocol.client.Message message)
        {
            InitializeComponent();
            _subject     = subject;
            _messageData = message;
            var name = Enum.GetName(typeof(ChatSubjects), subject);

            if (name != null)
            {
                NotificationTypeLabel.Content =
                    Client.TitleCaseString(name.Replace("_", " "));
            }

            //TODO: Get name from id
            if (!Client.AllPlayers.ContainsKey(message.From.User))
            {
                return;
            }

            var player = Client.AllPlayers[message.From.User];

            using (var reader = XmlReader.Create(new StringReader(message.Body)))
            {
                while (reader.Read())
                {
                    if (!reader.IsStartElement())
                    {
                        continue;
                    }

                    #region Parse Popup

                    switch (reader.Name)
                    {
                    case "inviteId":
                        reader.Read();
                        _inviteId = Convert.ToInt32(reader.Value);
                        break;

                    case "profileIconId":
                        reader.Read();
                        _profileIconId = Convert.ToInt32(reader.Value);
                        break;

                    case "gameType":
                        reader.Read();
                        _gameType = reader.Value;
                        break;

                    case "mapId":
                        reader.Read();
                        _mapId = Convert.ToInt32(reader.Value);
                        break;

                    case "queueId":
                        reader.Read();
                        _queueId = Convert.ToInt32(reader.Value);
                        break;

                    case "gameId":
                        reader.Read();
                        _gameId = Convert.ToInt32(reader.Value);
                        break;

                    case "teamName":
                        reader.Read();
                        _teamName = reader.Value;
                        break;

                    case "teamId":
                        reader.Read();
                        _teamId = reader.Value;
                        break;

                    case "msgType":
                        reader.Read();
                        _msgType = reader.Value;
                        break;
                    }

                    #endregion Parse Popup
                }
            }

            var UriSource = Path.Combine(Client.ExecutingDirectory, "Assets", "profileicon", _profileIconId + ".png");
            ProfileImage.Source = Client.GetImage(UriSource);

            if (name == "RANKED_TEAM_UPDATE")
            {
                switch (_msgType)
                {
                case "invited":
                    NotificationTextBox.Text = player.Username + " has invited you to a Ranked Team" + Environment.NewLine + "Team Name: " + _teamName + Environment.NewLine;
                    break;

                case "kicked":
                    NotificationTextBox.Text = "You have been kicked from a ranked team " + _teamName + ".";
                    break;

                default:
                    NotificationTextBox.Text = "Unhandled msgType in NotificationPopup: " + _msgType + Environment.NewLine + "Please create an issue on github.";
                    break;
                }
            }
            else
            {
                NotificationTextBox.Text = player.Username + " has invited you to a game" + Environment.NewLine
                                           + "Hosted on " + BaseMap.GetMap(_mapId).DisplayName + Environment.NewLine
                                           + "Game Type: " + Client.TitleCaseString(_gameType).Replace("_", " ") +
                                           Environment.NewLine;
            }

            if (!string.IsNullOrWhiteSpace(_msgType) && _msgType != "invited")
            {
                AcceptButton.Visibility  = Visibility.Hidden;
                DeclineButton.Visibility = Visibility.Hidden;
            }
        }
Esempio n. 9
0
        private void GameLobby_OnMessageReceived(object sender, object message)
        {
            if (message == null)
            {
                return;
            }

            if (message.GetType() != typeof(GameDTO))
            {
                return;
            }

            var dto = message as GameDTO;

            Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(async() =>
            {
                if (!HasConnectedToChat)
                {
                    //Run once
                    BaseMap map                  = BaseMap.GetMap(dto.MapId);
                    MapLabel.Content             = map.DisplayName;
                    ModeLabel.Content            = Client.TitleCaseString(dto.GameMode);
                    GameTypeConfigDTO configType = Client.LoginPacket.GameTypeConfigs.Find(x => x.Id == dto.GameTypeConfigId);
                    TypeLabel.Content            = GetGameMode(configType.Id);
                    SizeLabel.Content            = dto.MaxNumPlayers / 2 + "v" + dto.MaxNumPlayers / 2;

                    HasConnectedToChat = true;
                    try
                    {
                        string obfuscatedName = Client.GetObfuscatedChatroomName(dto.Name.ToLower() + Convert.ToInt32(dto.Id), ChatPrefixes.Arranging_Practice);
                        string jid            = Client.GetChatroomJID(obfuscatedName, dto.RoomPassword, false);
                        newRoom                    = Client.ConfManager.GetRoom(new JID(jid));
                        newRoom.Nickname           = Client.LoginPacket.AllSummonerData.Summoner.Name;
                        newRoom.OnRoomMessage     += newRoom_OnRoomMessage;
                        newRoom.OnParticipantJoin += newRoom_OnParticipantJoin;
                        newRoom.Join(dto.RoomPassword);
                    }
                    catch
                    {
                    }
                }
                switch (dto.GameState)
                {
                case "TEAM_SELECT":
                    {
                        bool isSpectator   = false;
                        OptomisticLock     = dto.OptimisticLock;
                        LaunchedTeamSelect = false;
                        BlueTeamListView.Items.Clear();
                        PurpleTeamListView.Items.Clear();
                        SpectatorListView.Items.Clear();

                        foreach (Participant playerTeam in dto.TeamOne)
                        {
                            if (playerTeam is PlayerParticipant)
                            {
                                var lobbyPlayer            = new CustomLobbyPlayer();
                                var player                 = playerTeam as PlayerParticipant;
                                lobbyPlayer                = RenderPlayer(player, dto.OwnerSummary.SummonerId == player.SummonerId);
                                Client.isOwnerOfGame       = dto.OwnerSummary.SummonerId == Client.LoginPacket.AllSummonerData.Summoner.SumId;
                                StartGameButton.IsEnabled  = Client.isOwnerOfGame;
                                AddBotBlueTeam.IsEnabled   = Client.isOwnerOfGame;
                                AddBotPurpleTeam.IsEnabled = Client.isOwnerOfGame;

                                BlueTeamListView.Items.Add(lobbyPlayer);

                                if (Client.Whitelist.Count <= 0)
                                {
                                    continue;
                                }

                                if (!Client.Whitelist.Contains(player.SummonerName.ToLower()))
                                {
                                    await Client.PVPNet.BanUserFromGame(Client.GameID, player.AccountId);
                                }
                            }
                            else if (playerTeam is BotParticipant)
                            {
                                var botParticipant = playerTeam as BotParticipant;
                                var botPlayer      = new BotControl();
                                botPlayer          = RenderBot(botParticipant);
                                BlueTeamListView.Items.Add(botPlayer);
                            }
                        }
                        foreach (Participant playerTeam in dto.TeamTwo)
                        {
                            if (playerTeam is PlayerParticipant)
                            {
                                var lobbyPlayer            = new CustomLobbyPlayer();
                                var player                 = playerTeam as PlayerParticipant;
                                lobbyPlayer                = RenderPlayer(player, dto.OwnerSummary.SummonerId == player.SummonerId);
                                Client.isOwnerOfGame       = dto.OwnerSummary.SummonerId == Client.LoginPacket.AllSummonerData.Summoner.SumId;
                                StartGameButton.IsEnabled  = Client.isOwnerOfGame;
                                AddBotBlueTeam.IsEnabled   = Client.isOwnerOfGame;
                                AddBotPurpleTeam.IsEnabled = Client.isOwnerOfGame;

                                PurpleTeamListView.Items.Add(lobbyPlayer);

                                if (Client.Whitelist.Count <= 0)
                                {
                                    continue;
                                }

                                if (!Client.Whitelist.Contains(player.SummonerName.ToLower()))
                                {
                                    await Client.PVPNet.BanUserFromGame(Client.GameID, player.AccountId);
                                }
                            }
                            else if (playerTeam is BotParticipant)
                            {
                                var botParticipant = playerTeam as BotParticipant;
                                var botPlayer      = new BotControl();
                                botPlayer          = RenderBot(botParticipant);
                                PurpleTeamListView.Items.Add(botPlayer);
                            }
                        }
                        foreach (GameObserver observer in dto.Observers)
                        {
                            if (observer.SummonerId == Client.LoginPacket.AllSummonerData.Summoner.SumId)
                            {
                                isSpectator = true;
                            }

                            var spectatorItem = new CustomLobbyObserver();

                            spectatorItem = RenderObserver(observer);
                            SpectatorListView.Items.Add(spectatorItem);
                        }
                        if (isSpectator)
                        {
                            AddBotPurpleTeam.Visibility            = Visibility.Hidden;
                            AddBotBlueTeam.Visibility              = Visibility.Hidden;
                            JoinBlueTeamFromSpectator.Visibility   = Visibility.Visible;
                            JoinPurpleTeamFromSpectator.Visibility = Visibility.Visible;
                        }
                        else
                        {
                            AddBotPurpleTeam.Visibility            = Visibility.Visible;
                            AddBotBlueTeam.Visibility              = Visibility.Visible;
                            JoinBlueTeamFromSpectator.Visibility   = Visibility.Hidden;
                            JoinPurpleTeamFromSpectator.Visibility = Visibility.Hidden;
                        }
                    }
                    break;

                case "PRE_CHAMP_SELECT":
                case "CHAMP_SELECT":
                    if (!LaunchedTeamSelect)
                    {
                        Client.ChampSelectDTO  = dto;
                        Client.LastPageContent = Client.Container.Content;
                        Client.SwitchPage(new ChampSelectPage(dto.RoomName, dto.RoomPassword).Load(this));
                        Client.GameStatus = "championSelect";
                        Client.SetChatHover();
                        LaunchedTeamSelect = true;
                    }
                    break;
                }
            }));
        }
Esempio n. 10
0
        private void ParseSpectatorGames()
        {
            if (gameList == null)
            {
                return;
            }
            if (gameList.Count <= 0)
            {
                return;
            }
            BlueBansLabel.Visibility   = Visibility.Hidden;
            PurpleBansLabel.Visibility = Visibility.Hidden;
            BlueBanListView.Items.Clear();
            PurpleBanListView.Items.Clear();
            BlueListView.Items.Clear();
            PurpleListView.Items.Clear();
            int GameId     = 0;
            var objectGame = gameList[SelectedGame];
            Dictionary <string, object> SpectatorGame = objectGame as Dictionary <string, object>;

            ImageGrid.Children.Clear();
            foreach (KeyValuePair <string, object> pair in SpectatorGame)
            {
                if (pair.Key == "participants")
                {
                    ArrayList players = pair.Value as ArrayList;

                    int i = 0;
                    foreach (var objectPlayer in players)
                    {
                        Dictionary <string, object> playerInfo = objectPlayer as Dictionary <string, object>;
                        int    teamId     = 100;
                        int    championId = 0;
                        int    spell1Id   = 0;
                        int    spell2Id   = 0;
                        string PlayerName = "";
                        foreach (KeyValuePair <string, object> playerPair in playerInfo)
                        {
                            if (playerPair.Key == "teamId")
                            {
                                teamId = (int)playerPair.Value;
                            }
                            if (playerPair.Key == "championId")
                            {
                                championId = (int)playerPair.Value;
                            }
                            if (playerPair.Key == "summonerName")
                            {
                                PlayerName = playerPair.Value as string;
                            }
                            if (playerPair.Key == "spell1Id")
                            {
                                spell1Id = (int)playerPair.Value;
                            }
                            if (playerPair.Key == "spell2Id")
                            {
                                spell2Id = (int)playerPair.Value;
                            }
                        }
                        ChampSelectPlayer control = new ChampSelectPlayer();
                        control.ChampionImage.Source = champions.GetChampion(championId).icon;
                        var uriSource = new Uri(Path.Combine(Client.ExecutingDirectory, "Assets", "spell", SummonerSpell.GetSpellImageName(spell1Id)), UriKind.Absolute);
                        control.SummonerSpell1.Source = new BitmapImage(uriSource);
                        uriSource = new Uri(Path.Combine(Client.ExecutingDirectory, "Assets", "spell", SummonerSpell.GetSpellImageName(spell2Id)), UriKind.Absolute);
                        control.SummonerSpell2.Source = new BitmapImage(uriSource);
                        control.PlayerName.Content    = PlayerName;

                        Image m = new Image();
                        Canvas.SetZIndex(m, -2); //Put background behind everything
                        m.Stretch             = Stretch.None;
                        m.Width               = 100;
                        m.Opacity             = 0.30;
                        m.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                        m.VerticalAlignment   = System.Windows.VerticalAlignment.Stretch;
                        m.Margin              = new System.Windows.Thickness(i++ *100, 0, 0, 0);
                        System.Drawing.Rectangle cropRect = new System.Drawing.Rectangle(new System.Drawing.Point(100, 0), new System.Drawing.Size(100, 560));
                        System.Drawing.Bitmap    src      = System.Drawing.Image.FromFile(Path.Combine(Client.ExecutingDirectory, "Assets", "champions", champions.GetChampion(championId).portraitPath)) as System.Drawing.Bitmap;
                        System.Drawing.Bitmap    target   = new System.Drawing.Bitmap(cropRect.Width, cropRect.Height);

                        using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(target))
                        {
                            g.DrawImage(src, new System.Drawing.Rectangle(0, 0, target.Width, target.Height),
                                        cropRect,
                                        System.Drawing.GraphicsUnit.Pixel);
                        }

                        m.Source = Client.ToWpfBitmap(target);
                        ImageGrid.Children.Add(m);

                        if (teamId == 100)
                        {
                            BlueListView.Items.Add(control);
                        }
                        else
                        {
                            PurpleListView.Items.Add(control);
                        }
                    }
                }
                else if (pair.Key == "gameId")
                {
                    GameId = (int)pair.Value;
                }
                else if (pair.Key == "mapId")
                {
                    MapLabel.Content = BaseMap.GetMap((int)pair.Value).DisplayName;
                }
                else if (pair.Key == "gameLength")
                {
                    var seconds = (int)pair.Value;
                    GameTimeLabel.Content = string.Format("{0:D}:{1:00} min", seconds / 60, seconds % 60);
                }
                else if (pair.Key == "bannedChampions")
                {
                    //ArrayList players = pair.Value as ArrayList;
                    //Dictionary<string, object> playerInfo = objectPlayer as Dictionary<string, object>;
                    //foreach (KeyValuePair<string, object> playerPair in playerInfo)
                    ArrayList keyArray = pair.Value as ArrayList;
                    if (keyArray.Count > 0)
                    {
                        BlueBansLabel.Visibility   = Visibility.Visible;
                        PurpleBansLabel.Visibility = Visibility.Visible;
                    }
                    foreach (Dictionary <string, object> keyArrayP in keyArray)
                    //Dictionary<string, object> keyArrayP = keyArray as Dictionary<string, object>;
                    {
                        int cid    = 0;
                        int teamId = 100;
                        foreach (KeyValuePair <string, object> keyArrayPair in keyArrayP)
                        {
                            if (keyArrayPair.Key == "championId")
                            {
                                cid = (int)keyArrayPair.Value;
                            }
                            if (keyArrayPair.Key == "teamId")
                            {
                                teamId = (int)keyArrayPair.Value;
                            }
                        }
                        ListViewItem item       = new ListViewItem();
                        Image        champImage = new Image();
                        champImage.Height = 58;
                        champImage.Width  = 58;
                        //temp
                        try
                        {
                            champImage.Source = champions.GetChampion(cid).icon;
                        }
                        catch { }

                        item.Content = champImage;
                        if (teamId == 100)
                        {
                            BlueBanListView.Items.Add(item);
                        }
                        else
                        {
                            PurpleBanListView.Items.Add(item);
                        }
                    }
                }
            }

            try
            {
                BaseRegion region        = BaseRegion.GetRegion((string)SpectatorComboBox.SelectedValue);
                string     spectatorJSON = "";
                string     url           = region.SpectatorLink + "consumer/getGameMetaData/" + region.InternalName + "/" + GameId + "/token";
                using (WebClient client = new WebClient())
                {
                    spectatorJSON = client.DownloadString(url);
                }
                JavaScriptSerializer        serializer       = new JavaScriptSerializer();
                Dictionary <string, object> deserializedJSON = serializer.Deserialize <Dictionary <string, object> >(spectatorJSON);
                MMRLabel.Content = "≈" + deserializedJSON["interestScore"];
            }
            catch { MMRLabel.Content = "N/A"; }
        }
        public void GotRecentGames(RecentGames result)
        {
            GameStats.Clear();
            result.GameStatistics.Sort((s1, s2) => s2.CreateDate.CompareTo(s1.CreateDate));
            foreach (PlayerGameStats Game in result.GameStatistics)
            {
                Game.QueueType = Client.TitleCaseString(Game.QueueType.Replace("ODIN", "Dominion").Replace("UNRANKED", "").Replace("_5x5", "").Replace("_", " ")).Replace("Aram", "ARAM").Trim();
                MatchStats Match = new MatchStats();

                foreach (RawStat Stat in Game.Statistics)
                {
                    var    type      = typeof(MatchStats);
                    string fieldName = Client.TitleCaseString(Stat.StatType.Replace('_', ' ')).Replace(" ", "");
                    var    f         = type.GetField(fieldName);
                    f.SetValue(Match, Stat.Value);
                }

                Match.Game = Game;

                GameStats.Add(Match);
            }

            Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
            {
                GamesListView.Items.Clear();
                BlueListView.Items.Clear();
                ItemsListView.Items.Clear();
                PurpleListView.Items.Clear();
                GameStatsListView.Items.Clear();
                foreach (MatchStats stats in GameStats)
                {
                    RecentGameOverview item        = new RecentGameOverview();
                    champions GameChamp            = champions.GetChampion((int)Math.Round(stats.Game.ChampionId));
                    item.ChampionImage.Source      = GameChamp.icon;
                    item.ChampionNameLabel.Content = GameChamp.displayName;
                    item.ScoreLabel.Content        =
                        string.Format("{0}/{1}/{2} ({3})",
                                      stats.ChampionsKilled,
                                      stats.NumDeaths,
                                      stats.Assists,
                                      stats.Game.QueueType);

                    item.MapLabel.Content      = BaseMap.GetMap(stats.Game.GameMapId).DisplayName;
                    item.DateLabel.Content     = stats.Game.CreateDate;
                    item.IPEarnedLabel.Content = "+" + stats.Game.IpEarned + " IP";
                    item.PingLabel.Content     = stats.Game.UserServerPing + "ms";

                    BrushConverter bc = new BrushConverter();
                    Brush brush       = (Brush)bc.ConvertFrom("#FF609E74");

                    if (stats.Lose == 1)
                    {
                        brush = (Brush)bc.ConvertFrom("#FF9E6060");
                    }

                    item.GridView.Background = brush;
                    item.GridView.Width      = 250;
                    GamesListView.Items.Add(item);
                }
            }));
        }