Exemplo n.º 1
0
Arquivo: Map.cs Projeto: uvbs/bot-2016
        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);
        }
Exemplo n.º 2
0
Arquivo: Map.cs Projeto: uvbs/bot-2016
        /// <summary>
        /// Gets a collection of tiles on the current floor.
        /// </summary>
        /// <returns></returns>
        public Map.TileCollection GetTilesOnScreen()
        {
            List <Map.Tile> listTiles = new List <Map.Tile>();

            Map.Tile playerTile = this.GetPlayerTile();
            if (playerTile == null)
            {
                return(new Map.TileCollection(this.Client, listTiles));
            }

            byte floor = this.GetPlayerFloor((byte)playerTile.WorldLocation.Z);

            ushort[] tileNumbers = this.Client.Memory.ReadUInt16Array(this.TileNumberStart +
                                                                      floor * (Constants.Map.MaxTilesPerFloor * this.Client.Addresses.Map.TileNumberStep),
                                                                      Constants.Map.MaxTilesPerFloor);

            int mapStart = this.MapStart;

            for (int i = 0; i < tileNumbers.Length; i++)
            {
                Map.Tile t = this.GetTile(tileNumbers[i], playerTile, mapStart);
                if (t != null)
                {
                    listTiles.Add(t);
                }
            }
            return(new Map.TileCollection(this.Client, listTiles));
        }
Exemplo n.º 3
0
Arquivo: Map.cs Projeto: uvbs/bot-2016
        /// <summary>
        /// Gets the player's tile.
        /// </summary>
        /// <returns></returns>
        public Map.Tile GetPlayerTile()
        {
            byte playerZ = this.Client.Player.Z;
            int  floor   = 0;

            if (playerZ <= 7)
            {
                floor = 7 - playerZ;
            }
            else
            {
                floor = 2;
            }
            int tileNumber = this.Client.Memory.ReadInt32(this.TileNumberStart +
                                                          (Constants.Map.MaxTilesPerFloor * floor * 4) +
                                                          Constants.Map.TileNumberCenterOffset);

            Map.Tile t = this.CachedTiles[tileNumber];
            t.UpdateObjects();
            uint id = this.Client.Player.ID;

            if (!t.ContainsCreature(id))
            {
                return(null);
            }
            t.WorldLocation      = this.Client.Player.Location;
            t.RealMemoryLocation = this.TileNumberToMemoryLocation(t.TileNumber, t);
            t.MemoryLocation     = this.CentralizeMemoryLocation(t.RealMemoryLocation, t);
            return(t);
        }
Exemplo n.º 4
0
Arquivo: Map.cs Projeto: uvbs/bot-2016
        /// <summary>
        /// Gets a tile.
        /// </summary>
        /// <param name="tileNumber">The tile number to look for.</param>
        /// <param name="playerTile">The player's tile, used to get memory location and world location.</param>
        /// <param name="mapBegin">The memory address of the beginning of the map structure.</param>
        /// <returns></returns>
        public Map.Tile GetTile(int tileNumber, Map.Tile playerTile, int mapBegin = 0)
        {
            if (tileNumber < 0 || tileNumber >= this.CachedTiles.Length)
            {
                return(null);
            }

            if (playerTile == null)
            {
                playerTile = this.GetPlayerTile();
            }
            if (playerTile == null)
            {
                return(null);
            }

            if (mapBegin == 0)
            {
                mapBegin = this.MapStart;
            }

            Map.Tile t = this.CachedTiles[tileNumber];
            t.Address = mapBegin + this.Client.Addresses.Map.TileStep * tileNumber;
            t.UpdateObjects();
            t.RealMemoryLocation = this.TileNumberToMemoryLocation(t.TileNumber, playerTile);
            t.MemoryLocation     = this.CentralizeMemoryLocation(t.RealMemoryLocation, playerTile);
            t.WorldLocation      = this.MemoryLocationToWorldLocation(t.MemoryLocation, playerTile);
            return(t);
        }
Exemplo n.º 5
0
Arquivo: Map.cs Projeto: uvbs/bot-2016
        /// <summary>
        /// Gets a tile number based on a memory location.
        /// </summary>
        /// <param name="tileNumber"></param>
        /// <param name="playerTile">The player's tile to use as reference.</param>
        /// <returns></returns>
        private Objects.Location TileNumberToMemoryLocation(int tileNumber, Map.Tile playerTile)
        {
            int y = Constants.Map.MaxY,
                x = Constants.Map.MaxX;

            Objects.Location loc = new Objects.Location();
            loc.Z = (int)(tileNumber / (y * x));
            loc.Y = (int)((tileNumber - (loc.Z * y * x)) / x);
            loc.X = (int)((tileNumber - (loc.Z * y * x)) - loc.Y * x);
            return(loc);
        }
Exemplo n.º 6
0
Arquivo: Map.cs Projeto: uvbs/bot-2016
        /// <summary>
        /// Gets a tile at a given world location.
        /// </summary>
        /// <param name="loc">The world location to look fopr.</param>
        /// <param name="playerTile">The player's tile, used to get memory location and world location.</param>
        /// <returns></returns>
        public Map.Tile GetTile(Location loc, Map.Tile playerTile = null, int mapStart = 0)
        {
            if (playerTile == null)
            {
                playerTile = this.GetPlayerTile();
            }
            if (playerTile == null)
            {
                return(null);
            }

            // todo: figure this shit out
            if (playerTile.WorldLocation.Z != loc.Z)
            {
                return(null);
            }

            Location diff = loc - playerTile.WorldLocation;
            // set index to player index
            int index = this.GetPlayerFloor((byte)playerTile.WorldLocation.Z) * Constants.Map.MaxTilesPerFloor +
                        Constants.Map.TileNumberCenterIndex;

            // subtract instead of add Z as map is from bottom to top
            //if (diff.Z != 0) index -= diff.Z * Constants.Map.MaxTilesPerFloor;
            if (diff.Y != 0)
            {
                index += diff.Y * Constants.Map.MaxX;
            }
            if (diff.X != 0)
            {
                index += diff.X;
            }

            if (index < 0 || index >= Constants.Map.MaxTiles)
            {
                return(null);
            }
            ushort tileNumber = this.Client.Memory.ReadUInt16(this.TileNumberStart +
                                                              this.Client.Addresses.Map.TileNumberStep * index);

            return(this.GetTile(tileNumber, playerTile, mapStart));
        }
Exemplo n.º 7
0
Arquivo: Map.cs Projeto: uvbs/bot-2016
        public Map.TileObject GetTopUseItem(Location worldLocation, bool useOn, Map.Tile playerTile = null)
        {
            Map.Tile pTile = playerTile;
            if (pTile == null)
            {
                pTile = this.GetPlayerTile();
            }
            if (pTile == null)
            {
                return(null);
            }

            Map.Tile tile = this.GetTile(worldLocation, pTile);
            if (tile == null)
            {
                return(null);
            }

            return(tile.GetTopUseItem(useOn));
        }
Exemplo n.º 8
0
Arquivo: Map.cs Projeto: uvbs/bot-2016
        /// <summary>
        /// Gets a world location based on a memory location.
        /// </summary>
        /// <param name="worldLocation">The world location to use as reference.</param>
        /// <param name="playerTile">The player's tile to use as reference.</param>
        /// <returns></returns>
        private Objects.Location WorldLocationToMemoryLocation(Objects.Location worldLocation, Map.Tile playerTile)
        {
            // get and apply diffs
            int diffX = worldLocation.X - playerTile.WorldLocation.X;
            int diffY = worldLocation.Y - playerTile.WorldLocation.Y;
            int diffZ = worldLocation.Z - playerTile.WorldLocation.Z;

            Objects.Location memLoc = playerTile.RealMemoryLocation.Offset(diffX, diffY, diffZ);

            // re-align values if they're out of range
            if (memLoc.X < 0)
            {
                memLoc.X += Constants.Map.MaxX;
            }
            else if (memLoc.X >= Constants.Map.MaxX)
            {
                memLoc.X -= Constants.Map.MaxX;
            }
            if (memLoc.Y < 0)
            {
                memLoc.Y += Constants.Map.MaxY;
            }
            else if (memLoc.Y >= Constants.Map.MaxY)
            {
                memLoc.Y -= Constants.Map.MaxY;
            }

            return(memLoc);
        }
Exemplo n.º 9
0
Arquivo: Map.cs Projeto: uvbs/bot-2016
 /// <summary>
 /// Gets a collection of nearby tiles from a given tile.
 /// </summary>
 /// <param name="tile">The tile to get the nearby tiles from.</param>
 /// <param name="range">At what range to get nearby tiles from.</param>
 /// <returns></returns>
 public Map.TileCollection GetNearbyTiles(Map.Tile tile, byte range)
 {
     return(this.GetNearbyTiles(tile.WorldLocation, range));
 }