Esempio n. 1
0
 public virtual void Despawn()
 {
     if (CurrentChunk != null) {
         CurrentChunk.Entities.Remove(this);
         CurrentChunk = null;
     }
 }
Esempio n. 2
0
        public void SendChunk(Chunk chunk)
        {
            Transmit(PacketType.PreChunk, chunk.ChunkX, chunk.ChunkZ, (sbyte) 1);

            byte[] uncompressed = chunk.GetBytes();
            MemoryStream mem = new MemoryStream();
            ZOutputStream stream = new ZOutputStream(mem, zlibConst.Z_BEST_COMPRESSION);
            stream.Write(uncompressed, 0, uncompressed.Length);
            stream.Close();
            byte[] data = mem.ToArray();

            Transmit(PacketType.MapChunk, 16 * chunk.ChunkX, (short) 0, 16 * chunk.ChunkZ,
                (sbyte) 15, (sbyte) 127, (sbyte) 15, data.Length, data);
        }
Esempio n. 3
0
        public virtual void Update()
        {
            Chunk oldChunk = CurrentChunk;
            Chunk newChunk = Spacecraft.Server.World.GetChunkAt((int) X, (int) Z);
            if (oldChunk != newChunk) {
                if (oldChunk != null) oldChunk.Entities.Remove(this);
                newChunk.Entities.Add(this);
                CurrentChunk = newChunk;
            }

            double dx = X - _LastX, dy = Y - _LastY, dz = Z - _LastZ;
            bool rotchanged = (Yaw != _LastYaw || Pitch != _LastPitch);
            _LastX = X; _LastY = Y; _LastZ = Z;
            _LastYaw = Yaw; _LastPitch = Pitch;
            if (dx != 0 || dy != 0 || dz != 0 || rotchanged) {
                foreach (Player p in Spacecraft.Server.PlayerList) {
                    if (p != this && p.VisibleEntities.Contains(this)) p.UpdateEntity(this, dx, dy, dz, rotchanged, false);
                }
            }
        }
Esempio n. 4
0
 public Chunk GetChunk(int chunkX, int chunkZ)
 {
     Builder<byte> b = new Builder<byte>();
     b.Append(BitConverter.GetBytes(chunkX));
     b.Append(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);
     }
 }
Esempio n. 5
0
 public List<Entity> EntitiesIn(Chunk c)
 {
     return c.Entities;
 }
Esempio n. 6
0
 public List<Chunk> GetChunksInRange(Chunk c)
 {
     List<Chunk> r = new List<Chunk>();
     for (int x = c.ChunkX - 5; x <= c.ChunkX + 5; ++x) {
         for (int z = c.ChunkZ - 5; z <= c.ChunkZ + 5; ++z) {
             if (Math.Abs(c.ChunkX - x) + Math.Abs(c.ChunkZ - z) < 8) {
                 r.Add(GetChunk(x, z));
             }
         }
     }
     return r;
 }
Esempio n. 7
0
 public Entity()
 {
     CurrentChunk = null;
     EntityID = Spacecraft.Random.Next();
 }