public void SpawnMapNpc(Npc mapNpc) { this._mapNpcs.Add(mapNpc); }
private void HandleMapData(PacketReceivedEventArgs args) { var map = new Map { Name = args.Message.ReadString(), Version = args.Message.ReadInt32() }; map.ResizeMap(args.Message.ReadInt32(), args.Message.ReadInt32()); for (int x = 0; x < map.Width; x++) { for (int y = 0; y < map.Height; y++) { map.SetTile(x, y, new Map.Tile()); map.GetTile(x, y).Blocked = args.Message.ReadBoolean(); foreach (Map.Layers layer in Enum.GetValues(typeof(Map.Layers))) { if (!args.Message.ReadBoolean()) continue; var textureNumber = args.Message.ReadInt32(); var left = args.Message.ReadInt32(); var top = args.Message.ReadInt32(); var width = args.Message.ReadInt32(); var height = args.Message.ReadInt32(); var textureRect = new IntRect(left, top, width, height); var tileSprite = new Sprite(ServiceLocator.ScreenManager.ActiveScreen.TextureManager.GetTexture("tileset" + textureNumber.ToString())) { TextureRect = textureRect }; map.GetTile(x, y).SetLayer(layer, new Map.Tile.Layer(tileSprite, x, y)); } } } var mapNpcCount = args.Message.ReadInt32(); for (int i = 0; i < mapNpcCount; i++) { var npc = new Npc() { Name = args.Message.ReadString(), Level = args.Message.ReadInt32(), Sprite = new Sprite(ServiceLocator.ScreenManager.ActiveScreen.TextureManager.GetTexture("npc" + args.Message.ReadInt32())), }; var position = args.Message.ReadVector(); npc.Position = new SFML.System.Vector2i(position.X, position.Y); } map.CacheMap(); this.Map = map; // Notify the server that we're now in the game. var net = ServiceLocator.NetManager; var packet = new Packet(PacketType.MapCheckPacket); packet.Message.Write(true); net.SendMessage(packet.Message, Lidgren.Network.NetDeliveryMethod.ReliableOrdered, ChannelTypes.WORLD); }