public void ExistingName_Does_Not_Create_Character()
        {
            const string name = "TestExistingCharacter";

            _handler.CreateCharacter(new CharNewPacket
            {
                Name = name
            });
            Assert.IsFalse(_characterDao.Where(s => s.Name == name).Skip(1).Any());
        }
예제 #2
0
파일: MapNpc.cs 프로젝트: lwp001/NosCore
        public void Initialize()
        {
            NpcMonster = _npcMonsters.Find(s => s.NpcMonsterVNum == VNum);
            Mp         = NpcMonster?.MaxMp ?? 0;
            Hp         = NpcMonster?.MaxHp ?? 0;
            Speed      = NpcMonster?.Speed ?? 0;
            PositionX  = MapX;
            PositionY  = MapY;
            IsAlive    = true;
            Requests   = new Subject <RequestData>();
            Requests.Subscribe(ShowDialog);
            var shopObj = _shops.FirstOrDefault(s => s.MapNpcId == MapNpcId);

            if (shopObj != null)
            {
                var shopItemsDto  = _shopItems.Where(s => s.ShopId == shopObj.ShopId);
                var shopItemsList = new ConcurrentDictionary <int, ShopItem>();
                Parallel.ForEach(shopItemsDto, shopItemGrouping =>
                {
                    var shopItem          = shopItemGrouping.Adapt <ShopItem>();
                    shopItem.ItemInstance = _itemProvider.Create(shopItemGrouping.ItemVNum, -1);
                    shopItemsList[shopItemGrouping.ShopItemId] = shopItem;
                });
                _shop           = shopObj.Adapt <Shop>();
                _shop.ShopItems = shopItemsList;
            }
        }
예제 #3
0
        public async Task <LanguageKey> AddFriend([FromBody] FriendShipRequest friendPacket)
        {
            var character = await _connectedAccountHttpClient.GetCharacterAsync(friendPacket.CharacterId, null).ConfigureAwait(false);

            var targetCharacter = await _connectedAccountHttpClient.GetCharacterAsync(friendPacket.FinsPacket?.CharacterId, null).ConfigureAwait(false);

            var friendRequest = _friendRequestHolder.FriendRequestCharacters.Where(s =>
                                                                                   (s.Value.Item2 == character.Item2?.ConnectedCharacter?.Id) &&
                                                                                   (s.Value.Item1 == targetCharacter.Item2?.ConnectedCharacter?.Id)).ToList();

            if ((character.Item2 != null) && (targetCharacter.Item2 != null))
            {
                if (character.Item2.ChannelId != targetCharacter.Item2.ChannelId)
                {
                    throw new ArgumentException();
                }

                var relations = _characterRelationDao.Where(s => s.CharacterId == friendPacket.CharacterId).ToList();
                if (relations.Count(s => s.RelationType == CharacterRelationType.Friend) >= 80)
                {
                    return(LanguageKey.FRIENDLIST_FULL);
                }

                if (relations.Any(s =>
                                  (s.RelationType == CharacterRelationType.Blocked) &&
                                  (s.RelatedCharacterId == friendPacket.FinsPacket !.CharacterId)))
                {
                    return(LanguageKey.BLACKLIST_BLOCKED);
                }

                if (relations.Any(s =>
                                  (s.RelationType == CharacterRelationType.Friend) &&
                                  (s.RelatedCharacterId == friendPacket.FinsPacket !.CharacterId)))
                {
                    return(LanguageKey.ALREADY_FRIEND);
                }

                if (character.Item2.ConnectedCharacter !.FriendRequestBlocked ||
                    targetCharacter.Item2.ConnectedCharacter !.FriendRequestBlocked)
                {
                    return(LanguageKey.FRIEND_REQUEST_BLOCKED);
                }

                if (!friendRequest.Any())
                {
                    _friendRequestHolder.FriendRequestCharacters[Guid.NewGuid()] =
                        new Tuple <long, long>(character.Item2.ConnectedCharacter.Id,
                                               targetCharacter.Item2.ConnectedCharacter.Id);
                    return(LanguageKey.FRIEND_REQUEST_SENT);
                }

                switch (friendPacket.FinsPacket !.Type)
                {
예제 #4
0
        public async Task <LanguageKey> AddBlacklist([FromBody] BlacklistRequest blacklistRequest)
        {
            var character = await _connectedAccountHttpClient.GetCharacterAsync(blacklistRequest.CharacterId, null).ConfigureAwait(false);

            var targetCharacter = await
                                  _connectedAccountHttpClient.GetCharacterAsync(blacklistRequest.BlInsPacket?.CharacterId, null).ConfigureAwait(false);

            if ((character.Item2 == null) || (targetCharacter.Item2 == null))
            {
                throw new ArgumentException();
            }

            var relations = _characterRelationDao.Where(s => s.CharacterId == blacklistRequest.CharacterId)
                            .ToList();

            if (relations.Any(s =>
                              (s.RelatedCharacterId == blacklistRequest.BlInsPacket?.CharacterId) &&
                              (s.RelationType != CharacterRelationType.Blocked)))
            {
                return(LanguageKey.CANT_BLOCK_FRIEND);
            }

            if (relations.Any(s =>
                              (s.RelatedCharacterId == blacklistRequest.BlInsPacket?.CharacterId) &&
                              (s.RelationType == CharacterRelationType.Blocked)))
            {
                return(LanguageKey.ALREADY_BLACKLISTED);
            }

            var data = new CharacterRelationDto
            {
                CharacterId        = character.Item2.ConnectedCharacter !.Id,
                RelatedCharacterId = targetCharacter.Item2.ConnectedCharacter !.Id,
                RelationType       = CharacterRelationType.Blocked
            };

            _characterRelationDao.InsertOrUpdate(ref data);
            return(LanguageKey.BLACKLIST_ADDED);
        }
예제 #5
0
        public GuiWindow(Map map, byte gridsize, int width, int height, GraphicsMode mode, string title) : base(
                width * gridsize, height * gridsize, mode, title)
        {
            _originalWidth  = width * gridsize;
            _originalHeight = height * gridsize;
            _map            = map;
            _gridsizeX      = gridsize;
            _gridsizeY      = gridsize;
            _gridsize       = gridsize;
            _monsters       = _mapMonsterDao.Where(s => s.MapId == map.MapId)
                              .Adapt <List <MapMonster> >();
            var npcMonsters = _npcMonsterDao.LoadAll().ToList();
            var mapInstance =
                new MapInstance(map, new Guid(), false, MapInstanceType.BaseMapInstance,
                                new MapItemProvider(new List <IHandler <MapItem, Tuple <MapItem, GetPacket> > >()),
                                null, _logger)
            {
                IsSleeping = false
            };

            foreach (var mapMonster in _monsters)
            {
                mapMonster.PositionX     = mapMonster.MapX;
                mapMonster.PositionY     = mapMonster.MapY;
                mapMonster.MapInstance   = mapInstance;
                mapMonster.MapInstanceId = mapInstance.MapInstanceId;
                mapMonster.Mp            = 100;
                mapMonster.Hp            = 100;
                mapMonster.Speed         = npcMonsters.Find(s => s.NpcMonsterVNum == mapMonster.MapId)?.Speed ?? 0;
                mapMonster.IsAlive       = true;
            }

            _npcs = _mapNpcDao.Where(s => s.MapId == map.MapId).Cast <MapNpc>().ToList();
            foreach (var mapNpc in _npcs)
            {
                mapNpc.PositionX     = mapNpc.MapX;
                mapNpc.PositionY     = mapNpc.MapY;
                mapNpc.MapInstance   = mapInstance;
                mapNpc.MapInstanceId = mapInstance.MapInstanceId;
                mapNpc.Mp            = 100;
                mapNpc.Hp            = 100;
                mapNpc.Speed         = npcMonsters.Find(s => s.NpcMonsterVNum == mapNpc.MapId)?.Speed ?? 0;
                mapNpc.IsAlive       = true;
            }

            Parallel.ForEach(_monsters.Where(s => s.Life == null), monster => monster.StartLife());
            Parallel.ForEach(_npcs.Where(s => s.Life == null), npc => npc.StartLife());
            GetMap();
        }
예제 #6
0
        public BazaarItemsHolder(IGenericDao <BazaarItemDto> bazaarItemDao,
                                 IGenericDao <IItemInstanceDto> itemInstanceDao, IGenericDao <CharacterDto> characterDao)
        {
            var billist           = bazaarItemDao.LoadAll().ToList();
            var bzItemInstanceIds = billist.Select(o => o.ItemInstanceId).ToList();
            var bzCharacterIds    = billist.Select(o => o.SellerId).ToList();
            var itemInstancelist  = itemInstanceDao.Where(s => bzItemInstanceIds.Contains(s.Id)).ToList();
            var characterList     = characterDao.Where(s => bzCharacterIds.Contains(s.CharacterId)).ToList();

            BazaarItems = new ConcurrentDictionary <long, BazaarLink>(billist.ToDictionary(x => x.BazaarItemId,
                                                                                           x => new BazaarLink
            {
                ItemInstance = itemInstancelist.First(s => s.Id == x.ItemInstanceId).Adapt <ItemInstanceDto>(),
                BazaarItem   = x, SellerName = characterList.First(s => s.CharacterId == x.SellerId).Name !
            }));
예제 #7
0
        public Miniland Initialize(Character character)
        {
            var minilandInfoDto = _minilandDao.FirstOrDefault(s => s.OwnerId == character.CharacterId);

            if (minilandInfoDto == null)
            {
                throw new ArgumentException();
            }

            var map      = _maps.FirstOrDefault(s => s.MapId == 20001);
            var miniland = _mapInstanceProvider.CreateMapInstance(map.Adapt <Map.Map>(), Guid.NewGuid(), map.ShopAllowed,
                                                                  MapInstanceType.NormalInstance, new List <IMapInstanceEventHandler> {
                new MinilandEntranceHandler(this)
            });

            var minilandInfo = minilandInfoDto.Adapt <Miniland>();

            minilandInfo.MapInstanceId   = miniland.MapInstanceId;
            minilandInfo.CharacterEntity = character;

            _minilandIds.TryAdd(character.CharacterId, minilandInfo);
            _mapInstanceProvider.AddMapInstance(miniland);
            miniland.LoadHandlers();

            var listobjects        = character.InventoryService.Values.Where(s => s.Type == NoscorePocketType.Miniland).ToArray();
            var idlist             = listobjects.Select(s => s.Id).ToArray();
            var minilandObjectsDto = _minilandObjectsDao.Where(s => idlist.Contains((Guid)s.InventoryItemInstanceId))
                                     .ToList();

            foreach (var mlobjdto in minilandObjectsDto)
            {
                var mlobj = mlobjdto.Adapt <MapDesignObject>();
                AddMinilandObject(mlobj, character.CharacterId,
                                  listobjects.First(s => s.Id == mlobjdto.InventoryItemInstanceId));
            }

            return(minilandInfo);
        }
예제 #8
0
        public void InsertShopItems(List <string[]> packetList)
        {
            List <ShopItemDto> shopitems = new List <ShopItemDto>();
            int  itemCounter             = 0;
            byte type = 0;

            foreach (var currentPacket in packetList.Where(o => o[0].Equals("n_inv") || o[0].Equals("shopping")))
            {
                if (currentPacket[0].Equals("n_inv"))
                {
                    short npcid = short.Parse(currentPacket[2]);
                    if (_shopDao.FirstOrDefault(s => s.MapNpcId == npcid) == null)
                    {
                        continue;
                    }

                    for (int i = 5; i < currentPacket.Length; i++)
                    {
                        string[]    item  = currentPacket[i].Split('.');
                        ShopItemDto sitem = null;

                        if (item.Length == 5)
                        {
                            sitem = new ShopItemDto
                            {
                                ShopId = _shopDao.FirstOrDefault(s => s.MapNpcId == npcid)
                                         .ShopId,
                                Type     = type,
                                Slot     = byte.Parse(item[1]),
                                ItemVNum = short.Parse(item[2])
                            };
                        }

                        if (item.Length == 6)
                        {
                            sitem = new ShopItemDto
                            {
                                ShopId = _shopDao.FirstOrDefault(s => s.MapNpcId == npcid)
                                         .ShopId,
                                Type     = type,
                                Slot     = byte.Parse(item[1]),
                                ItemVNum = short.Parse(item[2]),
                                Rare     = sbyte.Parse(item[3]),
                                Upgrade  = byte.Parse(item[4])
                            };
                        }

                        if (sitem == null || shopitems.Any(s =>
                                                           s.ItemVNum.Equals(sitem.ItemVNum) && s.ShopId.Equals(sitem.ShopId)) ||
                            _shopItemDao.Where(s => s.ShopId == sitem.ShopId)
                            .Any(s => s.ItemVNum.Equals(sitem.ItemVNum)))
                        {
                            continue;
                        }

                        shopitems.Add(sitem);
                        itemCounter++;
                    }
                }
                else
                {
                    if (currentPacket.Length > 3)
                    {
                        type = byte.Parse(currentPacket[1]);
                    }
                }
            }

            IEnumerable <ShopItemDto> shopItemDtos = shopitems;

            _shopItemDao.InsertOrUpdate(shopItemDtos);
            _logger.Information(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.SHOPITEMS_PARSED),
                                itemCounter);
        }
예제 #9
0
 public void AddMapInstance(MapInstance mapInstance)
 {
     MapInstances.TryAdd(mapInstance.MapInstanceId, mapInstance);
     LoadPortals(mapInstance, _portalDao.Where(s => s.SourceMapId == mapInstance.Map.MapId).ToList());
 }
예제 #10
0
        internal void InsertNpcMonsters(string folder)
        {
            var basicHp          = new int[100];
            var basicPrimaryMp   = new int[100];
            var basicSecondaryMp = new int[100];
            var basicXp          = new int[100];
            var basicJXp         = new int[100];

            // basicHPLoad
            var baseHp  = 138;
            var hPbasup = 18;

            for (var i = 0; i < 100; i++)
            {
                basicHp[i] = baseHp;
                hPbasup++;
                baseHp += hPbasup;

                if (i == 37)
                {
                    baseHp  = 1765;
                    hPbasup = 65;
                }

                if (i < 41)
                {
                    continue;
                }

                if ((99 - i) % 8 == 0)
                {
                    hPbasup++;
                }
            }

            //Race == 0
            basicPrimaryMp[0] = 10;
            basicPrimaryMp[1] = 10;
            basicPrimaryMp[2] = 15;

            var  primaryBasup = 5;
            byte count        = 0;
            var  isStable     = true;
            var  isDouble     = false;

            for (uint i = 3; i < 100; i++)
            {
                if (i % 10 == 1)
                {
                    basicPrimaryMp[i] += basicPrimaryMp[i - 1] + (primaryBasup * 2);
                    continue;
                }

                if (!isStable)
                {
                    primaryBasup++;
                    count++;

                    if (count == 2)
                    {
                        if (isDouble)
                        {
                            isDouble = false;
                        }
                        else
                        {
                            isStable = true;
                            isDouble = true;
                            count    = 0;
                        }
                    }

                    if (count == 4)
                    {
                        isStable = true;
                        count    = 0;
                    }
                }
                else
                {
                    count++;
                    if (count == 2)
                    {
                        isStable = false;
                        count    = 0;
                    }
                }

                basicPrimaryMp[i] = basicPrimaryMp[i - (i % 10 == 2 ? 2 : 1)] + primaryBasup;
            }

            // Race == 2
            basicSecondaryMp[0] = 60;
            basicSecondaryMp[1] = 60;
            basicSecondaryMp[2] = 78;

            var secondaryBasup = 18;
            var boostup        = false;

            for (uint i = 3; i < 100; i++)
            {
                if (i % 10 == 1)
                {
                    basicSecondaryMp[i] += basicSecondaryMp[i - 1] + (int)i + 10;
                    continue;
                }

                if (boostup)
                {
                    secondaryBasup += 3;
                    boostup         = false;
                }
                else
                {
                    secondaryBasup++;
                    boostup = true;
                }

                basicSecondaryMp[i] = basicSecondaryMp[i - (i % 10 == 2 ? 2 : 1)] + secondaryBasup;
            }

            // basicXPLoad
            for (var i = 0; i < 100; i++)
            {
                basicXp[i] = i * 180;
            }

            // basicJXpLoad
            for (var i = 0; i < 100; i++)
            {
                basicJXp[i] = 360;
            }

            var npcs = new List <NpcMonsterDto>();

            // Store like this: (vnum, (name, level))
            var  npc           = new NpcMonsterDto();
            var  drops         = new List <DropDto>();
            var  monstercards  = new List <BCardDto>();
            var  skills        = new List <NpcMonsterSkillDto>();
            var  itemAreaBegin = false;
            var  counter       = 0;
            long unknownData   = 0;

            using (var npcIdStream = new StreamReader(folder + FileNpcId, Encoding.Default))
            {
                string line;
                while ((line = npcIdStream.ReadLine()) != null)
                {
                    var currentLine = line.Split('\t');

                    if (currentLine.Length > 2 && currentLine[1] == "VNUM")
                    {
                        npc = new NpcMonsterDto
                        {
                            NpcMonsterVNum = Convert.ToInt16(currentLine[2])
                        };
                        itemAreaBegin = true;
                        unknownData   = 0;
                    }
                    else if (currentLine.Length > 2 && currentLine[1] == "NAME")
                    {
                        npc.Name = currentLine[2];
                    }
                    else if (currentLine.Length > 2 && currentLine[1] == "LEVEL")
                    {
                        if (!itemAreaBegin)
                        {
                            continue;
                        }

                        npc.Level = Convert.ToByte(currentLine[2]);
                    }
                    else if (currentLine.Length > 3 && currentLine[1] == "RACE")
                    {
                        npc.Race     = Convert.ToByte(currentLine[2]);
                        npc.RaceType = Convert.ToByte(currentLine[3]);
                    }
                    else if (currentLine.Length > 7 && currentLine[1] == "ATTRIB")
                    {
                        npc.Element         = Convert.ToByte(currentLine[2]);
                        npc.ElementRate     = Convert.ToInt16(currentLine[3]);
                        npc.FireResistance  = Convert.ToSByte(currentLine[4]);
                        npc.WaterResistance = Convert.ToSByte(currentLine[5]);
                        npc.LightResistance = Convert.ToSByte(currentLine[6]);
                        npc.DarkResistance  = Convert.ToSByte(currentLine[7]);
                    }
                    else if (currentLine.Length > 3 && currentLine[1] == "HP/MP")
                    {
                        npc.MaxHp = Convert.ToInt32(currentLine[2]) + basicHp[npc.Level];
                        npc.MaxMp = Convert.ToInt32(currentLine[3]) + npc.Race == 0 ? basicPrimaryMp[npc.Level]
                            : basicSecondaryMp[npc.Level];
                    }
                    else if (currentLine.Length > 2 && currentLine[1] == "EXP")
                    {
                        npc.Xp    = Math.Abs(Convert.ToInt32(currentLine[2]) + basicXp[npc.Level]);
                        npc.JobXp = Convert.ToInt32(currentLine[3]) + basicJXp[npc.Level];

                        //TODO find HeroXP algorithm
                        switch (npc.NpcMonsterVNum)
                        {
                        case 2510:
                        case 2501:
                            npc.HeroXp = 881;
                            break;

                        case 2512:
                        case 2502:
                            npc.HeroXp = 884;
                            break;

                        case 2503:
                            npc.HeroXp = 1013;
                            break;

                        case 2505:
                            npc.HeroXp = 871;
                            break;

                        case 2506:
                            npc.HeroXp = 765;
                            break;

                        case 2507:
                            npc.HeroXp = 803;
                            break;

                        case 2508:
                            npc.HeroXp = 825;
                            break;

                        case 2500:
                        case 2509:
                        case 2511:
                            npc.HeroXp = 879;
                            break;

                        case 2513:
                            npc.HeroXp = 1075;
                            break;

                        case 2515:
                            npc.HeroXp = 3803;
                            break;

                        case 2516:
                            npc.HeroXp = 836;
                            break;

                        case 2517:
                            npc.HeroXp = 450;
                            break;

                        case 2518:
                            npc.HeroXp = 911;
                            break;

                        case 2519:
                            npc.HeroXp = 845;
                            break;

                        case 2520:
                            npc.HeroXp = 3682;
                            break;

                        case 2521:
                            npc.HeroXp = 401;
                            break;

                        case 2522:
                            npc.HeroXp = 471;
                            break;

                        case 2523:
                            npc.HeroXp = 328;
                            break;

                        case 2524:
                            npc.HeroXp = 12718;
                            break;

                        case 2525:
                            npc.HeroXp = 412;
                            break;

                        case 2526:
                            npc.HeroXp = 11157;
                            break;

                        case 2527:
                            npc.HeroXp = 18057;
                            break;

                        case 2530:
                            npc.HeroXp = 28756;
                            break;

                        case 2559:
                            npc.HeroXp = 1308;
                            break;

                        case 2560:
                            npc.HeroXp = 1234;
                            break;

                        case 2561:
                            npc.HeroXp = 1168;
                            break;

                        case 2562:
                            npc.HeroXp = 959;
                            break;

                        case 2563:
                            npc.HeroXp = 947;
                            break;

                        case 2564:
                            npc.HeroXp = 952;
                            break;

                        case 2566:
                            npc.HeroXp = 1097;
                            break;

                        case 2567:
                            npc.HeroXp = 1096;
                            break;

                        case 2568:
                            npc.HeroXp = 4340;
                            break;

                        case 2569:
                            npc.HeroXp = 3534;
                            break;

                        case 2570:
                            npc.HeroXp = 4343;
                            break;

                        case 2571:
                            npc.HeroXp = 2205;
                            break;

                        case 2572:
                            npc.HeroXp = 5632;
                            break;

                        case 2573:
                            npc.HeroXp = 3756;
                            break;

                        default:
                            npc.HeroXp = 0;
                            break;
                        }
                    }
                    else if (currentLine.Length > 6 && currentLine[1] == "PREATT")
                    {
                        npc.IsHostile   = currentLine[2] != "0";
                        npc.NoticeRange = Convert.ToByte(currentLine[4]);
                        npc.Speed       = Convert.ToByte(currentLine[5]);
                        npc.RespawnTime = Convert.ToInt32(currentLine[6]);
                    }
                    else if (currentLine.Length > 6 && currentLine[1] == "WEAPON")
                    {
                        switch (currentLine[3])
                        {
                        case "1":
                            npc.DamageMinimum = Convert.ToInt16(((Convert.ToInt16(currentLine[2]) - 1) * 4) + 32
                                                                + Convert.ToInt16(currentLine[4])
                                                                + Math.Round(Convert.ToDecimal((npc.Level - 1) / 5)));
                            npc.DamageMaximum = Convert.ToInt16(((Convert.ToInt16(currentLine[2]) - 1) * 6) + 40
                                                                + Convert.ToInt16(currentLine[5])
                                                                - Math.Round(Convert.ToDecimal((npc.Level - 1) / 5)));
                            npc.Concentrate = Convert.ToInt16(((Convert.ToInt16(currentLine[2]) - 1) * 5) + 27
                                                              + Convert.ToInt16(currentLine[6]));
                            npc.CriticalChance = Convert.ToByte(4 + Convert.ToInt16(currentLine[7]));
                            npc.CriticalRate   = Convert.ToInt16(70 + Convert.ToInt16(currentLine[8]));
                            break;

                        case "2":
                            npc.DamageMinimum = Convert.ToInt16((Convert.ToInt16(currentLine[2]) * 6.5f) + 23
                                                                + Convert.ToInt16(currentLine[4]));
                            npc.DamageMaximum = Convert.ToInt16(((Convert.ToInt16(currentLine[2]) - 1) * 8) + 38
                                                                + Convert.ToInt16(currentLine[5]));
                            npc.Concentrate = Convert.ToInt16(70 + Convert.ToInt16(currentLine[6]));
                            break;

                        default:
                            continue;
                        }
                    }
                    else if (currentLine.Length > 6 && currentLine[1] == "ARMOR")
                    {
                        npc.CloseDefence         = Convert.ToInt16(((Convert.ToInt16(currentLine[2]) - 1) * 2) + 18);
                        npc.DistanceDefence      = Convert.ToInt16(((Convert.ToInt16(currentLine[2]) - 1) * 3) + 17);
                        npc.MagicDefence         = Convert.ToInt16(((Convert.ToInt16(currentLine[2]) - 1) * 2) + 13);
                        npc.DefenceDodge         = Convert.ToInt16(((Convert.ToInt16(currentLine[2]) - 1) * 5) + 31);
                        npc.DistanceDefenceDodge = Convert.ToInt16(((Convert.ToInt16(currentLine[2]) - 1) * 5) + 31);
                    }
                    else if (currentLine.Length > 7 && currentLine[1] == "ETC")
                    {
                        if (npc.NpcMonsterVNum >= 588 && npc.NpcMonsterVNum <= 607)
                        {
                            npc.MonsterType = MonsterType.Elite;
                        }

                        unknownData = Convert.ToInt64(currentLine[2]);
                        switch (unknownData)
                        {
                        case -2147481593:
                            npc.MonsterType = MonsterType.Special;
                            break;

                        case -2147483616:
                        case -2147483647:
                        case -2147483646:
                            npc.NoAggresiveIcon = (npc.Race == 8 && npc.RaceType == 0);
                            break;

                        default:
                            continue;
                        }
                    }
                    else if (currentLine.Length > 6 && currentLine[1] == "SETTING")
                    {
                        if (currentLine[4] == "0")
                        {
                            continue;
                        }

                        npc.VNumRequired   = Convert.ToInt16(currentLine[4]);
                        npc.AmountRequired = 1;
                    }
                    else if (currentLine.Length > 4 && currentLine[1] == "PETINFO")
                    {
                        if (npc.VNumRequired != 0 || (unknownData != -2147481593 && unknownData != -2147481599 &&
                                                      unknownData != -1610610681))
                        {
                            continue;
                        }

                        npc.VNumRequired   = Convert.ToInt16(currentLine[2]);
                        npc.AmountRequired = Convert.ToByte(currentLine[3]);
                    }
                    else if (currentLine.Length > 2 && currentLine[1] == "EFF")
                    {
                        npc.BasicSkill = Convert.ToInt16(currentLine[2]);
                    }
                    else if (currentLine.Length > 8 && currentLine[1] == "ZSKILL")
                    {
                        npc.AttackClass   = Convert.ToByte(currentLine[2]);
                        npc.BasicRange    = Convert.ToByte(currentLine[3]);
                        npc.BasicArea     = Convert.ToByte(currentLine[5]);
                        npc.BasicCooldown = Convert.ToInt16(currentLine[6]);
                    }
                    else if (currentLine.Length > 4 && currentLine[1] == "WINFO")
                    {
                        npc.AttackUpgrade = Convert.ToByte(unknownData == 1 ? currentLine[2] : currentLine[4]);
                    }
                    else if (currentLine.Length > 3 && currentLine[1] == "AINFO")
                    {
                        npc.DefenceUpgrade = Convert.ToByte(unknownData == 1 ? currentLine[2] : currentLine[3]);
                    }
                    else if (currentLine.Length > 1 && currentLine[1] == "SKILL")
                    {
                        for (var i = 2; i < currentLine.Length - 3; i += 3)
                        {
                            var vnum = short.Parse(currentLine[i]);
                            if (vnum == -1 || vnum == 0)
                            {
                                break;
                            }

                            if (_skillDao.FirstOrDefault(s => s.SkillVNum.Equals(vnum)) ==
                                null ||
                                _npcMonsterSkillDao
                                .Where(s => s.NpcMonsterVNum.Equals(npc.NpcMonsterVNum))
                                .Count(s => s.SkillVNum == vnum) != 0)
                            {
                                continue;
                            }

                            skills.Add(new NpcMonsterSkillDto
                            {
                                SkillVNum      = vnum,
                                Rate           = Convert.ToInt16(currentLine[i + 1]),
                                NpcMonsterVNum = npc.NpcMonsterVNum
                            });
                        }
                    }
                    else if (currentLine.Length > 1 && currentLine[1] == "CARD")
                    {
                        for (var i = 0; i < 4; i++)
                        {
                            var type = (byte)int.Parse(currentLine[(5 * i) + 2]);
                            if (type == 0 || type == 255)
                            {
                                continue;
                            }

                            var first    = int.Parse(currentLine[(5 * i) + 3]);
                            var itemCard = new BCardDto
                            {
                                NpcMonsterVNum = npc.NpcMonsterVNum,
                                Type           = type,
                                SubType        = (byte)(int.Parse(currentLine[(5 * i) + 5]) + (1 * 10) + 1
                                                        + (first > 0 ? 0 : 1)),
                                IsLevelScaled  = Convert.ToBoolean(first % 4),
                                IsLevelDivided = (uint)(first > 0 ? first : -first) % 4 == 2,
                                FirstData      = (short)((first > 0 ? first : -first) / 4),
                                SecondData     = (short)(int.Parse(currentLine[(5 * i) + 4]) / 4),
                                ThirdData      = (short)(int.Parse(currentLine[(5 * i) + 6]) / 4)
                            };
                            monstercards.Add(itemCard);
                        }
                    }
                    else if (currentLine.Length > 1 && currentLine[1] == "BASIC")
                    {
                        for (var i = 0; i < 4; i++)
                        {
                            var type = (byte)int.Parse(currentLine[(5 * i) + 2]);
                            if (type == 0)
                            {
                                continue;
                            }

                            var first    = int.Parse(currentLine[(5 * i) + 5]);
                            var itemCard = new BCardDto
                            {
                                NpcMonsterVNum = npc.NpcMonsterVNum,
                                Type           = type,
                                SubType        =
                                    (byte)(((int.Parse(currentLine[(5 * i) + 6]) + 1) * 10) + 1 + (first > 0 ? 0 : 1)),
                                FirstData      = (short)((first > 0 ? first : -first) / 4),
                                SecondData     = (short)(int.Parse(currentLine[(5 * i) + 4]) / 4),
                                ThirdData      = (short)(int.Parse(currentLine[(5 * i) + 3]) / 4),
                                CastType       = 1,
                                IsLevelScaled  = false,
                                IsLevelDivided = false
                            };
                            monstercards.Add(itemCard);
                        }
                    }
                    else if (currentLine.Length > 3 && currentLine[1] == "ITEM")
                    {
                        if (_npcMonsterDao
                            .FirstOrDefault(s => s.NpcMonsterVNum.Equals(npc.NpcMonsterVNum))
                            == null)
                        {
                            npcs.Add(npc);
                            counter++;
                        }

                        for (var i = 2; i < currentLine.Length - 3; i += 3)
                        {
                            var vnum = Convert.ToInt16(currentLine[i]);
                            if (vnum == -1)
                            {
                                break;
                            }

                            if (_dropDao.Where(s => s.MonsterVNum == npc.NpcMonsterVNum)
                                .Count(s => s.VNum == vnum) != 0)
                            {
                                continue;
                            }

                            drops.Add(new DropDto
                            {
                                VNum        = vnum,
                                Amount      = Convert.ToInt32(currentLine[i + 2]),
                                MonsterVNum = npc.NpcMonsterVNum,
                                DropChance  = Convert.ToInt32(currentLine[i + 1])
                            });
                        }

                        itemAreaBegin = false;
                    }
                }

                IEnumerable <NpcMonsterDto>      npcMonsterDtos      = npcs;
                IEnumerable <NpcMonsterSkillDto> npcMonsterSkillDtos = skills;
                IEnumerable <BCardDto>           monsterBCardDtos    = monstercards;

                _npcMonsterDao.InsertOrUpdate(npcMonsterDtos);
                _npcMonsterSkillDao.InsertOrUpdate(npcMonsterSkillDtos);
                _bCardDao.InsertOrUpdate(monsterBCardDtos);
                _logger.Information(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.NPCMONSTERS_PARSED),
                                    counter);
            }

            IEnumerable <DropDto> dropDtos = drops;

            _dropDao.InsertOrUpdate(dropDtos);
        }
예제 #11
0
        public override async Task ExecuteAsync(EntryPointPacket packet, ClientSession clientSession)
        {
            if (clientSession == null)
            {
                throw new ArgumentNullException(nameof(clientSession));
            }

            if (clientSession.Account == null)
            {
                var alreadyConnnected = false;
                var name = packet.Name;
                foreach (var channel in (await _channelHttpClient.GetChannelsAsync().ConfigureAwait(false)).Where(c => c.Type == ServerType.WorldServer))
                {
                    var accounts = await _connectedAccountHttpClient.GetConnectedAccountAsync(channel).ConfigureAwait(false);

                    var target = accounts.FirstOrDefault(s => s.Name == name);

                    if (target == null)
                    {
                        continue;
                    }

                    alreadyConnnected = true;
                    break;
                }

                if (alreadyConnnected)
                {
                    await clientSession.DisconnectAsync().ConfigureAwait(false);

                    return;
                }

                var account = _accountDao.FirstOrDefault(s => s.Name == name);

                if (account != null)
                {
                    var result =
                        packet.Password != "thisisgfmode" ? null : await _authHttpClient.GetAwaitingConnectionAsync(name, packet.Password, clientSession.SessionId).ConfigureAwait(false);

                    if (result != null || (packet.Password != "thisisgfmode" && account.Password?.Equals(packet.Password.ToSha512(), StringComparison.OrdinalIgnoreCase) == true))
                    {
                        var accountobject = new AccountDto
                        {
                            AccountId = account.AccountId,
                            Name      = account.Name,
                            Password  = account.Password !.ToLower(),
                            Authority = account.Authority,
                            Language  = account.Language
                        };
                        SessionFactory.Instance.Sessions
                        .FirstOrDefault(s => s.Value.SessionId == clientSession.SessionId)
                        .Value.RegionType = account.Language;
                        clientSession.InitializeAccount(accountobject);
                        //Send Account Connected
                    }
                    else
                    {
                        _logger.Error(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.INVALID_PASSWORD));
                        await clientSession.DisconnectAsync().ConfigureAwait(false);

                        return;
                    }
                }
                else
                {
                    _logger.Error(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.INVALID_ACCOUNT));
                    await clientSession.DisconnectAsync().ConfigureAwait(false);

                    return;
                }

                _logger.Information(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.ACCOUNT_ARRIVED),
                                    clientSession.Account !.Name);
            }

            var characters = _characterDao.Where(s =>
                                                 (s.AccountId == clientSession.Account !.AccountId) && (s.State == CharacterState.Active));

            // load characterlist packet for each character in Character
            await clientSession.SendPacketAsync(new ClistStartPacket { Type = 0 }).ConfigureAwait(false);

            foreach (var character in characters.Select(characterDto => characterDto.Adapt <Character>()))
            {
                var equipment = new WearableInstance?[16];

                /* IEnumerable<ItemInstanceDTO> inventory = _iteminstanceDAO.Where(s => s.CharacterId == character.CharacterId && s.Type == (byte)InventoryType.Wear);
                 *
                 *
                 * foreach (ItemInstanceDTO equipmentEntry in inventory)
                 * {
                 *   // explicit load of iteminstance
                 *   WearableInstance currentInstance = equipmentEntry as WearableInstance;
                 *   equipment[(short)currentInstance.Item.EquipmentSlot] = currentInstance;
                 *
                 * }
                 */
                var petlist = new List <short?>();
                var mates   = _mateDao.Where(s => s.CharacterId == character.CharacterId)
                              .ToList();
                for (var i = 0; i < 26; i++)
                {
                    if (mates.Count > i)
                    {
                        petlist.Add(mates[i].Skin);
                        petlist.Add(mates[i].VNum);
                    }
                    else
                    {
                        petlist.Add(-1);
                    }
                }

                // 1 1 before long string of -1.-1 = act completion
                await clientSession.SendPacketAsync(new ClistPacket
                {
                    Slot       = character.Slot,
                    Name       = character.Name,
                    Unknown    = 0,
                    Gender     = character.Gender,
                    HairStyle  = character.HairStyle,
                    HairColor  = character.HairColor,
                    Unknown1   = 0,
                    Class      = character.Class,
                    Level      = character.Level,
                    HeroLevel  = character.HeroLevel,
                    Equipments = new List <short?>
                    {
                        equipment[(byte)EquipmentType.Hat]?.ItemVNum,
                        equipment[(byte)EquipmentType.Armor]?.ItemVNum,
                        equipment[(byte)EquipmentType.WeaponSkin]?.ItemVNum ??
                        equipment[(byte)EquipmentType.MainWeapon]?.ItemVNum,
                        equipment[(byte)EquipmentType.SecondaryWeapon]?.ItemVNum,
                        equipment[(byte)EquipmentType.Mask]?.ItemVNum,
                        equipment[(byte)EquipmentType.Fairy]?.ItemVNum,
                        equipment[(byte)EquipmentType.CostumeSuit]?.ItemVNum,
                        equipment[(byte)EquipmentType.CostumeHat]?.ItemVNum
                    },
                    JobLevel        = character.JobLevel,
                    QuestCompletion = 1,
                    QuestPart       = 1,
                    Pets            = petlist,
                    Design          = equipment[(byte)EquipmentType.Hat]?.Item?.IsColored ?? false
                        ? equipment[(byte)EquipmentType.Hat]?.Design ?? 0 : 0,
                    Rename = false
                }).ConfigureAwait(false);
            }

            await clientSession.SendPacketAsync(new ClistEndPacket()).ConfigureAwait(false);
        }
예제 #12
0
        public void InsertPortals(List <string[]> packetList)
        {
            var   _maps         = _mapDao.LoadAll().ToList();
            short map           = 0;
            var   portalCounter = 0;
            var   lodPortal     = new PortalDto
            {
                SourceMapId      = 150,
                SourceX          = 172,
                SourceY          = 171,
                DestinationMapId = 98,
                Type             = PortalType.MapPortal,
                DestinationX     = 6,
                DestinationY     = 36,
                IsDisabled       = false
            };
            var portalsave4 = lodPortal;

            if (_portalDao.FirstOrDefault(s => s.SourceMapId == portalsave4.SourceMapId) ==
                null)
            {
                portalCounter++;
                _portalDao.InsertOrUpdate(ref lodPortal);
            }

            var minilandPortal = new PortalDto
            {
                SourceMapId      = 20001,
                SourceX          = 3,
                SourceY          = 8,
                DestinationMapId = 1,
                Type             = PortalType.MapPortal,
                DestinationX     = 48,
                DestinationY     = 132,
                IsDisabled       = false
            };

            var portalsave3 = minilandPortal;

            if (_portalDao.FirstOrDefault(s => s.SourceMapId == portalsave3.SourceMapId) ==
                null)
            {
                portalCounter++;
                _portalDao.InsertOrUpdate(ref minilandPortal);
            }

            var weddingPortal = new PortalDto
            {
                SourceMapId      = 2586,
                SourceX          = 34,
                SourceY          = 54,
                DestinationMapId = 145,
                Type             = PortalType.MapPortal,
                DestinationX     = 61,
                DestinationY     = 165,
                IsDisabled       = false
            };
            var portalsave2 = weddingPortal;

            if (_portalDao.FirstOrDefault(s => s.SourceMapId == portalsave2.SourceMapId) ==
                null)
            {
                portalCounter++;
                _portalDao.InsertOrUpdate(ref weddingPortal);
            }

            var glacerusCavernPortal = new PortalDto
            {
                SourceMapId      = 2587,
                SourceX          = 42,
                SourceY          = 3,
                DestinationMapId = 189,
                Type             = PortalType.MapPortal,
                DestinationX     = 48,
                DestinationY     = 156,
                IsDisabled       = false
            };
            var portalsave1 = glacerusCavernPortal;

            if (_portalDao.FirstOrDefault(s => s.SourceMapId == portalsave1.SourceMapId) ==
                null)
            {
                portalCounter++;
                _portalDao.InsertOrUpdate(ref glacerusCavernPortal);
            }

            foreach (var currentPacket in packetList.Where(o => o[0].Equals("at") || o[0].Equals("gp")))
            {
                if (currentPacket.Length > 5 && currentPacket[0] == "at")
                {
                    map = short.Parse(currentPacket[2]);
                    continue;
                }

                if (currentPacket.Length <= 4 || currentPacket[0] != "gp")
                {
                    continue;
                }

                var portal = new PortalDto
                {
                    SourceMapId      = map,
                    SourceX          = short.Parse(currentPacket[1]),
                    SourceY          = short.Parse(currentPacket[2]),
                    DestinationMapId = short.Parse(currentPacket[3]),
                    Type             = (PortalType)Enum.Parse(typeof(PortalType), currentPacket[4]),
                    DestinationX     = -1,
                    DestinationY     = -1,
                    IsDisabled       = false
                };

                if (_listPortals1.Any(s =>
                                      s.SourceMapId == map && s.SourceX == portal.SourceX && s.SourceY == portal.SourceY &&
                                      s.DestinationMapId == portal.DestinationMapId) ||
                    _maps.All(s => s.MapId != portal.SourceMapId) ||
                    _maps.All(s => s.MapId != portal.DestinationMapId))
                {
                    // Portal already in list
                    continue;
                }

                _listPortals1.Add(portal);
            }

            _listPortals1 = _listPortals1.OrderBy(s => s.SourceMapId).ThenBy(s => s.DestinationMapId)
                            .ThenBy(s => s.SourceY).ThenBy(s => s.SourceX).ToList();
            foreach (var portal in _listPortals1)
            {
                var p = _listPortals1.Except(_listPortals2).FirstOrDefault(s =>
                                                                           s.SourceMapId == portal.DestinationMapId && s.DestinationMapId == portal.SourceMapId);
                if (p == null)
                {
                    continue;
                }

                portal.DestinationX = p.SourceX;
                portal.DestinationY = p.SourceY;
                p.DestinationY      = portal.SourceY;
                p.DestinationX      = portal.SourceX;
                _listPortals2.Add(p);
                _listPortals2.Add(portal);
            }

            // foreach portal in the new list of Portals where none (=> !Any()) are found in the existing
            portalCounter += _listPortals2.Count(portal => !_portalDao
                                                 .Where(s => s.SourceMapId.Equals(portal.SourceMapId)).Any(
                                                     s => s.DestinationMapId == portal.DestinationMapId && s.SourceX == portal.SourceX &&
                                                     s.SourceY == portal.SourceY));

            // so this dude doesnt exist yet in DAOFactory -> insert it
            var portalsDtos = _listPortals2.Where(portal => !_portalDao
                                                  .Where(s => s.SourceMapId.Equals(portal.SourceMapId)).Any(
                                                      s => s.DestinationMapId == portal.DestinationMapId && s.SourceX == portal.SourceX &&
                                                      s.SourceY == portal.SourceY));

            _portalDao.InsertOrUpdate(portalsDtos);

            _logger.Information(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.PORTALS_PARSED),
                                portalCounter);
        }
예제 #13
0
        public LanguageKey AddFriend([FromBody] FriendShipRequest friendPacket)
        {
            var character       = _connectedAccountHttpClient.GetCharacter(friendPacket.CharacterId, null);
            var targetCharacter = _connectedAccountHttpClient.GetCharacter(friendPacket.FinsPacket.CharacterId, null);
            var friendRequest   = _friendRequestHolder.FriendRequestCharacters.Where(s =>
                                                                                     (s.Value.Item2 == character.Item2.ConnectedCharacter.Id) &&
                                                                                     (s.Value.Item1 == targetCharacter.Item2.ConnectedCharacter.Id)).ToList();

            if ((character.Item2 != null) && (targetCharacter.Item2 != null))
            {
                if (character.Item2.ChannelId != targetCharacter.Item2.ChannelId)
                {
                    throw new ArgumentException();
                }

                var relations = _characterRelationDao.Where(s => s.CharacterId == friendPacket.CharacterId).ToList();
                if (relations.Count(s => s.RelationType == CharacterRelationType.Friend) >= 80)
                {
                    return(LanguageKey.FRIENDLIST_FULL);
                }

                if (relations.Any(s =>
                                  (s.RelationType == CharacterRelationType.Blocked) &&
                                  (s.RelatedCharacterId == friendPacket.FinsPacket.CharacterId)))
                {
                    return(LanguageKey.BLACKLIST_BLOCKED);
                }

                if (relations.Any(s =>
                                  (s.RelationType == CharacterRelationType.Friend) &&
                                  (s.RelatedCharacterId == friendPacket.FinsPacket.CharacterId)))
                {
                    return(LanguageKey.ALREADY_FRIEND);
                }

                if (character.Item2.ConnectedCharacter.FriendRequestBlocked ||
                    targetCharacter.Item2.ConnectedCharacter.FriendRequestBlocked)
                {
                    return(LanguageKey.FRIEND_REQUEST_BLOCKED);
                }

                if (!friendRequest.Any())
                {
                    _friendRequestHolder.FriendRequestCharacters[Guid.NewGuid()] =
                        new Tuple <long, long>(character.Item2.ConnectedCharacter.Id,
                                               targetCharacter.Item2.ConnectedCharacter.Id);
                    return(LanguageKey.FRIEND_REQUEST_SENT);
                }

                switch (friendPacket.FinsPacket.Type)
                {
                case FinsPacketType.Accepted:
                    var data = new CharacterRelationDto
                    {
                        CharacterId        = character.Item2.ConnectedCharacter.Id,
                        RelatedCharacterId = targetCharacter.Item2.ConnectedCharacter.Id,
                        RelationType       = CharacterRelationType.Friend
                    };

                    _characterRelationDao.InsertOrUpdate(ref data);
                    var data2 = new CharacterRelationDto
                    {
                        CharacterId        = targetCharacter.Item2.ConnectedCharacter.Id,
                        RelatedCharacterId = character.Item2.ConnectedCharacter.Id,
                        RelationType       = CharacterRelationType.Friend
                    };

                    _characterRelationDao.InsertOrUpdate(ref data2);
                    _friendRequestHolder.FriendRequestCharacters.TryRemove(friendRequest.First().Key, out _);
                    return(LanguageKey.FRIEND_ADDED);

                case FinsPacketType.Rejected:
                    _friendRequestHolder.FriendRequestCharacters.TryRemove(friendRequest.First().Key, out _);
                    return(LanguageKey.FRIEND_REJECTED);

                default:
                    _logger.Error(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.INVITETYPE_UNKNOWN));
                    _friendRequestHolder.FriendRequestCharacters.TryRemove(friendRequest.First().Key, out _);
                    throw new ArgumentException();
                }
            }

            _friendRequestHolder.FriendRequestCharacters.TryRemove(friendRequest.First().Key, out _);
            throw new ArgumentException();
        }
예제 #14
0
        public override Task ExecuteAsync(SelectPacket packet, ClientSession clientSession)
        {
            try
            {
                if ((clientSession?.Account == null) || clientSession.HasSelectedCharacter)
                {
                    return(Task.CompletedTask);
                }

                var characterDto =
                    _characterDao.FirstOrDefault(s =>
                                                 (s.AccountId == clientSession.Account.AccountId) && (s.Slot == packet.Slot) &&
                                                 (s.State == CharacterState.Active));
                if (characterDto == null)
                {
                    return(Task.CompletedTask);
                }

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

                character.MapInstanceId = _mapInstanceProvider.GetBaseMapInstanceIdByMapId(character.MapId);
                character.MapInstance   = _mapInstanceProvider.GetMapInstance(character.MapInstanceId) !;
                character.PositionX     = character.MapX;
                character.PositionY     = character.MapY;
                character.Direction     = 2;
                character.Script        = character.CurrentScriptId != null?_scriptDao.FirstOrDefault(s => s.Id == character.CurrentScriptId) : null;

                character.Group !.JoinGroup(character);

                var inventories = _inventoryItemInstanceDao
                                  .Where(s => s.CharacterId == character.CharacterId)
                                  .ToList();
                var ids   = inventories.Select(o => o.ItemInstanceId).ToArray();
                var items = _itemInstanceDao.Where(s => ids.Contains(s.Id)).ToList();
                inventories.ForEach(k => character.InventoryService[k.ItemInstanceId] =
                                        InventoryItemInstance.Create(_itemProvider.Convert(items.First(s => s.Id == k.ItemInstanceId)),
                                                                     character.CharacterId, k));
                clientSession.SetCharacter(character);

#pragma warning disable CS0618
                clientSession.SendPacketsAsync(clientSession.Character.GenerateInv());
#pragma warning restore CS0618
                clientSession.SendPacketAsync(clientSession.Character.GenerateMlobjlst());
                if (clientSession.Character.Hp > clientSession.Character.HpLoad())
                {
                    clientSession.Character.Hp = (int)clientSession.Character.HpLoad();
                }

                if (clientSession.Character.Mp > clientSession.Character.MpLoad())
                {
                    clientSession.Character.Mp = (int)clientSession.Character.MpLoad();
                }

                clientSession.Character.Quests = new ConcurrentDictionary <Guid, CharacterQuest>(_characterQuestDao
                                                                                                 .Where(s => s.CharacterId == clientSession.Character.CharacterId).ToDictionary(x => x.Id, x =>
                {
                    var charquest   = x.Adapt <CharacterQuest>();
                    charquest.Quest = _quests.First(s => s.QuestId == charquest.QuestId).Adapt <GameObject.Quest>();
                    charquest.Quest.QuestObjectives =
                        _questObjectives.Where(s => s.QuestId == charquest.QuestId).ToList();
                    return(charquest);
                }));
                clientSession.Character.QuicklistEntries = _quickListEntriesDao
                                                           .Where(s => s.CharacterId == clientSession.Character.CharacterId).ToList();
                clientSession.Character.StaticBonusList = _staticBonusDao
                                                          .Where(s => s.CharacterId == clientSession.Character.CharacterId).ToList();
                clientSession.Character.Titles = _titleDao
                                                 .Where(s => s.CharacterId == clientSession.Character.CharacterId).ToList();
                clientSession.SendPacketAsync(new OkPacket());
            }
            catch (Exception ex)
            {
                _logger.Error("Select character failed.", ex);
            }
            return(Task.CompletedTask);
        }
예제 #15
0
        /// <summary>
        ///     Load Characters, this is the Entrypoint for the Client, Wait for 3 Packets.
        /// </summary>
        /// <param name="packet"></param>
        /// <returns></returns>
        public void LoadCharacters(EntryPointPacket packet)
        {
            if (Session.Account == null)
            {
                var servers = WebApiAccess.Instance.Get <List <ChannelInfo> >(WebApiRoute.Channel)
                              ?.Where(c => c.Type == ServerType.WorldServer).ToList();
                var name = packet.Name;
                var alreadyConnnected = false;
                foreach (var server in servers ?? new List <ChannelInfo>())
                {
                    if (WebApiAccess.Instance
                        .Get <List <ConnectedAccount> >(WebApiRoute.ConnectedAccount, server.WebApi)
                        .Any(a => a.Name == name))
                    {
                        alreadyConnnected = true;
                        break;
                    }
                }

                if (alreadyConnnected)
                {
                    Session.Disconnect();
                    return;
                }

                var account = _accountDao.FirstOrDefault(s => s.Name == name);

                if (account != null)
                {
                    if (account.Password.Equals(packet.Password.ToSha512(),
                                                StringComparison.OrdinalIgnoreCase))
                    {
                        var accountobject = new AccountDto
                        {
                            AccountId = account.AccountId,
                            Name      = account.Name,
                            Password  = account.Password.ToLower(),
                            Authority = account.Authority,
                            Language  = account.Language
                        };
                        SessionFactory.Instance.Sessions.FirstOrDefault(s => s.Value.SessionId == Session.SessionId)
                        .Value.RegionType = account.Language;
                        Session.InitializeAccount(accountobject);
                        //Send Account Connected
                    }
                    else
                    {
                        _logger.Error(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.INVALID_PASSWORD));
                        Session.Disconnect();
                        return;
                    }
                }
                else
                {
                    _logger.Error(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.INVALID_ACCOUNT));
                    Session.Disconnect();
                    return;
                }
            }

            var characters = _characterDao.Where(s =>
                                                 s.AccountId == Session.Account.AccountId && s.State == CharacterState.Active);

            _logger.Information(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.ACCOUNT_ARRIVED),
                                Session.Account.Name);

            // load characterlist packet for each character in Character
            Session.SendPacket(new ClistStartPacket {
                Type = 0
            });
            foreach (var character in characters.Select(characterDto => _adapter.Adapt <Character>(characterDto)))
            {
                var equipment = new WearableInstance[16];

                /* IEnumerable<ItemInstanceDTO> inventory = _iteminstanceDAO.Where(s => s.CharacterId == character.CharacterId && s.Type == (byte)InventoryType.Wear);
                 *
                 *
                 * foreach (ItemInstanceDTO equipmentEntry in inventory)
                 * {
                 *   // explicit load of iteminstance
                 *   WearableInstance currentInstance = equipmentEntry as WearableInstance;
                 *   equipment[(short)currentInstance.Item.EquipmentSlot] = currentInstance;
                 *
                 * }
                 */
                var petlist = new List <short?>();
                var mates   = _mateDao.Where(s => s.CharacterId == character.CharacterId)
                              .ToList();
                for (var i = 0; i < 26; i++)
                {
                    if (mates.Count > i)
                    {
                        petlist.Add(mates[i].Skin);
                        petlist.Add(mates[i].VNum);
                    }
                    else
                    {
                        petlist.Add(-1);
                    }
                }

                // 1 1 before long string of -1.-1 = act completion
                Session.SendPacket(new ClistPacket
                {
                    Slot       = character.Slot,
                    Name       = character.Name,
                    Unknown    = 0,
                    Gender     = (byte)character.Gender,
                    HairStyle  = (byte)character.HairStyle,
                    HairColor  = (byte)character.HairColor,
                    Unknown1   = 0,
                    Class      = character.Class,
                    Level      = character.Level,
                    HeroLevel  = character.HeroLevel,
                    Equipments = new List <short?>
                    {
                        equipment[(byte)EquipmentType.Hat]?.ItemVNum ?? -1,
                        equipment[(byte)EquipmentType.Armor]?.ItemVNum ?? -1,
                        equipment[(byte)EquipmentType.WeaponSkin]?.ItemVNum ??
                        (equipment[(byte)EquipmentType.MainWeapon]?.ItemVNum ?? -1),
                        equipment[(byte)EquipmentType.SecondaryWeapon]?.ItemVNum ?? -1,
                        equipment[(byte)EquipmentType.Mask]?.ItemVNum ?? -1,
                        equipment[(byte)EquipmentType.Fairy]?.ItemVNum ?? -1,
                        equipment[(byte)EquipmentType.CostumeSuit]?.ItemVNum ?? -1,
                        equipment[(byte)EquipmentType.CostumeHat]?.ItemVNum ?? -1
                    },
                    JobLevel        = character.JobLevel,
                    QuestCompletion = 1,
                    QuestPart       = 1,
                    Pets            = petlist,
                    Design          = equipment[(byte)EquipmentType.Hat]?.Item.IsColored ?? false
                        ? equipment[(byte)EquipmentType.Hat].Design : 0,
                    Unknown3 = 0
                });
            }

            Session.SendPacket(new ClistEndPacket());
        }
예제 #16
0
        public void SelectCharacter(SelectPacket selectPacket)
        {
            try
            {
                if (Session?.Account == null || Session.HasSelectedCharacter)
                {
                    return;
                }

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

                var character = _adapter.Adapt <Character>(characterDto);

                character.MapInstanceId = _mapInstanceProvider.GetBaseMapInstanceIdByMapId(character.MapId);
                character.MapInstance   = _mapInstanceProvider.GetMapInstance(character.MapInstanceId);
                character.PositionX     = character.MapX;
                character.PositionY     = character.MapY;
                character.Direction     = 2;
                character.Account       = Session.Account;
                character.Group.JoinGroup(character);
                Session.SetCharacter(character);

                var inventories = _itemInstanceDao
                                  .Where(s => s.CharacterId == character.CharacterId)
                                  .ToList();
                inventories.ForEach(k => character.Inventory[k.Id] = _itemProvider.Convert(k));
#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();
                }

                //var relations =
                //    _characterRelationDao.Where(s => s.CharacterId == Session.Character.CharacterId);
                //var relationsWithCharacter =
                //    _characterRelationDao.Where(s => s.RelatedCharacterId == Session.Character.CharacterId);

                //var characters = _characterDao
                //    .Where(s => relations.Select(v => v.RelatedCharacterId).Contains(s.CharacterId)).ToList();
                //var relatedCharacters = _characterDao.Where(s =>
                //    relationsWithCharacter.Select(v => v.RelatedCharacterId).Contains(s.CharacterId)).ToList();

                //foreach (var relation in _adapter.Adapt<IEnumerable<CharacterRelation>>(relations))
                //{
                //    relation.CharacterName = characters.Find(s => s.CharacterId == relation.RelatedCharacterId)?.Name;
                //    Session.Character.CharacterRelations[relation.CharacterRelationId] = relation;
                //}

                //foreach (var relation in _adapter.Adapt<IEnumerable<CharacterRelation>>(relationsWithCharacter))
                //{
                //    relation.CharacterName =
                //        relatedCharacters.Find(s => s.CharacterId == relation.RelatedCharacterId)?.Name;
                //    Session.Character.RelationWithCharacter[relation.CharacterRelationId] = relation;
                //}

                Session.SendPacket(new OkPacket());
            }
            catch (Exception ex)
            {
                _logger.Error("Select character failed.", ex);
            }
        }
예제 #17
0
        public override void Execute(SelectPacket packet, ClientSession clientSession)
        {
            try
            {
                if ((clientSession?.Account == null) || clientSession.HasSelectedCharacter)
                {
                    return;
                }

                var characterDto =
                    _characterDao.FirstOrDefault(s =>
                                                 (s.AccountId == clientSession.Account.AccountId) && (s.Slot == packet.Slot) &&
                                                 (s.State == CharacterState.Active));
                if (characterDto == null)
                {
                    return;
                }

                var character = _adapter.Adapt <Character>(characterDto);

                character.MapInstanceId = _mapInstanceProvider.GetBaseMapInstanceIdByMapId(character.MapId);
                character.MapInstance   = _mapInstanceProvider.GetMapInstance(character.MapInstanceId);
                character.PositionX     = character.MapX;
                character.PositionY     = character.MapY;
                character.Direction     = 2;
                character.Account       = clientSession.Account;
                character.Group.JoinGroup(character);

                var inventories = _inventoryItemInstanceDao
                                  .Where(s => s.CharacterId == character.CharacterId)
                                  .ToList();
                var ids   = inventories.Select(o => o.ItemInstanceId).ToArray();
                var items = _itemInstanceDao.Where(s => ids.Contains(s.Id)).ToList();
                inventories.ForEach(k => character.InventoryService[k.ItemInstanceId] =
                                        InventoryItemInstance.Create(_itemProvider.Convert(items.First(s => s.Id == k.ItemInstanceId)),
                                                                     character.CharacterId, k));
                clientSession.SetCharacter(character);

#pragma warning disable CS0618
                clientSession.SendPackets(clientSession.Character.GenerateInv());
#pragma warning restore CS0618
                clientSession.SendPacket(clientSession.Character.GenerateMlobjlst());
                if (clientSession.Character.Hp > clientSession.Character.HpLoad())
                {
                    clientSession.Character.Hp = (int)clientSession.Character.HpLoad();
                }

                if (clientSession.Character.Mp > clientSession.Character.MpLoad())
                {
                    clientSession.Character.Mp = (int)clientSession.Character.MpLoad();
                }

                clientSession.Character.QuicklistEntries = _quickListEntriesDao
                                                           .Where(s => s.CharacterId == clientSession.Character.CharacterId).ToList();
                clientSession.Character.StaticBonusList = _staticBonusDao
                                                          .Where(s => s.CharacterId == clientSession.Character.CharacterId).ToList();
                clientSession.Character.Titles = _titleDao
                                                 .Where(s => s.CharacterId == clientSession.Character.CharacterId).ToList();
                clientSession.SendPacket(new OkPacket());
            }
            catch (Exception ex)
            {
                _logger.Error("Select character failed.", ex);
            }
        }