public void AddLayer(string name, Layer layer) { _layers.Add(name, layer); }
public Pathfinder GetPathfinder(Layer layer) { return(_pathFinders[layer]); }
public static Map Load(string path) { var map = new Map(); using (var fileStream = new FileStream(path, FileMode.Open)) { using (var bR = new BinaryReader(fileStream)) { // Load the tileset information int tilesetCount = bR.ReadInt32(); for (int i = 0; i < tilesetCount; i++) { // We can throw this information away as it is used only in the editor suite. string tilesetPath = bR.ReadString(); } map.Name = bR.ReadString(); map.Dimensions = new Vector(bR.ReadInt32(), bR.ReadInt32()); map.Dark = bR.ReadBoolean(); map.Bounds = new Rect(0, 0, (int)map.Dimensions.X, (int)map.Dimensions.Y); int layerCount = bR.ReadInt32(); for (int i = 0; i < layerCount; i++) { string layerName = bR.ReadString(); int lIndex = bR.ReadInt32(); var layer = new Layer(map.Dimensions, layerName, lIndex); layer.Load(bR); layer.NPCSpawnerEvent += (sender, args) => { var npcDesc = Server.ServiceLocator.GetService <NPCManager>().GetNPC(args.Name); if (npcDesc == null) { Logger.LogEvent($"Error spawning NPC: {args.Name} does not exist!", LogTypes.ERROR, Environment.StackTrace); return; } NPC npc = new NPC(npcDesc, map) { Layer = (Layer)sender }; npc.WarpTo(args.Position); // This allows the tile spawner to keep track of npcs that exist, and respawn if neccessary (i.e., they die). args.HeartbeatListener.NPCs.Add(npc); }; map.AddLayer(layerName, layer); } } } // Look for spawnpoints foreach (var layer in map.Layers) { for (int x = 0; x < map.Dimensions.X; x++) { for (int y = 0; y < map.Dimensions.Y; y++) { if (layer.GetTile(x, y) != null && layer.GetTile(x, y).Attribute == TileAttributes.PlayerSpawn) { map.AddPlayerStartArea(new Vector(x * Settings.TileSize, y * Settings.TileSize), layer); } } } } return(map); }
public void AddPlayerStartArea(Vector playerStartArea, Layer layer) { _playerSpawnAreas.Add(new Tuple <Vector, Layer>(playerStartArea, layer)); }