Beispiel #1
0
        public void Test_Add_Player()
        {
            var entity = new Character(new Mock <IInventoryService>().Object, new Mock <IExchangeProvider>().Object, new Mock <IItemProvider>().Object, new Mock <IDao <CharacterDto, long> >().Object, new Mock <IDao <IItemInstanceDto?, Guid> >().Object, new Mock <IDao <InventoryItemInstanceDto, Guid> >().Object, new Mock <IDao <AccountDto, long> >().Object, Logger, new Mock <IDao <StaticBonusDto, long> >().Object, new Mock <IDao <QuicklistEntryDto, Guid> >().Object, new Mock <IDao <MinilandDto, Guid> >().Object, new Mock <IMinilandProvider>().Object, new Mock <IDao <TitleDto, Guid> >().Object, new Mock <IDao <CharacterQuestDto, Guid> >().Object)
            {
                Name      = "TestExistingCharacter",
                Slot      = 1,
                AccountId = 1,
                MapId     = 1,
                State     = CharacterState.Active
            };

            _group !.JoinGroup(entity);

            Assert.IsFalse(_group.Count == 2);
        }
Beispiel #2
0
        public void Test_Add_Player()
        {
            var entity = new Character(new Mock <IInventoryService>().Object, new Mock <IExchangeProvider>().Object, new Mock <IItemProvider>().Object, new Mock <IDao <CharacterDto, long> >().Object, new Mock <IDao <IItemInstanceDto?, Guid> >().Object, new Mock <IDao <InventoryItemInstanceDto, Guid> >().Object, new Mock <IDao <AccountDto, long> >().Object, Logger, new Mock <IDao <StaticBonusDto, long> >().Object, new Mock <IDao <QuicklistEntryDto, Guid> >().Object, new Mock <IDao <MinilandDto, Guid> >().Object, new Mock <IMinilandProvider>().Object, new Mock <IDao <TitleDto, Guid> >().Object,
                                       new Mock <IDao <CharacterQuestDto, Guid> >().Object, new HpService(), new MpService(), new ExperienceService(), new JobExperienceService(), new HeroExperienceService(), new SpeedService(), new ReputationService(), new DignityService(), TestHelpers.Instance.WorldConfiguration)
            {
                Name      = "TestExistingCharacter",
                Slot      = 1,
                AccountId = 1,
                MapId     = 1,
                State     = CharacterState.Active
            };

            _group !.JoinGroup(entity);

            Assert.IsFalse(_group.Count == 2);
        }
        private void InitializeTargetSession()
        {
            var targetAccount = new AccountDto {
                Name = "test2", Password = "******".ToSha512()
            };

            _accountDao.InsertOrUpdate(ref targetAccount);

            _targetChar = new Character(null, null, null, _characterRelationDao, _characterDao, _itemInstanceDao, _accountDao, _logger)
            {
                CharacterId = 1,
                Name        = "TestChar2",
                Slot        = 1,
                AccountId   = targetAccount.AccountId,
                MapId       = 1,
                State       = CharacterState.Active
            };

            CharacterDto character = _targetChar;

            _characterDao.InsertOrUpdate(ref character);
            var instanceAccessService = new MapInstanceProvider(new List <MapDto> {
                _map, _map2
            },
                                                                new MapItemProvider(new List <IHandler <MapItem, Tuple <MapItem, GetPacket> > >()),
                                                                _mapNpcDao,
                                                                _mapMonsterDao, _portalDao, new Adapter(), _logger);

            _targetSession = new ClientSession(null,
                                               new List <PacketController> {
                new DefaultPacketController(null, instanceAccessService, null, _logger)
            },
                                               instanceAccessService, null, _logger)
            {
                SessionId = 2
            };
            var handler2 = new DefaultPacketController(null, instanceAccessService, null, _logger);

            handler2.RegisterSession(_targetSession);

            _targetSession.InitializeAccount(targetAccount);

            _targetSession.SetCharacter(_targetChar);
            _targetSession.Character.MapInstance = instanceAccessService.GetBaseMapById(0);
            _targetSession.Character.CharacterId = 2;
            Broadcaster.Instance.RegisterSession(_targetSession);
        }
Beispiel #4
0
        public void Test_Leader_Change()
        {
            for (var i = 0; i < (long)_group !.Type; i++)
            {
                var entity = new Character(new Mock <IInventoryService>().Object, new Mock <IExchangeProvider>().Object, new Mock <IItemProvider>().Object, new Mock <IDao <CharacterDto, long> >().Object, new Mock <IDao <IItemInstanceDto?, Guid> >().Object, new Mock <IDao <InventoryItemInstanceDto, Guid> >().Object, new Mock <IDao <AccountDto, long> >().Object, Logger, new Mock <IDao <StaticBonusDto, long> >().Object, new Mock <IDao <QuicklistEntryDto, Guid> >().Object, new Mock <IDao <MinilandDto, Guid> >().Object, new Mock <IMinilandProvider>().Object, new Mock <IDao <TitleDto, Guid> >().Object, new Mock <IDao <CharacterQuestDto, Guid> >().Object)
                {
                    CharacterId = i + 1,
                    Name        = $"TestExistingCharacter{i}",
                    Slot        = 1,
                    AccountId   = i + 1,
                    MapId       = 1,
                    State       = CharacterState.Active
                };

                _group.JoinGroup(entity);
            }

            Assert.IsTrue(_group.IsGroupFull && _group.IsGroupLeader(_group.ElementAt(0).Value.Item2.VisualId));

            _group.LeaveGroup(_group.ElementAt(0).Value.Item2);

            Assert.IsTrue(!_group.IsGroupFull && _group.IsGroupLeader(_group.ElementAt(1).Value.Item2.VisualId));
        }
        public void Setup()
        {
            PacketFactory.Initialize <NoS0575Packet>();
            Broadcaster.Reset();
            var contextBuilder = new DbContextOptionsBuilder <NosCoreContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString());

            DataAccessHelper.Instance.InitializeForTest(contextBuilder.Options);
            var map = new MapDto {
                MapId = 1
            };

            DaoFactory.MapDao.InsertOrUpdate(ref map);
            var account = new AccountDto {
                Name = "AccountTest", Password = "******".ToSha512()
            };

            DaoFactory.AccountDao.InsertOrUpdate(ref account);
            WebApiAccess.RegisterBaseAdress();
            WebApiAccess.Instance.MockValues =
                new Dictionary <WebApiRoute, object>
            {
                { WebApiRoute.Channel, new List <ChannelInfo> {
                      new ChannelInfo()
                  } },
                { WebApiRoute.ConnectedAccount, new List <ConnectedAccount>() }
            };

            var _chara = new Character(null, null, null)
            {
                CharacterId = 1,
                Name        = "TestExistingCharacter",
                Slot        = 1,
                AccountId   = account.AccountId,
                MapId       = 1,
                State       = CharacterState.Active
            };

            _itemProvider = new ItemProvider(new List <Item>(),
                                             new List <IHandler <Item, Tuple <IItemInstance, UseItemPacket> > >());
            var instanceAccessService = new MapInstanceProvider(new List <NpcMonsterDto>(), new List <Map> {
                _map, _map2
            },
                                                                new MapItemProvider(new List <IHandler <MapItem, Tuple <MapItem, GetPacket> > >()),
                                                                new MapNpcProvider(_itemProvider, new List <ShopDto>(), new List <ShopItemDto>(), new List <NpcMonsterDto>(), new List <MapNpcDto>()),
                                                                new MapMonsterProvider(new List <Item>(), new List <ShopDto>(), new List <ShopItemDto>(), new List <NpcMonsterDto>(), new List <MapMonsterDto>()));
            var channelMock = new Mock <IChannel>();

            _session = new ClientSession(null, new List <PacketController> {
                new DefaultPacketController(null, instanceAccessService, null)
            }, instanceAccessService, null);
            _session.RegisterChannel(channelMock.Object);
            _session.InitializeAccount(account);
            _session.SessionId = 1;
            _handler           = new DefaultPacketController(new WorldConfiguration(), instanceAccessService, null);
            _handler.RegisterSession(_session);
            _session.SetCharacter(_chara);
            var mapinstance = instanceAccessService.GetBaseMapById(0);

            _session.Character.MapInstance         = instanceAccessService.GetBaseMapById(0);
            _session.Character.MapInstance         = mapinstance;
            _session.Character.MapInstance.Portals = new List <Portal> {
                new Portal
                {
                    DestinationMapId         = _map2.MapId,
                    Type                     = PortalType.Open,
                    SourceMapInstanceId      = mapinstance.MapInstanceId,
                    DestinationMapInstanceId = instanceAccessService.GetBaseMapById(1).MapInstanceId,
                    DestinationX             = 5,
                    DestinationY             = 5,
                    PortalId                 = 1,
                    SourceMapId              = _map.MapId,
                    SourceX                  = 0,
                    SourceY                  = 0,
                }
            };

            Broadcaster.Instance.RegisterSession(_session);
        }
        public void Setup()
        {
            TypeAdapterConfig.GlobalSettings.ForDestinationType <IInitializable>().AfterMapping(dest => Task.Run(() => dest.Initialize()));
            PacketFactory.Initialize <NoS0575Packet>();
            Broadcaster.Reset();
            var contextBuilder =
                new DbContextOptionsBuilder <NosCoreContext>().UseInMemoryDatabase(
                    databaseName: Guid.NewGuid().ToString());

            DataAccessHelper.Instance.InitializeForTest(contextBuilder.Options);
            var map = new MapDto {
                MapId = 1
            };

            _mapDao.InsertOrUpdate(ref map);
            var account = new AccountDto {
                Name = "AccountTest", Password = "******".ToSha512()
            };

            _accountDao.InsertOrUpdate(ref account);
            WebApiAccess.RegisterBaseAdress();
            WebApiAccess.Instance.MockValues =
                new Dictionary <WebApiRoute, object>
            {
                { WebApiRoute.Channel, new List <ChannelInfo> {
                      new ChannelInfo()
                  } },
                { WebApiRoute.ConnectedAccount, new List <ConnectedAccount>() }
            };

            var conf = new WorldConfiguration {
                BackpackSize = 3, MaxItemAmount = 999, MaxGoldAmount = 999_999_999
            };
            var _chara = new Character(new InventoryService(new List <ItemDto>(), conf, _logger), null, null, _characterRelationDao, _characterDao, _itemInstanceDao, _accountDao, _logger)
            {
                CharacterId = 1,
                Name        = "TestExistingCharacter",
                Slot        = 1,
                AccountId   = account.AccountId,
                MapId       = 1,
                State       = CharacterState.Active
            };

            ItemProvider itemProvider = new ItemProvider(new List <ItemDto>(),
                                                         new List <IHandler <Item, Tuple <IItemInstance, UseItemPacket> > >());

            _instanceProvider = new MapInstanceProvider(new List <MapDto> {
                _map, _mapShop
            },
                                                        new MapItemProvider(new List <IHandler <MapItem, Tuple <MapItem, GetPacket> > >()),
                                                        _mapNpcDao,
                                                        _mapMonsterDao, _portalDao, new Adapter(), _logger);
            _instanceProvider.Initialize();
            var channelMock = new Mock <IChannel>();

            _session = new ClientSession(null,
                                         new List <PacketController> {
                new DefaultPacketController(null, _instanceProvider, null, _logger)
            },
                                         _instanceProvider, null, _logger);
            _session.RegisterChannel(channelMock.Object);
            _session.InitializeAccount(account);
            _session.SessionId = 1;
            _handler           = new NpcPacketController(conf,
                                                         new NrunProvider(
                                                             new List <IHandler <Tuple <IAliveEntity, NrunPacket>, Tuple <IAliveEntity, NrunPacket> > >()), _logger);
            _handler.RegisterSession(_session);
            _session.SetCharacter(_chara);
            var mapinstance = _instanceProvider.GetBaseMapById(0);

            _session.Character.Account             = account;
            _session.Character.MapInstance         = mapinstance;
            _session.Character.MapInstance.Portals = new List <Portal>
            {
                new Portal
                {
                    DestinationMapId         = _map.MapId,
                    Type                     = PortalType.Open,
                    SourceMapInstanceId      = mapinstance.MapInstanceId,
                    DestinationMapInstanceId = mapinstance.MapInstanceId,
                    DestinationX             = 5,
                    DestinationY             = 5,
                    PortalId                 = 1,
                    SourceMapId              = _map.MapId,
                    SourceX                  = 0,
                    SourceY                  = 0,
                }
            };

            Broadcaster.Instance.RegisterSession(_session);
        }