Example #1
0
        public static bool IsValidUnit(this WoWUnit unit)
        {
            string fnname = "FTWExtensionMethods.IsValidUnit";

            if (unit == null)
            {
                return(false);
            }
            MyTimer.Start(fnname);
            bool   retval = true;
            string ispet  = unit.IsPet.ToString();
            string owner  = "<none>";
            string reason = "";

            if (Blacklist.Contains(unit.Guid))
            {
                if (unit.Combat && (
                        unit.IsTargetingMeOrPet ||
                        unit.IsTargetingMyPartyMember ||
                        unit.IsTargetingAnyMinion ||
                        unit.IsTargetingMyRaidMember ||
                        FTWCoreUnits.IsTargetingPartyPets(unit)
                        ))
                {
                    // ignore  blacklist
                    // HB will keep feeding you that target anyway.
                }
                else
                {
                    reason = "{0} is blacklisted";
                }
            }
            else if (!unit.CanSelect || !unit.Attackable)
            {
                reason = "can't select or attack {0}";
            }
            else if (unit.IsFriendly)
            {
                reason = "{0} is friendly";
            }
            else if (unit.IsDead)
            {
                reason = "{0} is dead";
            }
            // The following line causes you to ignore mobs your party is fighting.
            //else if (unit.TaggedByOther) reason = "{0} is tagged by other.";
            else if (unit.HealthPercent == 0)
            {
                reason = "{0}'s health is 0";
            }
            else if ((unit.IsPet && ((unit.OwnedByUnit != null && unit.OwnedByUnit.IsPlayer == true) || unit.OwnedByRoot == null || unit.OwnedByRoot.IsDead == false)))
            {
                reason = "{0} is pet";
            }
            else if (unit.IsNonCombatPet)
            {
                reason = "{0} is noncombat pet";
            }
            else if (unit.IsCritter)
            {
                reason = "{0} is critter";
            }
            else if (Battlegrounds.IsInsideBattleground && FTWProps.IgnoreMobsBattleground.Contains(unit.Name))
            {
                reason = "{0} is in ignored battleground mobs";
            }
            MyTimer.Stop(fnname);
            if (reason == "")
            {
                retval = true;
                if (false && unit.IsPet)
                {
                    if (unit.OwnedByRoot != null)
                    {
                        string prefix = "npc";
                        if (unit.OwnedByRoot.IsPlayer)
                        {
                            prefix = "player";
                        }
                        owner = string.Format("pet {0} owned by {1} {2}", unit.Name, prefix, unit.OwnedByRoot.Name);
                    }
                    else
                    {
                        owner = string.Format("pet {0} owned by no one", unit.Name);
                    }
                    FTWLogger.debug(Color.MediumVioletRed, owner);
                }
            }
            else
            {
                FTWLogger.debug(Color.MediumVioletRed, reason, unit.Name);
                retval = false;
            }
            return(retval);
        }