Exemplo n.º 1
0
        /// <summary>
        /// Registers a player on the map.
        /// </summary>
        /// <param name="TileX">Position on X axis</param>
        /// <param name="TileY">Position on Y axis</param>
        /// <param name="Player">Player object.</param>
        public void AddPlayer(int tileX, int tileY, WorldPlayer player)
        {
            byte zoneX = (byte)(tileX / 32);
            byte zoneY = (byte)(tileY / 32);

            _grid[zoneX, zoneY].Players[player.WorldID] = player;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Removes a plaer on the map.
        /// </summary>
        /// <param name="TileX">Position on X axis</param>
        /// <param name="TileY">Position on Y axis</param>
        /// <param name="Player">Player object.</param>
        public void RemovePlayer(int tileX, int tileY, WorldPlayer player)
        {
            byte zoneX = (byte)(tileX / 32);
            byte zoneY = (byte)(tileY / 32);

            _grid[zoneX, zoneY].Players.Remove(player.WorldID);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets all the players in surrounding zones.
        /// </summary>
        /// <param name="TileX">Position on X axis</param>
        /// <param name="TileY">Position on Y axis</param>
        /// <param name="Player">Player to base search on.</param>
        /// <returns>A list of players around the base player.</returns>
        public List <Character> GetPlayers(int tileX, int tileY, WorldPlayer basePlayer)
        {
            byte zoneX = (byte)(tileX / 32);
            byte zoneY = (byte)(tileY / 32);

            List <Character> playersInRange = new List <Character>();

            foreach (WorldPlayer playerObj in _grid[zoneX, zoneY].Players.Values)
            {
                if (playerObj != basePlayer)
                {
                    if (World.GetDistance(playerObj, basePlayer) < World.PLAYER_SIGHT_RANGE)
                    {
                        playersInRange.Add((Character)playerObj);
                    }
                }
            }

            foreach (WorldPlayer playerObj in _grid[zoneX + 1, zoneY].Players.Values)
            {
                if (playerObj != basePlayer)
                {
                    if (World.GetDistance(playerObj, basePlayer) < World.PLAYER_SIGHT_RANGE)
                    {
                        playersInRange.Add((Character)playerObj);
                    }
                }
            }

            foreach (WorldPlayer playerObj in _grid[zoneX, zoneY + 1].Players.Values)
            {
                if (playerObj != basePlayer)
                {
                    if (World.GetDistance(playerObj, basePlayer) < World.PLAYER_SIGHT_RANGE)
                    {
                        playersInRange.Add((Character)playerObj);
                    }
                }
            }

            foreach (WorldPlayer playerObj in _grid[zoneX - 1, zoneY].Players.Values)
            {
                if (playerObj != basePlayer)
                {
                    if (World.GetDistance(playerObj, basePlayer) < World.PLAYER_SIGHT_RANGE)
                    {
                        playersInRange.Add((Character)playerObj);
                    }
                }
            }

            foreach (WorldPlayer playerObj in _grid[zoneX, zoneY - 1].Players.Values)
            {
                if (playerObj != basePlayer)
                {
                    if (World.GetDistance(playerObj, basePlayer) < World.PLAYER_SIGHT_RANGE)
                    {
                        playersInRange.Add((Character)playerObj);
                    }
                }
            }

            return(playersInRange);
        }