Exemple #1
0
        public void UserCanNotSellInExchange()
        {
            _session.Character.InExchangeOrTrade = true;
            var items = new List <ItemDto>
            {
                new Item {
                    Type = NoscorePocketType.Etc, VNum = 1, IsTradable = true
                }
            };
            var itemBuilder = new ItemProvider(items,
                                               new List <IEventHandler <Item, Tuple <InventoryItemInstance, UseItemPacket> > >());

            _session.Character.InventoryService.AddItemToPocket(InventoryItemInstance.Create(itemBuilder.Create(1, 1), 0),
                                                                NoscorePocketType.Etc, 0);
            _session.Character.InventoryService.AddItemToPocket(InventoryItemInstance.Create(itemBuilder.Create(1, 2), 0),
                                                                NoscorePocketType.Etc, 1);
            _session.Character.InventoryService.AddItemToPocket(InventoryItemInstance.Create(itemBuilder.Create(1, 3), 0),
                                                                NoscorePocketType.Etc, 2);

            _session.Character.MapInstance = _instanceProvider.GetBaseMapById(1);
            _sellPacketHandler.Execute(new SellPacket {
                Slot = 0, Amount = 1, Data = (short)NoscorePocketType.Etc
            },
                                       _session);
            Assert.IsTrue(_session.Character.Gold == 0);
            Assert.IsNotNull(_session.Character.InventoryService.LoadBySlotAndType(0, NoscorePocketType.Etc));
        }
Exemple #2
0
        public void UserCanNotCreateShopWithMissingItem()
        {
            var items = new List <Item>
            {
                new Item {
                    Type = PocketType.Etc, VNum = 1
                },
            };
            var itemBuilder = new ItemProvider(items, new List <IHandler <Item, Tuple <IItemInstance, UseItemPacket> > >());

            _session.Character.Inventory.AddItemToPocket(itemBuilder.Create(1, 1));
            _session.Character.MapInstance = _instanceProvider.GetBaseMapById(1);
            _handler.CreateShop(shopPacket);
            Assert.IsNull(_session.Character.Shop);
        }
        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);
        }
Exemple #7
0
        private ClientSession PrepareSessionShop()
        {
            var conf = new WorldConfiguration {
                BackpackSize = 3, MaxItemAmount = 999, MaxGoldAmount = 999_999_999
            };
            var session2    = new ClientSession(conf, _logger, new List <IPacketHandler>(), _friendHttpClient, null, null);
            var channelMock = new Mock <IChannel>();

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

            session2.InitializeAccount(account);
            session2.SessionId = 1;

            session2.SetCharacter(new Character(new InventoryService(new List <ItemDto>(), conf, _logger), null, null,
                                                null, null, null, null, _logger, null, null, null, null, null)
            {
                CharacterId = 1,
                Name        = "chara2",
                Slot        = 1,
                AccountId   = 1,
                MapId       = 1,
                State       = CharacterState.Active
            });
            var mapinstance = _instanceProvider.GetBaseMapById(0);

            session2.Character.Account     = account;
            session2.Character.MapInstance = _instanceProvider.GetBaseMapById(0);
            session2.Character.MapInstance = mapinstance;

            _session.Character.Gold = 500000;
            var items = new List <ItemDto>
            {
                new Item {
                    Type = NoscorePocketType.Etc, VNum = 1, IsSoldable = true, Price = 1
                }
            };
            var itemBuilder = new ItemProvider(items,
                                               new List <IEventHandler <Item, Tuple <InventoryItemInstance, UseItemPacket> > >());

            _session.Character.ItemProvider = itemBuilder;
            var list = new ConcurrentDictionary <int, ShopItem>();
            var it   = itemBuilder.Create(1, 999);

            session2.Character.InventoryService.AddItemToPocket(
                InventoryItemInstance.Create(it, session2.Character.CharacterId), NoscorePocketType.Etc, 0);
            list.TryAdd(0, new ShopItem {
                Slot = 0, ItemInstance = it, Type = 0, Price = 1, Amount = 999
            });
            list.TryAdd(1, new ShopItem {
                Slot = 1, ItemInstance = it, Type = 0, Price = 1, Amount = 500
            });
            session2.Character.Shop = new Shop
            {
                Session   = session2,
                ShopItems = list
            };
            _session.Character.InventoryService.AddItemToPocket(
                InventoryItemInstance.Create(itemBuilder.Create(1, 999), session2.Character.CharacterId),
                NoscorePocketType.Etc, 0);
            _session.Character.InventoryService.AddItemToPocket(
                InventoryItemInstance.Create(itemBuilder.Create(1, 999), session2.Character.CharacterId),
                NoscorePocketType.Etc, 1);
            return(session2);
        }