Exemple #1
0
 public void Setup()
 {
     TestHelpers.Reset();
     Broadcaster.Reset();
     TestHelpers.Reset();
     _instanceProvider  = TestHelpers.Instance.MapInstanceProvider;
     _session           = TestHelpers.Instance.GenerateSession();
     _sellPacketHandler = new SellPacketHandler(TestHelpers.Instance.WorldConfiguration);
 }
Exemple #2
0
 public void Setup()
 {
     Broadcaster.Reset();
     TestHelpers.Reset();
     _friendHttpClient = new Mock <IFriendHttpClient>().Object;
     TestHelpers.Instance.WorldConfiguration.BackpackSize = 3;
     _instanceProvider = TestHelpers.Instance.MapInstanceProvider;
     _session          = TestHelpers.Instance.GenerateSession();
 }
        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);
        }
        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);
        }
Exemple #6
0
        public void Setup()
        {
            TypeAdapterConfig.GlobalSettings.ForDestinationType <IInitializable>().AfterMapping(dest => Task.Run(() => dest.Initialize()));
            TypeAdapterConfig <MapNpcDto, MapNpc> .NewConfig().ConstructUsing(src => new MapNpc(null, _shopDao, _shopItemDao, new List <NpcMonsterDto>(), _logger));

            PacketFactory.Initialize <NoS0575Packet>();
            var contextBuilder =
                new DbContextOptionsBuilder <NosCoreContext>().UseInMemoryDatabase(
                    databaseName: Guid.NewGuid().ToString());

            DataAccessHelper.Instance.InitializeForTest(contextBuilder.Options);

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

            _accountDao.InsertOrUpdate(ref account);

            var npc = new MapNpcDto();

            _mapNpcDao.InsertOrUpdate(ref npc);

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

            instanceAccessService.Initialize();
            var items = new List <ItemDto>
            {
                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
                },
                new Item
                {
                    Type   = PocketType.Main, VNum = 1078, ItemType = ItemType.Special,
                    Effect = ItemEffectType.DroppedSpRecharger, EffectValue = 10_000, WaitDelay = 5_000
                }
            };

            _item = new ItemProvider(items, new List <IHandler <Item, Tuple <IItemInstance, UseItemPacket> > >());
            var conf = new WorldConfiguration {
                MaxItemAmount = 999, BackpackSize = 99
            };

            _session = new ClientSession(conf,
                                         new List <PacketController> {
                new DefaultPacketController(conf, instanceAccessService, null, _logger)
            },
                                         instanceAccessService, null, _logger);
            _handler = new NpcPacketController(new WorldConfiguration(),
                                               new NrunProvider(new List <IHandler <Tuple <IAliveEntity, NrunPacket>, Tuple <IAliveEntity, NrunPacket> > >
            {
                new ChangeClassHandler()
            }), _logger);
            var _chara = new GameObject.Character(new InventoryService(items, _session.WorldConfiguration, _logger),
                                                  null, null, _characterRelationDao, _characterDao, _itemInstanceDao, _accountDao, _logger)
            {
                CharacterId = 1,
                Name        = "TestExistingCharacter",
                Slot        = 1,
                AccountId   = account.AccountId,
                MapId       = 0,
                State       = CharacterState.Active,
                Account     = account
            };

            var channelMock = new Mock <IChannel>();

            _session.RegisterChannel(channelMock.Object);
            _session.InitializeAccount(account);
            _session.SessionId = 1;
            _session.SetCharacter(_chara);
            var mapinstance = instanceAccessService.GetBaseMapById(0);

            _session.Character.MapInstance = instanceAccessService.GetBaseMapById(0);
            _session.Character.MapInstance = mapinstance;
            Broadcaster.Instance.RegisterSession(_session);
        }