public override async Task ExecuteAsync(PreqPacket _, ClientSession session)
        {
            if (((SystemTime.Now() - session.Character.LastPortal).TotalSeconds < 4) ||
                (session.Character.LastPortal > session.Character.LastMove))
            {
                await session.SendPacketAsync(session.Character.GenerateSay(
                                                  GameLanguage.Instance.GetMessageFromKey(LanguageKey.PORTAL_DELAY, session.Account.Language),
                                                  SayColorType.Yellow)).ConfigureAwait(false);

                return;
            }

            var portals = new List <Portal>();

            portals.AddRange(session.Character.MapInstance.Portals);
            portals.AddRange(_minilandProvider
                             .GetMinilandPortals(session.Character.CharacterId)
                             .Where(s => s.SourceMapInstanceId == session.Character.MapInstanceId));
            var portal = portals.Find(port =>
                                      _distanceCalculator.GetDistance((session.Character.PositionX, session.Character.PositionY), (port.SourceX, port.SourceY))
                                      <= 2);

            if (portal == null)
            {
                return;
            }

            if (portal.DestinationMapInstanceId == default)
            {
                return;
            }

            session.Character.LastPortal = SystemTime.Now();

            if ((_mapInstanceAccessorService.GetMapInstance(portal.SourceMapInstanceId) !.MapInstanceType
                 != MapInstanceType.BaseMapInstance) &&
                (_mapInstanceAccessorService.GetMapInstance(portal.DestinationMapInstanceId) !.MapInstanceType
                 == MapInstanceType.BaseMapInstance))
            {
                await session.ChangeMapAsync(session.Character.MapId, session.Character.MapX, session.Character.MapY).ConfigureAwait(false);
            }
Exemple #2
0
        public List <Portal> GetMinilandPortals(long characterId)
        {
            var nosville    = _mapInstanceAccessorService.GetBaseMapById(1);
            var oldNosville = _mapInstanceAccessorService.GetBaseMapById(145);
            var miniland    = _mapInstanceAccessorService.GetMapInstance(_minilandHolder.Minilands[characterId].MapInstanceId);

            return(new List <Portal>
            {
                new Portal
                {
                    SourceX = 48,
                    SourceY = 132,
                    DestinationX = 5,
                    DestinationY = 8,
                    Type = PortalType.Miniland,
                    SourceMapId = 1,
                    DestinationMapId = 20001,
                    DestinationMapInstanceId = miniland !.MapInstanceId,
                    SourceMapInstanceId = nosville !.MapInstanceId
                },
        public override async Task ExecuteAsync(SelectPacket packet, ClientSession clientSession)
        {
            try
            {
                var characterDto = await
                                   _characterDao.FirstOrDefaultAsync(s =>
                                                                     (s.AccountId == clientSession.Account.AccountId) && (s.Slot == packet.Slot) &&
                                                                     (s.State == CharacterState.Active)).ConfigureAwait(false);

                if (characterDto == null)
                {
                    _logger.Error(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.CHARACTER_SLOT_EMPTY), new
                    {
                        clientSession.Account.AccountId,
                        packet.Slot
                    });
                    return;
                }

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

                character.MapInstanceId = _mapInstanceAccessorService.GetBaseMapInstanceIdByMapId(character.MapId);
                character.MapInstance   = _mapInstanceAccessorService.GetMapInstance(character.MapInstanceId) !;
                character.PositionX     = character.MapX;
                character.PositionY     = character.MapY;
                character.Direction     = 2;
                character.Script        = character.CurrentScriptId != null ? await _scriptDao.FirstOrDefaultAsync(s => s.Id == character.CurrentScriptId).ConfigureAwait(false) : null;

                character.Group !.JoinGroup(character);

                var inventories = _inventoryItemInstanceDao
                                  .Where(s => s.CharacterId == character.CharacterId)
                                  ?.ToList() ?? new List <InventoryItemInstanceDto>();
                var ids   = inventories.Select(o => o.ItemInstanceId).ToArray();
                var items = _itemInstanceDao.Where(s => ids.Contains(s !.Id))?.ToList() ?? new List <IItemInstanceDto?>();
                inventories.ForEach(k => character.InventoryService[k.ItemInstanceId] =
                                        InventoryItemInstance.Create(_itemProvider.Convert(items.First(s => s !.Id == k.ItemInstanceId) !),
                                                                     character.CharacterId, k));
                await clientSession.SetCharacterAsync(character).ConfigureAwait(false);

#pragma warning disable CS0618
                await clientSession.SendPacketsAsync(clientSession.Character.GenerateInv()).ConfigureAwait(false);

#pragma warning restore CS0618
                await clientSession.SendPacketAsync(clientSession.Character.GenerateMlobjlst()).ConfigureAwait(false);

                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();
                }

                var quests = _characterQuestDao
                             .Where(s => s.CharacterId == clientSession.Character.CharacterId) ?? new List <CharacterQuestDto>();
                clientSession.Character.Quests = new ConcurrentDictionary <Guid, CharacterQuest>(quests.ToDictionary(x => x.Id, x =>
                {
                    var charquest   = x.Adapt <CharacterQuest>();
                    charquest.Quest = _quests.First(s => s.QuestId == charquest.QuestId).Adapt <GameObject.Services.QuestService.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() ?? new List <QuicklistEntryDto>();
                clientSession.Character.StaticBonusList = _staticBonusDao
                                                          .Where(s => s.CharacterId == clientSession.Character.CharacterId)?.ToList() ?? new List <StaticBonusDto>();
                clientSession.Character.Titles = _titleDao
                                                 .Where(s => s.CharacterId == clientSession.Character.CharacterId)?.ToList() ?? new List <TitleDto>();
                await clientSession.SendPacketAsync(new OkPacket()).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                _logger.Error(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.CHARACTER_SELECTION_FAILED), ex, new
                {
                    clientSession.Account.AccountId,
                    packet.Slot
                });
            }
        }