Ejemplo n.º 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));
        }
Ejemplo n.º 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;
 }
Ejemplo n.º 3
0
        public void Setup()
        {
            SystemTime.Freeze();
            PacketFactory.Initialize <NoS0575Packet>();
            var contextBuilder =
                new DbContextOptionsBuilder <NosCoreContext>().UseInMemoryDatabase(
                    databaseName: Guid.NewGuid().ToString());

            DataAccessHelper.Instance.InitializeForTest(contextBuilder.Options);
            var _acc = new AccountDto {
                Name = "AccountTest", Password = "******".ToSha512()
            };

            _chara = new CharacterDto
            {
                CharacterId = 1,
                Name        = "TestExistingCharacter",
                Slot        = 1,
                AccountId   = _acc.AccountId,
                MapId       = 1,
                State       = CharacterState.Active
            };
            _session.InitializeAccount(_acc);

            var items = new List <Item>
            {
                new Item {
                    Type = PocketType.Main, VNum = 1012, IsDroppable = true
                },
                new Item {
                    Type = PocketType.Main, VNum = 1013
                },
                new Item {
                    Type = PocketType.Equipment, VNum = 1, ItemType = ItemType.Weapon
                },
                new Item {
                    Type = PocketType.Equipment, VNum = 2, EquipmentSlot = EquipmentType.Fairy, Element = 2
                },
                new Item {
                    Type = PocketType.Equipment, VNum = 912, ItemType = ItemType.Specialist, ReputationMinimum = 2, Element = 1
                },
                new Item {
                    Type = PocketType.Equipment, VNum = 924, ItemType = ItemType.Fashion
                }
            };
            var conf = new WorldConfiguration {
                BackpackSize = 2, MaxItemAmount = 999
            };

            _itemBuilder           = new ItemBuilderService(items, new List <IHandler <Item, Tuple <IItemInstance, UseItemPacket> > >());
            _handler               = new InventoryPacketController(conf);
            _mapItemBuilderService = new MapItemBuilderService(new List <IHandler <MapItem, Tuple <MapItem, GetPacket> > > {
                new DropHandler(), new SpChargerHandler(), new GoldDropHandler()
            });
            _map = new MapInstance(new Map
            {
                Name = "testMap",
                Data = new byte[]
                {
                    8, 0, 8, 0,
                    0, 0, 0, 0, 0, 0, 0, 0,
                    0, 1, 1, 1, 0, 0, 0, 0,
                    0, 1, 1, 1, 0, 0, 0, 0,
                    0, 1, 1, 1, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 0
                }
            }
                                   , Guid.NewGuid(), false, MapInstanceType.BaseMapInstance, new List <NpcMonsterDto>(),
                                   _mapItemBuilderService, new MapNpcBuilderService(_itemBuilder, new List <ShopDto>(), new List <ShopItemDto>(), new List <NpcMonsterDto>(), new List <MapNpcDto>()),
                                   new MapMonsterBuilderService(new List <Item>(), new List <ShopDto>(), new List <ShopItemDto>(), new List <NpcMonsterDto>(), new List <MapMonsterDto>()));
            _handler.RegisterSession(_session);
            _session.SetCharacter(_chara.Adapt <Character>());
            _session.Character.MapInstance     = _map;
            _session.Character.Account         = _acc;
            _session.Character.Inventory       = new InventoryService(items, conf);
            _session.Character.ExchangeService = new ExchangeService(null, null);
        }