コード例 #1
0
        //MapPacket
        private static void HandleMap(MapPacket packet)
        {
            var mapId = packet.MapId;
            var map   = MapInstance.Get(mapId);

            if (map != null)
            {
                if (packet.Revision == map.Revision)
                {
                    return;
                }
                else
                {
                    map.Dispose(false, false);
                }
            }

            map = new MapInstance(mapId);
            MapInstance.Lookup.Set(mapId, map);
            lock (map.MapLock)
            {
                map.Load(packet.Data);
                map.LoadTileData(packet.TileData);
                map.AttributeData = packet.AttributeData;
                map.CreateMapSounds();
                if (mapId == Globals.Me.CurrentMap)
                {
                    Audio.PlayMusic(map.Music, 3, 3, true);
                }

                map.MapGridX    = packet.GridX;
                map.MapGridY    = packet.GridY;
                map.CameraHolds = packet.CameraHolds;
                map.Autotiles.InitAutotiles(map.GenerateAutotileGrid());

                //Process Entities and Items if provided in this packet
                if (packet.MapEntities != null)
                {
                    HandlePacket((dynamic)packet.MapEntities);
                }

                if (packet.MapItems != null)
                {
                    HandlePacket((dynamic)packet.MapItems);
                }

                if (Globals.PendingEvents.ContainsKey(mapId))
                {
                    foreach (var evt in Globals.PendingEvents[mapId])
                    {
                        map.AddEvent(evt.Key, evt.Value);
                    }

                    Globals.PendingEvents[mapId].Clear();
                }
            }

            if (MapInstance.OnMapLoaded != null)
            {
                MapInstance.OnMapLoaded(map);
            }
        }