Пример #1
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);
        }