예제 #1
0
        /// <summary>
        ///     Char_NEW character creation character
        /// </summary>
        /// <param name="characterCreatePacket"></param>
        public void CreateCharacter(CharNewPacket characterCreatePacket)
        {
            if (Session.HasCurrentMapInstance)
            {
                return;
            }

            // TODO: Hold Account Information in Authorized object
            var accountId     = Session.Account.AccountId;
            var slot          = characterCreatePacket.Slot;
            var characterName = characterCreatePacket.Name;

            if (DAOFactory.CharacterDAO.FirstOrDefault(s =>
                                                       s.AccountId == accountId && s.Slot == slot && s.State == CharacterState.Active) != null)
            {
                return;
            }

            var rg = new Regex(
                @"^[\u0021-\u007E\u00A1-\u00AC\u00AE-\u00FF\u4E00-\u9FA5\u0E01-\u0E3A\u0E3F-\u0E5B\u002E]*$");

            if (rg.Matches(characterName).Count == 1)
            {
                var character =
                    DAOFactory.CharacterDAO.FirstOrDefault(s =>
                                                           s.Name == characterName && s.State == CharacterState.Active);
                if (character == null)
                {
                    CharacterDTO chara = new GameObject.Character
                    {
                        Class           = (byte)CharacterClassType.Adventurer,
                        Gender          = characterCreatePacket.Gender,
                        HairColor       = characterCreatePacket.HairColor,
                        HairStyle       = characterCreatePacket.HairStyle,
                        Hp              = 221,
                        JobLevel        = 1,
                        Level           = 1,
                        MapId           = 1,
                        MapX            = (short)ServerManager.Instance.RandomNumber(78, 81),
                        MapY            = (short)ServerManager.Instance.RandomNumber(114, 118),
                        Mp              = 221,
                        MaxMateCount    = 10,
                        SpPoint         = 10000,
                        SpAdditionPoint = 0,
                        Name            = characterName,
                        Slot            = slot,
                        AccountId       = accountId,
                        MinilandMessage = "Welcome",
                        State           = CharacterState.Active
                    };
                    var insertResult = DAOFactory.CharacterDAO.InsertOrUpdate(ref chara);
                    LoadCharacters(null);
                }
                else
                {
                    Session.SendPacket(new InfoPacket
                    {
                        Message = Session.GetMessageFromKey(LanguageKey.ALREADY_TAKEN)
                    });
                }
            }
            else
            {
                Session.SendPacket(new InfoPacket
                {
                    Message = Session.GetMessageFromKey(LanguageKey.INVALID_CHARNAME)
                });
            }
        }
        public void SelectCharacter(SelectPacket selectPacket)
        {
            try
            {
                if (Session?.Account == null || Session.HasSelectedCharacter)
                {
                    return;
                }

                var characterDto =
                    DAOFactory.CharacterDAO.FirstOrDefault(s =>
                                                           s.AccountId == Session.Account.AccountId && s.Slot == selectPacket.Slot &&
                                                           s.State == CharacterState.Active);
                if (characterDto == null)
                {
                    return;
                }

                GameObject.Character character = characterDto.Adapt <GameObject.Character>();

                character.MapInstanceId = ServerManager.Instance.GetBaseMapInstanceIdByMapId(character.MapId);
                character.MapInstance   = ServerManager.Instance.GetMapInstance(character.MapInstanceId);
                character.PositionX     = character.MapX;
                character.PositionY     = character.MapY;
                character.Account       = Session.Account;
                Session.SetCharacter(character);

                var inventories = DAOFactory.ItemInstanceDAO.Where(s => s.CharacterId == character.CharacterId).ToList();
                character.Inventory = new Inventory()
                {
                    Configuration = _worldConfiguration
                };
                inventories.ForEach(k => character.Inventory[k.Id] = k.Adapt <ItemInstance>());
                #pragma warning disable CS0618
                Session.SendPackets(Session.Character.GenerateInv());
                #pragma warning restore CS0618

                if (Session.Character.Hp > Session.Character.HPLoad())
                {
                    Session.Character.Hp = (int)Session.Character.HPLoad();
                }

                if (Session.Character.Mp > Session.Character.MPLoad())
                {
                    Session.Character.Mp = (int)Session.Character.MPLoad();
                }

                IEnumerable <CharacterRelation> relations = DAOFactory.CharacterRelationDAO.Where(s => s.CharacterId == Session.Character.CharacterId).Cast <CharacterRelation>();
                IEnumerable <CharacterRelation> relationsWithCharacter = DAOFactory.CharacterRelationDAO.Where(s => s.RelatedCharacterId == Session.Character.CharacterId).Cast <CharacterRelation>();

                List <CharacterDTO> characters        = DAOFactory.CharacterDAO.Where(s => relations.Select(v => v.RelatedCharacterId).Contains(s.CharacterId)).ToList();
                List <CharacterDTO> relatedCharacters = DAOFactory.CharacterDAO.Where(s => relationsWithCharacter.Select(v => v.RelatedCharacterId).Contains(s.CharacterId)).ToList();

                foreach (CharacterRelation relation in relations)
                {
                    relation.CharacterName = characters.FirstOrDefault(s => s.CharacterId == relation.RelatedCharacterId)?.Name;
                    Session.Character.CharacterRelations[relation.CharacterRelationId] = relation;
                }

                foreach (CharacterRelation relation in relationsWithCharacter)
                {
                    relation.CharacterName = relatedCharacters.FirstOrDefault(s => s.CharacterId == relation.RelatedCharacterId)?.Name;
                    Session.Character.RelationWithCharacter[relation.CharacterRelationId] = relation;
                }

                Session.SendPacket(new OkPacket());
            }
            catch (Exception ex)
            {
                Logger.Log.Error("Select character failed.", ex);
            }
        }
예제 #3
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);
        }