Beispiel #1
0
        public void FindPickupObjects(Chunk newChunk)
        {
            List<Item> toRemove = new List<Item>();

            foreach (Chunk c in CXMineServer.Server.World.GetChunksInRange(newChunk, 1))
            {
                foreach (Item i in c.Items)
                {
                    int distance;
                    if (Utility.IsInRange(this, i, 40, out distance) && CanPick(i))
                    {
                        State.CollectItem(i.EId, EntityID, (short)i.Type, (byte)i.Count, (short)i.Uses);
                        toRemove.Add(i);
                    }

                    //CXMineServer.Log("Item distance: " + distance);
                }
            }

            for (int i = 0; i < toRemove.Count; ++i)
                toRemove[i].Delete();

            toRemove.Clear();
        }
Beispiel #2
0
 public Item(Chunk c)
 {
     _ParentChunk = c;
 }
Beispiel #3
0
        public void SendChunk(Chunk c)
        {
            PreChunk(c.ChunkX, c.ChunkZ, 1);
            // TODO: maybe we can cache some uncompressed chunk
            byte[] uncompressed = c.GetBytes();
            byte[] data;
            using(MemoryStream mem = new MemoryStream()) {
                using(ZOutputStream stream = new ZOutputStream(mem, zlibConst.Z_BEST_COMPRESSION)) {
                    stream.Write(uncompressed, 0, uncompressed.Length);
                }
                data = mem.ToArray();
            }
            CXMineServer.SendLogFile("Sending: MapChunk dimension: " + (data.Length + 18).ToString() + "\r\n");
            Send(new MapChunk(16 * c.ChunkX, (short)0, 16 * c.ChunkZ, 15, 127, 15, data.Length, data));

            //KeepAlive();
        }
Beispiel #4
0
 public Chunk GetChunk(int chunkX, int chunkZ)
 {
     List<byte> b = new List<byte>();
     b.AddRange(BitConverter.GetBytes(chunkX));
     b.AddRange(BitConverter.GetBytes(chunkZ));
     long index = BitConverter.ToInt64(b.ToArray(), 0);
     if (_Chunks.ContainsKey(index)) {
         return _Chunks[index];
     } else {
         return _Chunks[index] = new Chunk(chunkX, chunkZ, this);
     }
 }
Beispiel #5
0
 public static IEnumerable<Entity> EntitiesIn(Chunk c)
 {
     return c.Entities;
 }
Beispiel #6
0
 public IEnumerable<Chunk> GetChunksInVisibilityRange(Chunk c)
 {
     for (int x = c.ChunkX - visibleChunks; x <= c.ChunkX + visibleChunks; ++x)
     {
         for (int z = c.ChunkZ - visibleChunks; z <= c.ChunkZ + visibleChunks; ++z)
         {
             yield return GetChunk(x, z);
         }
     }
 }
Beispiel #7
0
 public IEnumerable<Chunk> GetChunksInRange(Chunk c, int range)
 {
     for (int x = c.ChunkX - range; x <= c.ChunkX + range; ++x)
     {
         for (int z = c.ChunkZ - range; z <= c.ChunkZ + range; ++z)
         {
             yield return GetChunk(x, z);
         }
     }
 }
Beispiel #8
0
        public static int DistanceBetweenChunks(Chunk from, Chunk to)
        {
            int distanceX = Math.Abs(to.ChunkX - from.ChunkX);
            int distanceZ = Math.Abs(to.ChunkZ - from.ChunkZ);

            return distanceX * distanceX + distanceZ * distanceZ;
        }