public SpellMetadataEventArgs(SpellMetadata spell)
        {
            if (spell == null)
            throw new ArgumentNullException("spell");

              this.spell = spell;
        }
Beispiel #2
0
        void EditSpell(SpellMetadata spell)
        {
            var originalName = spell.Name;

            var spellWindow = new SpellEditorWindow(spell);

            spellWindow.Owner = this;

            var result = spellWindow.ShowDialog();

            if (!result.HasValue || !result.Value)
            {
                return;
            }

            spellWindow.Spell.CopyTo(spell);
            BindingOperations.GetBindingExpression(spellListView, ListView.ItemsSourceProperty).UpdateTarget();

            if (!string.Equals(spell.Name, originalName, StringComparison.Ordinal))
            {
                SpellMetadataManager.Instance.RenameSpell(originalName, spell.Name);
            }

            skillListView.SelectedItem = spell;
            skillListView.ScrollIntoView(spell);
        }
        public void AddSpell(SpellMetadata spell)
        {
            if (spell == null)
            throw new ArgumentNullException("spell");

              string spellName = spell.Name.Trim();
              bool wasUpdated = false;

              if (spells.ContainsKey(spellName))
            wasUpdated = true;

              spells[spellName] = spell;

              if (wasUpdated)
            OnSpellChanged(spell);
              else
            OnSpellAdded(spell);
        }
        public SpellEditorWindow(SpellMetadata spell, bool isEditMode = true)
            : this()
        {
            nameTextBox.Text = originalName = spell.Name;
              groupNameTextBox.Text = spell.GroupName;
              manaUpDown.Value = spell.ManaCost;
              linesUpDown.Value = spell.NumberOfLines;
              cooldownTextBox.Text = spell.Cooldown.ToShortEnglish();
              improveCheckBox.IsChecked = !spell.CanImprove;

              SetPlayerClass(spell.Class);

              this.IsEditMode = isEditMode;

              if (isEditMode)
              {
            this.Title = "Edit Spell";
            okButton.Content = "_Save Changes";
              }
        }
Beispiel #5
0
        public SpellEditorWindow(SpellMetadata spell, bool isEditMode = true)
            : this()
        {
            nameTextBox.Text          = originalName = spell.Name;
            groupNameTextBox.Text     = spell.GroupName;
            manaUpDown.Value          = spell.ManaCost;
            linesUpDown.Value         = spell.NumberOfLines;
            cooldownTextBox.Text      = spell.Cooldown.ToShortEnglish();
            improveCheckBox.IsChecked = !spell.CanImprove;

            SetPlayerClass(spell.Class);

            this.IsEditMode = isEditMode;

            if (isEditMode)
            {
                this.Title       = "Edit Spell";
                okButton.Content = "_Save Changes";
            }
        }
Beispiel #6
0
        public void Update(ProcessMemoryAccessor accessor)
        {
            if (accessor == null)
            {
                throw new ArgumentNullException("accessor");
            }

            var version = Owner.Version;

            if (version == null)
            {
                ResetDefaults();
                return;
            }

            var spellbookVariable = version.GetVariable(SpellbookKey);

            if (spellbookVariable == null)
            {
                ResetDefaults();
                return;
            }

            Debug.WriteLine($"Updating spellbook (pid={accessor.ProcessId})...");

            Stream stream = null;

            try
            {
                stream = accessor.GetStream();
                using (var reader = new BinaryReader(stream, Encoding.ASCII))
                {
                    stream = null;
                    var spellbookPointer = spellbookVariable.DereferenceValue(reader);

                    if (spellbookPointer == 0)
                    {
                        ResetDefaults();
                        return;
                    }

                    reader.BaseStream.Position = spellbookPointer;
                    bool foundFasSpiorad     = false;
                    bool foundLyliacVineyard = false;
                    bool foundLyliacPlant    = false;

                    for (int i = 0; i < spellbookVariable.Count; i++)
                    {
                        SpellMetadata metadata = null;

                        try
                        {
                            bool            hasSpell   = reader.ReadInt16() != 0;
                            ushort          iconIndex  = reader.ReadUInt16();
                            SpellTargetMode targetMode = (SpellTargetMode)reader.ReadByte();
                            string          name       = reader.ReadFixedString(spellbookVariable.MaxLength);
                            string          prompt     = reader.ReadFixedString(spellbookVariable.MaxLength);
                            reader.ReadByte();

                            int currentLevel, maximumLevel;
                            if (!Ability.TryParseLevels(name, out name, out currentLevel, out maximumLevel))
                            {
                                if (!string.IsNullOrWhiteSpace(name))
                                {
                                    spells[i].Name = name.Trim();
                                }
                            }


                            spells[i].IsEmpty      = !hasSpell;
                            spells[i].IconIndex    = iconIndex;
                            spells[i].Icon         = IconManager.Instance.GetSpellIcon(iconIndex);
                            spells[i].TargetMode   = targetMode;
                            spells[i].Name         = name;
                            spells[i].Prompt       = prompt;
                            spells[i].CurrentLevel = currentLevel;
                            spells[i].MaximumLevel = maximumLevel;

                            if (!spells[i].IsEmpty && !string.IsNullOrWhiteSpace(spells[i].Name))
                            {
                                metadata = SpellMetadataManager.Instance.GetSpell(name);
                            }

                            spells[i].IsActive = this.IsActive(spells[i].Name);

                            foundFasSpiorad     |= string.Equals(spells[i].Name, Spell.FasSpioradKey, StringComparison.OrdinalIgnoreCase);
                            foundLyliacPlant    |= string.Equals(spells[i].Name, Spell.LyliacPlantKey, StringComparison.OrdinalIgnoreCase);
                            foundLyliacVineyard |= string.Equals(spells[i].Name, Spell.LyliacVineyardKey, StringComparison.OrdinalIgnoreCase);

                            if (metadata != null)
                            {
                                spells[i].NumberOfLines = metadata.NumberOfLines;
                                spells[i].ManaCost      = metadata.ManaCost;
                                spells[i].Cooldown      = metadata.Cooldown;
                                spells[i].CanImprove    = metadata.CanImprove;

                                DateTime timestamp = DateTime.MinValue;
                                if (spells[i].Cooldown > TimeSpan.Zero && spellCooldownTimestamps.TryGetValue(name, out timestamp))
                                {
                                    var elapsed = DateTime.Now - timestamp;
                                    spells[i].IsOnCooldown = elapsed < (spells[i].Cooldown + TimeSpan.FromMilliseconds(500));
                                }
                            }
                            else
                            {
                                spells[i].NumberOfLines = 1;
                                spells[i].ManaCost      = 0;
                                spells[i].Cooldown      = TimeSpan.Zero;
                                spells[i].CanImprove    = true;
                                spells[i].IsOnCooldown  = false;
                            }

                            if (!spells[i].IsEmpty)
                            {
                                Debug.WriteLine($"Spell slot {i + 1}: {spells[i].Name} (cur={spells[i].CurrentLevel}, max={spells[i].MaximumLevel}, lines={spells[i].NumberOfLines}, icon={spells[i].IconIndex})");
                            }
                        }
                        catch { }
                    }

                    owner.HasFasSpiorad     = foundFasSpiorad;
                    owner.HasLyliacPlant    = foundLyliacPlant;
                    owner.HasLyliacVineyard = foundLyliacVineyard;
                }
            }
            finally { stream?.Dispose(); }
        }
        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);
        }
 public void RecalculateSpellForAllStaves(SpellMetadata spell)
 {
     foreach (var staff in staves.Values)
     RecalculateSpell(staff, spell);
 }
        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);
        }
        void OnSpellRemoved(SpellMetadata spell)
        {
            var handler = this.SpellRemoved;

              if (handler != null)
            handler(this, new SpellMetadataEventArgs(spell));
        }
        void EditSpell(SpellMetadata spell)
        {
            var originalName = spell.Name;

              var spellWindow = new SpellEditorWindow(spell);
              spellWindow.Owner = this;

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

              spellWindow.Spell.CopyTo(spell);
              BindingOperations.GetBindingExpression(spellListView, ListView.ItemsSourceProperty).UpdateTarget();

              if (!string.Equals(spell.Name, originalName, StringComparison.Ordinal))
            SpellMetadataManager.Instance.RenameSpell(originalName, spell.Name);

              skillListView.SelectedItem = spell;
              skillListView.ScrollIntoView(spell);
        }