Esempio n. 1
0
        public GameMember(PlayerParticipant player, PlayerChampionSelectionDTO selection, TradeContractDTO trade, bool canTrade, int pickTurn) : this(player.SummonerInternalName)
        {
            Name     = player.SummonerName;
            Champion = selection?.ChampionId ?? 0;
            Spell1   = selection?.Spell1Id ?? 0;
            Spell2   = selection?.Spell2Id ?? 0;
            Active   = player.PickTurn == pickTurn;

            switch (trade?.State)
            {
            case null:
                Trade = canTrade ? TradeState.POSSIBLE : TradeState.INVALID;
                break;

            case "PENDING":
                Trade = trade.RequesterInternalSummonerName == player.SummonerInternalName ? TradeState.RECEIVED : TradeState.SENT;
                break;

            case "CANCELED":
                Trade = TradeState.CANCELLED;
                break;

            case "DECLINED":
                Trade = TradeState.POSSIBLE;
                break;

            default:
                Trade = TradeState.INVALID;
                break;
            }
        }
Esempio n. 2
0
        public ChampSelectPlayer(PlayerParticipant player, PlayerChampionSelectionDTO selection) : this()
        {
            if (player.SummonerId == Session.Current.Account.SummonerID)
            {
                Glow.Opacity = 1;
            }

            DisplaySelection(selection);

            NameLabel.Content = player.SummonerName;
            if (string.IsNullOrWhiteSpace(player.SummonerName))
            {
                NameLabel.Visibility = Visibility.Collapsed;
            }
            else
            {
                NameLabel.Visibility = Visibility.Visible;
            }
        }
Esempio n. 3
0
 private void DisplaySelection(PlayerChampionSelectionDTO selection)
 {
     if (selection?.Spell1Id > 0 && selection?.Spell2Id > 0 && selection?.ChampionId > 0)
     {
         ChampImage.Source  = DataDragon.GetChampIconImage(DataDragon.GetChampData(selection.ChampionId)).Load();
         Spell1Image.Source = DataDragon.GetSpellImage(DataDragon.GetSpellData(selection.Spell1Id)).Load();
         Spell2Image.Source = DataDragon.GetSpellImage(DataDragon.GetSpellData(selection.Spell2Id)).Load();
         Unknown.Visibility = Obscure.Visibility = Visibility.Collapsed;
     }
     else if (selection?.Spell1Id > 0 && selection?.Spell2Id > 0)
     {
         Spell1Image.Source = DataDragon.GetSpellImage(DataDragon.GetSpellData(selection.Spell1Id)).Load();
         Spell2Image.Source = DataDragon.GetSpellImage(DataDragon.GetSpellData(selection.Spell2Id)).Load();
         Grid.SetColumnSpan(Unknown, 1);
         Grid.SetColumnSpan(Obscure, 1);
         Unknown.Visibility = Obscure.Visibility = Visibility.Visible;
     }
     else
     {
         Unknown.Visibility = Obscure.Visibility = Visibility.Visible;
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Render individual players
        /// </summary>
        /// <param name="selection">The champion the player has selected</param>
        /// <param name="player">The participant details of the player</param>
        /// <returns></returns>
        internal ChampSelectPlayer RenderPlayer(PlayerChampionSelectionDTO selection, PlayerParticipant player)
        {
            ChampSelectPlayer control = new ChampSelectPlayer();

            //Render champion
            if (selection.ChampionId != 0)
            {
                control.ChampionImage.Source = champions.GetChampion(selection.ChampionId).icon;
            }
            //Render summoner spells
            if (selection.Spell1Id != 0)
            {
                string uriSource = Path.Combine(Client.ExecutingDirectory, "Assets", "spell", SummonerSpell.GetSpellImageName((int)selection.Spell1Id));
                control.SummonerSpell1.Source = Client.GetImage(uriSource);
                uriSource = Path.Combine(Client.ExecutingDirectory, "Assets", "spell", SummonerSpell.GetSpellImageName((int)selection.Spell2Id));
                control.SummonerSpell2.Source = Client.GetImage(uriSource);
            }
            //Set our summoner spells in client
            if (player.SummonerName == Client.LoginPacket.AllSummonerData.Summoner.Name)
            {
                string uriSource = Path.Combine(Client.ExecutingDirectory, "Assets", "spell", SummonerSpell.GetSpellImageName((int)selection.Spell1Id));
                SummonerSpell1Image.Source = Client.GetImage(uriSource);
                uriSource = Path.Combine(Client.ExecutingDirectory, "Assets", "spell", SummonerSpell.GetSpellImageName((int)selection.Spell2Id));
                SummonerSpell2Image.Source = Client.GetImage(uriSource);
                MyChampId = selection.ChampionId;
            }
            //Has locked in
            if (player.PickMode == 2)
            {
                string uriSource = "/LegendaryClient;component/Locked.png";
                control.LockedInIcon.Source = Client.GetImage(uriSource);
            }
            //Make obvious whos pick turn it is
            if (player.PickTurn != LatestDto.PickTurn && (LatestDto.GameState == "CHAMP_SELECT" || LatestDto.GameState == "PRE_CHAMP_SELECT"))
            {
                control.Opacity = 0.5;
            }
            else
            {
                //Full opacity when not picking or banning
                control.Opacity = 1;
            }
            //If trading with this player is possible
            if (CanTradeWith != null && (CanTradeWith.PotentialTraders.Contains(player.SummonerInternalName) || DevMode))
            {
                control.TradeButton.Visibility = System.Windows.Visibility.Visible;
            }
            //If this player is duo/trio/quadra queued with players
            if (player.TeamParticipantId != null && (double)player.TeamParticipantId != 0)
            {
                //Byte hack to get individual hex colors
                byte[] values = BitConverter.GetBytes((double)player.TeamParticipantId);
                if (!BitConverter.IsLittleEndian)
                {
                    Array.Reverse(values);
                }

                byte r = values[2];
                byte b = values[3];
                byte g = values[4];

                System.Drawing.Color myColor = System.Drawing.Color.FromArgb(r, b, g);

                var converter = new System.Windows.Media.BrushConverter();
                var brush     = (Brush)converter.ConvertFromString("#" + myColor.Name);
                control.TeamRectangle.Fill       = brush;
                control.TeamRectangle.Visibility = System.Windows.Visibility.Visible;
            }
            control.LockedInIcon.Visibility = System.Windows.Visibility.Visible;
            control.TradeButton.Tag         = new KeyValuePair <PlayerChampionSelectionDTO, PlayerParticipant>(selection, player);
            control.TradeButton.Click      += TradeButton_Click;
            control.PlayerName.Content      = player.SummonerName;
            return(control);
        }
Esempio n. 5
0
        /// <summary>
        /// Render the post selection grid after locked in
        /// </summary>
        /// <param name="selection">Details of champion you want to render</param>
        internal void RenderLockInGrid(PlayerChampionSelectionDTO selection)
        {
            ChampionSelectListView.Visibility  = Visibility.Hidden;
            AfterChampionSelectGrid.Visibility = Visibility.Visible;

            LockInButton.Content = "Locked In";

            //
            champions Champion = champions.GetChampion(selection.ChampionId);

            SkinSelectListView.Items.Clear();
            AbilityListView.Items.Clear();

            //Render default skin
            ListViewItem item      = new ListViewItem();
            Image        skinImage = new Image();
            string       uriSource = Path.Combine(Client.ExecutingDirectory, "Assets", "champions", Champion.portraitPath);

            skinImage.Source  = Client.GetImage(uriSource);
            skinImage.Width   = 191;
            skinImage.Stretch = Stretch.UniformToFill;
            item.Tag          = "0:" + Champion.id; //Hack
            item.Content      = skinImage;
            SkinSelectListView.Items.Add(item);

            //Render abilities
            List <championAbilities> Abilities = championAbilities.GetAbilities(selection.ChampionId);

            foreach (championAbilities ability in Abilities)
            {
                ChampionAbility championAbility = new ChampionAbility();
                uriSource = Path.Combine(Client.ExecutingDirectory, "Assets", "abilities", ability.iconPath);
                championAbility.AbilityImage.Source     = Client.GetImage(uriSource);
                championAbility.AbilityHotKey.Content   = ability.hotkey;
                championAbility.AbilityName.Content     = ability.name;
                championAbility.AbilityDescription.Text = ability.description;
                championAbility.Width  = 375;
                championAbility.Height = 75;
                AbilityListView.Items.Add(championAbility);
            }

            //Render champions
            foreach (ChampionDTO champ in ChampList)
            {
                if (champ.ChampionId == selection.ChampionId)
                {
                    foreach (ChampionSkinDTO skin in champ.ChampionSkins)
                    {
                        if (skin.Owned)
                        {
                            item              = new ListViewItem();
                            skinImage         = new Image();
                            uriSource         = Path.Combine(Client.ExecutingDirectory, "Assets", "champions", championSkins.GetSkin(skin.SkinId).portraitPath);
                            skinImage.Source  = Client.GetImage(uriSource);
                            skinImage.Width   = 191;
                            skinImage.Stretch = Stretch.UniformToFill;
                            item.Tag          = skin.SkinId;
                            item.Content      = skinImage;
                            SkinSelectListView.Items.Add(item);
                        }
                    }
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Main logic behind Champion Select
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="message"></param>
        private void ChampSelect_OnMessageReceived(object sender, object message)
        {
            if (message.GetType() == typeof(GameDTO))
            {
                #region In Champion Select

                GameDTO ChampDTO = message as GameDTO;
                LatestDto = ChampDTO;
                Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(async() =>
                {
                    //Allow all champions to be selected (reset our modifications)
                    ListViewItem[] ChampionArray = new ListViewItem[ChampionSelectListView.Items.Count];
                    ChampionSelectListView.Items.CopyTo(ChampionArray, 0);
                    foreach (ListViewItem y in ChampionArray)
                    {
                        y.IsHitTestVisible = true;
                        y.Opacity          = 1;
                    }

                    //Push all teams into one array to save a foreach call (looks messy)
                    List <Participant> AllParticipants = new List <Participant>(ChampDTO.TeamOne.ToArray());
                    AllParticipants.AddRange(ChampDTO.TeamTwo);
                    foreach (Participant p in AllParticipants)
                    {
                        if (p is PlayerParticipant)
                        {
                            PlayerParticipant play = (PlayerParticipant)p;
                            //If it is our turn to pick
                            if (play.PickTurn == ChampDTO.PickTurn)
                            {
                                if (play.SummonerId == Client.LoginPacket.AllSummonerData.Summoner.SumId)
                                {
                                    ChampionSelectListView.IsHitTestVisible = true;
                                    ChampionSelectListView.Opacity          = 1;
                                    GameStatusLabel.Content = "Your turn to pick!";
                                    break;
                                }
                            }
                        }
                        //Otherwise block selection of champions unless in dev mode
                        if (!DevMode)
                        {
                            ChampionSelectListView.IsHitTestVisible = false;
                            ChampionSelectListView.Opacity          = 0.5;
                        }
                        GameStatusLabel.Content = "Waiting for others to pick...";
                    }

                    //Champion select was cancelled
                    if (ChampDTO.GameState == "TEAM_SELECT")
                    {
                        if (CountdownTimer != null)
                        {
                            CountdownTimer.Stop();
                        }
                        FixChampSelect();
                        FakePage fakePage = new FakePage();
                        fakePage.Content  = LobbyContent;
                        Client.SwitchPage(fakePage);
                        return;
                    }
                    else if (ChampDTO.GameState == "PRE_CHAMP_SELECT")
                    {
                        //Banning phase. Enable banning phase and this will render only champions for ban
                        BanningPhase = true;
                        PurpleBansLabel.Visibility   = Visibility.Visible;
                        BlueBansLabel.Visibility     = Visibility.Visible;
                        BlueBanListView.Visibility   = Visibility.Visible;
                        PurpleBanListView.Visibility = Visibility.Visible;
                        GameStatusLabel.Content      = "Bans are on-going";
                        counter = configType.BanTimerDuration - 3;

                        #region Render Bans
                        BlueBanListView.Items.Clear();
                        PurpleBanListView.Items.Clear();
                        foreach (var x in ChampDTO.BannedChampions)
                        {
                            Image champImage  = new Image();
                            champImage.Height = 58;
                            champImage.Width  = 58;
                            champImage.Source = champions.GetChampion(x.ChampionId).icon;
                            if (x.TeamId == 100)
                            {
                                BlueBanListView.Items.Add(champImage);
                            }
                            else
                            {
                                PurpleBanListView.Items.Add(champImage);
                            }

                            foreach (ListViewItem y in ChampionArray)
                            {
                                if ((int)y.Tag == x.ChampionId)
                                {
                                    ChampionSelectListView.Items.Remove(y);
                                    //Remove from arrays
                                    foreach (ChampionDTO PlayerChamps in ChampList.ToArray())
                                    {
                                        if (x.ChampionId == PlayerChamps.ChampionId)
                                        {
                                            ChampList.Remove(PlayerChamps);
                                            break;
                                        }
                                    }

                                    foreach (ChampionBanInfoDTO BanChamps in ChampionsForBan.ToArray())
                                    {
                                        if (x.ChampionId == BanChamps.ChampionId)
                                        {
                                            ChampionsForBan.Remove(BanChamps);
                                            break;
                                        }
                                    }
                                }
                            }
                        }

                        #endregion Render Bans
                    }
                    else if (ChampDTO.GameState == "CHAMP_SELECT")
                    {
                        //Picking has started. If pickturn has changed reset timer
                        LastPickTurn = ChampDTO.PickTurn;
                        BanningPhase = false;
                    }
                    else if (ChampDTO.GameState == "POST_CHAMP_SELECT")
                    {
                        //Post game has started. Allow trading
                        CanTradeWith            = await Client.PVPNet.GetPotentialTraders();
                        HasLockedIn             = true;
                        GameStatusLabel.Content = "All players have picked!";
                        if (configType != null)
                        {
                            counter = configType.PostPickTimerDuration - 2;
                        }
                        else
                        {
                            counter = 10;
                        }
                    }
                    else if (ChampDTO.GameState == "START_REQUESTED")
                    {
                        GameStatusLabel.Content = "The game is about to start!";
                        DodgeButton.IsEnabled   = false; //Cannot dodge past this point!
                        counter = 1;
                    }
                    else if (ChampDTO.GameState == "TERMINATED")
                    {
                        //TODO
                    }

                    #region Display players

                    BlueListView.Items.Clear();
                    PurpleListView.Items.Clear();
                    int i           = 0;
                    bool PurpleSide = false;

                    //Aram hack, view other players champions & names (thanks to Andrew)
                    List <PlayerChampionSelectionDTO> OtherPlayers = new List <PlayerChampionSelectionDTO>(ChampDTO.PlayerChampionSelections.ToArray());
                    bool AreWePurpleSide = false;

                    foreach (Participant participant in AllParticipants)
                    {
                        Participant tempParticipant = participant;
                        i++;
                        ChampSelectPlayer control = new ChampSelectPlayer();
                        //Cast AramPlayers as PlayerParticipants. This removes reroll data
                        if (tempParticipant is AramPlayerParticipant)
                        {
                            tempParticipant = new PlayerParticipant(tempParticipant.GetBaseTypedObject());
                        }

                        if (tempParticipant is PlayerParticipant)
                        {
                            PlayerParticipant player   = tempParticipant as PlayerParticipant;
                            control.PlayerName.Content = player.SummonerName;

                            foreach (PlayerChampionSelectionDTO selection in ChampDTO.PlayerChampionSelections)
                            {
                                #region Disable picking selected champs

                                foreach (ListViewItem y in ChampionArray)
                                {
                                    if ((int)y.Tag == selection.ChampionId)
                                    {
                                        y.IsHitTestVisible = false;
                                        y.Opacity          = 0.5;
                                        if (configType != null)
                                        {
                                            if (configType.DuplicatePick)
                                            {
                                                y.IsHitTestVisible = true;
                                                y.Opacity          = 1;
                                            }
                                        }
                                    }
                                }

                                #endregion Disable picking selected champs

                                if (selection.SummonerInternalName == player.SummonerInternalName)
                                {
                                    //Clear our teams champion selection for aram hack
                                    OtherPlayers.Remove(selection);
                                    control = RenderPlayer(selection, player);
                                    //If we have locked in render skin select
                                    if (HasLockedIn && selection.SummonerInternalName == Client.LoginPacket.AllSummonerData.Summoner.InternalName && !DevMode)
                                    {
                                        if (PurpleSide)
                                        {
                                            AreWePurpleSide = true;
                                        }
                                        RenderLockInGrid(selection);
                                        if (player.PointSummary != null)
                                        {
                                            LockInButton.Content = string.Format("Reroll ({0}/{1})", player.PointSummary.CurrentPoints, player.PointSummary.PointsCostToRoll);
                                            if (player.PointSummary.NumberOfRolls > 0)
                                            {
                                                LockInButton.IsEnabled = true;
                                            }
                                            else
                                            {
                                                LockInButton.IsEnabled = false;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        else if (tempParticipant is ObfuscatedParticipant)
                        {
                            control.PlayerName.Content = "Summoner " + i;
                        }
                        else if (tempParticipant is BotParticipant)
                        {
                            BotParticipant bot                   = tempParticipant as BotParticipant;
                            string botChamp                      = bot.SummonerName.Split(' ')[0]; //Why is this internal name rito?
                            champions botSelectedChamp           = champions.GetChampion(botChamp);
                            PlayerParticipant part               = new PlayerParticipant();
                            PlayerChampionSelectionDTO selection = new PlayerChampionSelectionDTO();
                            selection.ChampionId                 = botSelectedChamp.id;
                            part.SummonerName                    = botSelectedChamp.displayName + " bot";
                            control = RenderPlayer(selection, part);
                        }
                        else
                        {
                            control.PlayerName.Content = "Unknown Summoner";
                        }
                        //Display purple side if we have gone through our team
                        if (i > ChampDTO.TeamOne.Count)
                        {
                            i          = 0;
                            PurpleSide = true;
                        }

                        if (!PurpleSide)
                        {
                            BlueListView.Items.Add(control);
                        }
                        else
                        {
                            PurpleListView.Items.Add(control);
                        }
                    }

                    //Do aram hack!
                    if (OtherPlayers.Count > 0)
                    {
                        if (AreWePurpleSide)
                        {
                            BlueListView.Items.Clear();
                        }
                        else
                        {
                            PurpleListView.Items.Clear();
                        }

                        foreach (PlayerChampionSelectionDTO hackSelection in OtherPlayers)
                        {
                            ChampSelectPlayer control = new ChampSelectPlayer();
                            PlayerParticipant player  = new PlayerParticipant();
                            player.SummonerName       = hackSelection.SummonerInternalName;
                            control = RenderPlayer(hackSelection, player);

                            if (AreWePurpleSide)
                            {
                                BlueListView.Items.Add(control);
                            }
                            else
                            {
                                PurpleListView.Items.Add(control);
                            }
                        }
                    }

                    #endregion Display players
                }));

                #endregion In Champion Select
            }
            else if (message.GetType() == typeof(PlayerCredentialsDto))
            {
                #region Launching Game

                PlayerCredentialsDto dto = message as PlayerCredentialsDto;
                Client.CurrentGame = dto;

                if (!HasLaunchedGame)
                {
                    HasLaunchedGame = true;
                    Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                    {
                        if (CountdownTimer != null)
                        {
                            CountdownTimer.Stop();
                        }
                        QuitCurrentGame();
                    }));
                    Client.LaunchGame();
                }

                #endregion Launching Game
            }
            else if (message.GetType() == typeof(TradeContractDTO))
            {
                Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                {
                    TradeContractDTO TradeDTO = message as TradeContractDTO;
                    if (TradeDTO.State == "PENDING")
                    {
                        PlayerTradeControl.Visibility = System.Windows.Visibility.Visible;
                        PlayerTradeControl.Tag        = TradeDTO;
                        PlayerTradeControl.AcceptButton.Visibility = System.Windows.Visibility.Visible;
                        PlayerTradeControl.DeclineButton.Content   = "Decline";

                        champions MyChampion = champions.GetChampion((int)TradeDTO.ResponderChampionId);
                        PlayerTradeControl.MyChampImage.Source  = MyChampion.icon;
                        PlayerTradeControl.MyChampLabel.Content = MyChampion.displayName;
                        champions TheirChampion = champions.GetChampion((int)TradeDTO.RequesterChampionId);
                        PlayerTradeControl.TheirChampImage.Source  = TheirChampion.icon;
                        PlayerTradeControl.TheirChampLabel.Content = TheirChampion.displayName;
                        PlayerTradeControl.RequestLabel.Content    = string.Format("{0} wants to trade!", TradeDTO.RequesterInternalSummonerName);
                    }
                    else if (TradeDTO.State == "CANCELED" || TradeDTO.State == "DECLINED" || TradeDTO.State == "BUSY")
                    {
                        PlayerTradeControl.Visibility = System.Windows.Visibility.Hidden;

                        NotificationPopup pop = new NotificationPopup(ChatSubjects.INVITE_STATUS_CHANGED,
                                                                      string.Format("{0} has {1} this trade", TradeDTO.RequesterInternalSummonerName, TradeDTO.State));

                        if (TradeDTO.State == "BUSY")
                        {
                            pop.NotificationTextBox.Text = string.Format("{0} is currently busy", TradeDTO.RequesterInternalSummonerName);
                        }

                        pop.Height = 200;
                        pop.OkButton.Visibility = System.Windows.Visibility.Visible;
                        pop.HorizontalAlignment = HorizontalAlignment.Right;
                        pop.VerticalAlignment   = VerticalAlignment.Bottom;
                        Client.NotificationGrid.Children.Add(pop);//*/
                    }
                }));
            }
        }
        /// <summary>
        /// Render the post selection grid after locked in
        /// </summary>
        /// <param name="selection">Details of champion you want to render</param>
        internal void RenderLockInGrid(PlayerChampionSelectionDTO selection)
        {
            champions Champion = champions.GetChampion(selection.ChampionId);

            if (Champion == null)
            {
                return;
            }

            ChampionSelectListView.Visibility  = Visibility.Hidden;
            AfterChampionSelectGrid.Visibility = Visibility.Visible;

            LockInButton.Content = "Locked In";

            SkinSelectListView.Items.Clear();
            AbilityListView.Items.Clear();

            //Render default skin
            ListViewItem item      = new ListViewItem();
            Image        skinImage = new Image();
            string       uriSource = Path.Combine(Client.ExecutingDirectory, "Assets", "champions", Champion.portraitPath);

            skinImage.Source  = Client.GetImage(uriSource);
            skinImage.Width   = 191;
            skinImage.Stretch = Stretch.UniformToFill;
            item.Tag          = "0:" + Champion.id; //Hack
            item.Content      = skinImage;
            SkinSelectListView.Items.Add(item);

            //Render abilities
            foreach (Spell ability in Champion.Spells)
            {
                ChampionAbility championAbility = new ChampionAbility();
                championAbility.DataContext = ability;
                uriSource = Path.Combine(Client.ExecutingDirectory, "Assets", "spell", ability.Image);
                championAbility.AbilityImage.Source = Client.GetImage(uriSource);
                championAbility.Width  = 375;
                championAbility.Height = 75;
                AbilityListView.Items.Add(championAbility);
            }

            //Render champions
            foreach (ChampionDTO champ in ChampList)
            {
                if (champ.ChampionId == selection.ChampionId)
                {
                    foreach (ChampionSkinDTO skin in champ.ChampionSkins)
                    {
                        if (skin.Owned)
                        {
                            item              = new ListViewItem();
                            skinImage         = new Image();
                            uriSource         = Path.Combine(Client.ExecutingDirectory, "Assets", "champions", championSkins.GetSkin(skin.SkinId).portraitPath);
                            skinImage.Source  = Client.GetImage(uriSource);
                            skinImage.Width   = 191;
                            skinImage.Stretch = Stretch.UniformToFill;
                            item.Tag          = skin.SkinId;
                            item.Content      = skinImage;
                            SkinSelectListView.Items.Add(item);
                        }
                    }
                }
            }
        }
Esempio n. 8
0
        public ChampSelectPlayer(ObfuscatedParticipant obfusc, PlayerChampionSelectionDTO selection) : this()
        {
            DisplaySelection(selection);

            NameLabel.Visibility = Visibility.Collapsed;
        }