Esempio n. 1
0
        private DataManager()
        {
            DictionaryListHelper <string, SpellData> helper = new DictionaryListHelper <string, SpellData>();
            var spellList = new List <SpellData>();

            ConfigUtil.ReadList(@"data\spells.txt").ForEach(line =>
            {
                try
                {
                    var spellData = TextFormatUtils.ParseCustomSpellData(line);
                    if (spellData != null)
                    {
                        spellList.Add(spellData);
                        SpellsNameDB[spellData.Name] = spellData;

                        if (!SpellsAbbrvDB.ContainsKey(spellData.NameAbbrv))
                        {
                            SpellsAbbrvDB[spellData.NameAbbrv] = spellData;
                        }
                        else if (string.Compare(SpellsAbbrvDB[spellData.NameAbbrv].Name, spellData.Name, true, CultureInfo.CurrentCulture) < 0)
                        {
                            // try to keep the newest version
                            SpellsAbbrvDB[spellData.NameAbbrv] = spellData;
                        }

                        if (spellData.LandsOnOther.StartsWith("'s ", StringComparison.Ordinal))
                        {
                            spellData.LandsOnOther = spellData.LandsOnOther.Substring(3);
                            helper.AddToList(PosessiveLandsOnOthers, spellData.LandsOnOther, spellData);
                        }
                        else if (spellData.LandsOnOther.Length > 1)
                        {
                            spellData.LandsOnOther = spellData.LandsOnOther.Substring(1);
                            helper.AddToList(NonPosessiveLandsOnOthers, spellData.LandsOnOther, spellData);
                        }

                        if (spellData.LandsOnYou.Length > 0) // just do stuff in common
                        {
                            helper.AddToList(LandsOnYou, spellData.LandsOnYou, spellData);
                        }
                    }
                }
                catch (OverflowException ex)
                {
                    LOG.Error("Error reading spell data", ex);
                }
            });

            // sort by duration for the timeline to pick better options
            foreach (var key in NonPosessiveLandsOnOthers.Keys)
            {
                NonPosessiveLandsOnOthers[key].Sort((a, b) =>
                {
                    int result = b.Duration.CompareTo(a.Duration);
                    return(result != 0 ? result : b.ID.CompareTo(a.ID));
                });
            }

            foreach (var key in PosessiveLandsOnOthers.Keys)
            {
                PosessiveLandsOnOthers[key].Sort((a, b) =>
                {
                    int result = b.Duration.CompareTo(a.Duration);
                    return(result != 0 ? result : b.ID.CompareTo(a.ID));
                });
            }

            foreach (var key in LandsOnYou.Keys)
            {
                LandsOnYou[key].Sort((a, b) =>
                {
                    int result = b.Duration.CompareTo(a.Duration);
                    return(result != 0 ? result : b.ID.CompareTo(a.ID));
                });
            }

            Dictionary <string, byte> keepOut = new Dictionary <string, byte>();
            var classEnums = Enum.GetValues(typeof(SpellClass)).Cast <SpellClass>().ToList();

            spellList.ForEach(spell =>
            {
                // exact match meaning class-only spell that are of certain target types
                var tgt = (SpellTarget)spell.Target;
                if ((tgt == SpellTarget.SELF || (spell.Level <= 250 && (tgt == SpellTarget.SINGLETARGET || tgt == SpellTarget.LOS))) && classEnums.Contains((SpellClass)spell.ClassMask))
                {
                    // these need to be unique and keep track if a conflict is found
                    if (SpellsToClass.ContainsKey(spell.Name))
                    {
                        SpellsToClass.Remove(spell.Name);
                        keepOut[spell.Name] = 1;
                    }
                    else if (!keepOut.ContainsKey(spell.Name))
                    {
                        SpellsToClass[spell.Name] = (SpellClass)spell.ClassMask;
                    }
                }
            });

            // load NPCs
            ConfigUtil.ReadList(@"data\npcs.txt").ForEach(line => AllNpcs[line.Trim()] = 1);

            PlayerManager.Instance.EventsNewTakenPetOrPlayerAction += (sender, name) => RemoveFight(name);
            PlayerManager.Instance.EventsNewVerifiedPlayer         += (sender, name) => RemoveFight(name);
            PlayerManager.Instance.EventsNewVerifiedPet            += (sender, name) => RemoveFight(name);
        }
        internal void Display()
        {
            lock (LockObject)
            {
                if (Running == false)
                {
                    Running = true;
                    showSelfOnly.IsEnabled = castTypes.IsEnabled = spellTypes.IsEnabled = false;

                    Task.Delay(50).ContinueWith(task =>
                    {
                        Dispatcher.InvokeAsync(() =>
                        {
                            foreach (var name in UniqueNames.Keys)
                            {
                                var column = new DataGridTextColumn()
                                {
                                    Header  = name,
                                    Width   = DataGridLength.Auto,
                                    Binding = new Binding(name)
                                };

                                var columnStyle = new Style(typeof(TextBlock));
                                columnStyle.Setters.Add(new Setter(TextBlock.ForegroundProperty, new Binding(name)
                                {
                                    Converter = new ReceivedSpellColorConverter()
                                }));
                                column.ElementStyle = columnStyle;
                                dataGrid.Columns.Add(column);
                            }
                        });

                        var allSpells  = new HashSet <ActionBlock>();
                        double maxTime = -1;
                        RaidStats.Ranges.TimeSegments.ForEach(segment =>
                        {
                            maxTime    = maxTime == -1 ? segment.BeginTime + RaidStats.TotalSeconds : maxTime;
                            var blocks = DataManager.Instance.GetCastsDuring(segment.BeginTime - SpellCountBuilder.COUNT_OFFSET, segment.EndTime);
                            blocks.ForEach(block =>
                            {
                                if (RaidStats.MaxTime == RaidStats.TotalSeconds || block.BeginTime <= maxTime)
                                {
                                    allSpells.Add(block);
                                }
                            });
                            blocks = DataManager.Instance.GetReceivedSpellsDuring(segment.BeginTime - SpellCountBuilder.COUNT_OFFSET, segment.EndTime);
                            blocks.ForEach(block =>
                            {
                                if (RaidStats.MaxTime == RaidStats.TotalSeconds || block.BeginTime <= maxTime)
                                {
                                    allSpells.Add(block);
                                }
                            });
                        });

                        var playerSpells = new Dictionary <string, List <string> >();
                        var helper       = new DictionaryListHelper <string, string>();
                        int max          = 0;

                        double lastTime = double.NaN;
                        foreach (var block in allSpells.OrderBy(block => block.BeginTime).ThenBy(block => (block.Actions.Count > 0 && block.Actions[0] is ReceivedSpell) ? 1 : -1))
                        {
                            if (!double.IsNaN(lastTime) && block.BeginTime != lastTime)
                            {
                                AddRow(playerSpells, max, lastTime);
                                playerSpells.Clear();
                                max = 0;
                            }

                            if (block.Actions.Count > 0)
                            {
                                int size = 0;
                                if ((CurrentCastType == 0 || CurrentCastType == 1) && block.Actions[0] is SpellCast)
                                {
                                    foreach (var cast in block.Actions.Cast <SpellCast>().Where(cast => IsValid(cast, UniqueNames, cast.Caster, out _)))
                                    {
                                        size = helper.AddToList(playerSpells, cast.Caster, cast.Spell);
                                    }
                                }
                                else if ((CurrentCastType == 0 || CurrentCastType == 2) && block.Actions[0] is ReceivedSpell)
                                {
                                    SpellData replaced = null;
                                    foreach (var received in block.Actions.Cast <ReceivedSpell>().Where(received => IsValid(received, UniqueNames, received.Receiver, out replaced)))
                                    {
                                        if (replaced != null)
                                        {
                                            size = helper.AddToList(playerSpells, received.Receiver, "Received " + replaced.NameAbbrv);
                                        }
                                    }
                                }

                                max = Math.Max(max, size);
                            }

                            lastTime = block.BeginTime;
                        }

                        if (playerSpells.Count > 0 && max > 0)
                        {
                            AddRow(playerSpells, max, lastTime);
                        }

                        Dispatcher.InvokeAsync(() =>
                        {
                            // only enable for current player
                            showSelfOnly.IsEnabled = UniqueNames.ContainsKey(ConfigUtil.PlayerName);
                            castTypes.IsEnabled    = spellTypes.IsEnabled = true;

                            lock (LockObject)
                            {
                                Running = false;
                            }
                        });
                    }, TaskScheduler.Default);
                }
            }
        }
Esempio n. 3
0
        private DataManager()
        {
            DictionaryListHelper <string, SpellData> helper = new DictionaryListHelper <string, SpellData>();
            var spellList = new List <SpellData>();

            // build ranks cache
            Enumerable.Range(1, 9).ToList().ForEach(r => RanksCache[r.ToString(CultureInfo.CurrentCulture)] = "");
            Enumerable.Range(1, 200).ToList().ForEach(r => RanksCache[TextFormatUtils.IntToRoman(r)]        = "");
            RanksCache["Third"]  = "Root";
            RanksCache["Fifth"]  = "Root";
            RanksCache["Octave"] = "Root";

            ConfigUtil.ReadList(@"data\spells.txt").ForEach(line =>
            {
                try
                {
                    var spellData = ParseCustomSpellData(line);
                    if (spellData != null)
                    {
                        spellList.Add(spellData);
                        SpellsNameDB[spellData.Name] = spellData;

                        if (!SpellsAbbrvDB.ContainsKey(spellData.NameAbbrv))
                        {
                            SpellsAbbrvDB[spellData.NameAbbrv] = spellData;
                        }
                        else if (string.Compare(SpellsAbbrvDB[spellData.NameAbbrv].Name, spellData.Name, true, CultureInfo.CurrentCulture) < 0)
                        {
                            // try to keep the newest version
                            SpellsAbbrvDB[spellData.NameAbbrv] = spellData;
                        }

                        if (spellData.LandsOnOther.StartsWith("'s ", StringComparison.Ordinal))
                        {
                            spellData.LandsOnOther = spellData.LandsOnOther.Substring(3);
                            helper.AddToList(PosessiveLandsOnOthers, spellData.LandsOnOther, spellData);
                        }
                        else if (!string.IsNullOrEmpty(spellData.LandsOnOther))
                        {
                            spellData.LandsOnOther = spellData.LandsOnOther.Substring(1);
                            helper.AddToList(NonPosessiveLandsOnOthers, spellData.LandsOnOther, spellData);
                        }

                        if (!string.IsNullOrEmpty(spellData.LandsOnYou)) // just do stuff in common
                        {
                            helper.AddToList(LandsOnYou, spellData.LandsOnYou, spellData);
                        }
                    }
                }
                catch (OverflowException ex)
                {
                    LOG.Error("Error reading spell data", ex);
                }
            });

            // sort by duration for the timeline to pick better options
            NonPosessiveLandsOnOthers.Values.ToList().ForEach(value => value.Sort((a, b) => DurationCompare(a, b)));
            PosessiveLandsOnOthers.Values.ToList().ForEach(value => value.Sort((a, b) => DurationCompare(a, b)));
            LandsOnYou.Values.ToList().ForEach(value => value.Sort((a, b) => DurationCompare(a, b)));

            var keepOut    = new Dictionary <string, byte>();
            var classEnums = Enum.GetValues(typeof(SpellClass)).Cast <SpellClass>().ToList();

            spellList.ForEach(spell =>
            {
                // exact match meaning class-only spell that are of certain target types
                var tgt = (SpellTarget)spell.Target;
                if ((tgt == SpellTarget.SELF || (spell.Level <= 250 && (tgt == SpellTarget.SINGLETARGET || tgt == SpellTarget.LOS))) && classEnums.Contains((SpellClass)spell.ClassMask))
                {
                    // these need to be unique and keep track if a conflict is found
                    if (SpellsToClass.ContainsKey(spell.Name))
                    {
                        SpellsToClass.Remove(spell.Name);
                        keepOut[spell.Name] = 1;
                    }
                    else if (!keepOut.ContainsKey(spell.Name))
                    {
                        SpellsToClass[spell.Name] = (SpellClass)spell.ClassMask;
                    }
                }
            });

            // load NPCs
            ConfigUtil.ReadList(@"data\npcs.txt").ForEach(line => AllNpcs[line.Trim()] = 1);

            // Load Adps
            AdpsKeys.ForEach(adpsKey => AdpsActive[adpsKey] = new Dictionary <string, uint>());
            AdpsKeys.ForEach(adpsKey => AdpsValues[adpsKey] = new Dictionary <string, uint>());

            string key = null;

            foreach (var line in ConfigUtil.ReadList(@"data\adpsMeter.txt"))
            {
                if (!string.IsNullOrEmpty(line) && line.Trim() is string trimmed && trimmed.Length > 0)
                {
                    if (trimmed[0] != '#' && !string.IsNullOrEmpty(key))
                    {
                        if (trimmed.Split('|') is string[] multiple && multiple.Length > 0)
                        {
                            foreach (var spellLine in multiple)
                            {
                                if (spellLine.Split('=') is string[] list && list.Length == 2 && uint.TryParse(list[1], out uint rate))
                                {
                                    if (SpellsAbbrvDB.TryGetValue(list[0], out SpellData spellData) || SpellsNameDB.TryGetValue(list[0], out spellData))
                                    {
                                        AdpsValues[key][spellData.NameAbbrv] = rate;

                                        if (!AdpsWearOff.TryGetValue(spellData.WearOff, out HashSet <SpellData> wearOffList))
                                        {
                                            AdpsWearOff[spellData.WearOff] = new HashSet <SpellData>();
                                        }

                                        AdpsWearOff[spellData.WearOff].Add(spellData);

                                        if (!AdpsLandsOn.TryGetValue(spellData.LandsOnYou, out HashSet <SpellData> landsOnList))
                                        {
                                            AdpsLandsOn[spellData.LandsOnYou] = new HashSet <SpellData>();
                                        }

                                        AdpsLandsOn[spellData.LandsOnYou].Add(spellData);
                                    }
                                }
                            }
                        }
                    }
                    else if (AdpsKeys.Contains(trimmed))
                    {
                        key = trimmed;
                    }
                }
            }

            PlayerManager.Instance.EventsNewTakenPetOrPlayerAction += (sender, name) => RemoveFight(name);
            PlayerManager.Instance.EventsNewVerifiedPlayer         += (sender, name) => RemoveFight(name);
            PlayerManager.Instance.EventsNewVerifiedPet            += (sender, name) => RemoveFight(name);

            int DurationCompare(SpellData a, SpellData b)
            {
                if (b.Duration.CompareTo(a.Duration) is int result && result == 0)
                {
                    if (int.TryParse(a.ID, out int aInt) && int.TryParse(b.ID, out int bInt) && aInt != bInt)
                    {
                        result = aInt > bInt ? -1 : 1;
                    }
                }

                return(result);
            }
        }
Esempio n. 4
0
        internal void Display()
        {
            lock (LockObject)
            {
                if (Running == false)
                {
                    Running = true;
                    showSelfOnly.IsEnabled = castTypes.IsEnabled = spellTypes.IsEnabled = false;

                    Task.Delay(50).ContinueWith(task =>
                    {
                        Dispatcher.InvokeAsync(() =>
                        {
                            foreach (var name in UniqueNames.Keys)
                            {
                                var column = new DataGridTextColumn()
                                {
                                    Header  = name,
                                    Width   = DataGridLength.Auto,
                                    Binding = new Binding(name)
                                };

                                var columnStyle = new Style(typeof(TextBlock));
                                columnStyle.Setters.Add(new Setter(TextBlock.ForegroundProperty, new Binding(name)
                                {
                                    Converter = new ReceivedSpellColorConverter()
                                }));
                                column.ElementStyle = columnStyle;
                                dataGrid.Columns.Add(column);
                            }
                        });

                        var allSpells    = new HashSet <TimedAction>();
                        var startTime    = SpellCountBuilder.QuerySpellBlocks(RaidStats, allSpells);
                        var playerSpells = new Dictionary <string, List <string> >();
                        var helper       = new DictionaryListHelper <string, string>();
                        int max          = 0;

                        double lastTime = double.NaN;
                        foreach (var action in allSpells.OrderBy(action => action.BeginTime).ThenBy(action => (action is ReceivedSpell) ? 1 : -1))
                        {
                            if (!double.IsNaN(lastTime) && action.BeginTime != lastTime)
                            {
                                AddRow(playerSpells, max, lastTime, startTime);
                                playerSpells.Clear();
                                max = 0;
                            }

                            int size = 0;
                            if ((CurrentCastType == 0 || CurrentCastType == 1) && action is SpellCast)
                            {
                                if (action is SpellCast cast && !cast.Interrupted && IsValid(cast, UniqueNames, cast.Caster, out _))
                                {
                                    size = helper.AddToList(playerSpells, cast.Caster, cast.Spell);
                                }
                            }
                            else if ((CurrentCastType == 0 || CurrentCastType == 2) && action is ReceivedSpell)
                            {
                                SpellData replaced = null;
                                if (action is ReceivedSpell received && IsValid(received, UniqueNames, received.Receiver, out replaced))
                                {
                                    if (replaced != null)
                                    {
                                        size = helper.AddToList(playerSpells, received.Receiver, "Received " + replaced.NameAbbrv);
                                    }
                                }
                            }

                            max      = Math.Max(max, size);
                            lastTime = action.BeginTime;
                        }

                        if (playerSpells.Count > 0 && max > 0)
                        {
                            AddRow(playerSpells, max, lastTime, startTime);
                        }

                        Dispatcher.InvokeAsync(() =>
                        {
                            // only enable for current player
                            showSelfOnly.IsEnabled = UniqueNames.ContainsKey(ConfigUtil.PlayerName);
                            castTypes.IsEnabled    = spellTypes.IsEnabled = true;

                            lock (LockObject)
                            {
                                Running = false;
                            }
                        });
                    }, TaskScheduler.Default);
                }
            }
        }