bool SwitchToBestStaff(SpellQueueItem item, out int?numberOfLines, out bool didRequireSwitch)
        {
            didRequireSwitch = false;

            numberOfLines = null;

            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            client.Update(PlayerFieldFlags.Inventory | PlayerFieldFlags.Equipment | PlayerFieldFlags.Stats);

            var equippedStaff = client.Equipment.GetSlot(EquipmentSlot.Weapon);
            var availableList = new List <string>(client.Inventory.ItemNames);

            int?currentNumberOfLines;

            if (equippedStaff != null)
            {
                currentNumberOfLines = StaffMetadataManager.Instance.GetLinesWithStaff(equippedStaff.Name, item.Name);
                availableList.Add(equippedStaff.Name);
            }
            else
            {
                currentNumberOfLines = null;
            }

            var staffToUse = StaffMetadataManager.Instance.GetBestStaffForSpell(item.Name, out numberOfLines, availableList, client.Stats.Level, client.Stats.AbilityLevel);

            if (staffToUse == null)
            {
                return(true);
            }

            if (currentNumberOfLines.HasValue && currentNumberOfLines.Value <= numberOfLines)
            {
                return(true);
            }

            if (string.Equals(staffToUse.Name, "No Staff", StringComparison.OrdinalIgnoreCase))
            {
                SetPlayerStatus(PlayerMacroStatus.Disarming);
                return(client.DisarmAndWait(PanelTimeout));
            }

            SetPlayerStatus(PlayerMacroStatus.SwitchingStaff);

            if (string.Equals(staffToUse.Name, equippedStaff.Name, StringComparison.OrdinalIgnoreCase))
            {
                return(true);
            }

            if (!client.EquipItemAndWait(staffToUse.Name, EquipmentSlot.Weapon, PanelTimeout, out didRequireSwitch))
            {
                return(false);
            }

            return(true);
        }
        void OnSpellRemoved(SpellQueueItem spell)
        {
            var handler = this.SpellRemoved;

            if (handler != null)
            {
                handler(this, new SpellQueueItemEventArgs(spell));
            }
        }
        SpellQueueItem GetFasSpiorad()
        {
            if (fasSpioradQueueItem == null)
            {
                fasSpioradQueueItem = new SpellQueueItem();
                fasSpioradQueueItem.Target.Units = TargetCoordinateUnits.None;
                fasSpioradQueueItem.Name         = Spell.FasSpioradKey;
            }

            return(fasSpioradQueueItem);
        }
        SpellQueueItem GetLyliacPlant(SpellTarget target)
        {
            if (lyliacPlantQueueItem == null)
            {
                lyliacPlantQueueItem      = new SpellQueueItem();
                lyliacPlantQueueItem.Name = Spell.LyliacPlantKey;
            }

            lyliacPlantQueueItem.Target = target;
            return(lyliacPlantQueueItem);
        }
        SpellQueueItem GetLyliacVineyard()
        {
            if (lyliacVineyardQueueItem == null)
            {
                lyliacVineyardQueueItem = new SpellQueueItem();
                lyliacVineyardQueueItem.Target.Units = TargetCoordinateUnits.None;
                lyliacVineyardQueueItem.Name         = Spell.LyliacVineyardKey;
            }

            return(lyliacVineyardQueueItem);
        }
        public bool SpellQueueMoveItemDown(SpellQueueItem item)
        {
            var hasChanges = false;

            lock (spellQueueLock)
                hasChanges = MoveListItemDown(spellQueue, item);

            if (hasChanges)
            {
                RaisePropertyChanged("QueuedSpells");
            }

            return(hasChanges);
        }
        public bool RemoveFromSpellQueue(SpellQueueItem spell)
        {
            var wasRemoved = false;

            lock (spellQueueLock)
                wasRemoved = spellQueue.Remove(spell);

            if (wasRemoved)
            {
                OnSpellRemoved(spell);
            }

            return(wasRemoved);
        }
        public void RemoveFromSpellQueueAtIndex(int index)
        {
            SpellQueueItem spell = null;

            lock (spellQueueLock)
            {
                spell = spellQueue?[index];
                spellQueue.RemoveAt(index);
            }

            if (spell != null)
            {
                OnSpellRemoved(spell);
            }
        }
        public void AddToSpellQueue(SpellQueueItem spell, int index = -1)
        {
            spell.IsUndefined = !SpellMetadataManager.Instance.ContainsSpell(spell.Name);

            lock (spellQueueLock)
                if (index < 0)
                {
                    spellQueue.Add(spell);
                }
                else
                {
                    spellQueue.Insert(index, spell);
                }

            OnSpellAdded(spell);
        }
        public SpellTargetWindow(Spell spell, SpellQueueItem item, bool isEditMode = true)
            : this(spell)
        {
            if (isEditMode)
              {
            this.Title = "Edit Target";
            okButton.Content = "_Save Changes";
              }

              this.SpellQueueItem.Id = item.Id;
              SetTargetForMode(item.Target);

              maxLevelCheckBox.IsChecked = item.HasTargetLevel;

              if (item.HasTargetLevel)
            maxLevelUpDown.Value = item.TargetLevel.Value;

              this.IsEditMode = isEditMode;
        }
        public SpellTargetWindow(Spell spell, SpellQueueItem item, bool isEditMode = true)
            : this(spell)
        {
            if (isEditMode)
            {
                this.Title       = "Edit Target";
                okButton.Content = "_Save Changes";
            }

            this.SpellQueueItem.Id = item.Id;
            SetTargetForMode(item.Target);

            maxLevelCheckBox.IsChecked = item.HasTargetLevel;

            if (item.HasTargetLevel)
            {
                maxLevelUpDown.Value = item.TargetLevel.Value;
            }

            this.IsEditMode = isEditMode;
        }
        bool DoSpellMacro()
        {
            if (this.IsSpellCasting)
            {
                return(false);
            }

            SpellQueueItem nextSpell = null;

            if (ShouldFasSpiorad())
            {
                nextSpell = GetFasSpiorad();
            }
            else
            {
                nextSpell = GetNextSpell();
            }

            if (lastUsedSpellItem != null && lastUsedSpellItem != nextSpell)
            {
                lastUsedSpellItem.IsActive = false;
            }

            if (nextSpell == null)
            {
                this.IsWaitingOnMana = false;
                return(false);
            }

            nextSpell.IsUndefined = !SpellMetadataManager.Instance.ContainsSpell(nextSpell.Name);
            CastSpell(nextSpell);

            lastUsedSpellItem          = nextSpell;
            lastUsedSpellItem.IsActive = true;
            return(true);
        }
Beispiel #13
0
        public void ImportMacroState(Player player, SavedMacroState state)
        {
            if (player == null)
            {
                throw new ArgumentNullException("player");
            }

            if (state == null)
            {
                throw new ArgumentNullException("state");
            }

            var macro = GetMacroState(player);

            if (macro == null)
            {
                return;
            }

            macro.Stop();

            var process = Process.GetCurrentProcess();

            if (player.HasHotkey)
            {
                HotkeyManager.Instance.UnregisterHotkey(process.MainWindowHandle, player.Hotkey);
                player.Hotkey = null;
            }

            player.Skillbook.ClearActiveSkills();
            macro.ClearSpellQueue();
            macro.ClearFlowerQueue();

            player.Update(PlayerFieldFlags.Spellbook);
            macro.UseLyliacVineyard         = player.HasLyliacVineyard && state.UseLyliacVineyard;
            macro.FlowerAlternateCharacters = player.HasLyliacPlant && state.FlowerAlternateCharacters;

            player.Update(PlayerFieldFlags.Skillbook);
            foreach (var skill in state.Skills)
            {
                if (!player.Skillbook.ContainSkill(skill.SkillName))
                {
                    continue;
                }

                player.Skillbook.ToggleActive(skill.SkillName, true);
            }

            foreach (var spell in state.Spells)
            {
                if (!player.Spellbook.ContainSpell(spell.SpellName))
                {
                    continue;
                }

                var spellInfo = player.Spellbook.GetSpell(spell.SpellName);
                if (spellInfo == null)
                {
                    continue;
                }

                var queueItem = new SpellQueueItem(spellInfo, spell);
                macro.AddToSpellQueue(queueItem);
            }

            if (player.HasLyliacPlant)
            {
                foreach (var flower in state.Flowers)
                {
                    if (flower.TargetMode == TargetCoordinateUnits.None)
                    {
                        continue;
                    }

                    var queueItem = new FlowerQueueItem(flower);
                    macro.AddToFlowerQueue(queueItem);
                }
            }

            var windowHandle = Process.GetCurrentProcess().MainWindowHandle;

            if (state.HotkeyKey != Key.None && (state.HotkeyModifiers != ModifierKeys.None || Hotkey.IsFunctionKey(state.HotkeyKey)))
            {
                var hotkey = new Hotkey(state.HotkeyModifiers, state.HotkeyKey);

                if (HotkeyManager.Instance.RegisterHotkey(windowHandle, hotkey))
                {
                    player.Hotkey = hotkey;
                }
            }
        }
Beispiel #14
0
 public SavedSpellState(SpellQueueItem item)
     : this(item.Name, item.Target, item.TargetLevel)
 {
 }
Beispiel #15
0
        public void ImportMacroState(Player player, SavedMacroState state)
        {
            if (player == null)
            throw new ArgumentNullException("player");

              if (state == null)
            throw new ArgumentNullException("state");

              var macro = GetMacroState(player);
              if (macro == null)
            return;

              macro.Stop();

              var process = Process.GetCurrentProcess();

              if (player.HasHotkey)
              {
            HotkeyManager.Instance.UnregisterHotkey(process.MainWindowHandle, player.Hotkey);
            player.Hotkey = null;
              }

              player.Skillbook.ClearActiveSkills();
              macro.ClearSpellQueue();
              macro.ClearFlowerQueue();

              player.Update(PlayerFieldFlags.Spellbook);
              macro.UseLyliacVineyard = player.HasLyliacVineyard && state.UseLyliacVineyard;
              macro.FlowerAlternateCharacters = player.HasLyliacPlant && state.FlowerAlternateCharacters;

              player.Update(PlayerFieldFlags.Skillbook);
              foreach (var skill in state.Skills)
              {
            if (!player.Skillbook.ContainSkill(skill.SkillName))
              continue;

            player.Skillbook.ToggleActive(skill.SkillName, true);
              }

              foreach (var spell in state.Spells)
              {
            if (!player.Spellbook.ContainSpell(spell.SpellName))
              continue;

            var spellInfo = player.Spellbook.GetSpell(spell.SpellName);
            if (spellInfo == null)
              continue;

            var queueItem = new SpellQueueItem(spellInfo, spell);
            macro.AddToSpellQueue(queueItem);
              }

              if (player.HasLyliacPlant)
            foreach (var flower in state.Flowers)
            {
              if (flower.TargetMode == TargetCoordinateUnits.None)
            continue;

              var queueItem = new FlowerQueueItem(flower);
              macro.AddToFlowerQueue(queueItem);
            }

              var windowHandle = Process.GetCurrentProcess().MainWindowHandle;

              if (state.HotkeyKey != Key.None && (state.HotkeyModifiers != ModifierKeys.None || Hotkey.IsFunctionKey(state.HotkeyKey)))
              {
            var hotkey = new Hotkey(state.HotkeyModifiers, state.HotkeyKey);

            if (HotkeyManager.Instance.RegisterHotkey(windowHandle, hotkey))
              player.Hotkey = hotkey;
              }
        }
 public SpellQueueItemEventArgs(SpellQueueItem spell)
 {
     this.spell = spell;
 }
        bool CastSpell(SpellQueueItem item)
        {
            int?modifiedNumberOfLines = null;

            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            var useShiftKey = UserSettingsManager.Instance.Settings.UseShiftForMedeniaPane;

            client.Update(PlayerFieldFlags.Spellbook);
            var spell = client.Spellbook.GetSpell(item.Name);

            if (spell == null)
            {
                return(false);
            }

            item.CurrentLevel = spell.CurrentLevel;
            item.MaximumLevel = spell.MaximumLevel;

            if (spell.IsOnCooldown)
            {
                return(false);
            }

            if (UserSettingsManager.Instance.Settings.RequireManaForSpells)
            {
                client.Update(PlayerFieldFlags.Stats);
                if (spell.ManaCost > client.Stats.CurrentMana)
                {
                    this.IsWaitingOnMana = true;
                    return(false);
                }
                else
                {
                    this.IsWaitingOnMana = false;
                }
            }
            else
            {
                this.IsWaitingOnMana = false;
            }

            bool didRequireSwitch = false;

            if (UserSettingsManager.Instance.Settings.AllowStaffSwitching)
            {
                if (!SwitchToBestStaff(item, out modifiedNumberOfLines, out didRequireSwitch))
                {
                    return(false);
                }

                if (didRequireSwitch)
                {
                    Thread.Sleep(SwitchDelay);
                }
            }

            if (item.Target.Units == TargetCoordinateUnits.Character)
            {
                var alt = PlayerManager.Instance.GetPlayerByName(item.Target.CharacterName);

                if (alt == null || !alt.IsLoggedIn)
                {
                    return(false);
                }

                client.Update(PlayerFieldFlags.Location);
                alt.Update(PlayerFieldFlags.Location);

                if (!client.Location.IsWithinRange(alt.Location))
                {
                    return(false);
                }
            }

            if (!modifiedNumberOfLines.HasValue)
            {
                client.Update(PlayerFieldFlags.Equipment);
                var weapon = client.Equipment.GetSlot(EquipmentSlot.Weapon);

                if (weapon != null)
                {
                    modifiedNumberOfLines = StaffMetadataManager.Instance.GetLinesWithStaff(weapon.Name, item.Name);
                }

                if (!modifiedNumberOfLines.HasValue)
                {
                    modifiedNumberOfLines = spell.NumberOfLines;
                }
            }

            var numberOfLines = modifiedNumberOfLines.Value;

            client.Spellbook.ActiveSpell = spell.Name;

            didRequireSwitch = false;
            if (client.SwitchToPanelAndWait(spell.Panel, PanelTimeout, out didRequireSwitch, useShiftKey))
            {
                if (didRequireSwitch)
                {
                    Thread.Sleep(SwitchDelay);
                }

                client.DoubleClickSlot(spell.Panel, spell.Slot);
                ClickTarget(item.Target);

                var spellCastDuration = CalculateLineDuration(numberOfLines) + TimeSpan.FromMilliseconds(100);
                var now = DateTime.Now;

                this.SpellCastDuration  = spellCastDuration;
                this.SpellCastTimestamp = now;
                item.LastUsedTimestamp  = now;

                client.Spellbook.SetCooldownTimestamp(spell.Name, now.Add(spellCastDuration));
                return(true);
            }

            return(false);
        }