Exemple #1
0
        /// <summary>
        /// Checks whether this location is inside a pre-defined area.
        /// </summary>
        /// <param name="areaEffect">The area effect used.</param>
        /// <param name="location">The center of the area.</param>
        /// <param name="direction">The direction of the area effect used.</param>
        /// <returns></returns>
        public bool IsInAreaEffect(Objects.AreaEffect areaEffect, Objects.Location location,
                                   Enums.Direction direction)
        {
            ushort y = 0;

            Objects.Location currentLoc = this.Clone();
            byte             dir        = areaEffect.Type == AreaEffect.EffectType.Spell ? (byte)direction : (byte)1;

            foreach (byte[] row in areaEffect.GetArea())
            {
                int center = row.Length / 2;
                for (int i = 0; i < row.Length; i++)
                {
                    if (row[i] != dir)
                    {
                        continue;
                    }
                    if (location.Offset(i - center, y, 0) == currentLoc)
                    {
                        return(true);
                    }
                }
                y++;
            }
            return(false);
        }
Exemple #2
0
        public IEnumerable <FileInfo> GetMapFiles(Objects.Location worldStart, Objects.Location worldEnd)
        {
            Objects.Location minimapStart = this.GetAlignedMiniMapLocation(
                new Objects.Location(Math.Min(worldStart.X, worldEnd.X),
                                     Math.Min(worldStart.Y, worldEnd.Y),
                                     Math.Min(worldStart.Z, worldEnd.Z)));
            Objects.Location minimapEnd = this.GetAlignedMiniMapLocation(
                new Objects.Location(Math.Max(worldStart.X, worldEnd.X),
                                     Math.Max(worldStart.Y, worldEnd.Y),
                                     Math.Max(worldStart.Z, worldEnd.Z)));

            for (int z = 0; z <= minimapEnd.Z - minimapStart.Z; z++)
            {
                for (int y = 0; y <= minimapEnd.Y - minimapStart.Y; y++)
                {
                    for (int x = 0; x <= minimapEnd.X - minimapStart.X; x++)
                    {
                        FileInfo fi = this.GetMapFile(minimapStart.Offset(x, y, z));
                        if (fi != null)
                        {
                            yield return(fi);
                        }
                    }
                }
            }
        }
Exemple #3
0
        private Objects.Location CentralizeMemoryLocation(Objects.Location memLoc, Map.Tile playerTile)
        {
            // 8,6 == center
            int diffX = 8 - playerTile.RealMemoryLocation.X;
            int diffY = 6 - playerTile.RealMemoryLocation.Y;

            Objects.Location loc = memLoc.Offset(diffX, diffY);
            int maxX = Constants.Map.MaxX, maxY = Constants.Map.MaxY;

            if (loc.X >= maxX)
            {
                loc.X -= maxX;
            }
            else if (loc.X < 0)
            {
                loc.X += maxX;
            }
            if (loc.Y >= maxY)
            {
                loc.Y -= maxY;
            }
            else if (loc.Y < 0)
            {
                loc.Y += maxY;
            }
            return(loc);
        }
 public Objects.Location GetLocation(string offset)
 {
     Objects.Location location = Core.client.PlayerLocation;
     if (offset.ToLower() == "playerlocation")
     {
         return location;
     }
     switch (offset.ToLower())
     {
         case "north":
             return location.Offset(0, -1, 0);
         case "south":
             return location.Offset(0, 1, 0);
         case "east":
             return location.Offset(1, 0, 0);
         case "west":
             return location.Offset(-1, 0, 0);
     }
     return location;
 }
Exemple #5
0
        public ChunkCollection GetCombinedChunks(ChunkTypes desiredType, Objects.Location start, Objects.Location end)
        {
            if (desiredType == ChunkTypes.Merged)
            {
                throw new Exception("desiredType can not be Merged");
            }

            ChunkCollection chunks = this.GetChunksInMemory(desiredType, start, end);

            if (chunks.IsEmpty())
            {
                return(this.GetChunksFromFiles(desiredType, start, end));
            }

            Objects.Location minimapStart = this.GetAlignedMiniMapLocation(new Objects.Location(Math.Min(start.X, end.X),
                                                                                                Math.Min(start.Y, end.Y), Math.Min(start.Z, end.Z)));
            Objects.Location minimapEnd = this.GetAlignedMiniMapLocation(new Objects.Location(Math.Max(start.X, end.X),
                                                                                              Math.Max(start.Y, end.Y), Math.Max(start.Z, end.Z)));

            // add chunks from files if necessary
            for (int z = 0; z <= minimapEnd.Z - minimapStart.Z; z++)
            {
                for (int y = 0; y <= minimapEnd.Y - minimapStart.Y; y++)
                {
                    for (int x = 0; x <= minimapEnd.X - minimapStart.X; x++)
                    {
                        Objects.Location loc = minimapStart.Offset(x, y, z);
                        if (chunks.GetChunkFromMiniMapLocation(loc) != null)
                        {
                            continue;                                                  // chunk found, skip
                        }
                        FileInfo fi = this.GetMapFile(loc);
                        if (!fi.Exists)
                        {
                            continue;
                        }
                        switch (desiredType)
                        {
                        case ChunkTypes.Cached:
                            chunks.AddChunk(new CachedChunk(this.Client, fi));
                            break;

                        case ChunkTypes.Fast:
                            chunks.AddChunk(new FastChunk(this.Client, fi));
                            break;
                        }
                    }
                }
            }

            return(chunks);
        }
Exemple #6
0
        public Map.TileCollection GetNearbyTiles(Objects.Location loc, byte range)
        {
            List <Map.Tile> tiles = new List <Map.Tile>();
            Tile            p     = this.GetPlayerTile();

            if (p == null)
            {
                return(new Map.TileCollection(this.Client, tiles));
            }
            for (int x = range * -1; x <= range; x++)
            {
                for (int y = range * -1; y <= range; y++)
                {
                    if (x == 0 && y == 0)
                    {
                        continue;                   // skip centre tile
                    }
                    tiles.Add(this.GetTile(loc.Offset(x, y), p));
                }
            }
            return(new Map.TileCollection(this.Client, tiles));
        }
Exemple #7
0
        public IEnumerable<Node> FindPath(Objects.Location start, Objects.Location end,
            Map.TileCollection tiles, Objects.MiniMap.MergedChunk mergedChunk,
            bool considerPlayerWalkable = false, bool considerCreatureOnLocationWalkable = false)
        {
            if (start == null || end == null || tiles == null || mergedChunk == null) return Enumerable.Empty<Node>();

            Objects.Location playerLoc = this.Client.Player.Location;
            Objects.Location topLeft = playerLoc.Offset(-Constants.Map.MemoryLocationCenterX, -Constants.Map.MemoryLocationCenterY),
                bottomRight = playerLoc.Offset(Constants.Map.MemoryLocationCenterX, Constants.Map.MemoryLocationCenterY);
            if (start.Z != end.Z ||
                start.X < topLeft.X || start.Y < topLeft.Y || start.X > bottomRight.X || start.Y > bottomRight.Y ||
                end.X < topLeft.X || end.Y < topLeft.Y || end.X > bottomRight.X || end.Y > bottomRight.Y)
            {
                return Enumerable.Empty<Node>();
            }

            var nodes = mergedChunk.GetNodes();
            Point gridLength = new Point(this.Grid.GetLength(0), this.Grid.GetLength(1)),
                nodeStartIndex = new Point(Math.Max(0, mergedChunk.WorldLocation.X - topLeft.X),
                    Math.Max(0, mergedChunk.WorldLocation.Y - topLeft.Y)),
                nodeEndIndex = new Point(Math.Min(gridLength.X, nodeStartIndex.X + nodes.GetLength(0)),
                    Math.Min(gridLength.Y, nodeStartIndex.Y + nodes.GetLength(1))),
                alignedStart = new Point(start.X - topLeft.X, start.Y - topLeft.Y),
                alignedEnd = new Point(end.X - topLeft.X, end.Y - topLeft.Y);

            lock (this.SyncObject)
            {
                // assign node values to pathfinder grid
                for (int x = 0; x < gridLength.X; x++)
                {
                    for (int y = 0; y < gridLength.Y; y++)
                    {
                        if (considerPlayerWalkable)
                        {
                            var tile = tiles.GetTile(topLeft.Offset(x, y));
                            if (tile != null && tile.ContainsCreature(this.Client.Player.ID))
                            {
                                this.Grid[x, y] = 1;
                                continue;
                            }
                        }

                        if (nodeStartIndex.X <= x && nodeEndIndex.X > x &&
                            nodeStartIndex.Y <= y && nodeEndIndex.Y > y)
                        {
                            Objects.MiniMap.Node node = nodes[x - nodeStartIndex.X, y - nodeStartIndex.Y];
                            this.Grid[x, y] = this.Client.MiniMap.IsTileWalkable(node.Color, node.Speed,
                                alignedEnd.X == x && alignedEnd.Y == y, this.ConsiderUnexploredAsUnwalkable) ?
                                node.Speed :
                                (byte)Enums.MiniMapSpeedValues.Unwalkable;
                        }
                        else
                        {
                            this.Grid[x, y] = (byte)Enums.MiniMapSpeedValues.Unwalkable;
                        }
                    }
                }

                return this.FindPath(alignedStart, alignedEnd);
            }
        }