예제 #1
0
        // Mostly stolen from Singular
        // 12Apr2013-06:29UTC chinajade
        public static string SafeName(this WoWObject obj)
        {
            const ulong GuidMask = 0x0ffff;

            if (obj.IsMe)
            {
                return("Me");
            }

            string name;

            if (obj is WoWPlayer)
            {
                name = ((WoWPlayer)obj).Class.ToString();
            }

            else if ((obj is WoWUnit) && obj.ToUnit().IsPet)
            {
                name = obj.ToUnit().OwnedByRoot.SafeName() + ":Pet";
            }

            else
            {
                name = string.Format("{0}.{1:F4}", obj.Name, (obj.Guid & GuidMask));
            }

            return(name);
        }
예제 #2
0
        public static string SafeName(this WoWObject obj)
        {
            if (obj.IsMe)
            {
                return("Me");
            }

            string name;

            if (obj is WoWPlayer)
            {
                if (!obj.ToPlayer().IsFriendly)
                {
                    name = "Enemy.";
                }
                else
                {
                    if (RaFHelper.Leader == obj)
                    {
                        name = "lead.";
                    }
                    else if (Group.Tanks.Any(t => t.Guid == obj.Guid))
                    {
                        name = "tank.";
                    }
                    else if (Group.Healers.Any(t => t.Guid == obj.Guid))
                    {
                        name = "healer.";
                    }
                    else
                    {
                        name = "dps.";
                    }
                }
                name += ShowPlayerNames ? ((WoWPlayer)obj).Name : ((WoWPlayer)obj).Class.ToString();
            }
            else if (obj is WoWUnit && obj.ToUnit().IsPet)
            {
                WoWUnit root = obj.ToUnit().OwnedByRoot;
                name = root == null ? "(unknown)" : root.SafeName() + ":Pet";
            }
            else
            {
                name = obj.Name;
            }

            return(name + "." + UnitID(obj.Guid));
        }
예제 #3
0
        public static string SafeName(this WoWObject obj)
        {
            if (obj.IsMe)
            {
                return("Myself");
            }

            string name;

            if (obj is WoWPlayer)
            {
                if (RaFHelper.Leader == obj)
                {
                    return("Tank");
                }

                name = ShowPlayerNames ? ((WoWPlayer)obj).Name : ((WoWPlayer)obj).Class.ToString();
            }
            else if (obj is WoWUnit && obj.ToUnit().IsPet)
            {
                name = "Pet";
            }
            else
            {
                name = obj.Name;
            }

            return(name);
        }
        // 30May2013-08:11UTC chinajade
        public static void CheckAuras(
            List <string> exclusionReasons,
            WoWObject wowObject,
            IEnumerable <int> auraIdsRequired,
            IEnumerable <int> auraIdsUnwanted)
        {
            Contract.Requires(exclusionReasons != null, context => "reasons != null");

            if (Query.IsViable(wowObject))
            {
                auraIdsRequired = auraIdsRequired ?? Enumerable.Empty <int>();
                auraIdsUnwanted = auraIdsUnwanted ?? Enumerable.Empty <int>();

                var wowUnit = wowObject.ToUnit();
                if (wowUnit != null)
                {
                    var wowUnitAuras = wowUnit.GetAllAuras().ToList();

                    if (!Query.IsStateMatch_AurasWanted(wowObject, auraIdsRequired))
                    {
                        exclusionReasons.Add(string.Format("MissingRequiredAura({0})",
                                                           string.Join(",", auraIdsRequired.Select(i => i.ToString()))));
                    }

                    if (!Query.IsStateMatch_AurasMissing(wowObject, auraIdsUnwanted))
                    {
                        exclusionReasons.Add(string.Format("HasUnwantedAura({0})",
                                                           string.Join(",", wowUnitAuras.Where(a => auraIdsUnwanted.Contains(a.SpellId)).Select(a => a.SpellId.ToString()))
                                                           ));
                    }
                }
            }
        }
예제 #5
0
        //  23Mar2013-05:38UTC chinajade
        public bool IsInLineOfSight(WoWObject wowObject)
        {
            WoWUnit wowUnit = wowObject.ToUnit();

            return((wowUnit == null)
                ? wowObject.InLineOfSight
                   // NB: For WoWUnit, we do two checks.  This keeps us out of trouble when the
                   // mobs are up a stairway and we're looking at them through a guardrail and
                   // other boundary conditions.
                : (wowUnit.InLineOfSight && wowUnit.InLineOfSpellSight));
        }
예제 #6
0
        private IEnumerable <WoWAura> TargetAurasShowing(WoWObject target,
                                                         Dictionary <int, int> auraMap)
        {
            if (!(target is WoWUnit))
            {
                return(_emptyAuras);
            }

            return(target.ToUnit().Auras.Values
                   .Where(aura => auraMap.Keys.Contains(aura.SpellId)));
        }
        // 30May2013-08:11UTC chinajade
        public static void CheckMobState(
            List <string> exclusionReasons,
            WoWObject wowObject,
            MobStateType mobState,
            double mobLowHealthThreshold)
        {
            var wowUnit = wowObject.ToUnit();

            if (Query.IsViable(wowUnit))
            {
                if (!Query.IsStateMatch_MobState(wowUnit, mobState, mobLowHealthThreshold))
                {
                    exclusionReasons.Add(wowUnit.HealthPercent <= mobLowHealthThreshold
                        ? string.Format("!{0}", mobState)
                        : string.Format("!{0}({1}%)", MobStateType.BelowHp, mobLowHealthThreshold));
                }
            }
        }
예제 #8
0
        // 24Feb2013-08:11UTC chinajade
        public bool IsViableForInteracting(WoWObject wowObject)
        {
            if (wowObject == null)
            {
                return(false);
            }

            bool isViableForInteracting =
                IsViable(wowObject) &&
                !_interactBlacklist.Contains(wowObject) &&
                (!IgnoreMobsInBlackspots || !Targeting.IsTooNearBlackspot(ProfileManager.CurrentProfile.Blackspots, wowObject.Location)) &&
                !IsInCompetition(wowObject);

            // We're done, if not a WoWUnit...
            WoWUnit wowUnit = wowObject.ToUnit();

            if (wowUnit == null)
            {
                return(isViableForInteracting);
            }

            return(isViableForInteracting && wowUnit.IsUntagged());
        }
예제 #9
0
        // 16Apr2013-10:11UTC chinajade
        public bool IsSharedWorldResource(WoWObject wowObject)
        {
            bool isSharedResource = false;
            var  wowGameObject    = wowObject.ToGameObject();
            var  wowUnit          = wowObject.ToUnit();

            isSharedResource |= (wowGameObject != null) && _sharedGameObjectTypes.Contains(wowGameObject.SubType);
            isSharedResource |= (wowUnit != null) && wowUnit.TappedByAllThreatLists;
            isSharedResource |= (wowUnit != null) && !wowUnit.IsHostile &&
                                (wowUnit.IsAnyTrainer ||
                                 wowUnit.IsAnyVendor ||
                                 wowUnit.IsAuctioneer ||
                                 wowUnit.IsBanker ||
                                 wowUnit.IsFlightMaster ||
                                 wowUnit.IsGuard ||
                                 wowUnit.IsGuildBanker ||
                                 wowUnit.IsInnkeeper ||
                                 wowUnit.IsQuestGiver ||
                                 wowUnit.IsStableMaster
                                );

            return(isSharedResource);
        }
        // 30May2013-08:11UTC chinajade
        public static List <string> CheckCore(
            WoWObject wowObject,
            QuestBehaviorBase coreAttributes)
        {
            var exclusionReasons = new List <string>();
            const BlacklistFlags interestingBlacklistFlags = BlacklistFlags.Combat | BlacklistFlags.Interact | BlacklistFlags.Pull;

            if (!Query.IsViable(wowObject))
            {
                exclusionReasons.Add("[NotViable]");
                return(exclusionReasons);
            }

            foreach (var blacklistEntry in Blacklist.GetEntries(wowObject.Guid))
            {
                if ((blacklistEntry.Flags & interestingBlacklistFlags) == 0)
                {
                    continue;
                }

                var blacklistInfo = new List <string>();

                var blacklistTimeRemaining = blacklistEntry.Started + blacklistEntry.Length - DateTime.Now;
                blacklistInfo.Add(string.Format("Time({0}/{1})",
                                                Utility.PrettyTime(blacklistTimeRemaining),
                                                Utility.PrettyTime(blacklistEntry.Length)));

                if (blacklistEntry.Flags.HasFlag(BlacklistFlags.Combat))
                {
                    blacklistInfo.Add("ForCombat");
                }
                if (blacklistEntry.Flags.HasFlag(BlacklistFlags.Interact))
                {
                    blacklistInfo.Add("ForInteract");
                }
                if (blacklistEntry.Flags.HasFlag(BlacklistFlags.Loot))
                {
                    blacklistInfo.Add("ForLoot");
                }
                if (blacklistEntry.Flags.HasFlag(BlacklistFlags.Node))
                {
                    blacklistInfo.Add("ForNode");
                }
                if (blacklistEntry.Flags.HasFlag(BlacklistFlags.Pull))
                {
                    blacklistInfo.Add("ForPull");
                }

                exclusionReasons.Add(string.Format("Blacklisted({0})", string.Join(",", blacklistInfo)));
            }

            if (!Query.IsStateMatch_IgnoreMobsInBlackspots(wowObject, coreAttributes.IgnoreMobsInBlackspots))
            {
                var coveringBlackspots =
                    from blackspot in Query.FindCoveringBlackspots(wowObject.Location)
                    select string.Format("Blackspot({0}, r:{1})", blackspot.Location, blackspot.Radius);

                exclusionReasons.Add(string.Format("InBlackspot(object @{0}; {1})",
                                                   wowObject.Location,
                                                   string.Join(", ", coveringBlackspots)));
            }

            if (!Query.IsStateMatch_MeshNavigable(wowObject, coreAttributes.MovementBy))
            {
                exclusionReasons.Add("NotMeshNavigable");
            }

            if (Query.IsInCompetition(wowObject, coreAttributes.NonCompeteDistance))
            {
                int playerCount = Query.FindPlayersNearby(wowObject.Location, coreAttributes.NonCompeteDistance).Count();

                if (playerCount > 0)
                {
                    exclusionReasons.Add(string.Format("InCompetition({0} players within {1:F1}, expires in {2})",
                                                       playerCount,
                                                       coreAttributes.NonCompeteDistance,
                                                       Utility.PrettyTime(Query.InCompetitionTimeRemaining(wowObject))));
                }

                var  wowUnit  = wowObject.ToUnit();
                bool isTagged = (wowUnit != null) && !Query.IsSharedWorldResource(wowUnit) && !wowUnit.IsUntagged();
                if (isTagged)
                {
                    exclusionReasons.Add("TaggedByOtherPlayer");
                }
            }

            return(exclusionReasons);
        }
예제 #11
0
        public bool      IsViableTarget(WoWObject   target)
        {
            bool        isViable;

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

            isViable = (target.IsValid
                        && (MobIds.Contains((int)target.Entry) || ObjectIds.Contains((int)target.Entry))
                        && (target.Distance < HuntingGroundRadius)
                        && !target.IsLocallyBlacklisted()
                        && !BlacklistIfPlayerNearby(target)
                        && (IgnoreMobsInBlackspots
                            ? Targeting.IsTooNearBlackspot(ProfileManager.CurrentProfile.Blackspots,
                                                            target.Location)
                            : true));

            if (isViable && (target is WoWUnit))
            {
                WoWUnit     wowUnit     = target.ToUnit();

                isViable = ((wowUnit.IsAlive && (MobState == MobStateType.Alive))
                            || (wowUnit.Dead && (MobState == MobStateType.Dead))
                            || (MobState == MobStateType.DontCare));
            }

            return (isViable);                                                         
        }
예제 #12
0
        // 24Feb2013-08:11UTC chinajade
        public bool IsViableForInteracting(WoWObject wowObject)
        {
            if (wowObject == null)
                { return false; }

            bool isViableForInteracting =
                IsViable(wowObject)
                && !_interactBlacklist.Contains(wowObject)
                && (!IgnoreMobsInBlackspots || !Targeting.IsTooNearBlackspot(ProfileManager.CurrentProfile.Blackspots, wowObject.Location))
                && !IsInCompetition(wowObject);

            // We're done, if not a WoWUnit...
            WoWUnit wowUnit = wowObject.ToUnit();
            if (wowUnit == null)
                { return isViableForInteracting; }

            return isViableForInteracting && wowUnit.IsUntagged();
        }
예제 #13
0
 public override void UpdateReference(WoWObject obj)
 {
     base.UpdateReference(obj);
     RefWoWUnit = obj.ToUnit();
 }
예제 #14
0
        private TimeSpan BlacklistInteractTarget(WoWObject selectedTarget)
        {
            // NB: The selectedTarget can sometimes go "non viable".
            // An example: We gossip with an NPC that results in a forced taxi ride.  Honorbuddy suspends
            // this behavior while the taxi ride is in progress, and when we land, the selectedTarget
            // is no longer viable to blacklist.
            if (!IsViable(selectedTarget))
                { return TimeSpan.Zero; }

            WoWUnit wowUnit = selectedTarget.ToUnit();
            bool isShortBlacklist = (wowUnit != null) && IsSharedWorldResource(wowUnit);
            TimeSpan blacklistDuration = TimeSpan.FromSeconds(isShortBlacklist ? 30 : 180);

            BlacklistForInteracting(selectedTarget, blacklistDuration);
            return blacklistDuration;
        }
예제 #15
0
        private bool IsClearTargetNeeded(WoWObject wowObject)
        {
            WoWUnit wowUnit = wowObject.ToUnit();

            return
                (wowUnit != null)
                && (Me.CurrentTarget == wowUnit)
                && !KeepTargetSelected;
        }
예제 #16
0
        // 16Apr2013-10:11UTC chinajade
        public bool IsSharedWorldResource(WoWObject wowObject)
        {
            bool isSharedResource = false;
            var wowGameObject = wowObject.ToGameObject();
            var wowUnit = wowObject.ToUnit();

            isSharedResource |= (wowGameObject != null) && _sharedGameObjectTypes.Contains(wowGameObject.SubType);
            isSharedResource |= (wowUnit != null) && wowUnit.TappedByAllThreatLists;
            isSharedResource |= (wowUnit != null) && !wowUnit.IsHostile
                                && (wowUnit.IsAnyTrainer
                                    || wowUnit.IsAnyVendor
                                    || wowUnit.IsAuctioneer
                                    || wowUnit.IsBanker
                                    || wowUnit.IsFlightMaster
                                    || wowUnit.IsGuard
                                    || wowUnit.IsGuildBanker
                                    || wowUnit.IsInnkeeper
                                    || wowUnit.IsQuestGiver
                                    || wowUnit.IsStableMaster
                                   );
            
            return isSharedResource;
        }
예제 #17
0
        protected override Composite CreateBehavior()
        {
            return(_root ?? (_root =

                                 new PrioritySelector(ctx => Object,

                                                      new Decorator(ctx => ctx != null && (((WoWObject)ctx).Distance > InteractRange || !((WoWObject)ctx).InLineOfSight),
                                                                    new Sequence(
                                                                        new Action(ctx => TreeRoot.StatusText = "Moving to use item on - " + ((WoWObject)ctx).Name),
                                                                        new Action(ctx => Navigator.MoveTo(((WoWObject)ctx).Location)))),

                                                      new Decorator(ctx => ctx != null && ((WoWObject)ctx).Distance <= InteractRange,
                                                                    new Sequence(
                                                                        new DecoratorContinue(c => StopMovingOnUse && Me.IsMoving,
                                                                                              new Sequence(
                                                                                                  new Action(ctx => WoWMovement.MoveStop()),
                                                                                                  new WaitContinue(5, ctx => !Me.IsMoving,
                                                                                                                   new Action(ctx => StyxWoW.SleepForLagDuration()))
                                                                                                  )),

                                                                        new Sequence(ctx => StyxWoW.Me.CarriedItems.FirstOrDefault(ret => ret.Entry == ItemId),
                                                                                     // Set the status text.
                                                                                     new Action(ctx => TreeRoot.StatusText = "Using item on " + Object.Name),

                                                                                     // If we don't have the item stop!
                                                                                     new DecoratorContinue(ctx => ctx == null,
                                                                                                           new Action(ctx => LogMessage("fatal", "Could not find ItemId({0}) in inventory.", ItemId))),

                                                                                     new DecoratorContinue(ctx => Object.Type == WoWObjectType.Unit,
                                                                                                           new Action(ctx => Object.ToUnit().Target())),

                                                                                     // Face the object.
                                                                                     new Action(ctx => WoWMovement.Face(Object.Guid)),

                                                                                     // Use the item.
                                                                                     new Action(ctx => ((WoWItem)ctx).UseContainerItem()),

                                                                                     new DecoratorContinue(ctx => HasGroundTarget,
                                                                                                           new Action(ctx => LegacySpellManager.ClickRemoteLocation(Object.Location))),

                                                                                     new WaitContinue(6, ctx => false,
                                                                                                      new Sequence(
                                                                                                          new Action(ctx => StyxWoW.SleepForLagDuration()),
                                                                                                          new Action(ctx => _npcBlacklist.Add(Object.Guid)),
                                                                                                          new Action(ctx => _waitTimer.Reset()),

                                                                                                          new DecoratorContinue(ctx => !_waitTimer.IsRunning,
                                                                                                                                new Action(ctx => _waitTimer.Start())),

                                                                                                          new Action(ctx => Counter++)
                                                                                                          )
                                                                                                      )
                                                                                     )
                                                                        )),

                                                      new Sequence(
                                                          new Action(ctx => LogMessage("info", "Moving to {0}", Location)),
                                                          new Action(ctx => Navigator.MoveTo(Location))
                                                          )
                                                      )));
        }
예제 #18
0
파일: Unit.cs 프로젝트: aash/Singular
        public static bool IsUnit(WoWObject o)
        {
            if (o != null)
            {
                try
                {
                    if (o.ToUnit() != null)
                        return true;
                }
                catch
                {
                }
            }

            return false;
        }
예제 #19
0
        private string Debug_TellWhyExcluded(WoWObject wowObject)
        {
            var reasons = new List<string>();

            if (!IsViable(wowObject))
                { return "[NotViable]"; }

            if (wowObject.Distance > CollectionDistance)
                { reasons.Add(string.Format("ExceedsCollectionDistance({0})", CollectionDistance)); }

            if ((MovementBy == MovementByType.NavigatorOnly) && !Navigator.CanNavigateFully(Me.Location, wowObject.Location))
                { reasons.Add("NotMeshNavigable"); }

            if (IsBlacklistedForInteraction(wowObject))
                { reasons.Add("Blacklisted"); }

            if (IgnoreMobsInBlackspots && Targeting.IsTooNearBlackspot(ProfileManager.CurrentProfile.Blackspots, wowObject.Location))
                { reasons.Add(string.Format("InBlackspot(object @{0})", wowObject.Location)); }

            if (IsInCompetition(wowObject))
            {
                reasons.Add(string.Format("InCompetition({0} players within {1:F1})",
                    FindPlayersNearby(wowObject.Location, NonCompeteDistance).Count(),
                    NonCompeteDistance));
            }

            WoWUnit wowUnit = wowObject.ToUnit();
            if (wowUnit != null)
            {
                var wowUnitAuras = wowUnit.GetAllAuras().ToList();

                if (NotMoving && wowUnit.IsMoving)
                    { reasons.Add("Moving"); }

                if ((AuraIdsOnMob.Length > 0) && !wowUnitAuras.Any(a => AuraIdsOnMob.Contains(a.SpellId)))
                {
                    reasons.Add(string.Format("MissingRequiredAura({0})",
                        string.Join(",", AuraIdsOnMob.Select(i => i.ToString()))));
                }

                if ((AuraIdsMissingFromMob.Length > 0) && wowUnitAuras.Any(a => AuraIdsMissingFromMob.Contains(a.SpellId)))
                {
                    reasons.Add(string.Format("HasUnwantedAura({0})",
                        string.Join(",", wowUnitAuras.Where(a => AuraIdsMissingFromMob.Contains(a.SpellId)).Select(a => a.SpellId.ToString()))
                        ));
                }

                if (!((MobState == MobStateType.DontCare)
                        || ((MobState == MobStateType.Dead) && wowUnit.IsDead)
                        || ((MobState == MobStateType.Alive) && wowUnit.IsAlive)
                        || ((MobState == MobStateType.AliveNotInCombat) && !wowUnit.Combat && wowUnit.IsAlive)
                        || ((MobState == MobStateType.BelowHp) && wowUnit.IsAlive && (wowUnit.HealthPercent < MobHpPercentLeft))))
                {
                    reasons.Add(MobState == MobStateType.BelowHp
                        ? string.Format("!{0}({1}%)", MobState, MobHpPercentLeft)
                        : string.Format("!{0}", MobState));
                }
            }

            return string.Format("{0} [{1}]", wowObject.Name, string.Join(",", reasons));
        }
예제 #20
0
        // 24Feb2013-08:11UTC chinajade
        private bool IsInteractNeeded(WoWObject wowObject)
        {
            if (wowObject == null)
                { return false; }

            bool isViableForInteracting = IsViableForInteracting(wowObject);
            WoWUnit wowUnit = wowObject.ToUnit();

            // We're done, if not a WoWUnit...
            if (wowUnit == null)
                { return isViableForInteracting; }
                
            // Additional qualifiers for WoWUnits...        
            return
                isViableForInteracting
                && (!NotMoving || !wowUnit.IsMoving)
                && ((AuraIdsOnMob.Length <= 0) || wowUnit.GetAllAuras().Any(a => AuraIdsOnMob.Contains(a.SpellId)))
                && ((AuraIdsMissingFromMob.Length <= 0) || !wowUnit.GetAllAuras().Any(a => AuraIdsMissingFromMob.Contains(a.SpellId)))
                && ((MobState == MobStateType.DontCare)
                    || ((MobState == MobStateType.Dead) && wowUnit.IsDead)
                    || ((MobState == MobStateType.AliveNotInCombat) && !wowUnit.Combat && wowUnit.IsAlive)
                    || ((MobState == MobStateType.Alive) && wowUnit.IsAlive)
                    || ((MobState == MobStateType.BelowHp) && wowUnit.IsAlive && (wowUnit.HealthPercent < MobHpPercentLeft)));
        }
예제 #21
0
        private IEnumerable<WoWAura> TargetAurasShowing(WoWObject target,
                                                           Dictionary<int, int> auraMap)
        {
            if (!(target is WoWUnit))
            { return (EmptyAuras); }

            return (target.ToUnit().Auras.Values
                    .Where(aura => auraMap.Keys.Contains(aura.SpellId)));
        }
예제 #22
0
        //  23Mar2013-05:38UTC chinajade
        public bool IsInLineOfSight(WoWObject wowObject)
        {
            WoWUnit wowUnit = wowObject.ToUnit();

            return (wowUnit == null)
                ? wowObject.InLineOfSight
                // NB: For WoWUnit, we do two checks.  This keeps us out of trouble when the
                // mobs are up a stairway and we're looking at them through a guardrail and
                // other boundary conditions.
                : (wowUnit.InLineOfSight && wowUnit.InLineOfSpellSight);
        }
예제 #23
0
 /// <summary>
 /// The SelectedInteractTarget may no longer be viable after interacting with it.
 /// For instance, the NPC may disappear, or if the toon was forced on a taxi ride
 /// as a result of the gossip, the SelectedInteractTarget will no longer be viable
 /// once we land.
 /// </summary>
 private string GetName(WoWObject target)
 {
     return IsViable(target)
                ? target.Name
                : (target == SelectedInteractTarget) ? "selected target"
                : (target.ToUnit() != null) ? "unit"
                : "object";
 }