public void UserCanNotCreateShopWithMissingItem()
        {
            var items = new List <Item>
            {
                new Item {
                    Type = PocketType.Etc, VNum = 1
                },
            };
            var itemBuilder = new ItemBuilderService(items, new List <IHandler <Item, Tuple <IItemInstance, UseItemPacket> > >());

            _session.Character.Inventory.AddItemToPocket(itemBuilder.Create(1, 1));
            _session.Character.MapInstance = _instanceAccessService.GetBaseMapById(1);
            _handler.CreateShop(shopPacket);
            Assert.IsNull(_session.Character.Shop);
        }
Exemple #2
0
        public void Teleport(TeleportPacket teleportPacket)
        {
            var session =
                Broadcaster.Instance.GetCharacter(s =>
                                                  s.Name == teleportPacket.TeleportArgument); //TODO setter to protect

            if (!short.TryParse(teleportPacket.TeleportArgument, out var mapId))
            {
                if (session == null)
                {
                    _logger.Error(Language.Instance.GetMessageFromKey(LanguageKey.USER_NOT_CONNECTED,
                                                                      Session.Account.Language));
                    return;
                }

                Session.ChangeMapInstance(session.MapInstanceId, session.MapX, session.MapY);
                return;
            }

            var mapInstance = _mapInstanceAccessService.GetBaseMapById(mapId);

            if (mapInstance == null)
            {
                _logger.Error(
                    Language.Instance.GetMessageFromKey(LanguageKey.MAP_DONT_EXIST, Session.Account.Language));
                return;
            }

            Session.ChangeMap(mapId, teleportPacket.MapX, teleportPacket.MapY);
        }
        public void Teleport(TeleportPacket teleportPacket)
        {
            var session =
                ServerManager.Instance.Sessions.Values.FirstOrDefault(s =>
                                                                      s.Character.Name == teleportPacket.TeleportArgument);

            if (!short.TryParse(teleportPacket.TeleportArgument, out var mapId))
            {
                if (session == null)
                {
                    Logger.Log.Error(Language.Instance.GetMessageFromKey(LanguageKey.USER_NOT_CONNECTED,
                                                                         Session.Account.Language));
                    return;
                }

                Session.ChangeMap(session.Character.MapId, session.Character.MapX, session.Character.MapY);
                return;
            }

            var mapInstance = _mapInstanceAccessService.GetBaseMapById(mapId);

            if (mapInstance == null)
            {
                Logger.Log.Error(
                    Language.Instance.GetMessageFromKey(LanguageKey.MAP_DONT_EXIST, Session.Account.Language));
                return;
            }

            Session.ChangeMap(mapId, teleportPacket.MapX, teleportPacket.MapY);
        }
        private void InitializeTargetSession()
        {
            var targetAccount = new AccountDto {
                Name = "test2", Password = "******".ToSha512()
            };

            DaoFactory.AccountDao.InsertOrUpdate(ref targetAccount);

            _targetChar = new CharacterDto
            {
                CharacterId = 1,
                Name        = "TestChar2",
                Slot        = 1,
                AccountId   = targetAccount.AccountId,
                MapId       = 1,
                State       = CharacterState.Active
            };

            DaoFactory.CharacterDao.InsertOrUpdate(ref _targetChar);
            var instanceAccessService = new MapInstanceAccessService(new List <NpcMonsterDto>(), new List <Map> {
                _map, _map2
            },
                                                                     new MapItemBuilderService(new List <IHandler <MapItem, Tuple <MapItem, GetPacket> > >()),
                                                                     new MapNpcBuilderService(_itemBuilderService, 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>()));

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

            handler2.RegisterSession(_targetSession);

            _targetSession.InitializeAccount(targetAccount);

            _targetSession.SetCharacter(_targetChar.Adapt <Character>());
            _targetSession.Character.MapInstance = instanceAccessService.GetBaseMapById(0);
            _targetSession.Character.CharacterId = 2;
            Broadcaster.Instance.RegisterSession(_targetSession);
        }
        private void InitializeTargetSession()
        {
            var targetAccount = new AccountDto {
                Name = "test2", Password = EncryptionHelper.Sha512("test")
            };

            DaoFactory.AccountDao.InsertOrUpdate(ref targetAccount);

            _targetChar = new CharacterDto
            {
                CharacterId = 1,
                Name        = "TestChar2",
                Slot        = 1,
                AccountId   = targetAccount.AccountId,
                MapId       = 1,
                State       = CharacterState.Active
            };

            DaoFactory.CharacterDao.InsertOrUpdate(ref _targetChar);
            var instanceAccessService = new MapInstanceAccessService(new List <NpcMonsterDto>(), new List <Map> {
                _map, _map2
            });

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

            handler2.RegisterSession(_targetSession);

            _targetSession.InitializeAccount(targetAccount);

            _targetSession.SetCharacter(_targetChar.Adapt <Character>());
            _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 CharacterDto
            {
                CharacterId = 1,
                Name        = "TestExistingCharacter",
                Slot        = 1,
                AccountId   = account.AccountId,
                MapId       = 1,
                State       = CharacterState.Active
            };

            DaoFactory.CharacterDao.InsertOrUpdate(ref _chara);

            _itemBuilderService = new ItemBuilderService(new List <Item>(),
                                                         new List <IHandler <Item, Tuple <IItemInstance, UseItemPacket> > >());
            _instanceAccessService = new MapInstanceAccessService(new List <NpcMonsterDto>(), new List <Map> {
                _map, _mapShop
            },
                                                                  new MapItemBuilderService(new List <IHandler <MapItem, Tuple <MapItem, GetPacket> > >()),
                                                                  new MapNpcBuilderService(_itemBuilderService, 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>()));

            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;
            var conf = new WorldConfiguration()
            {
                BackpackSize = 3, MaxItemAmount = 999, MaxGoldAmount = 999_999_999
            };

            _handler = new NpcPacketController(conf, new NrunAccessService(new List <IHandler <Tuple <IAliveEntity, NrunPacket>, Tuple <IAliveEntity, NrunPacket> > >()));
            _handler.RegisterSession(_session);
            _session.SetCharacter(_chara.Adapt <Character>());
            var mapinstance = _instanceAccessService.GetBaseMapById(0);

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

            _session.Character.Inventory = new InventoryService(new List <Item>(), conf);
            Broadcaster.Instance.RegisterSession(_session);
        }
        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 = EncryptionHelper.Sha512("test")
            };

            DaoFactory.AccountDao.InsertOrUpdate(ref account);
            WebApiAccess.RegisterBaseAdress();
            WebApiAccess.Instance.MockValues =
                new Dictionary <string, object>
            {
                { "api/channels", new List <WorldServerInfo> {
                      new WorldServerInfo()
                  } },
                { "api/connectedAccount", new List <ConnectedAccount>() }
            };

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

            DaoFactory.CharacterDao.InsertOrUpdate(ref _chara);
            var instanceAccessService = new MapInstanceAccessService(new List <NpcMonsterDto>(), new List <Map> {
                _map, _map2
            });
            var channelMock = new Mock <IChannel>();

            _session = new ClientSession(null, new List <PacketController> {
                new DefaultPacketController(null, instanceAccessService)
            }, instanceAccessService);
            _session.RegisterChannel(channelMock.Object);
            _session.InitializeAccount(account);
            _session.SessionId = 1;
            _handler           = new DefaultPacketController(null, instanceAccessService);
            _handler.RegisterSession(_session);
            _session.SetCharacter(_chara.Adapt <Character>());
            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);
        }