Example #1
0
        public static bool ValidUnit(WoWUnit p, bool showReason = false)
        {
            if (p == null || !p.IsValid)
                return false;

            if (StyxWoW.Me.IsInInstance && IgnoreMobs.Contains(p.Entry))
            {
                if (showReason) Logger.Write(invalidColor, "invalid attack unit {0} is an Instance Ignore Mob", p.SafeName());
                return false;
            }

            // Ignore shit we can't select
            if (!p.CanSelect )
            {
                if (showReason) Logger.Write(invalidColor, "invalid attack unit {0} cannot be Selected", p.SafeName());
                return false;
            }

            // Ignore shit we can't attack
            if (!p.Attackable)
            {
                if (showReason) Logger.Write(invalidColor, "invalid attack unit {0} cannot be Attacked", p.SafeName());
                return false;
            }

            // Duh
            if (p.IsDead)
            {
                if (showReason) Logger.Write(invalidColor, "invalid attack unit {0} is already Dead", p.SafeName());
                return false;
            }

            // check for enemy players here as friendly only seems to work on npc's
            if (p.IsPlayer)
            {
                WoWPlayer pp = p.ToPlayer();
                if (pp.IsHorde == StyxWoW.Me.IsHorde && !pp.IsHostile)
                {
                    if (showReason)
                        Logger.Write(invalidColor, "invalid attack player {0} not a hostile enemy", p.SafeName());
                    return false;
                }

                if (!pp.CanWeAttack())
                {
                    if (showReason)
                        Logger.Write(invalidColor, "invalid attack player {0} cannot be Attacked currently", p.SafeName());
                    return false;
                }

                return true;
            }

            // Ignore evading NPCs
            if (p.IsEvading())
            {
                if (showReason)
                    Logger.Write(invalidColor, "invalid unit, {0} game flagged as evading", p.SafeName());
                return false;
            }

            // Ignore friendlies!
            if (p.IsFriendly)
            {
                if (showReason) Logger.Write(invalidColor, "invalid attack unit {0} is Friendly", p.SafeName());
                return false;
            }

            // Dummies/bosses are valid by default. Period.
            if (p.IsTrainingDummy() || p.IsBoss())
                return true;

            // If it is a pet/minion/totem, lets find the root of ownership chain
            WoWPlayer pOwner = GetPlayerParent(p);

            // ignore if owner is player, alive, and not blacklisted then ignore (since killing owner kills it)
            // .. following .IsMe check to prevent treating quest mob summoned by us that we need to kill as invalid
            if (pOwner != null && pOwner.IsAlive && !pOwner.IsMe)
            {
                if (!ValidUnit(pOwner))
                {
                    if (showReason)
                        Logger.Write(invalidColor, "invalid attack unit {0} - pets parent not an attackable Player", p.SafeName());
                    return false;
                }
                if (!StyxWoW.Me.IsPvPFlagged)
                {
                    if (showReason)
                        Logger.Write(invalidColor, "valid attackable player {0} but I am not PvP Flagged", p.SafeName());
                    return false;
                }
                if (Blacklist.Contains(pOwner, BlacklistFlags.Combat))
                {
                    if (showReason)
                        Logger.Write(invalidColor, "invalid attack unit {0} - Parent blacklisted for combat", p.SafeName());
                    return false;
                }

                return true;
            }

            // And ignore non-combat pets
            if (p.IsNonCombatPet)
            {
                if (showReason) Logger.Write(invalidColor, "{0} is a Noncombat Pet", p.SafeName());
                return false;
            }

            // And ignore critters (except for those ferocious ones or if set as BotPoi)
            if (IsIgnorableCritter(p))
            {
                if (showReason) Logger.Write(invalidColor, "{0} is a Critter", p.SafeName());
                return false;
            }

            /*
                        if (p.CreatedByUnitGuid != 0 || p.SummonedByUnitGuid != 0)
                            return false;
            */
            return true;
        }