Example #1
0
        /// <summary>
        /// Locates a certain quantity of a requested item that isn't reserved, and returns their locations.
        /// Returns null if not enough items were found to satisfy the request.
        /// </summary>
        /// <returns></returns>
        public static List <Point2D> LocateUnreservedQuantityOfItem(int itemID, int quantityDesired, Point2D startingPoint, int dimension)
        {
            List <Point2D> nearestChunks = FindNearestChunks(itemID, startingPoint, dimension);

            int            quantityFound = 0;
            List <Point2D> locations     = new List <Point2D>();

            if (nearestChunks != null)
            {
                Chunk          chunk;
                List <Point2D> allResults = new List <Point2D>();//Holds all found item locations.
                foreach (Point2D item in nearestChunks)
                {
                    chunk = World.Data.World.GetChunk(dimension, item.X, item.Y);
                    RTree <Point2D> items  = chunk.Items[itemID];
                    List <Point2D>  result = items.Intersects(new Rectangle(WorldUtil.GetFirstTileLocation(chunk.ChunkLocation), WorldUtil.GetLastTileLocation(chunk.ChunkLocation)));
                    allResults.AddRange(result);
                }

                //Orders all items found by their proximity to the starting location.
                Geometry.OrderPointsByProximity(startingPoint, allResults);

                int length = allResults.Count;
                for (int i = 0; i < length && quantityFound < quantityDesired; i++)
                {
                    Point2D item       = allResults[i];
                    Tile    containing = World.Data.World.GetTile(dimension, item.X, item.Y);
                    Item    tileItem   = containing.MainObject as Item;
                    if (tileItem.ReservedID.Equals(Guid.Empty))
                    {
                        locations.Add(item);
                        quantityFound += tileItem.CurrentlyStacked;
                    }
                }
            }

            if (quantityFound >= quantityDesired)
            {
                return(locations);
            }
            else
            {
                return(null);
            }
        }
Example #2
0
        /// <summary>
        /// Returns true if there exists a certain item that is unreserved.
        /// </summary>
        /// <param name="itemID"></param>
        /// <param name="dimension"></param>
        /// <param name="startingPoint"></param>
        /// <returns></returns>
        public static bool IsItemAvailible(int itemID, int dimension, Point2D startingPoint)
        {
            List <Point2D> nearestChunks = FindNearestChunks(itemID, startingPoint, dimension);

            if (nearestChunks != null && nearestChunks.Count > 0)
            {
                Chunk chunk;
                foreach (Point2D item in nearestChunks)
                {
                    //0-15
                    chunk = World.Data.World.GetChunk(dimension, item.X, item.Y);
                    RTree <Point2D> items  = chunk.Items[itemID];
                    List <Point2D>  result = items.Intersects(new Rectangle(WorldUtil.GetFirstTileLocation(chunk.ChunkLocation), WorldUtil.GetLastTileLocation(chunk.ChunkLocation)));

                    foreach (Point2D it in result)
                    {
                        Tile tile     = World.Data.World.GetTile(dimension, it.X, it.Y);
                        Item tileItem = tile.MainObject as Item;
                        if (tileItem != null && tileItem.ReservedID == Guid.Empty)
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }