Ejemplo n.º 1
0
        public void ImportAccounts()
        {
            var acc1 = new AccountDto
            {
                Authority = AuthorityType.GameMaster,
                Name      = "admin",
                Password  = password
            };

            if (_accountDao.FirstOrDefault(s => s.Name == acc1.Name) == null)
            {
                _accountDao.InsertOrUpdate(ref acc1);
            }

            var acc2 = new AccountDto
            {
                Authority = AuthorityType.User,
                Name      = "test",
                Password  = password
            };

            if (_accountDao.FirstOrDefault(s => s.Name == acc1.Name) == null)
            {
                _accountDao.InsertOrUpdate(ref acc2);
            }
        }
        public void Test_Delete_Friend_When_Disconnected()
        {
            var guid       = Guid.NewGuid();
            var targetGuid = Guid.NewGuid();
            var list       = new List <CharacterDto>
            {
                _session.Character,
                new CharacterDto {
                    CharacterId = 2, Name = "test"
                }
            };

            _characterDao.Setup(s => s.FirstOrDefault(It.IsAny <Expression <Func <CharacterDto, bool> > >()))
            .Returns((Expression <Func <CharacterDto, bool> > exp) => list.FirstOrDefault(exp.Compile()));
            _characterRelationDao.InsertOrUpdate(new[]
            {
                new CharacterRelationDto
                {
                    RelatedCharacterId  = 2,
                    CharacterRelationId = targetGuid,
                    CharacterId         = _session.Character.CharacterId,
                    RelationType        = CharacterRelationType.Blocked
                }
            });
            var blDelPacket = new BlDelPacket
            {
                CharacterId = 2
            };

            _BlDelPacketHandler.Execute(blDelPacket, _session);

            Assert.IsTrue(_characterRelationDao.LoadAll().Count() == 0);
        }
Ejemplo n.º 3
0
        public bool DeleteBazaar(long id, short count, string requestCharacterName)
        {
            var bzlink = _holder.BazaarItems.Values.FirstOrDefault(s => s.BazaarItem?.BazaarItemId == id);

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

            if ((bzlink.ItemInstance?.Amount - count < 0) || (count < 0))
            {
                return(false);
            }

            if ((bzlink.ItemInstance?.Amount == count) && (requestCharacterName == bzlink.SellerName))
            {
                _bazaarItemDao.Delete(bzlink.BazaarItem !.BazaarItemId);
                _holder.BazaarItems.TryRemove(bzlink.BazaarItem.BazaarItemId, out _);
                _itemInstanceDao.Delete(bzlink.ItemInstance.Id);
            }
            else
            {
                var item = (IItemInstanceDto)bzlink.ItemInstance !;
                item.Amount -= count;
                _itemInstanceDao.InsertOrUpdate(ref item);
            }

            return(true);
        }
Ejemplo n.º 4
0
        public LanguageKey AddBazaar([FromBody] BazaarRequest bazaarRequest)
        {
            var items = _holder.BazaarItems.Values.Where(o => o.BazaarItem.SellerId == bazaarRequest.CharacterId);

            if (items.Count() > 10 * (bazaarRequest.HasMedal ? 10 : 1) - 1)
            {
                return(LanguageKey.LIMIT_EXCEEDED);
            }

            var item = _itemInstanceDao.FirstOrDefault(s => s.Id == bazaarRequest.ItemInstanceId);

            if ((item == null) || (item.Amount < bazaarRequest.Amount) || (bazaarRequest.Amount < 0) ||
                (bazaarRequest.Price < 0))
            {
                throw new ArgumentException();
            }

            Guid itemId;

            if (item.Amount == bazaarRequest.Amount)
            {
                itemId = item.Id;
            }
            else
            {
                itemId       = item.Id;
                item.Amount -= bazaarRequest.Amount;
                _itemInstanceDao.InsertOrUpdate(ref item);
                item.Id = Guid.NewGuid();
            }

            _itemInstanceDao.InsertOrUpdate(ref item);

            var bazaarItem = new BazaarItemDto
            {
                Amount         = bazaarRequest.Amount,
                DateStart      = SystemTime.Now(),
                Duration       = bazaarRequest.Duration,
                IsPackage      = bazaarRequest.IsPackage,
                MedalUsed      = bazaarRequest.HasMedal,
                Price          = bazaarRequest.Price,
                SellerId       = bazaarRequest.CharacterId,
                ItemInstanceId = item.Id
            };

            _bazaarItemDao.InsertOrUpdate(ref bazaarItem);
            _holder.BazaarItems.TryAdd(bazaarItem.BazaarItemId,
                                       new BazaarLink
            {
                BazaarItem   = bazaarItem, SellerName = bazaarRequest.CharacterName,
                ItemInstance = item.Adapt <ItemInstanceDto>()
            });

            return(LanguageKey.OBJECT_IN_BAZAAR);
        }
Ejemplo n.º 5
0
        public void ImportQuests(string folder)
        {
            _questRewards = _questRewardDao.LoadAll().ToDictionary(x => x.QuestRewardId, x => x);

            var actionList = new Dictionary <string, Func <Dictionary <string, string[][]>, object> >
            {
                { nameof(QuestDto.QuestId), chunk => Convert.ToInt16(chunk["VNUM"][0][1]) },
                { nameof(QuestDto.QuestType), chunk => Convert.ToInt32(chunk["VNUM"][0][2]) },
                { nameof(QuestDto.AutoFinish), chunk => chunk["VNUM"][0][3] == "1" },
                { nameof(QuestDto.IsDaily), chunk => chunk["VNUM"][0][4] == "-1" },
                { nameof(QuestDto.RequiredQuestId), chunk => chunk["VNUM"][0][5] != "-1" ? short.Parse(chunk["VNUM"][0][5]) : (short?)null },
                { nameof(QuestDto.IsSecondary), chunk => chunk["VNUM"][0][6] != "-1" },
                { nameof(QuestDto.LevelMin), chunk => Convert.ToByte(chunk["LEVEL"][0][1]) },
                { nameof(QuestDto.LevelMax), chunk => Convert.ToByte(chunk["LEVEL"][0][2]) },
                { nameof(QuestDto.TitleI18NKey), chunk => chunk["TITLE"][0][1] },
                { nameof(QuestDto.DescI18NKey), chunk => chunk["DESC"][0][1] },
                { nameof(QuestDto.TargetX), chunk => chunk["TARGET"][0][1] == "-1" ? (short?)null : Convert.ToInt16(chunk["TARGET"][0][1]) },
                { nameof(QuestDto.TargetY), chunk => chunk["TARGET"][0][2] == "-1"  ? (short?)null : Convert.ToInt16(chunk["TARGET"][0][2]) },
                { nameof(QuestDto.TargetMap), chunk => chunk["TARGET"][0][3] == "-1"  ? (short?)null : Convert.ToInt16(chunk["TARGET"][0][3]) },
                { nameof(QuestDto.StartDialogId), chunk => chunk["TARGET"][0][1] == "-1" ? (int?)null :  Convert.ToInt32(chunk["TALK"][0][1]) },
                { nameof(QuestDto.EndDialogId), chunk => chunk["TARGET"][0][2] == "-1" ? (int?)null :  Convert.ToInt32(chunk["TALK"][0][2]) },
                { nameof(QuestDto.NextQuestId), chunk => chunk["LINK"][0][1] == "-1" ? (short?)null :  Convert.ToInt16(chunk["LINK"][0][1]) },
                { nameof(QuestDto.QuestQuestReward), chunk => ImportQuestQuestRewards(chunk) },
                { nameof(QuestDto.QuestObjective), chunk => ImportQuestObjectives(chunk) },
            };
            var genericParser = new GenericParser <QuestDto>(folder + _fileQuestDat, "END", 0, actionList, _logger);
            var quests        = genericParser.GetDtos();

            _questDao.InsertOrUpdate(quests);
            _questQuestRewardDao.InsertOrUpdate(quests.Where(s => s.QuestQuestReward != null).SelectMany(s => s.QuestQuestReward));
            _questObjectiveDao.InsertOrUpdate(quests.Where(s => s.QuestObjective != null).SelectMany(s => s.QuestObjective));

            _logger.Information(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.QUESTS_PARSED), quests.Count);
        }
Ejemplo n.º 6
0
        public bool AddWarehouseItem([FromBody] WareHouseDepositRequest depositRequest)
        {
            var item = depositRequest.ItemInstance as IItemInstanceDto;

            item !.Id = Guid.NewGuid();
            _itemInstanceDao.InsertOrUpdate(ref item);
            var warehouse = new WarehouseDto
            {
                CharacterId = depositRequest.WarehouseType == WarehouseType.FamilyWareHouse ? null
                    : (long?)depositRequest.OwnerId,
                Id       = Guid.NewGuid(),
                FamilyId = depositRequest.WarehouseType == WarehouseType.FamilyWareHouse
                    ? (long?)depositRequest.OwnerId : null,
                Type = depositRequest.WarehouseType,
            };

            _warehouseDao.InsertOrUpdate(ref warehouse);
            var warehouseItem = new WarehouseItemDto
            {
                Slot           = depositRequest.Slot,
                Id             = Guid.NewGuid(),
                ItemInstanceId = item.Id,
                WarehouseId    = warehouse.Id
            };

            _warehouseItemDao.InsertOrUpdate(ref warehouseItem);
            return(true);
        }
Ejemplo n.º 7
0
        public void InsertMapMonster(List <string[]> packetList)
        {
            var   monsterCounter   = 0;
            short map              = 0;
            var   mobMvPacketsList = new List <int>();
            var   monsters         = new List <MapMonsterDto>();

            foreach (var currentPacket in packetList.Where(o => o[0].Equals("mv") && o[1].Equals("3")))
            {
                if (!mobMvPacketsList.Contains(Convert.ToInt32(currentPacket[2])))
                {
                    mobMvPacketsList.Add(Convert.ToInt32(currentPacket[2]));
                }
            }

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

                if (currentPacket.Length <= 7 || currentPacket[0] != "in" || currentPacket[1] != "3")
                {
                    continue;
                }

                var monster = new MapMonsterDto
                {
                    MapId        = map,
                    VNum         = short.Parse(currentPacket[2]),
                    MapMonsterId = int.Parse(currentPacket[3]),
                    MapX         = short.Parse(currentPacket[4]),
                    MapY         = short.Parse(currentPacket[5]),
                    Direction    = (byte)(currentPacket[6] == string.Empty ? 0 : byte.Parse(currentPacket[6])),
                    IsDisabled   = false
                };
                monster.IsMoving = mobMvPacketsList.Contains(monster.MapMonsterId);

                if (_npcMonsterDao.FirstOrDefault(s => s.NpcMonsterVNum.Equals(monster.VNum)) == null ||
                    _mapMonsterDao.FirstOrDefault(s => s.MapMonsterId.Equals(monster.MapMonsterId)) != null ||
                    monsters.Count(i => i.MapMonsterId == monster.MapMonsterId) != 0)
                {
                    continue;
                }

                monsters.Add(monster);
                monsterCounter++;
            }


            IEnumerable <MapMonsterDto> mapMonsterDtos = monsters;

            _mapMonsterDao.InsertOrUpdate(mapMonsterDtos);
            _logger.Information(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.MONSTERS_PARSED),
                                monsterCounter);
        }
Ejemplo n.º 8
0
        public MailData ViewMail(long id, [FromBody] JsonPatchDocument <MailDto> mailData)
        {
            var mail = _mailDao.FirstOrDefault(s => s.MailId == id);

            if (mail != null)
            {
                mailData.ApplyTo(mail);
                var bz = mail;
                _mailDao.InsertOrUpdate(ref bz);
                var savedData =
                    _parcelHolder[mail.IsSenderCopy ? (long)mail.SenderId : mail.ReceiverId][mail.IsSenderCopy]
                    .FirstOrDefault(s => s.Value.MailDto.MailId == id);
                var maildata = GenerateMailData(mail, savedData.Value.ItemType, savedData.Value.ItemInstance,
                                                savedData.Value.ReceiverName);
                maildata.MailId = savedData.Value.MailId;
                _parcelHolder[mail.IsSenderCopy ? (long)mail.SenderId : mail.ReceiverId][mail.IsSenderCopy][
                    savedData.Key] = maildata;
                return(maildata);
            }

            return(null);
        }
Ejemplo n.º 9
0
        public void InsertMapNpcs(List <string[]> packetList)
        {
            var   npcmonsterdb         = _npcMonsterDao.LoadAll().ToList();
            var   mapnpcdb             = _mapNpcDao.LoadAll().ToList();
            var   npcCounter           = 0;
            short map                  = 0;
            var   npcs                 = new List <MapNpcDto>();
            var   npcMvPacketsList     = packetList.Where(o => o.Length > 14 && o[0].Equals("mv") && o[1].Equals("2") && long.Parse(o[2]) < 20000).GroupBy(s => s[2]).Select(s => Convert.ToInt32(s.First()[2])).ToList();
            var   effPacketsDictionary = packetList.Where(o => o[0].Equals("eff") && o[1].Equals("2") && long.Parse(o[2]) <= 20000).GroupBy(s => Convert.ToInt16(s[2])).ToDictionary(x => x.Key, x => Convert.ToInt16(x.First()[3]));
            var   npcTalks             = _npcTalkDao.LoadAll().ToDictionary(s => s.DialogId, s => s);

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

                var mapnpcid = short.Parse(currentPacket[3]);
                var npctest  = new MapNpcDto
                {
                    MapX        = short.Parse(currentPacket[4]),
                    MapY        = short.Parse(currentPacket[5]),
                    MapId       = map,
                    VNum        = short.Parse(currentPacket[2]),
                    MapNpcId    = mapnpcid,
                    Effect      = effPacketsDictionary.ContainsKey(mapnpcid) ? effPacketsDictionary[mapnpcid] : (short)0,
                    EffectDelay = 4750,
                    IsMoving    = npcMvPacketsList.Contains(mapnpcid),
                    Direction   = byte.Parse(currentPacket[6]),
                    Dialog      = npcTalks.ContainsKey(short.Parse(currentPacket[9])) ? short.Parse(currentPacket[9]) : (short?)null,
                    IsSitting   = currentPacket[13] != "1",
                    IsDisabled  = false
                };

                if ((npcmonsterdb.FirstOrDefault(s => s.NpcMonsterVNum.Equals(npctest.VNum)) == null) ||
                    (mapnpcdb.FirstOrDefault(s => s.MapNpcId.Equals(npctest.MapNpcId)) !=
                     null) ||
                    (npcs.Count(i => i.MapNpcId == npctest.MapNpcId) != 0))
                {
                    continue;
                }

                npcs.Add(npctest);
                npcCounter++;
            }

            _mapNpcDao.InsertOrUpdate(npcs);
            _logger.Information(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.NPCS_PARSED), npcCounter);
        }
        public void Setup()
        {
            TypeAdapterConfig <CharacterDto, Character> .NewConfig().ConstructUsing(src => new Character(null, null, null, null, null, null, null, _logger));

            TypeAdapterConfig <MapMonsterDto, MapMonster> .NewConfig().ConstructUsing(src => new MapMonster(new List <NpcMonsterDto>(), _logger));

            new Mapper();
            PacketFactory.Initialize <NoS0575Packet>();
            var contextBuilder =
                new DbContextOptionsBuilder <NosCoreContext>().UseInMemoryDatabase(
                    databaseName: Guid.NewGuid().ToString());

            DataAccessHelper.Instance.InitializeForTest(contextBuilder.Options);
            var map = new MapDto {
                MapId = 1
            };

            _mapDao.InsertOrUpdate(ref map);
            var _acc = new AccountDto {
                Name = "AccountTest", Password = "******".ToSha512()
            };

            _accountDao.InsertOrUpdate(ref _acc);
            _chara = new Character(null, null, null, _characterRelationDao, _characterDao, _itemInstanceDao, _accountDao, _logger)
            {
                Name      = "TestExistingCharacter",
                Slot      = 1,
                AccountId = _acc.AccountId,
                MapId     = 1,
                State     = CharacterState.Active
            };
            CharacterDto character = _chara;

            _characterDao.InsertOrUpdate(ref character);
            _session.InitializeAccount(_acc);
            _handler = new CharacterScreenPacketController(null, null, new Adapter(), _characterDao, _accountDao, _itemInstanceDao, _mateDao, _logger);
            _handler.RegisterSession(_session);
        }
Ejemplo n.º 11
0
        public void InsertShops(List <string[]> packetList)
        {
            var shopCounter = 0;
            var shops       = new List <ShopDto>();
            var mapnpcdb    = _mapNpcDao.LoadAll().ToList();
            var shopdb      = _shopDao.LoadAll().ToList();

            foreach (var currentPacket in packetList.Where(o =>
                                                           (o.Length > 6) && o[0].Equals("shop") && o[1].Equals("2"))
                     )
            {
                var npcid = short.Parse(currentPacket[2]);
                var npc   = mapnpcdb.FirstOrDefault(s => s.MapNpcId == npcid);
                if (npc == null)
                {
                    continue;
                }

                var name = new StringBuilder();
                for (var j = 6; j < currentPacket.Length; j++)
                {
                    name.Append($"{currentPacket[j]}");
                    if (j != currentPacket.Length - 1)
                    {
                        name.Append(" ");
                    }
                }

                var shop = new ShopDto
                {
                    Name     = name.ToString(),
                    MapNpcId = npc.MapNpcId,
                    MenuType = byte.Parse(currentPacket[4]),
                    ShopType = byte.Parse(currentPacket[5])
                };

                if ((shopdb.FirstOrDefault(s => s.MapNpcId == npc.MapNpcId) != null) ||
                    shops.Any(s => s.MapNpcId == npc.MapNpcId))
                {
                    continue;
                }

                shops.Add(shop);
                shopCounter++;
            }

            _shopDao.InsertOrUpdate(shops);
            _logger.Information(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.SHOPS_PARSED),
                                shopCounter);
        }
Ejemplo n.º 12
0
        public void ImportQuestPrizes(string folder)
        {
            var actionList = new Dictionary <string, Func <Dictionary <string, string[][]>, object> >
            {
                { nameof(QuestRewardDto.QuestRewardId), chunk => Convert.ToInt16(chunk["VNUM"][0][1]) },
                { nameof(QuestRewardDto.RewardType), chunk => Convert.ToByte(chunk["VNUM"][0][2]) },
                { nameof(QuestRewardDto.Data), chunk => ImportData(chunk) },
                { nameof(QuestRewardDto.Amount), chunk => ImportAmount(chunk) },
            };
            var genericParser   = new GenericParser <QuestRewardDto>(folder + _fileQuestPrizeDat, "END", 0, actionList, _logger);
            var questRewardDtos = genericParser.GetDtos();

            _questRewardDtoDao.InsertOrUpdate(questRewardDtos);
            _logger.Information(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.QUEST_PRIZES_PARSED), questRewardDtos.Count);
        }
Ejemplo n.º 13
0
        public void DeleteMiniland(long characterId)
        {
            if (_minilandIds.ContainsKey(characterId))
            {
                var miniland = _mapInstanceProvider.GetMapInstance(_minilandIds[characterId].MapInstanceId);
                foreach (var obj in miniland.MapDesignObjects.Values)
                {
                    var dto = (MinilandObjectDto)obj;
                    _minilandObjectsDao.InsertOrUpdate(ref dto);
                }

                _mapInstanceProvider.RemoveMap(_minilandIds[characterId].MapInstanceId);
                _minilandIds.TryRemove(characterId, out _);
            }
        }
Ejemplo n.º 14
0
        public MailData?ViewMail(long id, [FromBody] JsonPatchDocument <MailDto> mailData)
        {
            var mail = _mailDao.FirstOrDefault(s => s.MailId == id);

            if (mail == null)
            {
                return(null);
            }


            mailData.ApplyTo(mail);
            var bz = mail;

            _mailDao.InsertOrUpdate(ref bz);
            var savedData =
                _parcelHolder[mail.IsSenderCopy ? (long)mail.SenderId ! : mail.ReceiverId][mail.IsSenderCopy]
Ejemplo n.º 15
0
        private void InitializeTargetSession()
        {
            var targetAccount = new AccountDto {
                Name = "test2", Password = "******".ToSha512()
            };

            _accountDao.InsertOrUpdate(ref targetAccount);

            _targetChar = new Character(null, null, null, _characterRelationDao, _characterDao, _itemInstanceDao, _accountDao, _logger)
            {
                CharacterId = 1,
                Name        = "TestChar2",
                Slot        = 1,
                AccountId   = targetAccount.AccountId,
                MapId       = 1,
                State       = CharacterState.Active
            };

            CharacterDto character = _targetChar;

            _characterDao.InsertOrUpdate(ref character);
            var instanceAccessService = new MapInstanceProvider(new List <MapDto> {
                _map, _map2
            },
                                                                new MapItemProvider(new List <IHandler <MapItem, Tuple <MapItem, GetPacket> > >()),
                                                                _mapNpcDao,
                                                                _mapMonsterDao, _portalDao, new Adapter(), _logger);

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

            handler2.RegisterSession(_targetSession);

            _targetSession.InitializeAccount(targetAccount);

            _targetSession.SetCharacter(_targetChar);
            _targetSession.Character.MapInstance = instanceAccessService.GetBaseMapById(0);
            _targetSession.Character.CharacterId = 2;
            Broadcaster.Instance.RegisterSession(_targetSession);
        }
Ejemplo n.º 16
0
        public override void Execute(CharacterDeletePacket packet, ClientSession clientSession)
        {
            if (clientSession.HasCurrentMapInstance)
            {
                return;
            }

            var account = _accountDao
                          .FirstOrDefault(s => s.AccountId.Equals(clientSession.Account.AccountId));

            if (account == null)
            {
                return;
            }

            if ((account.Password.ToLower() == packet.Password.ToSha512()) || (account.Name == packet.Password))
            {
                var character = _characterDao.FirstOrDefault(s =>
                                                             (s.AccountId == account.AccountId) && (s.Slot == packet.Slot) &&
                                                             (s.State == CharacterState.Active));
                if (character == null)
                {
                    return;
                }

                character.State = CharacterState.Inactive;
                _characterDao.InsertOrUpdate(ref character);

                clientSession.HandlePackets(new[]
                {
                    new EntryPointPacket
                    {
                        Header = "EntryPoint",
                        Title  = "EntryPoint",
                        Name   = account.Name
                    }
                });
            }
            else
            {
                clientSession.SendPacket(new InfoPacket
                {
                    Message = clientSession.GetMessageFromKey(LanguageKey.BAD_PASSWORD)
                });
            }
        }
Ejemplo n.º 17
0
        public void InsertMapMonster(List <string[]> packetList)
        {
            short map = 0;
            var   mobMvPacketsList = packetList.Where(o => o[0].Equals("mv") && o[1].Equals("3"))
                                     .Select(currentPacket => Convert.ToInt32(currentPacket[2])).Distinct().ToList();
            var monsters     = new List <MapMonsterDto>();
            var mapMonsterdb = _mapMonsterDao.LoadAll().ToList();
            var npcMonsterdb = _npcMonsterDao.LoadAll().ToList();

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

                var monster = new MapMonsterDto
                {
                    MapId        = map,
                    VNum         = short.Parse(currentPacket[2]),
                    MapMonsterId = int.Parse(currentPacket[3]),
                    MapX         = short.Parse(currentPacket[4]),
                    MapY         = short.Parse(currentPacket[5]),
                    Direction    = (byte)(currentPacket[6] == string.Empty ? 0 : byte.Parse(currentPacket[6])),
                    IsDisabled   = false,
                    IsMoving     = mobMvPacketsList.Contains(int.Parse(currentPacket[3]))
                };

                if ((npcMonsterdb.FirstOrDefault(s => s.NpcMonsterVNum.Equals(monster.VNum)) == null) ||
                    (mapMonsterdb.FirstOrDefault(s => s.MapMonsterId.Equals(monster.MapMonsterId)) != null) ||
                    (monsters.Count(i => i.MapMonsterId == monster.MapMonsterId) != 0))
                {
                    continue;
                }

                monsters.Add(monster);
            }

            _mapMonsterDao.InsertOrUpdate(monsters);
            _logger.Information(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.MONSTERS_PARSED),
                                monsters.Count);
        }
Ejemplo n.º 18
0
        public void InsertOrUpdateMaps(string folder, List <string[]> packetList)
        {
            var dictionaryId    = ParseDat(folder);
            var folderMap       = folder + _folderMap;
            var dictionaryMusic = packetList.Where(o => o[0].Equals("at") && (o.Length > 7))
                                  .GroupBy(x => x[2])
                                  .ToDictionary(x => x.Key, x => x.First()[7]);
            var maps = new DirectoryInfo(folderMap).GetFiles().Select(file => new MapDto
            {
                NameI18NKey = dictionaryId.FirstOrDefault(s => s.MapId == int.Parse(file.Name))?.NameI18NKey ?? string.Empty,
                Music       = dictionaryMusic.ContainsKey(file.Name) ? int.Parse(dictionaryMusic[file.Name]) : 0,
                MapId       = short.Parse(file.Name),
                Data        = File.ReadAllBytes(file.FullName),
                ShopAllowed = short.Parse(file.Name) == 147
            }).ToList();

            _mapDao.InsertOrUpdate(maps);
            _logger.Information(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.MAPS_PARSED), maps.Count);
        }
Ejemplo n.º 19
0
        public void Parse(string folder)
        {
            var actionList = new Dictionary <string, Func <Dictionary <string, string[][]>, object?> >
            {
                { nameof(NpcTalkDto.DialogId), chunk => Convert.ToInt16(chunk["%"][0][1]) },
                { nameof(NpcTalkDto.NameI18NKey), chunk => chunk["t"][0][1] },
            };

            var genericParser = new GenericParser <NpcTalkDto>(folder + _fileNpcTalkDat,
                                                               "%", 0, actionList, _logger);
            var npcTalks = genericParser.GetDtos(" ").ToList();

            npcTalks.Add(new NpcTalkDto {
                DialogId = 99, NameI18NKey = ""
            });
            _npcTalkDao.InsertOrUpdate(npcTalks);

            _logger.Information(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.NPCTALKS_PARSED), npcTalks.Count);
        }
Ejemplo n.º 20
0
        public void ImportAct(string folder)
        {
            var acts     = new List <ActDto>();
            var actParts = new List <ActPartDto>();

            using (var stream = new StreamReader(folder + _fileQuestDat, Encoding.Default))
            {
                string line;
                while ((line = stream.ReadLine()) != null)
                {
                    var splitted = line.Split(' ', '\t');
                    if (splitted.Length == 3 && splitted[0] == "A")
                    {
                        acts.Add(new ActDto
                        {
                            TitleI18NKey = splitted[2],
                            ActId        = Convert.ToByte(splitted[1]),
                            Scene        = (byte)(39 + Convert.ToByte(splitted[1]))
                        });
                        continue;
                    }

                    if (splitted.Length == 5 && splitted[0] == "Data")
                    {
                        actParts.Add(new ActPartDto
                        {
                            ActPartId     = Convert.ToByte(splitted[1]),
                            ActPartNumber = Convert.ToByte(splitted[3]),
                            ActId         = Convert.ToByte(splitted[2]),
                            MaxTs         = Convert.ToByte(splitted[4]),
                        });
                        continue;
                    }
                }
            }

            _actDao.InsertOrUpdate(acts);
            _actDescDao.InsertOrUpdate(actParts);
            _logger.Information(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.ACTS_PARTS_PARSED), actParts.Count);
        }
Ejemplo n.º 21
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);
        }
Ejemplo n.º 22
0
        public override async Task ExecuteAsync(CharacterDeletePacket packet, ClientSession clientSession)
        {
            if (clientSession.HasSelectedCharacter)
            {
                return;
            }

            var account = _accountDao
                          .FirstOrDefault(s => s.AccountId.Equals(clientSession.Account.AccountId));

            if (account == null)
            {
                return;
            }

            if ((account.Password !.ToLower() == packet.Password !.ToSha512()) || (account.Name == packet.Password))
            {
                var character = _characterDao.FirstOrDefault(s =>
                                                             (s.AccountId == account.AccountId) && (s.Slot == packet.Slot) &&
                                                             (s.State == CharacterState.Active));
                if (character == null)
                {
                    return;
                }

                character.State = CharacterState.Inactive;
                _characterDao.InsertOrUpdate(ref character);

                await clientSession.HandlePacketsAsync(new[]
                {
                    new EntryPointPacket
                    {
                        Header = "EntryPoint",
                        Title  = "EntryPoint",
                        Name   = account.Name
                    }
                }).ConfigureAwait(false);
            }
Ejemplo n.º 23
0
        public void Setup()
        {
            PacketFactory.Initialize <NoS0575Packet>();
            var contextBuilder =
                new DbContextOptionsBuilder <NosCoreContext>().UseInMemoryDatabase(
                    databaseName: Guid.NewGuid().ToString());

            DataAccessHelper.Instance.InitializeForTest(contextBuilder.Options);
            var map = new MapDto {
                MapId = 1
            };

            _mapDao.InsertOrUpdate(ref map);
            var _acc = new AccountDto {
                Name = Name, Password = "******".ToSha512()
            };

            _accountDao.InsertOrUpdate(ref _acc);
            _session.InitializeAccount(_acc);
            _handler = new LoginPacketController(new LoginConfiguration(), _accountDao);
            _handler.RegisterSession(_session);
            WebApiAccess.RegisterBaseAdress();
            WebApiAccess.Instance.MockValues = new Dictionary <WebApiRoute, object>();
        }
Ejemplo n.º 24
0
        public void InsertCards(string folder)
        {
            var actionList = new Dictionary <string, Func <Dictionary <string, string[][]>, object> >
            {
                { nameof(CardDto.CardId), chunk => Convert.ToInt16(chunk["VNUM"][0][2]) },
                { nameof(CardDto.NameI18NKey), chunk => chunk["NAME"][0][2] },
                { nameof(CardDto.Level), chunk => Convert.ToByte(chunk["GROUP"][0][3]) },
                { nameof(CardDto.EffectId), chunk => Convert.ToInt32(chunk["EFFECT"][0][2]) },
                { nameof(CardDto.BuffType), chunk => (BCardType.CardType)Convert.ToByte(chunk["STYLE"][0][3]) },
                { nameof(CardDto.Duration), chunk => Convert.ToInt32(chunk["TIME"][0][2]) },
                { nameof(CardDto.Delay), chunk => Convert.ToInt32(chunk["TIME"][0][3]) },
                { nameof(CardDto.BCards), AddBCards },
                { nameof(CardDto.TimeoutBuff), chunk => Convert.ToInt16(chunk["LAST"][0][2]) },
                { nameof(CardDto.TimeoutBuffChance), chunk => Convert.ToByte(chunk["LAST"][0][3]) }
            };
            var genericParser = new GenericParser <CardDto>(folder + FileCardDat,
                                                            "END", 1, actionList, _logger);
            var cards = genericParser.GetDtos().GroupBy(p => p.CardId).Select(g => g.First()).ToList();

            _cardDao.InsertOrUpdate(cards);
            _bcardDao.InsertOrUpdate(cards.Where(s => s.BCards != null).SelectMany(s => s.BCards));

            _logger.Information(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.CARDS_PARSED), cards.Count);
        }
Ejemplo n.º 25
0
        public void InsertPortals(List <string[]> packetList)
        {
            var   portalsdb     = _portalDao.LoadAll().ToList();
            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 (portalsdb.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 (portalsdb.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 (portalsdb.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 (portalsdb.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);
            }


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

            _portalDao.InsertOrUpdate(portalsDtos);

            _logger.Information(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.PORTALS_PARSED),
                                portalsDtos.Count + portalCounter);
        }
Ejemplo n.º 26
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 (_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 =
                    _characterDao.FirstOrDefault(s =>
                                                 s.Name == characterName && s.State == CharacterState.Active);
                if (character == null)
                {
                    var chara = new CharacterDto
                    {
                        Class = characterCreatePacket.IsMartialArtist ? CharacterClassType.MartialArtist
                            : CharacterClassType.Adventurer,
                        Gender          = characterCreatePacket.Gender,
                        HairColor       = characterCreatePacket.HairColor,
                        HairStyle       = characterCreatePacket.HairStyle,
                        Hp              = characterCreatePacket.IsMartialArtist ? 12965 : 221,
                        JobLevel        = 1,
                        Level           = (byte)(characterCreatePacket.IsMartialArtist ? 81 : 1),
                        MapId           = 1,
                        MapX            = (short)RandomFactory.Instance.RandomNumber(78, 81),
                        MapY            = (short)RandomFactory.Instance.RandomNumber(114, 118),
                        Mp              = characterCreatePacket.IsMartialArtist ? 2369 : 221,
                        MaxMateCount    = 10,
                        SpPoint         = 10000,
                        SpAdditionPoint = 0,
                        Name            = characterName,
                        Slot            = slot,
                        AccountId       = accountId,
                        MinilandMessage = "Welcome",
                        State           = CharacterState.Active
                    };
                    _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)
                });
            }
        }
Ejemplo n.º 27
0
        public void InsertShopItems(List <string[]> packetList)
        {
            var  shopitems   = new List <ShopItemDto>();
            var  itemCounter = 0;
            byte type        = 0;
            var  shopItemdb  = _shopItemDao.LoadAll().ToList();
            var  shopdb      = _shopDao.LoadAll().ToList();

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

                    for (var i = 5; i < currentPacket.Length; i++)
                    {
                        var item = currentPacket[i].Split('.');

                        if (item.Length < 5)
                        {
                            continue;
                        }

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


                        if (shopitems.Any(s =>
                                          s.ItemVNum.Equals(sitem.ItemVNum) && s.ShopId.Equals(sitem.ShopId)) ||
                            shopItemdb.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]);
                }
            }

            var groups           = shopitems.GroupBy(s => s.ShopId);
            var shopListItemDtos = new List <ShopItemDto>();

            foreach (var group in groups)
            {
                var shopItemDtos = group.OrderBy(s => s.Slot).ToList();
                for (byte i = 0; i < shopItemDtos.Count; i++)
                {
                    shopItemDtos.ElementAt(i).Slot = i;
                }

                shopListItemDtos.AddRange(shopItemDtos);
            }

            _shopItemDao.InsertOrUpdate(shopListItemDtos);
            _logger.Information(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.SHOPITEMS_PARSED),
                                itemCounter);
        }
Ejemplo n.º 28
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);
        }
Ejemplo n.º 29
0
        internal void InsertMapTypes()
        {
            var mts = new List <MapTypeDto> {
                new MapTypeDto
                {
                    MapTypeId        = (short)MapTypeType.Act1,
                    MapTypeName      = "Act1",
                    PotionDelay      = 300,
                    RespawnMapTypeId = (long)RespawnType.DefaultAct1,
                    ReturnMapTypeId  = (long)RespawnType.ReturnAct1
                },
                new MapTypeDto
                {
                    MapTypeId        = (short)MapTypeType.Act2,
                    MapTypeName      = "Act2",
                    PotionDelay      = 300,
                    RespawnMapTypeId = (long)RespawnType.DefaultAct1,
                    ReturnMapTypeId  = (long)RespawnType.ReturnAct1
                },
                new MapTypeDto
                {
                    MapTypeId        = (short)MapTypeType.Act3,
                    MapTypeName      = "Act3",
                    PotionDelay      = 300,
                    RespawnMapTypeId = (long)RespawnType.DefaultAct1,
                    ReturnMapTypeId  = (long)RespawnType.ReturnAct1
                },
                new MapTypeDto
                {
                    MapTypeId   = (short)MapTypeType.Act4,
                    MapTypeName = "Act4",
                    PotionDelay = 5000
                },
                new MapTypeDto
                {
                    MapTypeId        = (short)MapTypeType.Act51,
                    MapTypeName      = "Act5.1",
                    PotionDelay      = 300,
                    RespawnMapTypeId = (long)RespawnType.DefaultAct5,
                    ReturnMapTypeId  = (long)RespawnType.ReturnAct5
                },
                new MapTypeDto
                {
                    MapTypeId        = (short)MapTypeType.Act52,
                    MapTypeName      = "Act5.2",
                    PotionDelay      = 300,
                    RespawnMapTypeId = (long)RespawnType.DefaultAct5,
                    ReturnMapTypeId  = (long)RespawnType.ReturnAct5
                },
                new MapTypeDto
                {
                    MapTypeId        = (short)MapTypeType.Act61,
                    MapTypeName      = "Act6.1",
                    PotionDelay      = 300,
                    RespawnMapTypeId = (long)RespawnType.DefaultAct6,
                    ReturnMapTypeId  = (long)RespawnType.ReturnAct1
                },
                new MapTypeDto
                {
                    MapTypeId        = (short)MapTypeType.Act62,
                    MapTypeName      = "Act6.2",
                    PotionDelay      = 300,
                    RespawnMapTypeId = (long)RespawnType.DefaultAct6,
                    ReturnMapTypeId  = (long)RespawnType.ReturnAct1
                },
                new MapTypeDto
                {
                    MapTypeId        = (short)MapTypeType.Act61A,
                    MapTypeName      = "Act6.1a", // angel camp
                    PotionDelay      = 300,
                    RespawnMapTypeId = (long)RespawnType.DefaultAct6,
                    ReturnMapTypeId  = (long)RespawnType.ReturnAct1
                },
                new MapTypeDto
                {
                    MapTypeId        = (short)MapTypeType.Act61D,
                    MapTypeName      = "Act6.1d", // demon camp
                    PotionDelay      = 300,
                    RespawnMapTypeId = (long)RespawnType.DefaultAct6,
                    ReturnMapTypeId  = (long)RespawnType.ReturnAct1
                },
                new MapTypeDto
                {
                    MapTypeId        = (short)MapTypeType.CometPlain,
                    MapTypeName      = "CometPlain",
                    PotionDelay      = 300,
                    RespawnMapTypeId = (long)RespawnType.DefaultAct1,
                    ReturnMapTypeId  = (long)RespawnType.ReturnAct1
                },
                new MapTypeDto
                {
                    MapTypeId        = (short)MapTypeType.Mine1,
                    MapTypeName      = "Mine1",
                    PotionDelay      = 300,
                    RespawnMapTypeId = (long)RespawnType.DefaultAct1,
                    ReturnMapTypeId  = (long)RespawnType.ReturnAct1
                },
                new MapTypeDto
                {
                    MapTypeId        = (short)MapTypeType.Mine2,
                    MapTypeName      = "Mine2",
                    PotionDelay      = 300,
                    RespawnMapTypeId = (long)RespawnType.DefaultAct1,
                    ReturnMapTypeId  = (long)RespawnType.ReturnAct1
                },
                new MapTypeDto
                {
                    MapTypeId        = (short)MapTypeType.MeadowOfMine,
                    MapTypeName      = "MeadownOfPlain",
                    PotionDelay      = 300,
                    RespawnMapTypeId = (long)RespawnType.DefaultAct1,
                    ReturnMapTypeId  = (long)RespawnType.ReturnAct1
                },
                new MapTypeDto
                {
                    MapTypeId        = (short)MapTypeType.SunnyPlain,
                    MapTypeName      = "SunnyPlain",
                    PotionDelay      = 300,
                    RespawnMapTypeId = (long)RespawnType.DefaultAct1,
                    ReturnMapTypeId  = (long)RespawnType.ReturnAct1
                },
                new MapTypeDto
                {
                    MapTypeId        = (short)MapTypeType.Fernon,
                    MapTypeName      = "Fernon",
                    PotionDelay      = 300,
                    RespawnMapTypeId = (long)RespawnType.DefaultAct1,
                    ReturnMapTypeId  = (long)RespawnType.ReturnAct1
                },
                new MapTypeDto
                {
                    MapTypeId        = (short)MapTypeType.FernonF,
                    MapTypeName      = "FernonF",
                    PotionDelay      = 300,
                    RespawnMapTypeId = (long)RespawnType.DefaultAct1,
                    ReturnMapTypeId  = (long)RespawnType.ReturnAct1
                },
                new MapTypeDto
                {
                    MapTypeId        = (short)MapTypeType.Cliff,
                    MapTypeName      = "Cliff",
                    PotionDelay      = 300,
                    RespawnMapTypeId = (long)RespawnType.DefaultAct1,
                    ReturnMapTypeId  = (long)RespawnType.ReturnAct1
                },
                new MapTypeDto
                {
                    MapTypeId   = (short)MapTypeType.LandOfTheDead,
                    MapTypeName = "LandOfTheDead",
                    PotionDelay = 300
                },
                new MapTypeDto
                {
                    MapTypeId   = (short)MapTypeType.Act32,
                    MapTypeName = "Act 3.2",
                    PotionDelay = 300
                },
                new MapTypeDto
                {
                    MapTypeId   = (short)MapTypeType.CleftOfDarkness,
                    MapTypeName = "Cleft of Darkness",
                    PotionDelay = 300
                },
                new MapTypeDto
                {
                    MapTypeId   = (short)MapTypeType.CitadelAngel,
                    MapTypeName = "AngelCitadel",
                    PotionDelay = 300
                },
                new MapTypeDto
                {
                    MapTypeId   = (short)MapTypeType.CitadelDemon,
                    MapTypeName = "DemonCitadel",
                    PotionDelay = 300
                },
                new MapTypeDto
                {
                    MapTypeId        = (short)MapTypeType.Oasis,
                    MapTypeName      = "Oasis",
                    PotionDelay      = 300,
                    RespawnMapTypeId = (long)RespawnType.DefaultOasis,
                    ReturnMapTypeId  = (long)RespawnType.DefaultOasis
                },
                new MapTypeDto
                {
                    MapTypeId   = (short)MapTypeType.Act42,
                    MapTypeName = "Act42",
                    PotionDelay = 5000
                }
            };

            _dropDao.InsertOrUpdate(mts);
            _logger.Information(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.MAPTYPES_PARSED));
        }
Ejemplo n.º 30
0
        public void InsertI18N(string folder)
        {
            _folder = folder;
            string _line;
            var    actdesclist = _i18NActDescDao.LoadAll().ToList();

            foreach (RegionType region in Enum.GetValues(typeof(RegionType)))
            {
                var actdescdtos = new List <I18NActDescDto>();
                try
                {
                    using (var stream = new StreamReader(I18NTextFileName(ActDescTxt, region),
                                                         Encoding.Default))
                    {
                        while ((_line = stream.ReadLine()) != null)
                        {
                            var currentLine = _line.Split('\t');
                            if (actdesclist.Find(s => s.Key == currentLine[0] && s.RegionType == region)
                                == null && currentLine.Length > 1 && !actdescdtos.Exists(s => s.Key == currentLine[0]))
                            {
                                actdescdtos.Add(new I18NActDescDto
                                {
                                    Key        = currentLine[0],
                                    RegionType = region,
                                    Text       = currentLine[1]
                                });
                            }
                        }

                        _i18NActDescDao.InsertOrUpdate(actdescdtos);

                        _logger.Information(string.Format(
                                                LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.I18N_ACTDESC_PARSED),
                                                actdescdtos.Count,
                                                region));
                    }
                }
                catch (FileNotFoundException)
                {
                    _logger.Warning(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.LANGUAGE_MISSING));
                }
            }

            var cardlist = _i18NCardDao.LoadAll().ToList();

            foreach (RegionType region in Enum.GetValues(typeof(RegionType)))
            {
                var carddtos = new List <I18NCardDto>();
                try
                {
                    using (var stream = new StreamReader(I18NTextFileName(CardTxt, region),
                                                         Encoding.Default))
                    {
                        while ((_line = stream.ReadLine()) != null)
                        {
                            var currentLine = _line.Split('\t');
                            if (cardlist.Find(s => s.Key == currentLine[0] && s.RegionType == region) == null &&
                                currentLine.Length > 1 && !carddtos.Exists(s => s.Key == currentLine[0]))
                            {
                                carddtos.Add(new I18NCardDto
                                {
                                    Key        = currentLine[0],
                                    RegionType = region,
                                    Text       = currentLine[1]
                                });
                            }
                        }

                        _i18NCardDao.InsertOrUpdate(carddtos);

                        _logger.Information(string.Format(
                                                LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.I18N_CARD_PARSED), carddtos.Count,
                                                region));
                    }
                }
                catch (FileNotFoundException)
                {
                    _logger.Warning(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.LANGUAGE_MISSING));
                }
            }

            var bcardlist = _i18NbCardDao.LoadAll().ToList();

            foreach (RegionType region in Enum.GetValues(typeof(RegionType)))
            {
                var bcarddtos = new List <I18NbCardDto>();
                try
                {
                    using (var stream = new StreamReader(I18NTextFileName(BCardTxt, region),
                                                         Encoding.Default))
                    {
                        while ((_line = stream.ReadLine()) != null)
                        {
                            var currentLine = _line.Split('\t');
                            if (bcardlist.Find(s => s.Key == currentLine[0] && s.RegionType == region)
                                == null && currentLine.Length > 1 && !bcarddtos.Exists(s => s.Key == currentLine[0]))
                            {
                                bcarddtos.Add(new I18NbCardDto
                                {
                                    Key        = currentLine[0],
                                    RegionType = region,
                                    Text       = currentLine[1]
                                });
                            }
                        }

                        _i18NbCardDao.InsertOrUpdate(bcarddtos);

                        _logger.Information(string.Format(
                                                LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.I18N_BCARD_PARSED), bcarddtos.Count,
                                                region));
                    }
                }
                catch (FileNotFoundException)
                {
                    _logger.Warning(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.LANGUAGE_MISSING));
                }
            }

            var itemlist = _i18NItemDao.LoadAll().ToList();

            foreach (RegionType region in Enum.GetValues(typeof(RegionType)))
            {
                var itemdtos = new List <I18NItemDto>();
                try
                {
                    using (var stream = new StreamReader(I18NTextFileName(ItemTxt, region),
                                                         Encoding.Default))
                    {
                        while ((_line = stream.ReadLine()) != null)
                        {
                            var currentLine = _line.Split('\t');
                            if (itemlist.Find(s => s.Key == currentLine[0] && s.RegionType == region) == null &&
                                currentLine.Length > 1 && !itemdtos.Exists(s => s.Key == currentLine[0]))
                            {
                                itemdtos.Add(new I18NItemDto
                                {
                                    Key        = currentLine[0],
                                    RegionType = region,
                                    Text       = currentLine[1]
                                });
                            }
                        }

                        _i18NItemDao.InsertOrUpdate(itemdtos);

                        _logger.Information(string.Format(
                                                LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.I18N_ITEM_PARSED), itemdtos.Count,
                                                region));
                    }
                }
                catch (FileNotFoundException)
                {
                    _logger.Warning(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.LANGUAGE_MISSING));
                }
            }

            var mapiddatalist = _i18NMapIdDataDao.LoadAll().ToList();

            foreach (RegionType region in Enum.GetValues(typeof(RegionType)))
            {
                var mapiddatadtos = new List <I18NMapIdDataDto>();
                try
                {
                    using (var stream = new StreamReader(I18NTextFileName(MapIdDataTxt, region),
                                                         Encoding.Default))
                    {
                        while ((_line = stream.ReadLine()) != null)
                        {
                            var currentLine = _line.Split('\t');
                            if (mapiddatalist.Find(s => s.Key == currentLine[0] && s.RegionType == region)
                                == null && currentLine.Length > 1 &&
                                !mapiddatadtos.Exists(s => s.Key == currentLine[0]))
                            {
                                mapiddatadtos.Add(new I18NMapIdDataDto
                                {
                                    Key        = currentLine[0],
                                    RegionType = region,
                                    Text       = currentLine[1]
                                });
                            }
                        }

                        _i18NMapIdDataDao.InsertOrUpdate(mapiddatadtos);

                        _logger.Information(string.Format(
                                                LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.I18N_MAPIDDATA_PARSED),
                                                mapiddatadtos.Count, region));
                    }
                }
                catch (FileNotFoundException)
                {
                    _logger.Warning(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.LANGUAGE_MISSING));
                }
            }

            var mappointdatalist = _i18NMapPointDataDao.LoadAll().ToList();

            foreach (RegionType region in Enum.GetValues(typeof(RegionType)))
            {
                var mappointdatadtos = new List <I18NMapPointDataDto>();
                try
                {
                    using (var stream = new StreamReader(I18NTextFileName(MapPointDataTxt, region),
                                                         Encoding.Default))
                    {
                        while ((_line = stream.ReadLine()) != null)
                        {
                            var currentLine = _line.Split('\t');
                            if (mappointdatalist.Find(s =>
                                                      s.Key == currentLine[0] && s.RegionType == region) == null &&
                                currentLine.Length > 1 &&
                                !mappointdatadtos.Exists(s => s.Key == currentLine[0]))
                            {
                                mappointdatadtos.Add(new I18NMapPointDataDto
                                {
                                    Key        = currentLine[0],
                                    RegionType = region,
                                    Text       = currentLine[1]
                                });
                            }
                        }

                        _i18NMapPointDataDao.InsertOrUpdate(mappointdatadtos);

                        _logger.Information(string.Format(
                                                LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.I18N_MAPPOINTDATA_PARSED),
                                                mappointdatadtos.Count, region));
                    }
                }
                catch (FileNotFoundException)
                {
                    _logger.Warning(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.LANGUAGE_MISSING));
                }
            }

            var npcmonsterlist = _i18NNpcMonsterDao.LoadAll().ToList();

            foreach (RegionType region in Enum.GetValues(typeof(RegionType)))
            {
                var npcmonsterdto = new List <I18NNpcMonsterDto>();
                try
                {
                    using (var stream = new StreamReader(I18NTextFileName(MonsterTxt, region),
                                                         Encoding.Default))
                    {
                        while ((_line = stream.ReadLine()) != null)
                        {
                            var currentLine = _line.Split('\t');
                            if (npcmonsterlist.Find(s => s.Key == currentLine[0] && s.RegionType == region)
                                == null && currentLine.Length > 1 &&
                                !npcmonsterdto.Exists(s => s.Key == currentLine[0]))
                            {
                                npcmonsterdto.Add(new I18NNpcMonsterDto
                                {
                                    Key        = currentLine[0],
                                    RegionType = region,
                                    Text       = currentLine[1]
                                });
                            }
                        }

                        _i18NNpcMonsterDao.InsertOrUpdate(npcmonsterdto);

                        _logger.Information(string.Format(
                                                LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.I18N_MPCMONSTER_PARSED),
                                                npcmonsterdto.Count, region));
                    }
                }
                catch (FileNotFoundException)
                {
                    _logger.Warning(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.LANGUAGE_MISSING));
                }
            }

            var npcmonstertalklist = _i18NNpcMonsterTalkDao.LoadAll().ToList();

            foreach (RegionType region in Enum.GetValues(typeof(RegionType)))
            {
                var npctalkdtos = new List <I18NNpcMonsterTalkDto>();
                try
                {
                    using (var stream = new StreamReader(I18NTextFileName(NpcTalkTxt, region),
                                                         Encoding.Default))
                    {
                        while ((_line = stream.ReadLine()) != null)
                        {
                            var currentLine = _line.Split('\t');
                            if (npcmonstertalklist.Find(
                                    s => s.Key == currentLine[0] && s.RegionType == region) == null &&
                                currentLine.Length > 1 && !npctalkdtos.Exists(s => s.Key == currentLine[0]))
                            {
                                npctalkdtos.Add(new I18NNpcMonsterTalkDto
                                {
                                    Key        = currentLine[0],
                                    RegionType = region,
                                    Text       = currentLine[1]
                                });
                            }
                        }

                        _i18NNpcMonsterTalkDao.InsertOrUpdate(npctalkdtos);

                        _logger.Information(string.Format(
                                                LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.I18N_NPCMONSTERTALK_PARSED),
                                                npctalkdtos.Count, region));
                    }
                }
                catch (FileNotFoundException)
                {
                    _logger.Warning(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.LANGUAGE_MISSING));
                }
            }

            var questlist = _i18NQuestDao.LoadAll().ToList();

            foreach (RegionType region in Enum.GetValues(typeof(RegionType)))
            {
                var questdtos = new List <I18NQuestDto>();
                try
                {
                    using (var stream = new StreamReader(I18NTextFileName(QuestTxt, region),
                                                         Encoding.Default))
                    {
                        while ((_line = stream.ReadLine()) != null)
                        {
                            var currentLine = _line.Split('\t');
                            if (questlist.Find(s => s.Key == currentLine[0] && s.RegionType == region)
                                == null && currentLine.Length > 1 && !questdtos.Exists(s => s.Key == currentLine[0]))
                            {
                                questdtos.Add(new I18NQuestDto
                                {
                                    Key        = currentLine[0],
                                    RegionType = region,
                                    Text       = currentLine[1]
                                });
                            }
                        }

                        _i18NQuestDao.InsertOrUpdate(questdtos);

                        _logger.Information(string.Format(
                                                LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.I18N_QUEST_PARSED), questdtos.Count,
                                                region));
                    }
                }
                catch (FileNotFoundException)
                {
                    _logger.Warning(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.LANGUAGE_MISSING));
                }
            }

            var skilllist = _i18NSkillDao.LoadAll().ToList();

            foreach (RegionType region in Enum.GetValues(typeof(RegionType)))
            {
                var skilldtos = new List <I18NSkillDto>();
                try
                {
                    using (var stream = new StreamReader(I18NTextFileName(SkillTxt, region),
                                                         Encoding.Default))
                    {
                        while ((_line = stream.ReadLine()) != null)
                        {
                            var currentLine = _line.Split('\t');
                            if (skilllist.Find(s => s.Key == currentLine[0] && s.RegionType == region)
                                == null && !skilldtos.Exists(s => s.Key == currentLine[0]))
                            {
                                skilldtos.Add(new I18NSkillDto
                                {
                                    Key        = currentLine[0],
                                    RegionType = region,
                                    Text       = currentLine[1]
                                });
                            }
                        }

                        _i18NSkillDao.InsertOrUpdate(skilldtos);

                        _logger.Information(string.Format(
                                                LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.I18N_SKILL_PARSED), skilldtos.Count,
                                                region));
                    }
                }
                catch (FileNotFoundException)
                {
                    _logger.Warning(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.LANGUAGE_MISSING));
                }
            }
        }