Esempio n. 1
0
        public override async Task ExecuteAsync(MJoinPacket mJoinPacket, ClientSession session)
        {
            var target     = Broadcaster.Instance.GetCharacter(s => s.VisualId == mJoinPacket.VisualId);
            var friendList = await _friendHttpClient.GetListFriendsAsync(session.Character.CharacterId).ConfigureAwait(false);

            if (target != null && friendList.Any(s => s.CharacterId == mJoinPacket.VisualId))
            {
                var miniland = _minilandProvider.GetMiniland(mJoinPacket.VisualId);
                if (miniland.State == MinilandState.Open)
                {
                    await session.ChangeMapInstanceAsync(miniland.MapInstanceId, 5, 8).ConfigureAwait(false);
                }
                else
                {
                    if (miniland.State == MinilandState.Private &&
                        friendList.Where(w => w.RelationType != CharacterRelationType.Blocked)
                        .Select(s => s.CharacterId)
                        .ToList()
                        .Contains(target.VisualId))
                    {
                        await session.ChangeMapInstanceAsync(miniland.MapInstanceId, 5, 8).ConfigureAwait(false);

                        return;
                    }
                    await session.SendPacketAsync(new InfoPacket
                    {
                        Message = GameLanguage.Instance.GetMessageFromKey(LanguageKey.MINILAND_CLOSED_BY_FRIEND,
                                                                          session.Account.Language)
                    }).ConfigureAwait(false);
                }
            }
        }
Esempio n. 2
0
        public override async Task ExecuteAsync(RmvobjPacket rmvobjPacket, ClientSession clientSession)
        {
            var minilandobject =
                clientSession.Character.InventoryService.LoadBySlotAndType(rmvobjPacket.Slot, NoscorePocketType.Miniland);

            if (minilandobject == null)
            {
                return;
            }

            if (_minilandProvider.GetMiniland(clientSession.Character.CharacterId).State != MinilandState.Lock)
            {
                await clientSession.SendPacketAsync(new MsgPacket
                {
                    Message = GameLanguage.Instance.GetMessageFromKey(LanguageKey.MINILAND_NEED_LOCK,
                                                                      clientSession.Account.Language)
                }).ConfigureAwait(false);

                return;
            }

            if (!clientSession.Character.MapInstance.MapDesignObjects.ContainsKey(minilandobject.Id))
            {
                return;
            }

            var minilandObject = clientSession.Character.MapInstance.MapDesignObjects[minilandobject.Id];

            clientSession.Character.MapInstance.MapDesignObjects.TryRemove(minilandobject.Id, out _);
            await clientSession.SendPacketAsync(minilandObject.GenerateEffect(true)).ConfigureAwait(false);

            await clientSession.SendPacketAsync(new MinilandPointPacket
                                                { MinilandPoint = minilandobject.ItemInstance !.Item !.MinilandObjectPoint, Unknown = 100 }).ConfigureAwait(false);
        public async Task CanChangeMinilandMessageAsync()
        {
            var mleditPacket = new MLEditPacket()
            {
                MinilandInfo = "test",
                Type         = 1
            };
            await _mlEditPacketHandler !.ExecuteAsync(mleditPacket, _session !).ConfigureAwait(false);
            var   lastpacket = (InfoiPacket?)_session !.LastPackets.FirstOrDefault(s => s is InfoiPacket);

            Assert.AreEqual(Game18NConstString.MinilandChanged, lastpacket !.Message);
            var miniland = _minilandProvider.GetMiniland(_session.Character.CharacterId);

            Assert.AreEqual("test", miniland.MinilandMessage);
            var lastpacket2 = (MlintroPacket?)_session !.LastPackets.FirstOrDefault(s => s is MlintroPacket);

            Assert.AreEqual("test", lastpacket2?.Intro);
        }
        public async Task SetupAsync()
        {
            TypeAdapterConfig <MapNpcDto, MapNpc> .NewConfig()
            .ConstructUsing(src => new MapNpc(null, Logger, TestHelpers.Instance.DistanceCalculator));

            Broadcaster.Reset();
            await TestHelpers.ResetAsync().ConfigureAwait(false);

            _session = await TestHelpers.Instance.GenerateSessionAsync().ConfigureAwait(false);

            _session2 = await TestHelpers.Instance.GenerateSessionAsync().ConfigureAwait(false);

            var session3 = await TestHelpers.Instance.GenerateSessionAsync().ConfigureAwait(false);

            TestHelpers.Instance.FriendHttpClient
            .Setup(s => s.GetListFriendsAsync(It.IsAny <long>()))
            .ReturnsAsync(new List <CharacterRelationStatus>
            {
                new CharacterRelationStatus
                {
                    CharacterId         = _session2.Character.CharacterId,
                    CharacterName       = _session2.Character.Name,
                    IsConnected         = true,
                    RelationType        = CharacterRelationType.Friend,
                    CharacterRelationId = Guid.NewGuid()
                }
            });
            await TestHelpers.Instance.MinilandDao.TryInsertOrUpdateAsync(new MinilandDto()
            {
                OwnerId = _session.Character.CharacterId,
            });

            _minilandProvider = new MinilandService(TestHelpers.Instance.MapInstanceAccessorService,
                                                    TestHelpers.Instance.FriendHttpClient.Object,
                                                    new List <MapDto> {
                new Map
                {
                    MapId       = 20001,
                    NameI18NKey = "miniland",
                    Data        = new byte[] {}
                }
            },
                                                    TestHelpers.Instance.MinilandDao,
                                                    TestHelpers.Instance.MinilandObjectDao, new MinilandHolder());
            await _minilandProvider.InitializeAsync(_session.Character, TestHelpers.Instance.MapInstanceGeneratorService);

            var miniland = _minilandProvider.GetMiniland(_session.Character.CharacterId);
            await _session.ChangeMapInstanceAsync(miniland.MapInstanceId);

            await _session2.ChangeMapInstanceAsync(miniland.MapInstanceId);

            await session3.ChangeMapInstanceAsync(miniland.MapInstanceId);

            _mlEditPacketHandler = new MlEditPacketHandler(_minilandProvider);
        }
Esempio n. 5
0
        public async Task SaveAsync()
        {
            try
            {
                var account = Session.Account;
                await _accountDao.TryInsertOrUpdateAsync(account).ConfigureAwait(false);

                CharacterDto character = (Character)MemberwiseClone();
                await _characterDao.TryInsertOrUpdateAsync(character).ConfigureAwait(false);

                var quicklistEntriesToDelete = _quicklistEntriesDao
                                               .Where(i => i.CharacterId == CharacterId) !.ToList()
                                               .Where(i => QuicklistEntries.All(o => o.Id != i.Id)).ToList();
                await _quicklistEntriesDao.TryDeleteAsync(quicklistEntriesToDelete.Select(s => s.Id).ToArray()).ConfigureAwait(false);

                await _quicklistEntriesDao.TryInsertOrUpdateAsync(QuicklistEntries).ConfigureAwait(false);

                // load and concat inventory with equipment
                var itemsToDelete = _inventoryItemInstanceDao
                                    .Where(i => i.CharacterId == CharacterId) !.ToList()
                                    .Where(i => InventoryService.Values.All(o => o.Id != i.Id)).ToList();

                await _inventoryItemInstanceDao.TryDeleteAsync(itemsToDelete.Select(s => s.Id).ToArray()).ConfigureAwait(false);

                await _itemInstanceDao.TryDeleteAsync(itemsToDelete.Select(s => s.ItemInstanceId).ToArray()).ConfigureAwait(false);

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

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

                var staticBonusToDelete = _staticBonusDao
                                          .Where(i => i.CharacterId == CharacterId) !.ToList()
                                          .Where(i => StaticBonusList.All(o => o.StaticBonusId != i.StaticBonusId)).ToList();
                await _staticBonusDao.TryDeleteAsync(staticBonusToDelete.Select(s => s.StaticBonusId)).ConfigureAwait(false);

                await _staticBonusDao.TryInsertOrUpdateAsync(StaticBonusList).ConfigureAwait(false);

                await _titleDao.TryInsertOrUpdateAsync(Titles).ConfigureAwait(false);

                var minilandDto = (MinilandDto)_minilandProvider.GetMiniland(CharacterId);
                await _minilandDao.TryInsertOrUpdateAsync(minilandDto).ConfigureAwait(false);

                var questsToDelete = _characterQuestsDao
                                     .Where(i => i.CharacterId == CharacterId) !.ToList()
                                     .Where(i => Quests.Values.All(o => o.QuestId != i.QuestId)).ToList();
                await _characterQuestsDao.TryDeleteAsync(questsToDelete.Select(s => s.Id)).ConfigureAwait(false);

                await _characterQuestsDao.TryInsertOrUpdateAsync(Quests.Values).ConfigureAwait(false);
            }
            catch (Exception e)
            {
                _logger.Error("Save Character failed. SessionId: " + Session.SessionId, e);
            }
        }
Esempio n. 6
0
        public async Task ExecuteAsync(RequestData <Tuple <InventoryItemInstance, UseItemPacket> > requestData)
        {
            var itemInstance = requestData.Data.Item1;
            var packet       = requestData.Data.Item2;

            if (requestData.ClientSession.Character.MapInstance.MapInstanceType != MapInstanceType.BaseMapInstance)
            {
                await requestData.ClientSession.Character.SendPacketAsync(new SayPacket
                {
                    Message = GameLanguage.Instance.GetMessageFromKey(LanguageKey.CANT_USE,
                                                                      requestData.ClientSession.Account.Language),
                    Type = SayColorType.Yellow
                }).ConfigureAwait(false);

                return;
            }

            if (requestData.ClientSession.Character.IsVehicled)
            {
                await requestData.ClientSession.Character.SendPacketAsync(new SayPacket
                {
                    Message = GameLanguage.Instance.GetMessageFromKey(LanguageKey.CANT_USE_IN_VEHICLE,
                                                                      requestData.ClientSession.Account.Language),
                    Type = SayColorType.Yellow
                }).ConfigureAwait(false);

                return;
            }

            if (packet.Mode == 0)
            {
                await requestData.ClientSession.SendPacketAsync(new DelayPacket
                {
                    Type   = 3,
                    Delay  = 5000,
                    Packet = requestData.ClientSession.Character.GenerateUseItem((PocketType)itemInstance.Type,
                                                                                 itemInstance.Slot,
                                                                                 2, 0)
                }).ConfigureAwait(false);

                return;
            }

            requestData.ClientSession.Character.InventoryService.RemoveItemAmountFromInventory(1, itemInstance.ItemInstanceId);
            await requestData.ClientSession.SendPacketAsync(
                itemInstance.GeneratePocketChange((PocketType)itemInstance.Type, itemInstance.Slot)).ConfigureAwait(false);

            var miniland = _minilandProvider.GetMiniland(requestData.ClientSession.Character.CharacterId);
            await requestData.ClientSession.ChangeMapInstanceAsync(miniland.MapInstanceId, 5, 8).ConfigureAwait(false);
        }
Esempio n. 7
0
        public override async Task ExecuteAsync(MLEditPacket mlEditPacket, ClientSession clientSession)
        {
            var miniland = _minilandProvider.GetMiniland(clientSession.Character.CharacterId);

            switch (mlEditPacket.Type)
            {
            case 1:
                await clientSession.SendPacketAsync(new MlintroPacket { Intro = mlEditPacket.MinilandInfo !.Replace(' ', '^') }).ConfigureAwait(false);

                miniland.MinilandMessage = mlEditPacket.MinilandInfo;
                await clientSession.SendPacketAsync(new InfoiPacket
                {
                    Message = Game18NConstString.MinilandChanged
                }).ConfigureAwait(false);

                break;
Esempio n. 8
0
        public override async Task ExecuteAsync(AddobjPacket addobjPacket, ClientSession clientSession)
        {
            var minilandobject =
                clientSession.Character.InventoryService.LoadBySlotAndType(addobjPacket.Slot, NoscorePocketType.Miniland);

            if (minilandobject == null)
            {
                return;
            }

            if (clientSession.Character.MapInstance.MapDesignObjects.ContainsKey(minilandobject.Id))
            {
                await clientSession.SendPacketAsync(new MsgiPacket
                {
                    Message = Game18NConstString.YouAlreadyHaveThisMinilandObject
                }).ConfigureAwait(false);

                return;
            }

            if (_minilandProvider.GetMiniland(clientSession.Character.CharacterId).State != MinilandState.Lock)
            {
                await clientSession.SendPacketAsync(new MsgPacket
                {
                    Message = GameLanguage.Instance.GetMessageFromKey(LanguageKey.MINILAND_NEED_LOCK,
                                                                      clientSession.Account.Language)
                }).ConfigureAwait(false);

                return;
            }

            var minilandobj = new MapDesignObject
            {
                MinilandObjectId = Guid.NewGuid(),
                MapX             = addobjPacket.PositionX,
                MapY             = addobjPacket.PositionY,
                Level1BoxAmount  = 0,
                Level2BoxAmount  = 0,
                Level3BoxAmount  = 0,
                Level4BoxAmount  = 0,
                Level5BoxAmount  = 0
            };


            if (minilandobject.ItemInstance?.Item?.ItemType == ItemType.House)
            {
                var min = clientSession.Character.MapInstance.MapDesignObjects
                          .FirstOrDefault(s => (s.Value.InventoryItemInstance?.ItemInstance?.Item?.ItemType == ItemType.House) &&
                                          (s.Value.InventoryItemInstance.ItemInstance.Item.ItemSubType ==
                                           minilandobject.ItemInstance.Item.ItemSubType)).Value;
                if (min != null)
                {
                    await clientSession.HandlePacketsAsync(new[] { new RmvobjPacket {
                                                                       Slot = min.InventoryItemInstance?.Slot ?? 0
                                                                   } }).ConfigureAwait(false);
                }
            }

            _minilandProvider.AddMinilandObject(minilandobj, clientSession.Character.CharacterId, minilandobject);

            await clientSession.SendPacketAsync(minilandobj.GenerateEffect()).ConfigureAwait(false);

            await clientSession.SendPacketAsync(new MinilandPointPacket
                                                { MinilandPoint = minilandobject.ItemInstance?.Item?.MinilandObjectPoint ?? 0, Unknown = 100 }).ConfigureAwait(false);

            await clientSession.SendPacketAsync(minilandobj.GenerateMapDesignObject()).ConfigureAwait(false);
        }
Esempio n. 9
0
        public override async Task ExecuteAsync(MinigamePacket minigamePacket, ClientSession clientSession)
        {
            _clientSession  = clientSession;
            _minigamePacket = minigamePacket;
            _miniland       = _minilandProvider.GetMiniland(clientSession.Character.CharacterId);
            _minilandObject =
                clientSession.Character.MapInstance.MapDesignObjects.Values.FirstOrDefault(s =>
                                                                                           s.Slot == minigamePacket.Id);
            if ((_minilandObject == null) || (_miniland == null))
            {
                return;
            }

            if (_minilandObject?.InventoryItemInstance?.ItemInstance?.Item?.IsWarehouse != false)
            {
                return;
            }

            var game = (byte)(_minilandObject.InventoryItemInstance.ItemInstance.Item.EquipmentSlot ==
                              EquipmentType.MainWeapon
                    ? (4 + _minilandObject.InventoryItemInstance.ItemInstance.ItemVNum) % 10
                    : (int)_minilandObject.InventoryItemInstance.ItemInstance.Item.EquipmentSlot / 3);

            //todo check if enought points

            switch (minigamePacket.Type)
            {
            case 1:
                await PlayAsync(game).ConfigureAwait(false);

                break;

            case 2:
                await BroadcastEffectAsync().ConfigureAwait(false);

                break;

            case 3:
                await ShowBoxLevelsAsync(game).ConfigureAwait(false);

                break;

            case 4:
                await SelectGiftAsync().ConfigureAwait(false);

                break;

            case 5:
                await ShowMinilandManagmentAsync().ConfigureAwait(false);

                break;

            case 6:
                await RefillAsync().ConfigureAwait(false);

                break;

            case 7:
                await ShowGiftsAsync().ConfigureAwait(false);

                break;

            case 8:
                await OpenGiftBatchAsync().ConfigureAwait(false);

                break;

            case 9:
                await UseCouponAsync().ConfigureAwait(false);

                break;
            }
        }
Esempio n. 10
0
        public override async Task ExecuteAsync(UseObjPacket useobjPacket, ClientSession clientSession)
        {
            var miniland       = _minilandProvider.GetMiniland(clientSession.Character.CharacterId);
            var minilandObject =
                clientSession.Character.MapInstance.MapDesignObjects.Values.FirstOrDefault(s =>
                                                                                           s.Slot == useobjPacket.ObjectId);

            if (minilandObject == null)
            {
                return;
            }

            if (!minilandObject.InventoryItemInstance !.ItemInstance !.Item !.IsWarehouse)
            {
                var game = (byte)(minilandObject.InventoryItemInstance.ItemInstance.Item.EquipmentSlot ==
                                  EquipmentType.MainWeapon
                        ? (4 + minilandObject.InventoryItemInstance.ItemInstance.ItemVNum) % 10
                        : (int)minilandObject.InventoryItemInstance.ItemInstance.Item.EquipmentSlot / 3);
                var full = false;
                await clientSession.SendPacketAsync(new MloInfoPacket
                {
                    IsOwner        = miniland.MapInstanceId == clientSession.Character.MapInstanceId,
                    ObjectVNum     = minilandObject.InventoryItemInstance.ItemInstance.ItemVNum,
                    Slot           = (byte)useobjPacket.ObjectId,
                    MinilandPoints = miniland.MinilandPoint,
                    LawDurability  = minilandObject.DurabilityPoint < 1000,
                    IsFull         = full,
                    MinigamePoints = new MloInfoPacketSubPacket[]
                    {
                        new MloInfoPacketSubPacket
                        {
                            MinimumPoints = 0, MaximumPoints = MinilandHelper.Instance.MinilandMaxPoint[game][0]
                        },
                        new MloInfoPacketSubPacket
                        {
                            MinimumPoints = MinilandHelper.Instance.MinilandMaxPoint[game][0] + 1,
                            MaximumPoints = MinilandHelper.Instance.MinilandMaxPoint[game][1]
                        },
                        new MloInfoPacketSubPacket
                        {
                            MinimumPoints = MinilandHelper.Instance.MinilandMaxPoint[game][1] + 1,
                            MaximumPoints = MinilandHelper.Instance.MinilandMaxPoint[game][2]
                        },
                        new MloInfoPacketSubPacket
                        {
                            MinimumPoints = MinilandHelper.Instance.MinilandMaxPoint[game][2] + 1,
                            MaximumPoints = MinilandHelper.Instance.MinilandMaxPoint[game][3]
                        },
                        new MloInfoPacketSubPacket
                        {
                            MinimumPoints = MinilandHelper.Instance.MinilandMaxPoint[game][3] + 1,
                            MaximumPoints = MinilandHelper.Instance.MinilandMaxPoint[game][4]
                        },
                        new MloInfoPacketSubPacket
                        {
                            MinimumPoints = MinilandHelper.Instance.MinilandMaxPoint[game][4] + 1,
                            MaximumPoints = MinilandHelper.Instance.MinilandMaxPoint[game][5]
                        }
                    }
                }).ConfigureAwait(false);
            }