public void Initialize(IClassRotation specialization)
        {
            settings = HunterSettings.Current;
            if (settings.PartyDrinkName != "")
            {
                ToolBox.AddToDoNotSellList(settings.PartyDrinkName);
            }

            AIOSpell baseSpell = SerpentSting.KnownSpell ? SerpentSting : RaptorStrike;

            cast = new Cast(baseSpell, null, settings);

            this.specialization          = specialization as Hunter;
            (RotationType, RotationRole) = ToolBox.GetRotationType(specialization);
            TalentsManager.InitTalents(settings);

            _petPulseThread.DoWork += PetThread;
            _petPulseThread.RunWorkerAsync();

            FightEvents.OnFightStart       += FightStartHandler;
            FightEvents.OnFightEnd         += FightEndHandler;
            FightEvents.OnFightLoop        += FightLoopHandler;
            MovementEvents.OnMovementPulse += MovementEventsOnMovementPulse;

            Rotation();
        }
        protected override void PullRotation()
        {
            base.PullRotation();

            WoWUnit Target = ObjectManager.Target;

            ToolBox.CheckAutoAttack(Attack);

            // Seal of Righteousness
            if (Me.ManaPercentage > settings.PartyProtSealOfWisdom &&
                !Me.HaveBuff("Seal of Righteousness") &&
                cast.OnSelf(SealOfRighteousness))
            {
                return;
            }

            // Seal of Wisdom
            if (Me.ManaPercentage <= settings.PartyProtSealOfWisdom &&
                !Me.HaveBuff("Seal of Wisdom") &&
                cast.OnSelf(SealOfWisdom))
            {
                return;
            }

            AIOSpell avengersShield = settings.PartyAvengersShieldnRank1 ? AvengersShieldRank1 : AvengersShield;

            // Pull logic
            if (ToolBox.Pull(cast, true, new List <AIOSpell> {
                avengersShield, Judgement
            }))
            {
                _combatMeleeTimer = new Timer(500);
                return;
            }
        }
 private void FightStartHandler(WoWUnit unit, CancelEventArgs cancel)
 {
     if (Regrowth.KnownSpell)
     {
         AIOSpell bearFormSpell = DireBearForm.KnownSpell ? DireBearForm : BearForm;
         bigHealComboCost   = Regrowth.Cost + Rejuvenation.Cost + bearFormSpell.Cost;
         smallHealComboCost = Regrowth.Cost + bearFormSpell.Cost;
     }
 }
        private bool Cast(AIOSpell spell)
        {
            if (_cast.OnSelf(spell))
            {
                if (spell.Name.Contains(" Totem") || spell.Name.Contains("Totem of"))
                {
                    _lastTotemPosition = Me.Position;
                }

                return(true);
            }

            return(false);
        }
        public MageFoodManager(Cast cast)
        {
            Drink().ForEach(d => ToolBox.AddToDoNotSellList(d));
            Food().ForEach(f => ToolBox.AddToDoNotSellList(f));
            ManaStones().ForEach(m => ToolBox.AddToDoNotSellList(m));
            _cast = cast;

            List <AIOSpell> conjureManaStoneSpells = new List <AIOSpell>()
            {
                ConjureManaEmerald,
                ConjureManaRuby,
                ConjureManaCitrine,
                ConjureManaJade,
                ConjureManaAgate
            };

            _bestConjureManaStone = conjureManaStoneSpells.Find(s => s.KnownSpell);
        }
        protected virtual void BuffRotation()
        {
            // Delete additional Soul Shards
            if (ToolBox.CountItemStacks("Soul Shard") > settings.NumberOfSoulShards)
            {
                Logger.Log("Deleting excess Soul Shard");
                ToolBox.LuaDeleteOneItem("Soul Shard");
            }

            // Define the demon to summon
            AIOSpell SummonSpell  = null;
            bool     shouldSummon = false;

            if (SummonImp.KnownSpell)
            {
                if (ToolBox.CountItemStacks("Soul Shard") < 1 || !SummonVoidwalker.KnownSpell && !SummonFelguard.KnownSpell)
                {
                    SummonSpell = SummonImp;
                }

                if (SummonVoidwalker.KnownSpell && !SummonFelguard.KnownSpell)
                {
                    SummonSpell = SummonVoidwalker;
                }

                if (specialization.RotationType == Enums.RotationType.Party)
                {
                    SummonSpell = SummonImp;
                }

                if (SummonFelguard.KnownSpell)
                {
                    SummonSpell = SummonFelguard;
                }

                if (!ObjectManager.Pet.IsValid ||
                    ObjectManager.Pet.ManaPercentage < settings.ManaThresholdResummon && SummonSpell != SummonImp ||
                    ObjectManager.Pet.HealthPercent < settings.HealthThresholdResummon ||
                    !SummonSpell.Name.Contains(WarlockPetAndConsumables.MyWarlockPet()))
                {
                    shouldSummon = true;
                }
            }

            if (shouldSummon)
            {
                // Make sure we have mana to summon
                if (ObjectManager.Me.Mana < SummonSpell.Cost &&
                    !ObjectManager.Me.HaveBuff("Drink") &&
                    !Me.InCombatFlagOnly)
                {
                    Logger.Log($"Not enough mana to summon {SummonSpell.Name}, forcing regen");
                    wManager.wManagerSetting.CurrentSetting.DrinkPercent = 95;
                    Thread.Sleep(1000);
                    return;
                }

                Thread.Sleep(Usefuls.Latency + 500); // Safety for Mount check
                if (!ObjectManager.Me.IsMounted && !ObjectManager.Me.IsOnTaxi)
                {
                    if (cast.OnSelf(FelDomination))
                    {
                        Thread.Sleep(200);
                    }
                    if (cast.OnSelf(SummonSpell))
                    {
                        Usefuls.WaitIsCasting();
                        Thread.Sleep(1000); // Prevent double summon
                        return;
                    }
                }
            }
            else
            {
                wManager.wManagerSetting.CurrentSetting.DrinkPercent = _saveDrinkPercent;
            }
        }
        protected bool PartyBlessingBuffs()
        {
            AIOSpell myBuffSpell = null;

            if (specialization is RetributionParty)
            {
                myBuffSpell = BlessingOfMight;
            }
            if (specialization is PaladinHolyParty || !BlessingOfKings.KnownSpell)
            {
                myBuffSpell = BlessingOfWisdom;
            }
            if (specialization is PaladinProtectionParty)
            {
                myBuffSpell = BlessingOfKings;
            }

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

            if (!RecordedBlessingBuffs.Exists(b => b.CasterName == Me.Name && b.TargetName == Me.Name))
            {
                if (Me.HaveBuff(myBuffSpell.Name))
                {
                    ToolBox.CancelPlayerBuff(myBuffSpell.Name);
                }
                if (cast.OnSelf(myBuffSpell))
                {
                    return(true);
                }
            }
            else
            {
                if (!Me.HaveBuff(myBuffSpell.Name))
                {
                    RecordedBlessingBuffs.Remove(RecordedBlessingBuffs.Find(b => b.CasterName == Me.Name && b.TargetName == Me.Name));
                    return(true);
                }
            }

            foreach (AIOPartyMember member in AIOParty.GroupAndRaid)
            {
                // Avoid paladin loop buff
                if (member.WowClass == WoWClass.Paladin &&
                    AIOParty.GroupAndRaid.Exists(m => m.WowClass == WoWClass.Paladin && (m.HaveBuff("Drink") || m.GetDistance > 25)))
                {
                    continue;
                }

                List <AIOSpell> buffsForThisMember = settings.PartyDetectSpecs ? GetBlessingPerSpec(member.Specialization, member.WowClass) : GetBlessingPerClass(member.WowClass);
                if (member.IsDead ||
                    !member.IsValid ||
                    member.Guid == Me.Guid ||
                    buffsForThisMember == null ||
                    (settings.PartyDetectSpecs && member.Specialization == null))
                {
                    continue;
                }

                // check if ideal member buffs -> eg Hunter has wisdom + kings (not ideal)
                bool memberbuffsAreIdeal  = true;
                int  lastFoundBuffIndex   = -1;
                int  lastMissingBuffIndex = -1;
                for (int i = 0; i < buffsForThisMember.Count; i++)
                {
                    if (member.HaveBuff(buffsForThisMember[i].Name))
                    {
                        lastFoundBuffIndex = i;
                    }
                    else
                    {
                        lastMissingBuffIndex = i;
                    }

                    if (lastMissingBuffIndex < lastFoundBuffIndex &&
                        lastMissingBuffIndex > -1 &&
                        !RecordedBlessingBuffs.Exists(b => b.CasterName == member.Name && b.TargetName == member.Name && b.SpellName == buffsForThisMember[i].Name))
                    {
                        memberbuffsAreIdeal = false;
                        break;
                    }
                }

                BlessingBuff?myBuffOnThisTarget = RecordedBlessingBuffs.Find(b => b.CasterName == Me.Name && b.TargetName == member.Name);
                if (member.HaveBuff(myBuffOnThisTarget?.SpellName) && (memberbuffsAreIdeal /*|| member.WowClass == WoWClass.Paladin*/))
                {
                    continue;
                }

                for (int i = 0; i < buffsForThisMember.Count; i++)
                {
                    if (!member.HaveBuff(buffsForThisMember[i].Name) &&
                        cast.OnFocusUnit(buffsForThisMember[i], member))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        protected virtual void BuffRotation()
        {
            // PARTY buff rotations
            if (specialization.RotationType == Enums.RotationType.Party)
            {
                // Aura
                if (!Me.HaveBuff(settings.PartyAura) &&
                    cast.OnSelf(AIOSpell.GetSpellByName(settings.PartyAura)))
                {
                    return;
                }

                // PARTY Resurrection
                List <AIOPartyMember> needRes = AIOParty.GroupAndRaid
                                                .FindAll(m => m.IsDead)
                                                .OrderBy(m => m.GetDistance)
                                                .ToList();
                if (needRes.Count > 0 && cast.OnFocusUnit(Redemption, needRes[0]))
                {
                    return;
                }

                if (settings.PartyHealOOC || specialization is PaladinHolyParty)
                {
                    // PARTY Heal
                    List <AIOPartyMember> needHeal = AIOParty.GroupAndRaid
                                                     .FindAll(m => m.HealthPercent < 70)
                                                     .OrderBy(m => m.HealthPercent)
                                                     .ToList();
                    if (needHeal.Count > 0 && cast.OnFocusUnit(HolyLight, needHeal[0]))
                    {
                        return;
                    }

                    // PARTY Flash of Light
                    List <AIOPartyMember> needFoL = AIOParty.GroupAndRaid
                                                    .FindAll(m => m.HealthPercent < 85)
                                                    .OrderBy(m => m.HealthPercent)
                                                    .ToList();
                    if (needFoL.Count > 0 && cast.OnFocusUnit(FlashOfLight, needFoL[0]))
                    {
                        return;
                    }
                }

                // PARTY Purifiy
                WoWPlayer needsPurify = AIOParty.GroupAndRaid
                                        .Find(m => ToolBox.HasDiseaseDebuff(m.Name) || ToolBox.HasPoisonDebuff(m.Name));
                if (needsPurify != null && cast.OnFocusUnit(Purify, needsPurify))
                {
                    return;
                }

                // Party Cleanse
                WoWPlayer needsCleanse = AIOParty.GroupAndRaid
                                         .Find(m => ToolBox.HasMagicDebuff(m.Name));
                if (needsCleanse != null && cast.OnFocusUnit(Cleanse, needsCleanse))
                {
                    return;
                }

                // Blessings
                if (PartyBlessingBuffs())
                {
                    return;
                }

                // PARTY Drink
                if (AIOParty.PartyDrink(settings.PartyDrinkName, settings.PartyDrinkThreshold))
                {
                    return;
                }
            }
        }