public static bool CanWeCheckAutoCastForAnyOfThese(params string[] spells)
        {
            if (!StyxWoW.Me.GotAlivePet)
            {
                return(false);
            }

            if (spells == null || !spells.Any())
            {
                return(false);
            }

            if (StyxWoW.Me.PetSpells == null)
            {
                return(false);
            }

            HashSet <string> taunt = new HashSet <string>(spells);
            WoWPetSpell      ps    = StyxWoW.Me.PetSpells.FirstOrDefault(s => s.Spell != null && taunt.Contains(s.Spell.Name));

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

            bool allowed;
            bool active = PetManager.IsAutoCast(ps, out allowed);

            if (!allowed)
            {
                return(false);
            }

            return(true);
        }
        public static Composite Buff(string spell, UnitSelectionDelegate onUnit, SimpleBooleanDelegate require, params string[] buffNames)
        {
            return(new Decorator(
                       ret =>
            {
                if (onUnit == null || require == null)
                {
                    return false;
                }

                _buffUnit = onUnit(ret);
                if (_buffUnit == null)
                {
                    return false;
                }

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

                if (Spell.DoubleCastContains(_buffUnit, spell))
                {
                    return false;
                }

                if (!buffNames.Any())
                {
                    return !_buffUnit.HasAura(spell);
                }

                bool buffFound;
                try
                {
                    buffFound = buffNames.Any(b => _buffUnit.HasAura(b));
                }
                catch
                {
                    // mark as found buff, so we return false
                    buffFound = true;
                }

                return !buffFound;
            },
                       new Sequence(
                           // new Action(ctx => _lastBuffCast = name),
                           new Action(r => PetManager.CastPetAction(spell)),
                           new Action(ret => Spell.UpdateDoubleCast(spell, _buffUnit))
                           )
                       ));
        }
        private static bool HandleAutoCastForSpell(string spellName)
        {
            WoWPetSpell ps = StyxWoW.Me.PetSpells.FirstOrDefault(s => s.ToString() == spellName);

            // Disable pet growl in instances but enable it outside.
            if (ps == null)
            {
                Logger.WriteDebug("PetManager: '{0}' is NOT an ability known by this Pet", spellName);
            }
            else
            {
                bool allowed;
                bool active = PetManager.IsAutoCast(ps, out allowed);
                if (!allowed)
                {
                    Logger.Write(LogColor.Hilite, "PetManager: '{0}' is NOT an auto-cast ability for this Pet", spellName);
                }
                else
                {
                    if (SingularRoutine.CurrentWoWContext == WoWContext.Instances)
                    {
                        if (!active)
                        {
                            Logger.Write(LogColor.Hilite, "PetManager: '{0}' Auto-Cast Already Disabled", spellName);
                        }
                        else
                        {
                            Logger.Write(LogColor.Hilite, "PetManager: Disabling '{0}' Auto-Cast", spellName);
                            Lua.DoString("DisableSpellAutocast(GetSpellInfo(" + ps.Spell.Id + "))");
                        }
                    }
                    else
                    {
                        if (active)
                        {
                            Logger.Write(LogColor.Hilite, "PetManager: '{0}' Auto-Cast Already Enabled", spellName);
                        }
                        else
                        {
                            Logger.Write(LogColor.Hilite, "PetManager: Enabling '{0}' Auto-Cast", spellName);
                            Lua.DoString("EnableSpellAutocast(GetSpellInfo(" + ps.Spell.Id + "))");
                        }
                    }

                    return(true);
                }
            }

            return(false);
        }
        public static bool Attack(WoWUnit unit)
        {
            if (unit == null || StyxWoW.Me.Pet == null || !IsPetUseAllowed)
            {
                return(false);
            }

            if (StyxWoW.Me.Pet.CurrentTargetGuid != unit.Guid && (lastPetAttack != unit.Guid || waitNextPetAttack.IsFinished))
            {
                lastPetAttack = unit.Guid;
                if (SingularSettings.Debug)
                {
                    Logger.WriteDebug("PetAttack: on {0} @ {1:F1} yds", unit.SafeName(), unit.SpellDistance());
                }
                PetManager.CastPetAction("Attack", unit);
                waitNextPetAttack.Reset();
                return(true);
            }

            return(false);
        }
        public static bool Passive()
        {
            if (lastPetAttack != WoWGuid.Empty)
            {
                lastPetAttack = WoWGuid.Empty;
            }

            if (StyxWoW.Me.Pet == null || StyxWoW.Me.Pet.CurrentTargetGuid == WoWGuid.Empty)
            {
                return(false);
            }

            if (StyxWoW.Me.Pet.CurrentTarget == null)
            {
                Logger.Write(LogColor.Hilite, "/petpassive");
            }
            else
            {
                Logger.Write(LogColor.Hilite, "/petpassive (stop attacking {0})", StyxWoW.Me.Pet.CurrentTarget.SafeName());
            }

            PetManager.CastPetAction("Passive");
            return(true);
        }
        internal static void Pulse()
        {
            if (!NeedsPetSupport)
            {
                return;
            }

            if (StyxWoW.Me.Mounted)
            {
                _wasMounted = true;
            }

            if (_wasMounted && !StyxWoW.Me.Mounted)
            {
                _wasMounted = false;
                PetSummonAfterDismountTimer.Reset();
            }

            if (StyxWoW.Me.GotAlivePet && StyxWoW.Me.Pet != null)
            {
                if (_petGuid != StyxWoW.Me.Pet.Guid)
                {
                    // clear any existing spells
                    PetSpells.Clear();

                    // only load spells if we have one that is non-null
                    // .. as initial load happens before Me.PetSpells is initialized and we were saving 'null' spells
                    if (StyxWoW.Me.PetSpells.Any(s => s.Spell != null || s.Action != WoWPetSpell.PetAction.None))
                    {
                        // save Pet's Guid so we don't have to repeat
                        _petGuid = StyxWoW.Me.Pet.Guid;

                        NeedToCheckPetTauntAutoCast = SingularSettings.Instance.PetAutoControlTaunt;

                        // Cache the list. yea yea, we should just copy it, but I'd rather have shallow copies of each object, rather than a copy of the list.
                        PetSpells.AddRange(StyxWoW.Me.PetSpells);
                        PetSummonAfterDismountTimer.Reset();
                        Logger.WriteDiagnostic("---PetSpells Loaded for: {0} Pet ---", PetManager.GetPetTalentTree());
                        foreach (var sp in PetSpells)
                        {
                            if (sp.Spell == null)
                            {
                                Logger.WriteDebug("   {0} spell={1}  Action={0}", sp.ActionBarIndex, sp.ToString(), sp.Action.ToString());
                            }
                            else
                            {
                                Logger.WriteDebug("   {0} spell={1} #{2}", sp.ActionBarIndex, sp.ToString(), sp.Spell.Id);
                            }
                        }
                        Logger.WriteDebug(" ");
                    }
                }

                HandleAutoCast();
            }
            else if (_petGuid != WoWGuid.Empty)
            {
                PetSpells.Clear();
                _petGuid = WoWGuid.Empty;
            }
        }