Inheritance: ObservableObject
Ejemplo n.º 1
0
        int CalculateLinesForSpell(StaffMetadata staff, SpellMetadata spell)
        {
            var originalLines = spell.NumberOfLines;
            var lines         = spell.NumberOfLines;

            foreach (var modifiers in staff.Modifiers)
            {
                if (modifiers.MinThreshold > 0 && originalLines < modifiers.MinThreshold)
                {
                    continue;
                }

                if (modifiers.MaxThreshold > 0 && originalLines > modifiers.MaxThreshold)
                {
                    continue;
                }

                switch (modifiers.Scope)
                {
                case ModifierScope.None:
                    continue;

                case ModifierScope.Single:
                    if (!string.Equals(modifiers.ScopeName, spell.Name, StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }
                    break;

                case ModifierScope.Group:
                    if (!string.Equals(modifiers.ScopeName, spell.GroupName, StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }
                    break;
                }

                switch (modifiers.Action)
                {
                case ModifierAction.Increase:
                    lines += modifiers.Value;
                    break;

                case ModifierAction.Decrease:
                    lines -= modifiers.Value;
                    break;

                case ModifierAction.Set:
                    lines = modifiers.Value;
                    break;
                }
            }

            return(Math.Max(0, lines));
        }
Ejemplo n.º 2
0
        void OnStaffModifiersChanged(StaffMetadata staff, SpellLineModifiers modifiers)
        {
            RecalculateAllSpells(staff);

            var handler = StaffModifiersChanged;

            if (handler != null)
            {
                handler(staff, new SpellLineModifiersEventArgs(modifiers));
            }
        }
Ejemplo n.º 3
0
        public void RecalculateAllSpells(StaffMetadata staff)
        {
            if (staff == null)
            {
                throw new ArgumentNullException("staff");
            }

            var allLines = CalculateLines(staff);

            computedLines[staff.Name] = allLines;
        }
Ejemplo n.º 4
0
        public void CopyTo(StaffMetadata other, bool copyModifiers = true)
        {
            other.Name         = Name;
            other.Level        = Level;
            other.AbilityLevel = AbilityLevel;
            other.Class        = Class;

            if (copyModifiers)
            {
                other.Modifiers = new List <SpellLineModifiers>(Modifiers);
            }
        }
Ejemplo n.º 5
0
        ComputedSpellLines CalculateLines(StaffMetadata staff)
        {
            var staffSpellLines = new ComputedSpellLines();

            foreach (var spell in SpellMetadataManager.Instance.Spells)
            {
                var lines = CalculateLinesForSpell(staff, spell);
                staffSpellLines.SetLines(spell.Name, lines);
            }

            return(staffSpellLines);
        }
Ejemplo n.º 6
0
        public void RecalculateSpell(StaffMetadata staff, SpellMetadata spell)
        {
            ComputedSpellLines allLines = null;
            var lines = CalculateLinesForSpell(staff, spell);

            if (!computedLines.TryGetValue(staff.Name, out allLines))
            {
                allLines = CalculateLines(staff);
                computedLines[staff.Name] = allLines;
            }

            allLines.SetLines(spell.Name, lines);
        }
Ejemplo n.º 7
0
        void OnStaffRemoved(StaffMetadata staff)
        {
            staff.ModifiersAdded   -= staff_ModifiersChanged;
            staff.ModifiersChanged -= staff_ModifiersChanged;
            staff.ModifiersRemoved -= staff_ModifiersChanged;

            var handler = this.StaffRemoved;

            if (handler != null)
            {
                handler(this, new StaffMetadataEventArgs(staff));
            }
        }
Ejemplo n.º 8
0
        public void AddStaff(StaffMetadata staff)
        {
            if (staff == null)
            throw new ArgumentNullException("staff");

              var alreadyExists = staves.ContainsKey(staff.Name);

              staves[staff.Name] = staff;
              RecalculateAllSpells(staff);

              if (alreadyExists)
            OnStaffUpdated(staff);
              else
            OnStaffAdded(staff);
        }
Ejemplo n.º 9
0
        public void AddStaff(StaffMetadata staff)
        {
            if (staff == null)
            {
                throw new ArgumentNullException("staff");
            }

            var alreadyExists = staves.ContainsKey(staff.Name);

            staves[staff.Name] = staff;
            RecalculateAllSpells(staff);

            if (alreadyExists)
            {
                OnStaffUpdated(staff);
            }
            else
            {
                OnStaffAdded(staff);
            }
        }
Ejemplo n.º 10
0
        public bool RenameStaff(string originalName, string newName)
        {
            StaffMetadata      staff = null;
            ComputedSpellLines lines = null;

            var wasStaffFound = staves.TryRemove(originalName, out staff);
            var wasLinesFound = computedLines.TryRemove(originalName, out lines);

            if (wasLinesFound)
            {
                computedLines[newName] = lines;
            }

            if (wasStaffFound)
            {
                OnStaffRemoved(staff);
                staves[newName] = staff;
                OnStaffAdded(staff);
            }

            return(wasStaffFound);
        }
Ejemplo n.º 11
0
        public StaffEditorWindow(StaffMetadata staff, bool isEditMode = true)
            : this()
        {
            nameTextBox.Text = originalName = staff.Name;

              if (staff.AbilityLevel > 0)
              {
            levelUpDown.Value = staff.AbilityLevel;
            isAbilityLevelCheckBox.IsChecked = true;
              }
              else
              {
            levelUpDown.Value = staff.Level;
            isAbilityLevelCheckBox.IsChecked = false;
              }

              SetPlayerClass(staff.Class);

              this.IsEditMode = isEditMode;

              if (isEditMode)
            this.Title = "Edit Staff";
        }
Ejemplo n.º 12
0
        void OnStaffUpdated(StaffMetadata staff)
        {
            staff.ModifiersAdded += staff_ModifiersChanged;
              staff.ModifiersChanged += staff_ModifiersChanged;
              staff.ModifiersRemoved += staff_ModifiersChanged;

              var handler = this.StaffUpdated;

              if (handler != null)
            handler(this, new StaffMetadataEventArgs(staff));
        }
Ejemplo n.º 13
0
        int CalculateLinesForSpell(StaffMetadata staff, SpellMetadata spell)
        {
            var originalLines = spell.NumberOfLines;
              var lines = spell.NumberOfLines;

              foreach (var modifiers in staff.Modifiers)
              {
            if (modifiers.MinThreshold > 0 && originalLines < modifiers.MinThreshold)
              continue;

            if (modifiers.MaxThreshold > 0 && originalLines > modifiers.MaxThreshold)
              continue;

            switch (modifiers.Scope)
            {
              case ModifierScope.None:
            continue;

              case ModifierScope.Single:
            if (!string.Equals(modifiers.ScopeName, spell.Name, StringComparison.OrdinalIgnoreCase))
              continue;
            break;

              case ModifierScope.Group:
            if (!string.Equals(modifiers.ScopeName, spell.GroupName, StringComparison.OrdinalIgnoreCase))
              continue;
            break;
            }

            switch (modifiers.Action)
            {
              case ModifierAction.Increase:
            lines += modifiers.Value;
            break;

              case ModifierAction.Decrease:
            lines -= modifiers.Value;
            break;

              case ModifierAction.Set:
            lines = modifiers.Value;
            break;
            }
              }

              return Math.Max(0, lines);
        }
Ejemplo n.º 14
0
        void OnStaffModifiersChanged(StaffMetadata staff, SpellLineModifiers modifiers)
        {
            RecalculateAllSpells(staff);

              var handler = StaffModifiersChanged;

              if (handler != null)
            handler(staff, new SpellLineModifiersEventArgs(modifiers));
        }
Ejemplo n.º 15
0
        public void RecalculateSpell(StaffMetadata staff, SpellMetadata spell)
        {
            ComputedSpellLines allLines = null;
              var lines = CalculateLinesForSpell(staff, spell);

              if (!computedLines.TryGetValue(staff.Name, out allLines))
              {
            allLines = CalculateLines(staff);
            computedLines[staff.Name] = allLines;
              }

              allLines.SetLines(spell.Name, lines);
        }
Ejemplo n.º 16
0
        ComputedSpellLines CalculateLines(StaffMetadata staff)
        {
            var staffSpellLines = new ComputedSpellLines();

              foreach (var spell in SpellMetadataManager.Instance.Spells)
              {
            var lines = CalculateLinesForSpell(staff, spell);
            staffSpellLines.SetLines(spell.Name, lines);
              }

              return staffSpellLines;
        }
Ejemplo n.º 17
0
        public void RecalculateAllSpells(StaffMetadata staff)
        {
            if (staff == null)
            throw new ArgumentNullException("staff");

              var allLines = CalculateLines(staff);
              computedLines[staff.Name] = allLines;
        }
Ejemplo n.º 18
0
        public StaffMetadata GetBestStaffForSpell(string spellName, out int?numberOfLines, IEnumerable <string> possibleStaves = null, int maximumLevel = 0, int maximumAbilityLevel = 0)
        {
            numberOfLines = null;

            StaffMetadata bestStaff = null;

            spellName = spellName.Trim();

            var spell     = SpellMetadataManager.Instance.GetSpell(spellName);
            int?bestLines = null;

            foreach (var lines in computedLines)
            {
                StaffMetadata staff = null;
                if (!staves.TryGetValue(lines.Key, out staff))
                {
                    continue;
                }

                if (possibleStaves != null && !possibleStaves.Contains(staff.Name, StringComparer.OrdinalIgnoreCase))
                {
                    continue;
                }

                if (staff.Level > maximumLevel || staff.AbilityLevel > maximumAbilityLevel)
                {
                    continue;
                }

                var spellLines = lines.Value.GetLines(spellName);

                if (!spellLines.HasValue)
                {
                    continue;
                }

                if (!bestLines.HasValue)
                {
                    bestStaff = staff;
                    bestLines = spellLines.Value;
                }
                else if (spellLines.Value < bestLines)
                {
                    bestStaff = staff;
                    bestLines = spellLines.Value;
                }
                else if (spellLines.Value == bestLines)
                {
                    if (staff.Level > bestStaff.Level && staff.AbilityLevel > bestStaff.AbilityLevel)
                    {
                        bestStaff = staff;
                    }
                }
            }

            if (spell != null && bestLines.HasValue && bestLines.Value > spell.NumberOfLines)
            {
                numberOfLines = spell.NumberOfLines;
                bestStaff     = StaffMetadata.NoStaff;
            }
            else
            {
                numberOfLines = bestLines;
            }

            return(bestStaff);
        }
Ejemplo n.º 19
0
 public StaffMetadataEventArgs(StaffMetadata staff)
 {
     this.staff = staff;
 }
Ejemplo n.º 20
0
 public StaffMetadataEventArgs(StaffMetadata staff)
 {
     this.staff = staff;
 }
        void EditStaff(StaffMetadata staff)
        {
            var originalName = staff.Name;

              var staffWindow = new StaffEditorWindow(staff);
              staffWindow.Owner = this;

              var result = staffWindow.ShowDialog();
              if (!result.HasValue || !result.Value)
            return;

              staffWindow.Staff.CopyTo(staff, copyModifiers: false);
              BindingOperations.GetBindingExpression(stavesListBox, ListBox.ItemsSourceProperty).UpdateTarget();

              if (!string.Equals(staff.Name, originalName, StringComparison.Ordinal))
            StaffMetadataManager.Instance.RenameStaff(originalName, staff.Name);

              stavesListBox.SelectedItem = staff;
              stavesListBox.ScrollIntoView(staff);
        }
        void EditModifiers(StaffMetadata staff, SpellLineModifiers modifiers)
        {
            var modifiersWindow = new LineModifiersEditorWindow(modifiers);
              modifiersWindow.Owner = this;

              var result = modifiersWindow.ShowDialog();
              if (!result.HasValue || !result.Value)
            return;

              staff.ChangeModifiers(modifiers, modifiersWindow.Modifiers);
              lineModifiersListBox.Items.Refresh();

              lineModifiersListBox.SelectedItem = modifiers;
              lineModifiersListBox.ScrollIntoView(modifiers);
        }
Ejemplo n.º 23
0
        public void CopyTo(StaffMetadata other, bool copyModifiers = true)
        {
            other.Name = Name;
              other.Level = Level;
              other.AbilityLevel = AbilityLevel;
              other.Class = Class;

              if (copyModifiers)
            other.Modifiers = new List<SpellLineModifiers>(Modifiers);
        }