示例#1
0
        public MapInstance GenerateMapInstance(short mapId, MapInstanceType type)
        {
            var map = Maps.Find(m => m.MapId.Equals(mapId));

            if (map == null)
            {
                return(null);
            }

            var guid        = Guid.NewGuid();
            var mapInstance = new MapInstance(map, guid, false, type);

            mapInstance.LoadPortals();
            mapInstance.LoadMonsters();
            mapInstance.LoadNpcs();
            mapInstance.StartLife();
            Mapinstances.TryAdd(guid, mapInstance);
            return(mapInstance);
        }
示例#2
0
        public void Initialize()
        {
            // parse rates
            try
            {
                var i              = 0;
                var monstercount   = 0;
                var mapPartitioner = Partitioner.Create(DAOFactory.MapDAO.LoadAll().Cast <Map.Map>(),
                                                        EnumerablePartitionerOptions.NoBuffering);
                var mapList = new ConcurrentDictionary <short, Map.Map>();
                Parallel.ForEach(mapPartitioner, new ParallelOptions {
                    MaxDegreeOfParallelism = 8
                }, map =>
                {
                    var guid = Guid.NewGuid();
                    map.Initialize();
                    mapList[map.MapId] = map;
                    var newMap         = new MapInstance(map, guid, map.ShopAllowed, MapInstanceType.BaseMapInstance);
                    Mapinstances.TryAdd(guid, newMap);
                    Task.Run(() => newMap.LoadPortals());
                    monstercount += newMap.Monsters.Count;
                    i++;
                });
                Maps.AddRange(mapList.Select(s => s.Value));
                if (i != 0)
                {
                    Logger.Log.Info(string.Format(LogLanguage.Instance.GetMessageFromKey(LanguageKey.MAPS_LOADED), i));
                }
                else
                {
                    Logger.Log.Error(LogLanguage.Instance.GetMessageFromKey(LanguageKey.NO_MAP));
                }

                Logger.Log.Info(string.Format(LogLanguage.Instance.GetMessageFromKey(LanguageKey.MAPMONSTERS_LOADED),
                                              monstercount));
            }
            catch (Exception ex)
            {
                Logger.Log.Error("General Error", ex);
            }
        }