Esempio n. 1
0
        public override async Task ExecuteAsync(CharNewPacket packet, ClientSession clientSession)
        {
            // TODO: Hold Account Information in Authorized object
            var accountId     = clientSession.Account.AccountId;
            var slot          = packet.Slot;
            var characterName = packet.Name;

            if (await _characterDao.FirstOrDefaultAsync(s =>
                                                        (s.AccountId == accountId) && (s.Slot == slot) && (s.State == CharacterState.Active)).ConfigureAwait(false) != null)
            {
                return;
            }

            var rg = new Regex(Nameregex);

            if (rg.Matches(characterName !).Count == 1)
            {
                var character = await
                                _characterDao.FirstOrDefaultAsync(s =>
                                                                  (s.Name == characterName) && (s.State == CharacterState.Active)).ConfigureAwait(false);

                if (character == null)
                {
                    var level  = (byte)(packet.IsMartialArtist ? 81 : 1);
                    var @class = packet.IsMartialArtist ? CharacterClassType.MartialArtist
                        : CharacterClassType.Adventurer;
                    var chara = new CharacterDto
                    {
                        Class           = @class,
                        Gender          = packet.Gender,
                        HairColor       = packet.HairColor,
                        HairStyle       = packet.HairStyle,
                        Hp              = (int)_hpService.GetHp(@class, level),
                        JobLevel        = 1,
                        Level           = level,
                        MapId           = 1,
                        MapX            = (short)RandomHelper.Instance.RandomNumber(78, 81),
                        MapY            = (short)RandomHelper.Instance.RandomNumber(114, 118),
                        Mp              = (int)_mpService.GetMp(@class, level),
                        MaxMateCount    = 10,
                        SpPoint         = 10000,
                        SpAdditionPoint = 0,
                        Name            = characterName,
                        Slot            = slot,
                        AccountId       = accountId,
                        State           = CharacterState.Active
                    };
                    chara = await _characterDao.TryInsertOrUpdateAsync(chara).ConfigureAwait(false);

                    var miniland = new MinilandDto
                    {
                        MinilandId       = Guid.NewGuid(),
                        State            = MinilandState.Open,
                        MinilandMessage  = ((short)Game18NConstString.Welcome).ToString(),
                        OwnerId          = chara.CharacterId,
                        WelcomeMusicInfo = 3800
                    };
                    await _minilandDao.TryInsertOrUpdateAsync(miniland).ConfigureAwait(false);

                    var charaGo    = chara.Adapt <Character>();
                    var itemsToAdd = new List <BasicEquipment>();
                    foreach (var item in _worldConfiguration.BasicEquipments)
                    {
                        switch (item.Key)
                        {
                        case nameof(CharacterClassType.Adventurer) when @class != CharacterClassType.Adventurer:
                        case nameof(CharacterClassType.Archer) when @class != CharacterClassType.Archer:
                        case nameof(CharacterClassType.Mage) when @class != CharacterClassType.Mage:
                        case nameof(CharacterClassType.MartialArtist) when @class != CharacterClassType.MartialArtist:
                        case nameof(CharacterClassType.Swordsman) when @class != CharacterClassType.Swordsman:
                            break;

                        default:
                            itemsToAdd.AddRange(_worldConfiguration.BasicEquipments[item.Key]);
                            break;
                        }
                    }

                    foreach (var itemToAdd in itemsToAdd)
                    {
                        charaGo.InventoryService.AddItemToPocket(InventoryItemInstance.Create(_itemBuilderService.Create(itemToAdd.VNum, itemToAdd.Amount), charaGo.CharacterId), itemToAdd.NoscorePocketType);
                    }


                    await _quicklistEntryDao.TryInsertOrUpdateAsync(new[] {
                        new QuicklistEntryDto
                        {
                            Id          = Guid.NewGuid(),
                            CharacterId = chara.CharacterId,
                            Slot        = 1,
                            Type        = 0,
                            IconType    = 2,
                            IconVNum    = 0
                        },
                        new QuicklistEntryDto
                        {
                            Id          = Guid.NewGuid(),
                            CharacterId = chara.CharacterId,
                            Slot        = 9,
                            Type        = 1,
                            IconType    = 3,
                            IconVNum    = 1
                        },
                        new QuicklistEntryDto
                        {
                            Id          = Guid.NewGuid(),
                            CharacterId = chara.CharacterId,
                            Slot        = 0,
                            Type        = 1,
                            IconType    = 1,
                            IconVNum    = 1
                        },
                        new QuicklistEntryDto
                        {
                            Id          = Guid.NewGuid(),
                            CharacterId = chara.CharacterId,
                            Slot        = 8,
                            Type        = 1,
                            IconType    = 1,
                            IconVNum    = 16
                        },
                    });

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

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

                    await clientSession.SendPacketAsync(new SuccessPacket()).ConfigureAwait(false);

                    await clientSession.HandlePacketsAsync(new[] { new EntryPointPacket() }).ConfigureAwait(false);
                }
                else
                {
                    await clientSession.SendPacketAsync(new InfoiPacket
                    {
                        Message = Game18NConstString.CharacterNameAlreadyTaken
                    }).ConfigureAwait(false);
                }
            }
Esempio n. 2
0
        public override async Task ExecuteAsync(CreateItemPacket createItemPacket, ClientSession session)
        {
            var   vnum    = createItemPacket.VNum;
            sbyte rare    = 0;
            byte  upgrade = 0;
            byte  design  = 0;
            short amount  = 1;

            if (vnum == 1046)
            {
                return; // cannot create gold as item, use $Gold instead
            }

            var iteminfo = _items.Find(item => item.VNum == vnum);

            if (iteminfo == null)
            {
                await session.SendPacketAsync(new MsgPacket
                {
                    Message = GameLanguage.Instance.GetMessageFromKey(LanguageKey.NO_ITEM, session.Account.Language),
                    Type    = 0
                }).ConfigureAwait(false);

                return;
            }

            if (iteminfo.IsColored || (iteminfo.Effect == ItemEffectType.BoxEffect))
            {
                if (createItemPacket.DesignOrAmount.HasValue)
                {
                    design = (byte)createItemPacket.DesignOrAmount.Value;
                }

                rare = createItemPacket.Upgrade.HasValue && (iteminfo.Effect == ItemEffectType.BoxEffect)
                    ? (sbyte)createItemPacket.Upgrade.Value : rare;
            }
            else if (iteminfo.Type == NoscorePocketType.Equipment)
            {
                if (createItemPacket.Upgrade.HasValue)
                {
                    if (iteminfo.EquipmentSlot != EquipmentType.Sp)
                    {
                        upgrade = createItemPacket.Upgrade.Value;
                    }
                    else
                    {
                        design = createItemPacket.Upgrade.Value;
                    }

                    if ((iteminfo.EquipmentSlot != EquipmentType.Sp) && (upgrade == 0) &&
                        (iteminfo.BasicUpgrade != 0))
                    {
                        upgrade = iteminfo.BasicUpgrade;
                    }
                }

                if (createItemPacket.DesignOrAmount.HasValue)
                {
                    if (iteminfo.EquipmentSlot == EquipmentType.Sp)
                    {
                        upgrade = (byte)createItemPacket.DesignOrAmount.Value;
                    }
                    else if (iteminfo.EquipmentSlot == EquipmentType.Armor || iteminfo.EquipmentSlot == EquipmentType.MainWeapon || iteminfo.EquipmentSlot == EquipmentType.SecondaryWeapon)
                    {
                        rare = (sbyte)createItemPacket.DesignOrAmount.Value;
                    }
                }
            }
            else if (createItemPacket.DesignOrAmount.HasValue && !createItemPacket.Upgrade.HasValue)
            {
                amount = createItemPacket.DesignOrAmount.Value > _worldConfiguration.Value.MaxItemAmount
                    ? _worldConfiguration.Value.MaxItemAmount : createItemPacket.DesignOrAmount.Value;
            }

            var inv = session.Character.InventoryService.AddItemToPocket(InventoryItemInstance.Create(_itemProvider.Create(
                                                                                                          vnum,
                                                                                                          amount, rare, upgrade, design), session.Character.CharacterId));

            if (inv == null || inv.Count <= 0)
            {
                await session.SendPacketAsync(new MsgiPacket
                {
                    Message = Game18NConstString.NotEnoughSpace,
                    Type    = 0
                }).ConfigureAwait(false);

                return;
            }

            await session.SendPacketAsync(inv.GeneratePocketChange()).ConfigureAwait(false);

            var firstItem = inv[0];

            if (session.Character.InventoryService.LoadBySlotAndType(firstItem.Slot,
                                                                     firstItem.Type) !.ItemInstance is WearableInstance wearable)
            {
                switch (wearable.Item !.EquipmentSlot)
                {