public void CreateCharacterWhenInGame_Does_Not_Create_Character()
        {
            _session.SetCharacter(_chara.Adapt <Character>());
            _session.Character.MapInstance =
                new MapInstance(new Map(), new Guid(), true, MapInstanceType.BaseMapInstance, _npcMonsters);
            const string name = "TestCharacter";

            _handler.CreateCharacter(new CharNewPacket
            {
                Name = name
            });
            Assert.IsNull(DaoFactory.CharacterDao.FirstOrDefault(s => s.Name == name));
        }
Example #2
0
        public Character LoadCharacter(CharacterDto characterDto)
        {
            Character character = characterDto.Adapt <Character>();

            character.Inventory = _inventory;
            return(character);
        }
Example #3
0
        public Character LoadCharacter(CharacterDto characterDto)
        {
            Character character = characterDto.Adapt <Character>();

            character.Inventory          = _inventory;
            character.ItemBuilderService = _itemBuilderService;
            return(character);
        }
        public void Setup()
        {
            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 = EncryptionHelper.Sha512("test")
            };

            _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 = 912, ItemType = ItemType.Specialist
                },
                new Item {
                    Type = PocketType.Equipment, VNum = 924, ItemType = ItemType.Fashion
                }
            };
            var conf = new WorldConfiguration {
                BackpackSize = 1, MaxItemAmount = 999
            };

            _itemBuilder = new ItemBuilderService(items);
            _handler     = new InventoryPacketController(conf);

            _handler.RegisterSession(_session);
            _session.SetCharacter(_chara.Adapt <Character>());
            _session.Character.MapInstance = _map;
            _session.Character.Inventory   = new InventoryService(items, conf);
        }
Example #5
0
        public void Setup()
        {
            PacketFactory.Initialize <NoS0575Packet>();
            Broadcaster.Instance.Reset();
            var contextBuilder =
                new DbContextOptionsBuilder <NosCoreContext>().UseInMemoryDatabase(Guid.NewGuid().ToString());

            DataAccessHelper.Instance.InitializeForTest(contextBuilder.Options);

            GroupAccess.Instance.Groups = new ConcurrentDictionary <long, Group>();
            for (byte i = 0; i < (byte)(GroupType.Group + 1); i++)
            {
                var handler = new GroupPacketController();
                var session = new ClientSession(null, new List <PacketController> {
                    handler
                }, null);
                session.SessionId = i;

                Broadcaster.Instance.RegisterSession(session);
                var acc = new AccountDto {
                    Name = $"AccountTest{i}", Password = EncryptionHelper.Sha512("test")
                };
                var charaDto = new CharacterDto
                {
                    CharacterId = i,
                    Name        = $"TestExistingCharacter{i}",
                    Slot        = 1,
                    AccountId   = acc.AccountId,
                    MapId       = 1,
                    State       = CharacterState.Active
                };

                session.InitializeAccount(acc);
                _handlers.Add(handler);
                handler.RegisterSession(session);

                var chara = charaDto.Adapt <Character>();
                chara.Session = session;
                _characters.Add(i, chara);
                chara.Group.JoinGroup(chara);
                session.SetCharacter(chara);
                session.Character.MapInstance = new MapInstance(new Map(), Guid.NewGuid(), true, MapInstanceType.BaseMapInstance, null);
            }
        }
Example #6
0
        public void Setup()
        {
            PacketFactory.Initialize <NoS0575Packet>();
            Broadcaster.Reset();
            GroupAccess.Instance.Groups = new ConcurrentDictionary <long, Group>();
            for (byte i = 0; i < (byte)(GroupType.Group + 1); i++)
            {
                var handler = new GroupPacketController();
                var session = new ClientSession(null, new List <PacketController> {
                    handler
                }, null, null)
                {
                    SessionId = i
                };

                Broadcaster.Instance.RegisterSession(session);
                var acc = new AccountDto {
                    Name = $"AccountTest{i}", Password = "******".ToSha512()
                };
                var charaDto = new CharacterDto
                {
                    CharacterId = i,
                    Name        = $"TestExistingCharacter{i}",
                    Slot        = 1,
                    AccountId   = acc.AccountId,
                    MapId       = 1,
                    State       = CharacterState.Active
                };

                session.InitializeAccount(acc);
                _handlers.Add(handler);
                handler.RegisterSession(session);

                var chara = charaDto.Adapt <Character>();
                chara.Session = session;
                _characters.Add(i, chara);
                chara.Group.JoinGroup(chara);
                session.SetCharacter(chara);
                session.Character.MapInstance = new MapInstance(new Map(), Guid.NewGuid(), true, MapInstanceType.BaseMapInstance,
                                                                null, new MapItemBuilderService(new List <IHandler <MapItem, Tuple <MapItem, GetPacket> > >()),
                                                                null, null);
            }
        }
        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);
        }
Example #9
0
        public override async Task ExecuteAsync(CharNewPacket packet, ClientSession clientSession)
        {
            // TODO: Hold Account Information in Authorized object
            var accountId     = clientSession.Account.AccountId;
            var slot          = packet.Slot;
            var characterName = packet.Name;

            if (await _characterDao.FirstOrDefaultAsync(s =>
                                                        (s.AccountId == accountId) && (s.Slot == slot) && (s.State == CharacterState.Active)).ConfigureAwait(false) != null)
            {
                return;
            }

            var rg = new Regex(Nameregex);

            if (rg.Matches(characterName !).Count == 1)
            {
                var character = await
                                _characterDao.FirstOrDefaultAsync(s =>
                                                                  (s.Name == characterName) && (s.State == CharacterState.Active)).ConfigureAwait(false);

                if (character == null)
                {
                    var level  = (byte)(packet.IsMartialArtist ? 81 : 1);
                    var @class = packet.IsMartialArtist ? CharacterClassType.MartialArtist
                        : CharacterClassType.Adventurer;
                    var chara = new CharacterDto
                    {
                        Class           = @class,
                        Gender          = packet.Gender,
                        HairColor       = packet.HairColor,
                        HairStyle       = packet.HairStyle,
                        Hp              = (int)_hpService.GetHp(@class, level),
                        JobLevel        = 1,
                        Level           = level,
                        MapId           = 1,
                        MapX            = (short)RandomHelper.Instance.RandomNumber(78, 81),
                        MapY            = (short)RandomHelper.Instance.RandomNumber(114, 118),
                        Mp              = (int)_mpService.GetMp(@class, level),
                        MaxMateCount    = 10,
                        SpPoint         = 10000,
                        SpAdditionPoint = 0,
                        Name            = characterName,
                        Slot            = slot,
                        AccountId       = accountId,
                        State           = CharacterState.Active
                    };
                    chara = await _characterDao.TryInsertOrUpdateAsync(chara).ConfigureAwait(false);

                    var miniland = new MinilandDto
                    {
                        MinilandId       = Guid.NewGuid(),
                        State            = MinilandState.Open,
                        MinilandMessage  = ((short)Game18NConstString.Welcome).ToString(),
                        OwnerId          = chara.CharacterId,
                        WelcomeMusicInfo = 3800
                    };
                    await _minilandDao.TryInsertOrUpdateAsync(miniland).ConfigureAwait(false);

                    var charaGo    = chara.Adapt <Character>();
                    var itemsToAdd = new List <BasicEquipment>();
                    foreach (var item in _worldConfiguration.BasicEquipments)
                    {
                        switch (item.Key)
                        {
                        case nameof(CharacterClassType.Adventurer) when @class != CharacterClassType.Adventurer:
                        case nameof(CharacterClassType.Archer) when @class != CharacterClassType.Archer:
                        case nameof(CharacterClassType.Mage) when @class != CharacterClassType.Mage:
                        case nameof(CharacterClassType.MartialArtist) when @class != CharacterClassType.MartialArtist:
                        case nameof(CharacterClassType.Swordsman) when @class != CharacterClassType.Swordsman:
                            break;

                        default:
                            itemsToAdd.AddRange(_worldConfiguration.BasicEquipments[item.Key]);
                            break;
                        }
                    }

                    foreach (var itemToAdd in itemsToAdd)
                    {
                        charaGo.InventoryService.AddItemToPocket(InventoryItemInstance.Create(_itemBuilderService.Create(itemToAdd.VNum, itemToAdd.Amount), charaGo.CharacterId), itemToAdd.NoscorePocketType);
                    }


                    await _quicklistEntryDao.TryInsertOrUpdateAsync(new[] {
                        new QuicklistEntryDto
                        {
                            Id          = Guid.NewGuid(),
                            CharacterId = chara.CharacterId,
                            Slot        = 1,
                            Type        = 0,
                            IconType    = 2,
                            IconVNum    = 0
                        },
                        new QuicklistEntryDto
                        {
                            Id          = Guid.NewGuid(),
                            CharacterId = chara.CharacterId,
                            Slot        = 9,
                            Type        = 1,
                            IconType    = 3,
                            IconVNum    = 1
                        },
                        new QuicklistEntryDto
                        {
                            Id          = Guid.NewGuid(),
                            CharacterId = chara.CharacterId,
                            Slot        = 0,
                            Type        = 1,
                            IconType    = 1,
                            IconVNum    = 1
                        },
                        new QuicklistEntryDto
                        {
                            Id          = Guid.NewGuid(),
                            CharacterId = chara.CharacterId,
                            Slot        = 8,
                            Type        = 1,
                            IconType    = 1,
                            IconVNum    = 16
                        },
                    });

                    await _itemInstanceDao.TryInsertOrUpdateAsync(charaGo.InventoryService.Values.Select(s => s.ItemInstance !).ToArray()).ConfigureAwait(false);

                    await _inventoryItemInstanceDao.TryInsertOrUpdateAsync(charaGo.InventoryService.Values.ToArray()).ConfigureAwait(false);

                    await clientSession.SendPacketAsync(new SuccessPacket()).ConfigureAwait(false);

                    await clientSession.HandlePacketsAsync(new[] { new EntryPointPacket() }).ConfigureAwait(false);
                }
                else
                {
                    await clientSession.SendPacketAsync(new InfoiPacket
                    {
                        Message = Game18NConstString.CharacterNameAlreadyTaken
                    }).ConfigureAwait(false);
                }
            }
Example #10
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);
        }
        public void Setup()
        {
            PacketFactory.Initialize <NoS0575Packet>();
            Broadcaster.Instance.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")
            };
            var targetAccount = new AccountDto {
                Name = "test2", Password = EncryptionHelper.Sha512("test")
            };

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

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

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

            DaoFactory.CharacterDao.InsertOrUpdate(ref _chara);
            _session.InitializeAccount(account);
            _session.SessionId = 1;
            _handler           = new DefaultPacketController(null, null);
            _handler.RegisterSession(_session);

            _targetSession.InitializeAccount(targetAccount);
            _targetSession.SessionId = 2;
            _handler2 = new DefaultPacketController(null, null);
            _handler2.RegisterSession(_targetSession);

            DaoFactory.CharacterDao.InsertOrUpdate(ref _targetChar);
            _targetSession.InitializeAccount(targetAccount);

            _session.SetCharacter(_chara.Adapt <Character>());
            _session.Character.MapInstance = new MapInstance(new Map(), Guid.NewGuid(), true, MapInstanceType.BaseMapInstance, null);

            _targetSession.SetCharacter(_targetChar.Adapt <Character>());
            _targetSession.Character.MapInstance = new MapInstance(new Map(), Guid.NewGuid(), true, MapInstanceType.BaseMapInstance, null);

            Broadcaster.Instance.RegisterSession(_session);
            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);
        }
Example #13
0
        public void Setup()
        {
            PacketFactory.Initialize <NoS0575Packet>();
            var contextBuilder = new DbContextOptionsBuilder <NosCoreContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString());

            DataAccessHelper.Instance.InitializeForTest(contextBuilder.Options);
            var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());

            XmlConfigurator.Configure(logRepository, new FileInfo(ConfigurationPath + "/log4net.config"));
            Logger.InitializeLogger(LogManager.GetLogger(typeof(DefaultPacketControllerTests)));
            var map = new MapDto {
                MapId = 1
            };

            DaoFactory.MapDao.InsertOrUpdate(ref map);
            var account = new AccountDto {
                Name = "AccountTest", Password = EncryptionHelper.Sha512("test")
            };
            var targetAccount = new AccountDto {
                Name = "test2", Password = EncryptionHelper.Sha512("test")
            };

            DaoFactory.AccountDao.InsertOrUpdate(ref account);
            DaoFactory.AccountDao.InsertOrUpdate(ref targetAccount);

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

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

            DaoFactory.CharacterDao.InsertOrUpdate(ref _chara);
            _session.InitializeAccount(account);
            _handler = new DefaultPacketController(null, null);
            _handler.RegisterSession(_session);

            DaoFactory.CharacterDao.InsertOrUpdate(ref _targetChar);
            _targetSession.InitializeAccount(targetAccount);

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

            _session.SetCharacter(_chara.Adapt <Character>());
            _session.Character.MapInstance = new MapInstance(new Map(), Guid.NewGuid(), true, MapInstanceType.BaseMapInstance, null);
            _targetSession.SetCharacter(_targetChar.Adapt <Character>());
            _targetSession.Character.MapInstance = new MapInstance(new Map(), Guid.NewGuid(), true, MapInstanceType.BaseMapInstance, null);
            ServerManager.Instance.Sessions      = new ConcurrentDictionary <long, ClientSession>();
            ServerManager.Instance.Sessions.TryAdd(_chara.CharacterId, _session);
            ServerManager.Instance.Sessions.TryAdd(_targetChar.CharacterId, _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 = 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);
        }