Пример #1
0
 /// <summary>
 /// Visually adds rune to skill (move from backpack to runes' slot)
 /// </summary>
 /// <param name="rune"></param>
 /// <param name="powerSNOId"></param>
 /// <param name="skillIndex"></param>
 public void SetRune(Item rune, int powerSNOId, int skillIndex)
 {
     if ((skillIndex < 0) || (skillIndex > 5))
     {
         return;
     }
     if (rune == null)
     {
         _skillSocketRunes[skillIndex] = 0;
         return;
     }
     if (_inventoryGrid.Items.ContainsKey(rune.DynamicID))
     {
         _inventoryGrid.RemoveItem(rune);
     }
     else
     {
         // unattuned rune changes to attuned w/o getting into inventory
         rune.World.Leave(rune);
         rune.Reveal(_owner);
     }
     _equipment.Items.Add(rune.DynamicID, rune);
     _skillSocketRunes[skillIndex] = rune.DynamicID;
     // will set only one of these to rank
     _owner.Attributes[GameAttribute.Rune_A, powerSNOId] = rune.Attributes[GameAttribute.Rune_A];
     _owner.Attributes[GameAttribute.Rune_B, powerSNOId] = rune.Attributes[GameAttribute.Rune_B];
     _owner.Attributes[GameAttribute.Rune_C, powerSNOId] = rune.Attributes[GameAttribute.Rune_C];
     _owner.Attributes[GameAttribute.Rune_D, powerSNOId] = rune.Attributes[GameAttribute.Rune_D];
     _owner.Attributes[GameAttribute.Rune_E, powerSNOId] = rune.Attributes[GameAttribute.Rune_E];
     // position of rune is read from mpq as INDEX of skill in skill kit - loaded in helper /xsochor
     rune.SetInventoryLocation(15, RuneHelper.GetRuneIndexForPower(powerSNOId), 0);
 }
Пример #2
0
        public Rune(string id, string firstValue, string secondValue, string thirdValue)
        {
            RuneId = id;

            RuneJson staticData = RuneHelper.GetRune(id);

            RuneName     = staticData.Name;
            Descriptions = new List <string>();
            for (int i = 0; i < staticData.EndOfGameStatDescs.Count; i++)
            {
                Descriptions.Add(RuneHelper.FillInDescriptions(staticData.EndOfGameStatDescs[i], firstValue, secondValue, thirdValue));
            }

            Value0 = int.TryParse(firstValue, out int parsedValue0) ? parsedValue0 : 0;
            Value1 = int.TryParse(secondValue, out int parsedValue1) ? parsedValue1 : 0;
            Value2 = int.TryParse(thirdValue, out int parsedValue2) ? parsedValue2 : 0;
        }
Пример #3
0
        private async void Application_Startup(object sender, StartupEventArgs e)
        {
            CreateCommonObjects();

            // Apply appearence theme
            ApplyThemeSetting();

            // Apply language setting
            LanguageHelper.SetProgramLanguage(_settingsManager.Settings.ProgramLanguage);

            // Load data
            RuneHelper.LoadRunes(_settingsManager.Settings.ProgramLanguage);

#if DEBUG
            _log.Error("Debug mode, writing log");
#endif

            if (e.Args.Length == 1)
            {
                var selectedFile = e.Args[0];
                // 0 = directly play, 1 = open in replaybook
                if (_settingsManager.Settings.FileAction == Settings.Models.FileAction.Play)
                {
                    StartDialogHost();
                    await _player.PlayReplay(selectedFile).ConfigureAwait(true);

                    Application.Current.Shutdown();
                }
                else if (_settingsManager.Settings.FileAction == Settings.Models.FileAction.Open)
                {
                    StartSingleReplayWindow(selectedFile);
                }
                else
                {
                }
            }
            else
            {
                StartMainWindow();
            }
        }
Пример #4
0
        /// <summary>
        /// Returns the similarity percentage of two <see cref="ReadOnlySpan{char}"/>.
        /// </summary>
        /// <param name="span">The first text instance.</param>
        /// <param name="other">The second text instance.</param>
        /// <param name="comparison">How to compare two chars.</param>
        /// <returns>A number between 0 and 1 that represents a percentage similarity between the two strings.</returns>
        /// <remarks>
        /// If both arguments are empty, 1 will be returned.
        /// </remarks>
        public static double SimilarityTo(this ReadOnlySpan <char> span, ReadOnlySpan <char> other, StringComparison comparison = StringComparison.Ordinal)
        {
            if (span.Length == 0 && other.Length == 0)
            {
                return(1);
            }

            // Runes are still a bit clunky to work with. Since there is no clean way to get the count
            // head of time we need to rent out a buffer using StackList instead of stackalloc-ing
            // directly.

            var textRunes  = new StackList <Rune>(1);
            var otherRunes = new StackList <Rune>(1);

            try
            {
                foreach (var rune in span.EnumerateRunes())
                {
                    textRunes.Append(rune);
                }

                foreach (var rune in other.EnumerateRunes())
                {
                    otherRunes.Append(rune);
                }

                return(RuneHelper.SimilarityTo(ref textRunes, ref otherRunes, comparison));
            }
            finally
            {
                // Intellisense is still giving a false warning about disposal
                // when using is used inline with the declaration, so for now
                // we will wrap in try/finally.
                textRunes.Dispose();
                otherRunes.Dispose();
            }
        }
Пример #5
0
        private async void DownloadImageButton_Click(object sender, RoutedEventArgs e)
        {
            if (!(Application.Current.MainWindow.DataContext is MainWindowViewModel context))
            {
                return;
            }

            // Clear the error text box
            DownloadImageErrorText.Text = String.Empty;

            // What do we download?
            bool downloadChamps = ChampionCheckBox.IsChecked ?? false;
            bool downloadItems  = ItemCheckBox.IsChecked ?? false;
            bool downloadRunes  = RunesCheckBox.IsChecked ?? false;

            // Nothing was selected, do nothing
            if (downloadChamps == false && downloadItems == false && downloadRunes == false)
            {
                DownloadImageErrorText.Text = (string)TryFindResource("WswDownloadNoSelectionError");
                return;
            }

            // Create all the requests we need
            List <RequestBase> requests = new List <RequestBase>();

            if (downloadChamps)
            {
                requests.AddRange(await context.RequestManager.GetAllChampionRequests()
                                  .ConfigureAwait(true));
            }
            if (downloadItems)
            {
                requests.AddRange(await context.RequestManager.GetAllItemRequests()
                                  .ConfigureAwait(true));
            }
            if (downloadRunes)
            {
                requests.AddRange(await context.RequestManager.GetAllRuneRequests(RuneHelper.GetAllRunes())
                                  .ConfigureAwait(true));
            }

            // No requests? nothing to do
            if (requests.Count < 1)
            {
                DownloadImageErrorText.Text = (string)TryFindResource("WswDownloadMissingError");
                return;
            }

            // Disable buttons while download happens
            ItemCheckBox.IsEnabled        = false;
            ChampionCheckBox.IsEnabled    = false;
            DownloadImageButton.IsEnabled = false;
            RunesCheckBox.IsChecked       = false;

            // Make progress elements visible
            DownloadProgressGrid.Visibility = Visibility.Visible;

            DownloadProgressBar.Value   = 0;
            DownloadProgressBar.Minimum = 0;
            DownloadProgressBar.Maximum = requests.Count;

            foreach (var request in requests)
            {
                var response = await context.RequestManager.MakeRequestAsync(request)
                               .ConfigureAwait(true);

                string splitSubstring = response.ResponsePath;
                if (splitSubstring.Length > 50)
                {
                    splitSubstring = response.ResponsePath.Substring(0, 35) + "..." + response.ResponsePath.Substring(response.ResponsePath.Length - 15);
                }

                DownloadProgressText.Text = splitSubstring;

                DownloadProgressBar.Value++;
            }
        }
Пример #6
0
        public async Task LoadRuneThumbnails(ReplayDetail replay)
        {
            _log.Information("Loading/downloading thumbnails for runes...");
            if (replay == null)
            {
                throw new ArgumentNullException(nameof(replay));
            }

            string dataVersion = await RequestManager.GetLatestDataDragonVersionAsync().ConfigureAwait(true);

            List <Rune> allRunes = new List <Rune>();
            List <Task> allTasks = new List <Task>();

            allRunes.AddRange(replay.AllPlayers.Select(x => x.KeystoneRune));
            allRunes.AddRange(replay.AllPlayers.SelectMany(x => x.Runes));
            allRunes.AddRange(replay.AllPlayers.SelectMany(x => x.StatsRunes));

            _log.Information($"Processing {allRunes.Count} rune thumbnail requests");
            foreach (Rune rune in allRunes)
            {
                RuneJson runeData = RuneHelper.GetRune(rune.RuneId);
                // If an item does not exist, set it to nothing!
                if (string.IsNullOrEmpty(runeData.Icon))
                {
                    Application.Current.Dispatcher.Invoke(delegate
                    {
                        rune.OverlayIcon = ResourceTools.GetObjectFromResource <Geometry>("ErrorPathIcon");
                    });
                    // move on to the next rune
                    continue;
                }

                // Set default item image, to be replaced
                Application.Current.Dispatcher.Invoke((Action) delegate
                {
                    rune.OverlayIcon = ResourceTools.GetObjectFromResource <Geometry>("DownloadPathIcon");
                });

                // make requests for images
                allTasks.Add(Task.Run(async() =>
                {
                    ResponseBase response = await RequestManager.MakeRequestAsync(new RuneRequest
                    {
                        DataDragonVersion = dataVersion,
                        RuneKey           = runeData.Key,
                        TargetPath        = runeData.Icon
                    }).ConfigureAwait(true);

                    if (response.IsFaulted)
                    {
                        _log.Warning($"Failed to load image for {(response.Request as RuneRequest).RuneKey}");
                        Application.Current.Dispatcher.Invoke(delegate
                        {
                            rune.OverlayIcon = ResourceTools.GetObjectFromResource <Geometry>("ErrorPathIcon");
                        });
                    }
                    else
                    {
                        if (response.FromCache) // load image from file
                        {
                            Application.Current.Dispatcher.Invoke(delegate
                            {
                                rune.OverlayIcon = null; // hide overlay icons, if any
                                rune.ImageSource = ResourceTools.GetImageSourceFromPath(response.ResponsePath);
                            });
                        }
                        else // load image straight from response if its not cachsed
                        {
                            Application.Current.Dispatcher.Invoke(delegate
                            {
                                rune.OverlayIcon = null; // hide overlay icons, if any
                                rune.ImageSource = response.ResponseBytes.ToBitmapImage();
                            });
                        }
                    }
                }));
            }

            await Task.WhenAll(allTasks).ConfigureAwait(true);
        }
Пример #7
0
        private async void DownloadButton_OnClick(object sender, RoutedEventArgs e)
        {
            if (!(sender is Button))
            {
                return;
            }
            if (!(this.DataContext is WelcomeSetupWindow parent))
            {
                return;
            }
            if (!(parent.DataContext is MainWindowViewModel context))
            {
                return;
            }

            // Clear the error text box
            ErrorText.Text = String.Empty;

            // What do we download?
            bool downloadChamps = ChampionCheckBox.IsChecked ?? false;
            bool downloadItems  = ItemCheckBox.IsChecked ?? false;
            bool downloadRunes  = RunesCheckBox.IsChecked ?? false;

            // Nothing was selected, do nothing
            if (downloadChamps == false && downloadItems == false && downloadRunes == false)
            {
                ErrorText.Text = (string)TryFindResource("WswDownloadNoSelectionError");
                return;
            }

            // Create all the requests we need
            var requests = new List <RequestBase>();

            if (downloadChamps)
            {
                requests.AddRange(await context.RequestManager.GetAllChampionRequests()
                                  .ConfigureAwait(true));
            }
            if (downloadItems)
            {
                requests.AddRange(await context.RequestManager.GetAllItemRequests()
                                  .ConfigureAwait(true));
            }
            if (downloadRunes)
            {
                requests.AddRange(await context.RequestManager.GetAllRuneRequests(RuneHelper.GetAllRunes())
                                  .ConfigureAwait(true));
            }

            // No requests? nothing to do
            if (requests.Count < 1)
            {
                ErrorText.Text = (string)TryFindResource("WswDownloadMissingError");
                return;
            }

            // Disable buttons while download happens
            DownloadButton.IsEnabled   = false;
            ItemCheckBox.IsEnabled     = false;
            ChampionCheckBox.IsEnabled = false;
            RunesCheckBox.IsEnabled    = false;

            NextButton.IsEnabled     = false;
            PreviousButton.IsEnabled = false;
            SkipButton.IsEnabled     = false;

            // Make progress elements visible
            DownloadProgressGrid.Visibility = Visibility.Visible;

            DownloadProgressBar.Value   = 0;
            DownloadProgressBar.Minimum = 0;
            DownloadProgressBar.Maximum = requests.Count;

            foreach (RequestBase request in requests)
            {
                ResponseBase response = await context.RequestManager.MakeRequestAsync(request)
                                        .ConfigureAwait(true);

                DownloadProgressText.Text = response.ResponsePath;

                DownloadProgressBar.Value++;
            }
        }