상속: ObservableObject
예제 #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));
        }
예제 #2
0
        void OnStaffModifiersChanged(StaffMetadata staff, SpellLineModifiers modifiers)
        {
            RecalculateAllSpells(staff);

            var handler = StaffModifiersChanged;

            if (handler != null)
            {
                handler(staff, new SpellLineModifiersEventArgs(modifiers));
            }
        }
예제 #3
0
        public void RecalculateAllSpells(StaffMetadata staff)
        {
            if (staff == null)
            {
                throw new ArgumentNullException("staff");
            }

            var allLines = CalculateLines(staff);

            computedLines[staff.Name] = allLines;
        }
예제 #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);
            }
        }
예제 #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);
        }
예제 #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);
        }
예제 #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));
            }
        }
예제 #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);
        }
예제 #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);
            }
        }
예제 #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);
        }
        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";
        }
예제 #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));
        }
예제 #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);
        }
예제 #14
0
        void OnStaffModifiersChanged(StaffMetadata staff, SpellLineModifiers modifiers)
        {
            RecalculateAllSpells(staff);

              var handler = StaffModifiersChanged;

              if (handler != null)
            handler(staff, new SpellLineModifiersEventArgs(modifiers));
        }
예제 #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);
        }
예제 #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;
        }
예제 #17
0
        public void RecalculateAllSpells(StaffMetadata staff)
        {
            if (staff == null)
            throw new ArgumentNullException("staff");

              var allLines = CalculateLines(staff);
              computedLines[staff.Name] = allLines;
        }
예제 #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);
        }
 public StaffMetadataEventArgs(StaffMetadata staff)
 {
     this.staff = staff;
 }
예제 #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);
        }
예제 #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);
        }