Exemplo n.º 1
0
        private static void ParseTiles(XElement xMap, ServerMap map)
        {
            foreach (var xLayer in xMap.Elements("layer"))
            {
                var layerType = xLayer.Attribute("name").Value;

                foreach (var xChunk in xLayer.Element("data").Elements("chunk"))
                {
                    var csvData = Regex.Replace((string)xChunk.Value, @"\t|\n|\r", "");
                    var chunkX  = Int16.Parse(xChunk.Attribute("x").Value) / Chunk.SIZE;
                    var chunkY  = Int16.Parse(xChunk.Attribute("y").Value) / Chunk.SIZE;

                    if (layerType == LAYER_FLOOR)
                    {
                        var chunk = new ServerChunk()
                        {
                            x = chunkX,
                            y = chunkY
                        };
                        var tileArray = csvData.Split(',');
                        for (int y = 0; y < Chunk.SIZE; y++)
                        {
                            for (int x = 0; x < Chunk.SIZE; x++)
                            {
                                var tile = Int16.Parse(tileArray[x + y * Chunk.SIZE]);
                                chunk.SetTile(x, y, tile);
                            }
                        }
                        map.AddChunk(chunk);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private static void ParseTiles(XElement xMap, ServerMap map)
        {
            foreach (var xLayer in xMap.Elements("layer"))
            {
                var layerType = xLayer.Attribute("name").Value;

                foreach (var xChunk in xLayer.Element("data").Elements("chunk"))
                {
                    var csvData = Regex.Replace((string)xChunk.Value, @"\t|\n|\r", "");
                    var chunkX  = Int16.Parse(xChunk.Attribute("x").Value) / Chunk.SIZE;
                    var chunkY  = Int16.Parse(xChunk.Attribute("y").Value) / Chunk.SIZE;

                    if (layerType == LAYER_FLOOR)
                    {
                        var chunk = new ServerChunk()
                        {
                            x = chunkX,
                            y = chunkY
                        };
                        var tileArray = csvData.Split(',');
                        for (int y = 0; y < Chunk.SIZE; y++)
                        {
                            for (int x = 0; x < Chunk.SIZE; x++)
                            {
                                var tilePositionX = chunk.x * Chunk.SIZE + x;
                                var tilePositionY = chunk.y * Chunk.SIZE + y;
                                var tileId        = Int16.Parse(tileArray[x + y * Chunk.SIZE]);
                                chunk.Tiles[x, y] = new MapTile(new Position(tilePositionX, tilePositionY), tileId);
                            }
                        }
                        chunk.BuildChunkPacketData();
                        map.AddChunk(chunk);
                    }
                }
            }
        }
Exemplo n.º 3
0
 public void MoveFromChunk(Entity e, ServerChunk from)
 {
     this.EntitiesInChunk[e.EntityType].Add(e);
     from.EntitiesInChunk[e.EntityType].Remove(e);
 }