/// <summary> /// Get a chunk by chunk coodinates /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> public MapLayerChunk GetChunk(int x, int y, int layer) { MapLayerChunk chunk = null; layerchunks.TryGetValue(GetChunkKey(x, y, layer), out chunk); return(chunk); }
public MapLayerChunk GetOrCreateChunk(int x, int y, int layer) { bool cExists = ChunkExists(x, y, layer); MapLayerChunk c = CreateChunk(x, y, layer); return(c); //return ChunkExists(x, y) ? CreateChunk(x, y) : CreateChunk(x, y); }
internal void DeleteTile(int x, int y, int layer) { //(int)MathF.Floor((float)_x / (float)MapManager.Settings.chunkSize) int chunkX = (int)MathF.Floor((float)x / (float)Settings.chunkSize); int chunkY = (int)MathF.Floor((float)y / (float)Settings.chunkSize); MapLayerChunk c = GetOrCreateChunk(chunkX, chunkY, layer); c.DeleteTile(x, y); }
/// <summary> /// Creates a chunk at the given chunk coordinates, eg: 1, 2; 2, 2; 2, 1; 10,22; etc..... /// </summary> /// <param name="posX">Chunk posX</param> /// <param name="posY">Chunk PosY</param> /// <returns></returns> public MapLayerChunk CreateChunk(int x, int y, int layer) { MapLayerChunk c = GetChunk(x, y, layer); if (c == null) { c = new MapLayerChunk(); layerchunks.Add(GetChunkKey(x, y, layer), c); } return(c); }
public MapTile SetTile(int x, int y, int layer, int tileID) { //(int)MathF.Floor((float)_x / (float)MapManager.Settings.chunkSize) int chunkX = (int)MathF.Floor((float)x / (float)Settings.chunkSize); int chunkY = (int)MathF.Floor((float)y / (float)Settings.chunkSize); MapLayerChunk c = GetOrCreateChunk(chunkX, chunkY, layer); //RegionalServer.logList.Add(new object[] { ConsoleColor.White, "1" }); //RegionalServer.UpdateConsole(); if (layer < 0) { return(c.SetTileEntity(x, y, tileID)); // Returning the tile entity tile } //RegionalServer.logList.Add(new object[] { ConsoleColor.White, "2" }); //RegionalServer.UpdateConsole(); return(c.SetTile(x, y, tileID)); //or the tile itself }
internal void SendChunkToClient(Client client, int x, int y, int layer) { MapLayerChunk c = GetChunk(x, y, layer); MapTile t = null; if (c != null) { Debug.Log("Sending chunk, " + x + ", " + y + ", " + layer); //Creating the message NetOutgoingMessage msg = RegionalServer.server.CreateMessage(); //Creating the message header msg.Write((byte)1); //WORLD msg.Write((byte)255); //Rater193's header message group msg.Write((byte)Messages.ClientLoadMapChunk); //Load map chunk header id //Writing map data //Chunk coords msg.Write((int)x); //X msg.Write((int)y); //Y msg.Write((int)layer); //LAYER msg.Write((byte)MapManager.Settings.chunkSize); //ChunkSize //Chunk data for (int _x = 0; _x < MapManager.Settings.chunkSize; _x++) { for (int _y = 0; _y < MapManager.Settings.chunkSize; _y++) { t = c.GetTile(_x, _y); if (layer >= 0) { if (t == null) { msg.Write((int)0); } else { msg.Write((int)t.tileID); } } else { //Sending the tile entity instead of the tile, to save on bandwidth performance if (t != null) { if (t.tileEntity != null) { Debug.Log("Sending tile entity!"); Debug.Log("t.tileEntity: " + t.tileEntity); Debug.Log("t.tileEntity.renderID: " + t.tileEntity.renderID); msg.Write((int)t.tileEntity.renderID); } else { Debug.Log("Target tile has no tile entity?"); msg.Write((int)-1); } } else { msg.Write((int)-1); } } } } RegionalServer.server.SendMessage(msg, client.connection, NetDeliveryMethod.ReliableOrdered, 10); //Server.server.SendMessage(msg, client.connection, NetDeliveryMethod.Unreliable); } }