private static void ReadCreateObjectBlock(ref Packet packet, Guid guid, uint map, int index)
        {
            var objType = packet.ReadEnum <ObjectType>("Object Type", TypeCode.Byte, index);
            var moves   = ReadMovementUpdateBlock547(ref packet, guid, index);
            var updates = CoreParsers.UpdateHandler.ReadValuesUpdateBlock(ref packet, objType, index, true);

            WoWObject obj;

            switch (objType)
            {
            case ObjectType.Unit:
                obj = new Unit();
                break;

            case ObjectType.GameObject:
                obj = new GameObject();
                break;

            case ObjectType.Item:
                obj = new Item();
                break;

            case ObjectType.Player:
                obj = new Player();
                break;

            default:
                obj = new WoWObject();
                break;
            }

            obj.Type         = objType;
            obj.Movement     = moves;
            obj.UpdateFields = updates;
            obj.Map          = map;
            obj.Area         = CoreParsers.WorldStateHandler.CurrentAreaId;
            obj.PhaseMask    = (uint)CoreParsers.MovementHandler.CurrentPhaseMask;

            // If this is the second time we see the same object (same guid,
            // same position) update its phasemask
            if (Storage.Objects.ContainsKey(guid))
            {
                var existObj = Storage.Objects[guid].Item1;
                CoreParsers.UpdateHandler.ProcessExistingObject(ref existObj, obj, guid); // can't do "ref Storage.Objects[guid].Item1 directly
            }
            else
            {
                Storage.Objects.Add(guid, obj, packet.TimeSpan);
            }

            if (guid.HasEntry() && (objType == ObjectType.Unit || objType == ObjectType.GameObject))
            {
                packet.AddSniffData(Utilities.ObjectTypeToStore(objType), (int)guid.GetEntry(), "SPAWN");
            }
        }
        private static void ReadCreateObjectBlock(Packet packet, WowGuid guid, uint map, object index)
        {
            ObjectType objType        = ObjectTypeConverter.Convert(packet.ReadByteE <ObjectTypeLegacy>("Object Type", index));
            var        moves          = ReadMovementUpdateBlock(packet, guid, index);
            var        updates        = CoreParsers.UpdateHandler.ReadValuesUpdateBlockOnCreate(packet, objType, index);
            var        dynamicUpdates = CoreParsers.UpdateHandler.ReadDynamicValuesUpdateBlockOnCreate(packet, objType, index);

            WoWObject obj;

            switch (objType)
            {
            case ObjectType.Unit:
                obj = new Unit();
                break;

            case ObjectType.GameObject:
                obj = new GameObject();
                break;

            case ObjectType.Player:
                obj = new Player();
                break;

            default:
                obj = new WoWObject();
                break;
            }

            obj.Type                = objType;
            obj.Movement            = moves;
            obj.UpdateFields        = updates;
            obj.DynamicUpdateFields = dynamicUpdates;
            obj.Map       = map;
            obj.Area      = CoreParsers.WorldStateHandler.CurrentAreaId;
            obj.Zone      = CoreParsers.WorldStateHandler.CurrentZoneId;
            obj.PhaseMask = (uint)CoreParsers.MovementHandler.CurrentPhaseMask;
            obj.Phases    = new HashSet <ushort>(CoreParsers.MovementHandler.ActivePhases);

            // If this is the second time we see the same object (same guid,
            // same position) update its phasemask
            if (Storage.Objects.ContainsKey(guid))
            {
                var existObj = Storage.Objects[guid].Item1;
                CoreParsers.UpdateHandler.ProcessExistingObject(ref existObj, obj, guid); // can't do "ref Storage.Objects[guid].Item1 directly
            }
            else
            {
                Storage.Objects.Add(guid, obj, packet.TimeSpan);
            }

            if (guid.HasEntry() && (objType == ObjectType.Unit || objType == ObjectType.GameObject))
            {
                packet.AddSniffData(Utilities.ObjectTypeToStore(objType), (int)guid.GetEntry(), "SPAWN");
            }
        }
 protected async override Task Run()
 {
     if (!IsDone)
     {
         WoWObject obj = null;
         if (InteractType == InteractActionType.NPC)
         {
             if (Entry != 0)
             {
                 obj =
                     ObjectManager.GetObjectsOfType <WoWUnit>().Where(u => u.Entry == Entry).OrderBy(
                         u => u.Distance).FirstOrDefault();
             }
             else if (StyxWoW.Me.GotTarget)
             {
                 obj = StyxWoW.Me.CurrentTarget;
             }
         }
         else if (InteractType == InteractActionType.GameObject)
         {
             obj =
                 ObjectManager.GetObjectsOfType <WoWGameObject>().OrderBy(u => u.Distance).FirstOrDefault(
                     u => (Entry > 0 && u.Entry == Entry) || (u.SubType == GameObjectType &&
                                                              (GameObjectType != WoWGameObjectType.SpellFocus ||
                                                               (GameObjectType == WoWGameObjectType.SpellFocus &&
                                                                u.SpellFocus == SpellFocus))));
         }
         if (obj != null)
         {
             WoWPoint moveToLoc = WoWMathHelper.CalculatePointFrom(Me.Location, obj.Location, 3);
             if (moveToLoc.Distance(Me.Location) > 4)
             {
                 Util.MoveTo(moveToLoc);
             }
             else
             {
                 if (InteractDelay > 0 &&
                     (!_interactSw.IsRunning || _interactSw.ElapsedMilliseconds < InteractDelay))
                 {
                     _interactSw.Start();
                 }
                 else
                 {
                     _interactSw.Reset();
                     obj.Interact();
                     IsDone = true;
                 }
             }
         }
         if (IsDone)
         {
             PBLog.Log("InteractAction complete");
         }
     }
 }
Beispiel #4
0
        public WoWObject ObjectCheck(uint _Entry)
        {
            WoWObject ReturnObject = null;

            ObjectManager.Update();
            foreach (WoWObject obj in ObjectManager.GetObjectsOfType <WoWObject>().Where(o => o.Entry == _Entry))
            {
                ReturnObject = obj;
            }
            return(ReturnObject);
        }
        // 23Mar2013-05:38UTC chinajade
        public static bool IsInLineOfSight(WoWObject wowObject)
        {
            WoWUnit wowUnit = wowObject as WoWUnit;

            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));
        }
Beispiel #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)));
        }
Beispiel #7
0
 bool AuraCheck(WoWObject obj)
 {
     if (string.IsNullOrEmpty(AuraName) || !(obj is WoWUnit))
     {
         return(true);
     }
     if (((WoWUnit)obj).HasAura(AuraName))
     {
         return(true);
     }
     return(false);
 }
Beispiel #8
0
        public bool ShouldPursue(WoWObject woWObject, out float priority)
        {
            var pursueObject = PursueObjects.FirstOrDefault(p => p.ShouldPursue(woWObject));

            if (pursueObject == null)
            {
                priority = 0;
                return(false);
            }
            priority = pursueObject.Priority;
            return(true);
        }
Beispiel #9
0
        // 11Apr2013-04:41UTC chinajade
        public bool IsInCompetition(WoWObject wowObject)
        {
            ProvideBoolDelegate excludeGroupMembers = (potentialGroupMember =>
            {
                var asWoWPlayer = potentialGroupMember as WoWPlayer;

                return((asWoWPlayer != null) && !asWoWPlayer.IsInMyParty);
            });

            return(!IsSharedWorldResource(wowObject) &&
                   FindPlayersNearby(wowObject.Location, NonCompeteDistance, excludeGroupMembers).Any());
        }
Beispiel #10
0
        private int Callback(ulong guid, uint filter)
        {
            IntPtr pointer = _getObjectByGuid(guid, -1);

            if (pointer == IntPtr.Zero)
            {
                return(1);
            }

            if (_objects.ContainsKey(guid))
            {
                _objects[guid].Pointer = pointer;
            }
            else
            {
                var           obj  = new WoWObject(pointer);
                WoWObjectType type = obj.Type;

                if (type.HasFlag(WoWObjectType.Player))
                {
                    _objects.Add(guid, new WoWPlayer(pointer));
                }
                else if (type.HasFlag(WoWObjectType.Unit))
                {
                    _objects.Add(guid, new WoWUnit(pointer));
                }
                else if (type.HasFlag(WoWObjectType.Container))
                {
                    _objects.Add(guid, new WoWContainer(pointer));
                }
                else if (type.HasFlag(WoWObjectType.Item))
                {
                    _objects.Add(guid, new WoWItem(pointer));
                }
                else if (type.HasFlag(WoWObjectType.Corpse))
                {
                    _objects.Add(guid, new WoWCorpse(pointer));
                }
                else if (type.HasFlag(WoWObjectType.GameObject))
                {
                    _objects.Add(guid, new WoWGameObject(pointer));
                }
                else if (type.HasFlag(WoWObjectType.DynamicObject))
                {
                    _objects.Add(guid, new WoWDynamicObject(pointer));
                }
                else
                {
                    _objects.Add(guid, obj);
                }
            }
            return(1);
        }
Beispiel #11
0
        public static double SurfacePathDistance(this WoWObject objectTo)
        {
            PathInformation info = Navigator.LookupPathInfo(objectTo);

            if (info.Navigability == PathNavigability.Navigable)
            {
                // Don't care about whether this is a min distance or exact one...
                return(info.Distance);
            }

            return(double.NaN);
        }
        //  3Jul2013-08:11UTC chinajade
        public static void CheckCollectionDistance(
            List <string> exclusionReasons,
            WoWObject wowObject,
            double collectionDistance)
        {
            var objectCollectionDistance = wowObject.CollectionDistance();

            if (objectCollectionDistance > collectionDistance)
            {
                exclusionReasons.Add(string.Format("ExceedsCollectionDistance({0:F1}, saw {1:F1})", collectionDistance, objectCollectionDistance));
            }
        }
        // 30May2013-08:11UTC chinajade
        public static bool IsStateMatch_AurasMissing(WoWObject wowObject, IEnumerable <int> auraIdsMissing)
        {
            Contract.Requires(wowObject != null, context => "wowObject != null");
            Contract.Requires(auraIdsMissing != null, context => "auraIdsMissing != null");

            var wowUnit = wowObject as WoWUnit;

            return
                ((wowUnit == null) ||       // Unit has no auras to check
                 !auraIdsMissing.Any() ||   // No aura qualifiers provided
                 !wowUnit.GetAllAuras().Any(a => auraIdsMissing.Contains(a.SpellId)));
        }
Beispiel #14
0
        public static double CollectionDistance(this WoWObject objectTo)
        {
            // NB: we use the 'surface path' to calculate distance to mobs.
            // This is important in tunnels/caves where mobs may be within X feet of us,
            // but they are below or above us, and we have to traverse much tunnel to get to them.
            // NB: If either the player or the mob is 'off the mesh', then a SurfacePath distance
            // calculation will be absurdly large.  In these situations, we resort to direct line-of-sight
            // distances.
            double pathDist = objectTo.SurfacePathDistance();

            return(double.IsNaN(pathDist) ? objectTo.Distance : pathDist);
        }
        public static bool IsPoiMatch(WoWObject wowObject, PoiType poiType, NavType?navType = null)
        {
            if (!IsViable(wowObject))
            {
                return(false);
            }

            return((BotPoi.Current != null) &&
                   (BotPoi.Current.Guid == wowObject.Guid) &&
                   (BotPoi.Current.Type == poiType) &&
                   ((navType == null) || (BotPoi.Current.NavType == navType)));
        }
        /// <summary>Buys an item from the specified wow object.</summary>
        /// <param name="wowObject">The wow object. Navigates to <paramref name="searchLocation" /> null</param>
        /// <param name="searchLocation">The search location of <paramref name="wowObject" />.</param>
        /// <param name="itemId">The item identifier.</param>
        /// <param name="quantity">The quantity to buy.</param>
        /// <param name="movementBy">The movement type to use.</param>
        /// <param name="navigationFailedAction">
        ///     The action to take if <paramref name="wowObject" /> or
        ///     <paramref name="searchLocation" /> cant be navigated to
        /// </param>
        /// <param name="notFoundAction">
        ///     The action to take if
        ///     <paramref name="wowObject" /> is not found at
        ///     <paramref name="searchLocation" />.
        /// </param>
        /// <param name="noVendorFrameAction">
        ///     The action to take if interaction with
        ///     <paramref name="wowObject" /> didn't open a vendor frame.
        /// </param>
        /// <param name="itemNotFoundAction">The action to take if <paramref name="wowObject"/> does not offer <paramref name="itemId"/> </param>
        /// <param name="insufficientFundsAction">The action to take if toon doesn't have enough funds to buy <paramref name="itemId"/> </param>
        /// <returns></returns>
        /// <exception cref="Exception">A delegate callback throws an exception.</exception>
        public static async Task <bool> BuyItem(
            WoWObject wowObject,
            Vector3 searchLocation,
            int itemId,
            int quantity,
            MovementByType movementBy      = MovementByType.FlightorPreferred,
            Action navigationFailedAction  = null,
            Action notFoundAction          = null,
            Action noVendorFrameAction     = null,
            Action itemNotFoundAction      = null,
            Action insufficientFundsAction = null)
        {
            if (!MerchantFrame.Instance.IsVisible)
            {
                return(await Gossip(
                           wowObject,
                           searchLocation,
                           movementBy,
                           navigationFailedAction,
                           notFoundAction,
                           null,
                           noVendorFrameAction,
                           GossipEntry.GossipEntryType.Vendor));
            }

            var item = MerchantFrame.Instance.GetAllMerchantItems().FirstOrDefault(i => i.ItemId == itemId);

            if (item == null)
            {
                if (itemNotFoundAction != null)
                {
                    itemNotFoundAction();
                }
                return(false);
            }

            if (!MerchantFrame.Instance.BuyItem(item.Index, quantity))
            {
                if (insufficientFundsAction != null)
                {
                    insufficientFundsAction();
                }
                return(false);
            }

            await CommonCoroutines.SleepForRandomUiInteractionTime();

            MerchantFrame.Instance.Close();
            await CommonCoroutines.SleepForLagDuration();

            return(true);
        }
        protected override void DefaultRemoveTargetsFilter(List <WoWObject> units)
        {
            bool isHorde = StyxWoW.Me.IsHorde;
            var  mistweaver_settings_ignore_percent = MistweaverSettings.Instance.IgnorePercent;

            for (int i = units.Count - 1; i >= 0; i--)
            {
                WoWObject o = units[i];
                if (!(o is WoWPlayer))
                {
                    units.RemoveAt(i);
                    continue;
                }

                WoWPlayer p = o.ToPlayer();

                if (p.IsDead || p.IsGhost)
                {
                    units.RemoveAt(i);
                    continue;
                }

                if (p.IsHostile)
                {
                    units.RemoveAt(i);
                    continue;
                }

                if (!p.IsInMyPartyOrRaid)
                {
                    units.RemoveAt(i);
                    continue;
                }

                if (p.HealthPercent > mistweaver_settings_ignore_percent)
                {
                    units.RemoveAt(i);
                    continue;
                }

                if (p.DistanceSqr > 40 * 40)
                {
                    units.RemoveAt(i);
                    continue;
                }
            }

            if (!units.Any(o => o.IsMe) && StyxWoW.Me.HealthPercent < mistweaver_settings_ignore_percent)
            {
                units.Add(StyxWoW.Me);
            }
        }
Beispiel #18
0
 public static Reaction GetReaction(WoWObject localObj, WoWObject mobObj)
 {
     try
     {
         return(GetReaction(new WoWUnit(localObj.GetBaseAddress).Faction,
                            new WoWUnit(mobObj.GetBaseAddress).Faction));
     }
     catch (Exception exception)
     {
         Logging.WriteError("GetReaction(WoWObject localObj, WoWObject mobObj): " + exception);
         return(Reaction.Unknown);
     }
 }
Beispiel #19
0
        public void Refresh()
        {
            wowConnection.TryToRefreshObjectManager();
            WoWObject.GetAllObjects(ref Game1.allUnits, ref Game1.allSpells, ref Game1.allPlayers, wowConnection);
            player.Refresh(wowConnection);
            byte combatByte = wowConnection.Connection.ReadByte(wowConnection.Connection.ReadUInt(player.BaseAddress + MemoryOffsets.ObjectManagerLocalCombatInfoArray) + MemoryOffsets.UnitIsInCombat);

            channeledSpell = wowConnection.Connection.ReadByte((uint)wowConnection.Connection.MainModule.BaseAddress + MemoryOffsets.GlobalInfoSpellBeingChanelled);
            castedSpell    = wowConnection.Connection.ReadByte((uint)wowConnection.Connection.MainModule.BaseAddress + MemoryOffsets.GlobalInfoSpellBeingCasted);
            isInCombat     = (combatByte & 0x4) != 0;
            RefreshTarget();
            RefreshPet();
        }
Beispiel #20
0
        /// <summary>Turns in a quest at object </summary>
        /// <param name="wowObject"> The turnin object. </param>
        /// <param name="questId"> The quest Id. If 0 (default) then first completed quest is turned in. </param>
        /// <param name="searchLocation">The search location of <paramref name="wowObject" />.</param>
        /// <param name="movementBy">The movement type to use.</param>
        /// <param name="navigationFailedAction">
        ///     The action to take if <paramref name="wowObject" /> or <paramref name="searchLocation"/> cant be navigated to
        /// </param>
        /// <param name="notFoundAction">
        ///     The action to take if <paramref name="wowObject" /> is not found at
        ///     <paramref name="searchLocation" />.
        /// </param>
        /// <returns><c>true</c> if an action was taken; <c>false</c> otherwise</returns>
        /// <exception cref="Exception">A delegate callback throws an exception.</exception>
        public static async Task <bool> TurninQuest(
            WoWObject wowObject,
            WoWPoint searchLocation,
            uint questId = 0,
            MovementByType movementBy     = MovementByType.FlightorPreferred,
            Action navigationFailedAction = null,
            Action notFoundAction         = null)
        {
            if (wowObject == null)
            {
                if (!Navigator.AtLocation(searchLocation))
                {
                    if (await MoveTo(searchLocation, "Quest turnin search area", movementBy))
                    {
                        return(true);
                    }

                    if (navigationFailedAction != null)
                    {
                        navigationFailedAction();
                    }
                    return(false);
                }

                if (notFoundAction != null)
                {
                    notFoundAction();
                }
                else
                {
                    TreeRoot.StatusText = "Waiting for the WoW object selected for quest turnin to spawn";
                }
                return(true);
            }

            if (!wowObject.WithinInteractRange)
            {
                if (await MoveTo(wowObject.Location, wowObject.SafeName, movementBy))
                {
                    return(true);
                }

                if (navigationFailedAction != null)
                {
                    navigationFailedAction();
                }
                return(false);
            }

            return(await ScriptHelpers.TurninQuest(wowObject, questId));
        }
Beispiel #21
0
 public void LoggingInternalGoToGameObject(Point previousPosition, int entry, WoWObject obj)
 {
     if (!obj.IsValid)
     {
         return;
     }
     Logging.Write("InternalGoToGameObject ended after traveling " + previousPosition.DistanceTo(ObjectManager.Me.Position) + " yards");
     Logging.Write("Initial Position: " + previousPosition);
     Logging.Write("Current Position: " + ObjectManager.Me.Position);
     Logging.Write("Searching for object entry: " + entry);
     Logging.Write("Object " + obj.Name + " found.");
     Logging.Write("Position: " + obj.Position);
     Logging.Write("Last distance to target: " + ObjectManager.Me.Position.DistanceTo(obj.Position));
 }
        public static void ReadCreateObjectBlock(ref Packet packet, Guid guid, uint map, int index)
        {
            var objType = packet.ReadEnum <ObjectType>("Object Type", TypeCode.Byte, index);
            var moves   = ReadMovementUpdateBlock(ref packet, guid, index);
            var updates = ReadValuesUpdateBlock(ref packet, objType, index);

            var obj = new WoWObject {
                Type = objType, Movement = moves, UpdateFields = updates, Map = map
            };

            Stuffing.Objects.TryAdd(guid, obj);

            HandleUpdateFieldChangedValues(guid, objType, updates, moves, true);
        }
 bool IsValidGuildBank(WoWObject obj)
 {
     if (obj is WoWGameObject)
     {
         var banker = (WoWGameObject)obj;
         return(banker.SubType == WoWGameObjectType.GuildBank && (banker.CreatedByGuid == 0 || banker.CreatedByGuid == Me.Guid));
     }
     if (obj is WoWUnit)
     {
         var banker = (WoWUnit)obj;
         return(banker.IsGuildBanker && banker.IsAlive && banker.CanSelect);
     }
     return(false);
 }
 protected override RunStatus Run(object context)
 {
     if (!IsDone)
     {
         WoWObject obj = null;
         if (InteractType == InteractActionType.NPC)
         {
             if (Entry != 0)
             {
                 obj = ObjectManager.GetObjectsOfType <WoWUnit>().Where(u => u.Entry == Entry).OrderBy(u => u.Distance).FirstOrDefault();
             }
             else if (ObjectManager.Me.GotTarget)
             {
                 obj = ObjectManager.Me.CurrentTarget;
             }
         }
         else if (InteractType == InteractActionType.GameObject)
         {
             obj = ObjectManager.GetObjectsOfType <WoWGameObject>().Where(u => (Entry > 0 && u.Entry == Entry) || (u.SubType == GameObjectType &&
                                                                                                                   (GameObjectType != WoWGameObjectType.SpellFocus || (GameObjectType == WoWGameObjectType.SpellFocus && u.SpellFocus == SpellFocus))))
                   .OrderBy(u => u.Distance).FirstOrDefault();
         }
         if (obj != null)
         {
             if (!obj.WithinInteractRange)
             {
                 Util.MoveTo(WoWMathHelper.CalculatePointFrom(me.Location, obj.Location, 3));
             }
             else
             {
                 if (InteractDelay > 0 && (!interactSw.IsRunning || interactSw.ElapsedMilliseconds < InteractDelay))
                 {
                     interactSw.Start();
                 }
                 else
                 {
                     interactSw.Reset();
                     obj.Interact();
                     IsDone = true;
                 }
             }
         }
         if (!IsDone)
         {
             return(RunStatus.Running);
         }
     }
     return(RunStatus.Failure);
 }
Beispiel #25
0
        /// <summary>
        /// Returns the time it takes to traverse to the DESTINATION.  The caller
        /// can supply a FACTOROFSAFETY that acts as a multiplier on the calculated time.
        /// The caller can provide a LOWERLIMITOFMAXTIME to place a minimum bound on the
        /// traversal time returned.
        /// The caller can provide UPPERLIMITONMAXTIME to place an upper bound on the
        /// traversal time calculated.
        /// <para>Notes:<list type="bullet">
        /// <item><description><para> * If we are on the ground, the traversal time is calculated
        /// based on the ground path to the destination.  This may require navigating around obstacles,
        /// or via a particular path to the destination.  If we are swimming or flying, the the
        /// travesal time is calculated as straight line-of-sight to the destination.</para></description></item>
        /// <item><description><para> * The FACTOROFSAFETY defaults to 1.0.  The 1.0 value calculates
        /// the precise time needed to arrive at the destination if everything goes perfect.
        /// The factor of safety should be increased to accomodate 'stuck' situations, mounting
        /// time, and other factors.  In most situations, a good value for factor of safety
        /// is about 2.5.</para></description></item>
        /// <item><description><para> * The LOWERLIMITOFMAXTIME places a lower bound on the
        /// traversal time.  This lower limit is imposed after the factor of safety has
        /// been applied.</para></description></item>
        /// <item><description><para> * The UPPERLIMITONMAXTIME places an upper bound on the
        /// traversal time.  This upper limit is imposed after the factor of safety has
        /// been applied.  We can get times that are effectively 'infinite' in situations
        /// where the Navigator was unable to calculate a path to the target.  This puts
        /// an upper limit on such bogus values.</para></description></item>
        /// </list></para>
        /// </summary>
        /// <param name="destination"></param>
        /// <param name="factorOfSafety"></param>
        /// <param name="lowerLimitOnMaxTime"></param>
        /// <param name="upperLimitOnMaxTime"></param>
        /// <returns></returns>
        public static TimeSpan MaximumTraversalTime(this WoWObject destination,
                                                    double factorOfSafety        = 1.0,
                                                    TimeSpan?lowerLimitOnMaxTime = null,
                                                    TimeSpan?upperLimitOnMaxTime = null)
        {
            var pathDistance = destination.SurfacePathDistance();

            double distanceToCover =
                !double.IsNaN(pathDistance)
                ? pathDistance
                : WoWMovement.ActiveMover.Location.Distance(destination.Location);

            return(Utility.MaximumTraversalTime(distanceToCover, factorOfSafety, lowerLimitOnMaxTime,
                                                upperLimitOnMaxTime));
        }
Beispiel #26
0
        /// <summary>
        /// Function to get all Players around a Object
        /// </summary>
        /// <param name="Object">The Object</param>
        /// <returns>true if there are one or more Players around a Object</returns>
        static public bool PlayerAround(WoWObject Object)
        {
            List <WoWPlayer> PlayerList = ObjectManager.GetObjectsOfType <WoWPlayer>()
                                          .Where(r => !r.IsDead).OrderBy(r => r.Distance).ToList();

            foreach (WoWPlayer r in PlayerList)
            {
                if (Object.Location.Distance(r.Location) < 5)
                {
                    return(true);
                }
            }

            return(false);
        }
        public static WoWPoint GetPointToGainDistance(WoWObject target, double minDistanceNeeded)
        {
            var minDistance = (float)(minDistanceNeeded + /*epsilon*/ (2 * Navigator.PathPrecision));
            var myLocation  = Me.Location;

            Func <WoWObject, WoWPoint, bool> isPointViable = (selectedTarget, potentialDestination) =>
            {
                var targetLocation = selectedTarget.Location;

                return
                    (targetLocation.Distance(potentialDestination) > minDistance &&
                     (myLocation.Distance(potentialDestination) < targetLocation.Distance(potentialDestination)) &&
                     GameWorld.IsInLineOfSight(potentialDestination, targetLocation));
            };

            // If the previously calculated point is still viable, use it...
            if (isPointViable(target, s_gainDistancePoint))
            {
                return(s_gainDistancePoint);
            }

            // Otherwise, find a new point...
            WoWObject moveTowardsObject = null;

            if (!(StyxWoW.Me.IsFlying || StyxWoW.Me.IsSwimming))
            {
                using (StyxWoW.Memory.AcquireFrame())
                {
                    moveTowardsObject =
                        (from wowObject in ObjectManager.GetObjectsOfType <WoWObject>(true, false)
                         where
                         wowObject.IsValid &&
                         isPointViable(target, wowObject.Location)
                         orderby
                         myLocation.PathTraversalCost(wowObject.Location)
                         select wowObject)
                        .FirstOrDefault();
                }
            }

            s_gainDistancePoint =
                (moveTowardsObject != null)
                    ? moveTowardsObject.Location
                // Resort to brute force...
                    : WoWMathHelper.CalculatePointFrom(myLocation, target.Location, minDistance);

            return(s_gainDistancePoint);
        }
Beispiel #28
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));
        }
        // 25Aug2013 chinajade
        public static TimeSpan InCompetitionTimeRemaining(WoWObject wowObject)
        {
            DateTime waitStart;

            if (s_inCompetitionTimers.TryGetValue(wowObject.Guid, out waitStart))
            {
                var now = DateTime.Now;

                if (now <= (waitStart + s_inCompetitionMaxWaitTime))
                {
                    return(waitStart + s_inCompetitionMaxWaitTime - now);
                }
            }

            return(TimeSpan.Zero);
        }
        public static WoWPoint AnticipatedLocation(this WoWObject wowObject, TimeSpan atTime)
        {
            var wowUnit = wowObject as WoWUnit;

            if (wowUnit == null)
            {
                return(wowObject.Location);
            }

            var anticipatedLocation =
                wowUnit.Location.RayCast(
                    wowUnit.RenderFacing,
                    (float)(wowUnit.MovementInfo.CurrentSpeed * atTime.TotalSeconds));

            return(anticipatedLocation);
        }
Beispiel #31
0
        public MoveToInteract(WoWUnit npc)
            : base(npc.Location, npc.InteractRange)
        {
            // Should check the unit!
            if (!npc.IsValid)
            {
                Status = new Result(ActionResult.Failed, "Unit is not valid");
                GarrisonButler.Diagnostic("Creating MoveToInteract Failed npc is not valid");
                return;
            }

            GarrisonButler.Diagnostic("Creating MoveToInteract with npc: {0}", npc.SafeName);
            if (npc.Location == default(WoWPoint))
            {
                Status = new Result(ActionResult.Failed,
                    "Unit (" + _object.SafeName + ") location is equal to default value.");
                return;
            }
            _object = npc;
            Status = new Result(ActionResult.Init);
        }
Beispiel #32
0
        public MoveToInteract(WoWObject obj)
            : base(obj.Location, obj.InteractRange)
        {
            // Should check the unit!
            if (!obj.IsValid)
            {
                Status = new Result(ActionResult.Failed, "Object is not valid");
                GarrisonButler.Diagnostic("Creating MoveToInteract Failed Object is not valid");
                return;
            }

            GarrisonButler.Diagnostic("Creating MoveToInteract with WoWObject: {0}", obj.SafeName);
            if (obj.Location == default(WoWPoint))
            {
                Status = new Result(ActionResult.Failed,
                    "Object (" + _object.SafeName + ") location is equal to default value.");
                return;
            }
            _object = obj;
            Status = new Result(ActionResult.Init);
        }
Beispiel #33
0
 public static double _radians(WoWObject obj)
 {
     return _rotation(obj)*(System.Math.PI/180);
 }
 bool ObjCheck(WoWObject obj, int[] ids)
 {
     bool ret = false;
     if (ids.Contains((int)obj.Entry) && obj.Distance <= CollectionDistance && obj.InLineOfSight &&
         !_npcBlacklist.Contains(obj.Guid) && AuraCheck(obj))
     {
         ret = (!IsDead || !(obj is WoWUnit) || ((WoWUnit)obj).Dead) &&
               (IsDead || !(obj is WoWUnit) || !((WoWUnit)obj).Dead);
     }
     // temp fix to HB killing targets without letting us using item...
     if (ret && obj is WoWUnit)
         Blacklist.Add(obj, new System.TimeSpan(0, 10, 0));
     return ret;
 }
Beispiel #35
0
 public void Use(WoWObject target)
 {
     if (_useItem == null)
         _useItem = Manager.Memory.RegisterDelegate<UseItemDelegate>((IntPtr)Pointers.Item.UseItem);
     var guid = target.Guid;
     _useItem(Manager.LocalPlayer.Pointer, ref guid, 0);
 }
        private bool BlacklistIfPlayerNearby(WoWObject target)
        {
            WoWUnit nearestCompetingPlayer = ObjectManager.GetObjectsOfType<WoWUnit>(true, false)
                                                    .OrderBy(player => player.Location.Distance(target.Location))
                                                    .FirstOrDefault(player => player.IsPlayer
                                                                                && player.IsAlive
                                                                                && !player.IsInOurParty());

            // If player is too close to the target, ignore target for a bit...
            if ((nearestCompetingPlayer != null)
                && (nearestCompetingPlayer.Location.Distance(target.Location) <= 25))
            {
                BehaviorBlacklist.Add(target.Guid, TimeSpan.FromSeconds(90));
                return (true);
            }

            return (false);
        }
Beispiel #37
0
        /// <summary>
        /// The created behavior was meant to be used in a PrioritySelector.
        /// It may also have uses inside other TreeSharp Composites.
        /// </summary>
        /// 
        /// <returns>
        /// <para>* RunStatus.Failure, if looting is not needed</para>
        /// <para>* RunStatus.Success, if we're in the process of looting things</para>
        /// </returns>
        /// 
        public Composite        CreateBehavior(ForceLootDelegate    forceLoot)
        {
            return (_behaviorRoot ?? (_behaviorRoot =
                new Decorator(ret => ((CharacterSettings.Instance.LootMobs || forceLoot()) && (LootList.Count() > 0)),
                    new PrioritySelector(

                        // If we're swimming, we need to do loot cleanup for ourselves...
                        new Decorator(ret => (Me.IsSwimming || forceLoot()),
                            new PrioritySelector(context => _currentTarget = LootList.FirstOrDefault(),

                                // If not at nearest target, move to it...
                                new Decorator(ret => (_currentTarget.Distance > _currentTarget.InteractRange),
                                    new Action(delegate
                                    {
                                        TreeRoot.StatusText = string.Format("Moving to loot target '{0}' (distance {1})...",
                                                                            _currentTarget.Name,
                                                                            _currentTarget.Distance);
                                        UnderwaterMoveTo(_currentTarget.Location);
                                    })),

                                // Within interact range, so loot it...
                                // NOTE: that we have to locally blacklist looted targets.  They sometimes
                                // have unique (e.g., quest-starting type) items on them.  If we already have
                                // have such an item in our inventory, the target remains lootable, but there
                                // is nothing we can pick up from it.  The blacklist prevents us from getting
                                // into silly loops because of such mechanics.
                                new Sequence(
                                    new Action(delegate { WoWMovement.MoveStop(); }),
                                    new WaitContinue(Delay_WowClientLagTime, ret => false, new ActionAlwaysSucceed()),
                                    new Action(delegate { _currentTarget.Interact(); }),
                                    new WaitContinue(Delay_WowClientWaitForLootFrame,
                                                     ret => LootFrame.Instance.IsVisible,
                                                     new ActionAlwaysSucceed()),
                                    new DecoratorContinue(ret => LootFrame.Instance.IsVisible,
                                        new Action(ret => LootFrame.Instance.LootAll())),
                                    new Action(delegate { _currentTarget.LootingBlacklist(Delay_BlacklistLootedMob); })
                                    )
                            )),

                        // We're not swimming, so we want to wait for the 'normal' looting behavior
                        // to scoop up the loot before allowing other behaviors to continue...
                        // This keeps it from taking a few steps towards next mob, only to go back to
                        // previous mob and loot it.  This technique can still fail if Honorbddy is slow to update
                        // infomation.  However, it shuts a lot of back-tracking.
                        new WaitContinue(Delay_WaitForLootCleanup, ret => false, new ActionAlwaysSucceed())
                    )
                )));
        }
Beispiel #38
0
 // Polar (R, theta, Z)
 public static double _R(WoWObject obj1, WoWObject obj2)
 {
     return System.Math.Sqrt(System.Math.Pow(_relX(obj1, obj2), 2) + System.Math.Pow(_relY(obj1, obj2), 2)); // (x^2 + Y^2)^(1/2)
 }
Beispiel #39
0
 /// <summary>
 /// Relative Z. (coordinate system centered on obj1 at (0,0,0)
 /// </summary>
 /// <param name="obj1">The obj1.</param>
 /// <param name="obj2">The obj2.</param>
 /// <returns>obj2 - obj1</returns>
 public static float _relZ(WoWObject obj1, WoWObject obj2)
 {
     return obj2.Z - obj1.Z;
 }
Beispiel #40
0
 public static float _rot(WoWObject obj)
 {
     return Me.Rotation;
 }
		private bool IsDistanceCloseNeeded(WoWObject wowObject)
		{
			double targetDistance = WoWMovement.ActiveMover.Location.Distance(wowObject.Location);

			var isWithinRange =
				(targetDistance <= MoveWithinMaxRangeOfMob)
				&& (IgnoreLoSToTarget || Query.IsInLineOfSight(wowObject));

			return !isWithinRange;
		}
 private static bool IsViable(WoWObject pWoWObject)
 {
     return pWoWObject != null && pWoWObject.IsValid && StyxWoW.IsInGame;
 }
Beispiel #43
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);                                                         
        }
Beispiel #44
0
        private TimeSpan        CalculateAutoBlacklistTime(WoWObject    wowObject)
        {
            double      timeToWowObject = ((Me.Location.Distance(wowObject.Location) / Me.MovementInfo.SwimSpeed)
                                           * 2.5);     // factor of safety

            timeToWowObject = Math.Max(timeToWowObject, 20.0);  // 20sec hard lower-limit

            return (TimeSpan.FromSeconds(timeToWowObject));
        }
        private bool CanNavigateFully(WoWObject target)
        {
            if (Navigator.CanNavigateFully(Me.Location, target.Location))
            {
                return (true);
            }

            return (false);
        }
		// 30May2013-08:11UTC chinajade
		private List<string> TargetExclusionChecks(WoWObject wowObject)
		{
			var exclusionReasons = TargetExclusionAnalysis.CheckCore(wowObject, this);

			TargetExclusionAnalysis.CheckAuras(exclusionReasons, wowObject, TargetOnlyIfMobHasAuraId, TargetOnlyIfMobMissingAuraId);

			var wowUnit = wowObject as WoWUnit;
			if (wowUnit != null)
			{
				if (wowUnit.HealthPercent < TargetOnlyIfHealthPercentAbove)
				{
					exclusionReasons.Add(string.Format("Health({0:F1}) < TargetOnlyIfHealthPercentAbove({1:F1})",
						wowUnit.HealthPercent, TargetOnlyIfHealthPercentAbove));
				}

				if (wowUnit.HealthPercent > TargetOnlyIfHealthPercentBelow)
				{
					exclusionReasons.Add(string.Format("Health({0:F1}) > TargetOnlyIfHealthPercentBelow({1:F1})",
						wowUnit.HealthPercent, TargetOnlyIfHealthPercentBelow));
				}
			}

			return exclusionReasons;
		}
Beispiel #47
0
        private static void SetLootPoi(WoWObject lootObj)
        {
            if (BotPoi.Current.Type != PoiType.None || lootObj == null || !lootObj.IsValid)
                return;

            var gameObject = lootObj as WoWGameObject;
            if (gameObject != null)
            {
                var obj = gameObject;
                if (obj.SubType == WoWGameObjectType.FishingHole)
                    return;
                BotPoi.Current = new BotPoi(lootObj, PoiType.Harvest);
            }
            else
            {
                var unit = lootObj as WoWUnit;
                if (unit == null) return;
                if (unit.CanLoot)
                    BotPoi.Current = new BotPoi(lootObj, PoiType.Loot);
                else if (unit.CanSkin)
                    BotPoi.Current = new BotPoi(lootObj, PoiType.Skin);
            }
        }
Beispiel #48
0
 /// <summary>
 /// Relative Y. (coordinate system centered on obj1 at (0,0,0)
 /// </summary>
 /// <param name="obj1">The obj1.</param>
 /// <param name="obj2">The obj2.</param>
 /// <returns>obj2 - obj1</returns>
 public static float _relY(WoWObject obj1, WoWObject obj2)
 {
     return obj2.Y - obj1.Y;
 }
Beispiel #49
0
        // If player is close to a target that is interesting to us, ignore the target...
        // The player may be going for the same mob, and we don't want to draw attention.
        // We'll blacklist the mob for a bit, in case the player is running around, or following
        // us.  The excaption is ithe player is in our party, then we can freely kill any target
        // close to him.
        private bool    BlacklistIfPlayerNearby(WoWObject   target)
        {
            WoWUnit     nearestCompetingPlayer   = ObjectManager.GetObjectsOfType<WoWUnit>(true, false)
                                                    .OrderBy(player => player.Location.Distance(target.Location))
                                                    .FirstOrDefault(player => player.IsPlayer
                                                                                && player.IsAlive
                                                                                && !player.IsInOurParty());

            // If player is too close to the target, ignore target for a bit...
            if ((nearestCompetingPlayer != null)
                && (nearestCompetingPlayer.Location.Distance(target.Location) <= NonCompeteDistance))
            {
                target.LocallyBlacklist(Delay_BlacklistPlayerTooClose);
                return (true);
            }

            return (false);
        }
Beispiel #50
0
 /// <summary>
 /// Relative X. (coordinate system centered on obj1 at (0,0,0)
 /// </summary>
 /// <param name="obj1">The obj1.</param>
 /// <param name="obj2">The obj2.</param>
 /// <returns>obj2 - obj1</returns>
 public static float _relX(WoWObject obj1, WoWObject obj2)
 {
     return obj2.X - obj1.X;
 }
Beispiel #51
0
 public void         MobEngaged(WoWObject     wowObject)
 {
     if (wowObject == CurrentTarget)
         { _currentTargetAutoBlacklistTimer.Stop(); }
 }
 public static bool IsViable(WoWObject pWoWObject) {
     return (pWoWObject != null) && pWoWObject.IsValid;
 }
Beispiel #53
0
 /// <summary>
 /// The Vector from obj1 to obj2
 /// </summary>
 /// <param name="obj1">The obj1.</param>
 /// <param name="obj2">The obj2.</param>
 /// <returns>A Vector <x, y, z></returns>
 public static Vector3 _obj1ToObj2(WoWObject obj1, WoWObject obj2)
 {
     return new Vector3(_relX(obj1, obj2), _relY(obj1, obj2), _relZ(obj1, obj2));
 }
 public static void FindMobileBank() {
     MobileBank = ObjectManager.GetObjectsOfTypeFast<WoWObject>().FirstOrDefault(bank => bank.IsValid && bank.Entry == 206602);
 }
 public void Add(WoWObject wowObject, TimeSpan timeSpan)
 {
     if (wowObject != null)
         { Add(wowObject.Guid, timeSpan); }
 }
 public bool Contains(WoWObject wowObject)
 {
     return (wowObject == null)
         ? false
         : Contains(wowObject.Guid);
 }
 bool AuraCheck(WoWObject obj)
 {
     if (string.IsNullOrEmpty(AuraName) || !(obj is WoWUnit))
         return true;
     if (((WoWUnit)obj).HasAura(AuraName))
         return true;
     return false;
 }
        private TimeSpan CalculateAutoBlacklistTime(WoWObject wowObject)
        {
            double timeToWowObject;

            if (Me.IsSwimming)
            { timeToWowObject = Me.Location.Distance(wowObject.Location) / Me.MovementInfo.SwimmingForwardSpeed; }
            else
            { timeToWowObject = Me.Location.SurfacePathDistance(wowObject.Location) / Me.MovementInfo.RunSpeed; }

            timeToWowObject *= 2.5;     // factor of safety
            timeToWowObject = Math.Max(timeToWowObject, 20.0);  // 20sec hard lower-limit

            return (TimeSpan.FromSeconds(timeToWowObject));
        }
Beispiel #59
0
        private int Callback(ulong guid, uint filter)
        {
            IntPtr pointer = _getObjectByGuid(guid, -1);
            if (pointer == IntPtr.Zero)
                return 1;

            if (_objects.ContainsKey(guid))
                _objects[guid].Pointer = pointer;
            else
            {
                var obj = new WoWObject(pointer);
                WoWObjectType type = obj.Type;

                if (type.HasFlag(WoWObjectType.Player))
                    _objects.Add(guid, new WoWPlayer(pointer));
                else if (type.HasFlag(WoWObjectType.Unit))
                    _objects.Add(guid, new WoWUnit(pointer));
                else if (type.HasFlag(WoWObjectType.Container))
                    _objects.Add(guid, new WoWContainer(pointer));
                else if (type.HasFlag(WoWObjectType.Item))
                    _objects.Add(guid, new WoWItem(pointer));
                else if (type.HasFlag(WoWObjectType.Corpse))
                    _objects.Add(guid, new WoWCorpse(pointer));
                else if (type.HasFlag(WoWObjectType.GameObject))
                    _objects.Add(guid, new WoWGameObject(pointer));
                else if (type.HasFlag(WoWObjectType.DynamicObject))
                    _objects.Add(guid, new WoWDynamicObject(pointer));
                else
                    _objects.Add(guid, obj);
            }
            return 1;
        }
Beispiel #60
0
 public static bool ContainsGUID(WoWObject wowObject)
 {
     return (wowObject != null) && ContainsGUID(wowObject.Guid);
 }