예제 #1
0
        public MapInstanceAccessService(List <NpcMonsterDto> npcMonsters, List <Map.Map> maps,
                                        MapItemBuilderService mapItemBuilderService, MapNpcBuilderService mapNpcBuilderService,
                                        MapMonsterBuilderService mapMonsterBuilderService)
        {
            var mapPartitioner = Partitioner.Create(maps, EnumerablePartitionerOptions.NoBuffering);
            var mapList        = new ConcurrentDictionary <short, Map.Map>();
            var npccount       = 0;
            var monstercount   = 0;

            Parallel.ForEach(mapPartitioner, new ParallelOptions {
                MaxDegreeOfParallelism = 8
            }, map =>
            {
                var guid           = Guid.NewGuid();
                mapList[map.MapId] = map;
                var newMap         = new MapInstance(map, guid, map.ShopAllowed, MapInstanceType.BaseMapInstance, npcMonsters,
                                                     mapItemBuilderService, mapNpcBuilderService, mapMonsterBuilderService);
                MapInstances.TryAdd(guid, newMap);
                newMap.LoadMonsters();
                newMap.LoadNpcs();
                newMap.StartLife();
                monstercount += newMap.Monsters.Count;
                npccount     += newMap.Npcs.Count;
            });
            var mapInstancePartitioner =
                Partitioner.Create(MapInstances.Values, EnumerablePartitionerOptions.NoBuffering);

            Parallel.ForEach(mapInstancePartitioner, new ParallelOptions {
                MaxDegreeOfParallelism = 8
            }, mapInstance =>
            {
                var partitioner = Partitioner.Create(
                    DaoFactory.PortalDao.Where(s => s.SourceMapId.Equals(mapInstance.Map.MapId)),
                    EnumerablePartitionerOptions.None);
                var portalList = new ConcurrentDictionary <int, Portal>();
                Parallel.ForEach(partitioner, portalDto =>
                {
                    Portal portal = portalDto.Adapt <Portal>();
                    portal.SourceMapInstanceId      = mapInstance.MapInstanceId;
                    portal.DestinationMapInstanceId = GetBaseMapInstanceIdByMapId(portal.DestinationMapId);
                    portalList[portal.PortalId]     = portal;
                });
                mapInstance.Portals.AddRange(portalList.Select(s => s.Value));
            });
            maps.AddRange(mapList.Select(s => s.Value));
        }
예제 #2
0
 public MapInstance(Map.Map map, Guid guid, bool shopAllowed, MapInstanceType type,
                    List <NpcMonsterDto> npcMonsters, MapItemBuilderService mapItemBuilderService,
                    MapNpcBuilderService mapNpcBuilderService, MapMonsterBuilderService mapMonsterBuilderService)
 {
     _npcMonsters    = npcMonsters;
     XpRate          = 1;
     DropRate        = 1;
     ShopAllowed     = shopAllowed;
     MapInstanceType = type;
     Map             = map;
     MapInstanceId   = guid;
     Portals         = new List <Portal>();
     _monsters       = new ConcurrentDictionary <long, MapMonster>();
     _npcs           = new ConcurrentDictionary <long, MapNpc>();
     MapItems        = new ConcurrentDictionary <long, MapItem>();
     _isSleeping     = true;
     LastUnregister  = SystemTime.Now().AddMinutes(-1);
     ExecutionEnvironment.TryGetCurrentExecutor(out var executor);
     Sessions = new DefaultChannelGroup(executor);
     _mapItemBuilderService    = mapItemBuilderService;
     _mapNpcBuilderService     = mapNpcBuilderService;
     _mapMonsterBuilderService = mapMonsterBuilderService;
 }