Esempio n. 1
0
        public void LoadCharacters(string packet)
        {
            string[] loginPacketParts = packet.Split(' ');

            // Load account by given SessionId
            if (Session.Account == null)
            {
                bool hasRegisteredAccountLogin = true;
                try
                {
                    hasRegisteredAccountLogin = ServiceFactory.Instance.CommunicationService.HasRegisteredAccountLogin(loginPacketParts[4], Session.SessionId);
                }
                catch (Exception ex)
                {
                    Logger.Log.Error("WCF Communication Failed.", ex);
                }
                if (loginPacketParts.Length > 4 && hasRegisteredAccountLogin)
                {
                    AccountDTO accountDTO = DAOFactory.AccountDAO.LoadByName(loginPacketParts[4]);

                    if (accountDTO != null)
                    {
                        if (accountDTO.Password.ToLower().Equals(EncryptionBase.sha512(loginPacketParts[6])))
                        {
                            var account = new Account()
                            {
                                AccountId      = accountDTO.AccountId,
                                Name           = accountDTO.Name,
                                Password       = accountDTO.Password.ToLower(),
                                Authority      = accountDTO.Authority,
                                LastCompliment = accountDTO.LastCompliment,
                            };
                            foreach (PenaltyLogDTO penalty in DAOFactory.PenaltyLogDAO.LoadByAccount(accountDTO.AccountId))
                            {
                                account.PenaltyLogs.Add(new PenaltyLog()
                                {
                                    AccountId    = penalty.AccountId,
                                    DateEnd      = penalty.DateEnd,
                                    DateStart    = penalty.DateStart,
                                    Reason       = penalty.Reason,
                                    Penalty      = penalty.Penalty,
                                    PenaltyLogId = penalty.PenaltyLogId
                                });
                            }
                            foreach (GeneralLogDTO general in DAOFactory.GeneralLogDAO.LoadByAccount(accountDTO.AccountId))
                            {
                                account.GeneralLogs.Add(new GeneralLog()
                                {
                                    AccountId   = general.AccountId,
                                    LogData     = general.LogData,
                                    IpAddress   = general.IpAddress,
                                    LogType     = general.LogType,
                                    LogId       = general.LogId,
                                    Timestamp   = general.Timestamp,
                                    CharacterId = general.CharacterId
                                });
                            }
                            Session.InitializeAccount(account);
                        }
                        else
                        {
                            Logger.Log.ErrorFormat($"Client {Session.ClientId} forced Disconnection, invalid Password or SessionId.");
                            Session.Disconnect();
                        }
                    }
                    else
                    {
                        Logger.Log.ErrorFormat($"Client {Session.ClientId} forced Disconnection, invalid AccountName.");
                        Session.Disconnect();
                    }
                }
                else
                {
                    Logger.Log.ErrorFormat($"Client {Session.ClientId} forced Disconnection, login has not been registered or Account is already logged in.");
                    Session.Disconnect();
                    return;
                }
            }

            //TODO: Wrap Database access up to GO
            IEnumerable <CharacterDTO> characters = DAOFactory.CharacterDAO.LoadByAccount(Session.Account.AccountId);

            Logger.Log.InfoFormat(Language.Instance.GetMessageFromKey("ACCOUNT_ARRIVED"), Session.SessionId);
            Session.SendPacket("clist_start 0");
            foreach (CharacterDTO character in characters)
            {
                IEnumerable <InventoryDTO> inventory = DAOFactory.InventoryDAO.LoadByType(character.CharacterId, InventoryType.Equipment);

                WearableInstance[] equipment = new WearableInstance[16];
                foreach (InventoryDTO equipmentEntry in inventory)
                {
                    //explicit load of iteminstance
                    WearableInstance currentInstance = equipmentEntry.ItemInstance as WearableInstance;
                    equipment[currentInstance.Item.EquipmentSlot] = currentInstance;
                }
                // 1 1 before long string of -1.-1 = act completion
                Session.SendPacket($"clist {character.Slot} {character.Name} 0 {character.Gender} {character.HairStyle} {character.HairColor} 0 {character.Class} {character.Level} {character.HeroLevel} {(equipment[(byte)EquipmentType.Hat] != null ? equipment[(byte)EquipmentType.Hat].ItemVNum : -1)}.{(equipment[(byte)EquipmentType.Armor] != null ? equipment[(byte)EquipmentType.Armor].ItemVNum : -1)}.{(equipment[(byte)EquipmentType.WeaponSkin] != null ? equipment[(byte)EquipmentType.WeaponSkin].ItemVNum : equipment[(byte)EquipmentType.MainWeapon] != null ? equipment[(byte)EquipmentType.MainWeapon].ItemVNum : -1)}.{(equipment[(byte)EquipmentType.SecondaryWeapon] != null ? equipment[(byte)EquipmentType.SecondaryWeapon].ItemVNum : -1)}.{(equipment[(byte)EquipmentType.Mask] != null ? equipment[(byte)EquipmentType.Mask].ItemVNum : -1)}.{(equipment[(byte)EquipmentType.Fairy] != null ? equipment[(byte)EquipmentType.Fairy].ItemVNum : -1)}.{(equipment[(byte)EquipmentType.CostumeSuit] != null ? equipment[(byte)EquipmentType.CostumeSuit].ItemVNum : -1)}.{(equipment[(byte)EquipmentType.CostumeHat] != null ? equipment[(byte)EquipmentType.CostumeHat].ItemVNum : -1)} {character.JobLevel}  1 1 -1.-1.-1.-1.-1.-1.-1.-1.-1.-1.-1.-1.-1.-1.-1.-1.-1.-1.-1.-1.-1.-1.-1.-1.-1.-1 0 0");
            }
            Session.SendPacket("clist_end");
        }
Esempio n. 2
0
        public void Pdtse(string packet)
        {
            Logger.Debug(packet, Session.SessionId);
            string[] packetsplit = packet.Split(' ');
            if (packetsplit.Count() < 4)
            {
                return;
            }
            byte  type = 0;
            short VNum = 0;

            if (!byte.TryParse(packetsplit[2], out type) || !short.TryParse(packetsplit[3], out VNum))
            {
                return;
            }
            if (type == 1)
            {
                MapNpc npc = Session.CurrentMap.Npcs.FirstOrDefault(s => s.MapNpcId == Session.Character.LastNRunId);
                if (npc != null)
                {
                    Recipe rec = npc.Recipes.FirstOrDefault(s => s.ItemVNum == VNum);
                    if (rec != null && rec.Amount > 0)
                    {
                        string rece = $"m_list 3 {rec.Amount}";
                        foreach (RecipeItemDTO ite in rec.Items)
                        {
                            if (ite.Amount > 0)
                            {
                                rece += $" {ite.ItemVNum} {ite.Amount}";
                            }
                        }
                        rece += " -1";
                        Session.SendPacket(rece);
                    }
                }
            }
            else
            {
                MapNpc npc = Session.CurrentMap.Npcs.FirstOrDefault(s => s.MapNpcId == Session.Character.LastNRunId);
                if (npc != null)
                {
                    Recipe rec = npc.Recipes.FirstOrDefault(s => s.ItemVNum == VNum);
                    if (rec != null)
                    {
                        if (rec.Amount <= 0)
                        {
                            return;
                        }
                        foreach (RecipeItemDTO ite in rec.Items)
                        {
                            if (Session.Character.Inventory.CountItem(ite.ItemVNum) < ite.Amount)
                            {
                                return;
                            }
                        }

                        ItemInstance inv = Session.Character.Inventory.AddNewToInventory(rec.ItemVNum, rec.Amount);
                        if (inv.GetType().Equals(typeof(WearableInstance)))
                        {
                            WearableInstance item = inv as WearableInstance;
                            if (item != null && (item.Item.EquipmentSlot == EquipmentType.Armor || item.Item.EquipmentSlot == EquipmentType.MainWeapon || item.Item.EquipmentSlot == EquipmentType.SecondaryWeapon))
                            {
                                item.SetRarityPoint();
                            }
                        }

                        if (inv != null)
                        {
                            short Slot = inv.Slot;
                            if (Slot != -1)
                            {
                                foreach (RecipeItemDTO ite in rec.Items)
                                {
                                    Session.Character.Inventory.RemoveItemAmount(ite.ItemVNum, ite.Amount);
                                }
                                Session.SendPacket(Session.Character.GenerateInventoryAdd(inv.ItemVNum, inv.Amount, inv.Type, inv.Slot, 0, inv.Rare, inv.Upgrade, 0));

                                Session.SendPacket($"pdti 11 {inv.ItemVNum} {rec.Amount} 29 {inv.Upgrade} 0");
                                Session.SendPacket(Session.Character.GenerateGuri(19, 1, 1324));

                                Session.SendPacket(Session.Character.GenerateMsg(String.Format(Language.Instance.GetMessageFromKey("CRAFTED_OBJECT"), inv.Item.Name, rec.Amount), 0));
                            }
                        }
                        else
                        {
                            Session.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("NOT_ENOUGH_PLACE"), 0));
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        public override void Use(ClientSession session, ref ItemInstance inv, byte option = 0, string[] packetsplit = null)
        {
            if (Effect == 0)
            {
                if (EffectValue != 0)
                {
                    if (session.Character.IsSitting)
                    {
                        session.Character.IsSitting = false;
                        session.SendPacket(session.Character.GenerateRest());
                    }
                    session.SendPacket(UserInterfaceHelper.Instance.GenerateGuri(12, 1, session.Character.CharacterId, EffectValue));
                }
                else if (EffectValue == 0)
                {
                    if (packetsplit == null || packetsplit.Length <= 9)
                    {
                        return;
                    }
                    if (!byte.TryParse(packetsplit[8], out byte typeEquip) || !short.TryParse(packetsplit[9], out short slotEquip))
                    {
                        return;
                    }
                    if (session.Character.IsSitting)
                    {
                        session.Character.IsSitting = false;
                        session.SendPacket(session.Character.GenerateRest());
                    }
                    if (option != 0)
                    {
                        bool isUsed = false;
                        switch (inv.ItemVNum)
                        {
                        case 1219:
                            WearableInstance equip = session.Character.Inventory.LoadBySlotAndType <WearableInstance>(slotEquip, (InventoryType)typeEquip);
                            if (equip != null && equip.IsFixed)
                            {
                                equip.IsFixed = false;
                                session.SendPacket(session.Character.GenerateEff(3003));
                                session.SendPacket(UserInterfaceHelper.Instance.GenerateGuri(17, 1, session.Character.CharacterId, slotEquip));
                                session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("ITEM_UNFIXED"), 12));
                                isUsed = true;
                            }
                            break;

                        case 1365:
                        case 9039:
                            SpecialistInstance specialist = session.Character.Inventory.LoadBySlotAndType <SpecialistInstance>(slotEquip, (InventoryType)typeEquip);
                            if (specialist != null && specialist.Rare == -2)
                            {
                                specialist.Rare = 0;
                                session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("SP_RESURRECTED"), 0));
                                session.SendPacket(UserInterfaceHelper.Instance.GenerateGuri(13, 1, session.Character.CharacterId, 1));
                                session.Character.SpPoint = 10000;
                                if (session.Character.SpPoint > 10000)
                                {
                                    session.Character.SpPoint = 10000;
                                }
                                session.SendPacket(session.Character.GenerateSpPoint());
                                session.SendPacket(specialist.GenerateInventoryAdd());
                                isUsed = true;
                            }
                            break;
                        }
                        if (!isUsed)
                        {
                            session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("ITEM_IS_NOT_FIXED"), 11));
                        }
                        else
                        {
                            session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                        }
                    }
                    else
                    {
                        session.SendPacket($"qna #u_i^1^{session.Character.CharacterId}^{(byte)inv.Type}^{inv.Slot}^0^1^{typeEquip}^{slotEquip} {Language.Instance.GetMessageFromKey("QNA_ITEM")}");
                    }
                }
            }
            else
            {
                Logger.Log.Warn(string.Format(Language.Instance.GetMessageFromKey("NO_HANDLER_ITEM"), GetType()));
            }
        }
Esempio n. 4
0
        public override void Execute(EntryPointPacket packet, ClientSession clientSession)
        {
            if (clientSession.Account == null)
            {
                var alreadyConnnected = false;
                var name = packet.Name;
                foreach (var channel in _channelHttpClient.GetChannels().Where(c => c.Type == ServerType.WorldServer))
                {
                    var accounts = _connectedAccountHttpClient.GetConnectedAccount(channel);
                    var target   = accounts.FirstOrDefault(s => s.Name == name);

                    if (target != null)
                    {
                        alreadyConnnected = true;
                        break;
                    }
                }

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

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

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

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

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

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

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

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

            clientSession.SendPacket(new ClistEndPacket());
        }
Esempio n. 5
0
        public ItemInstance Create(short itemToCreateVNum, long characterId, short amount = 1, sbyte rare = 0,
                                   byte upgrade = 0, byte design = 0)
        {
            Item.Item itemToCreate = _items.Find(s => s.VNum == itemToCreateVNum);
            switch (itemToCreate.Type)
            {
            case PocketType.Miniland:
                return(new ItemInstance(itemToCreate)
                {
                    CharacterId = characterId,
                    Amount = amount,
                    DurabilityPoint = itemToCreate.MinilandObjectPoint / 2
                });

            case PocketType.Equipment:
                switch (itemToCreate.ItemType)
                {
                case ItemType.Specialist:
                    return(new SpecialistInstance(itemToCreate)
                    {
                        SpLevel = 1,
                        Amount = amount,
                        CharacterId = characterId,
                        Design = design,
                        Upgrade = upgrade
                    });

                case ItemType.Box:
                    return(new BoxInstance(itemToCreate)
                    {
                        Amount = amount,
                        CharacterId = characterId,
                        Upgrade = upgrade,
                        Design = design
                    });

                default:
                    var wear = new WearableInstance(itemToCreate)
                    {
                        Amount      = amount,
                        Rare        = rare,
                        CharacterId = characterId,
                        Upgrade     = upgrade,
                        Design      = design
                    };
                    if (wear.Rare > 0)
                    {
                        wear.SetRarityPoint();
                    }

                    return(wear);
                }

            default:
                return(new ItemInstance(itemToCreate)
                {
                    Type = itemToCreate.Type,
                    Amount = amount,
                    CharacterId = characterId
                });
            }
        }
Esempio n. 6
0
        public void Pdtse(string packet)
        {
            Logger.Debug(packet, Session.SessionId);
            string[] packetsplit = packet.Split(' ');
            if (packetsplit.Count() < 4)
            {
                return;
            }

            byte type = 0;

            byte.TryParse(packetsplit[2], out type);
            if (type == 1)
            {
                MapNpc npc = Session.CurrentMap.Npcs.FirstOrDefault(s => s.MapNpcId == Session.Character.LastNRunId);
                if (npc != null)
                {
                    Recipe rec = npc.Recipes.FirstOrDefault(s => s.ItemVNum == short.Parse(packetsplit[3]));
                    if (rec != null && rec.Amount > 0)
                    {
                        String rece = $"m_list 3 {rec.Amount}";
                        foreach (RecipeItem ite in rec.Items)
                        {
                            if (ite.Amount > 0)
                            {
                                rece += String.Format($" {ite.ItemVNum} {ite.Amount}");
                            }
                        }
                        rece += " -1";
                        Session.Client.SendPacket(rece);
                    }
                }
            }
            else
            {
                MapNpc npc = Session.CurrentMap.Npcs.FirstOrDefault(s => s.MapNpcId == Session.Character.LastNRunId);
                if (npc != null)
                {
                    Recipe rec = npc.Recipes.FirstOrDefault(s => s.ItemVNum == short.Parse(packetsplit[3]));
                    if (rec != null)
                    {
                        if (rec.Amount <= 0)
                        {
                            return;
                        }
                        foreach (RecipeItem ite in rec.Items)
                        {
                            if (Session.Character.InventoryList.CountItem(ite.ItemVNum) < ite.Amount)
                            {
                                return;
                            }
                        }

                        Inventory inv = Session.Character.InventoryList.AddNewItemToInventory(rec.ItemVNum, rec.Amount);
                        if (inv.ItemInstance.GetType().Equals(typeof(WearableInstance)))
                        {
                            WearableInstance item = inv.ItemInstance as WearableInstance;
                            item.SetRarityPoint();
                        }

                        if (inv != null)
                        {
                            short Slot = inv.Slot;
                            if (Slot != -1)
                            {
                                foreach (RecipeItem ite in rec.Items)
                                {
                                    Session.Character.InventoryList.RemoveItemAmount(ite.ItemVNum, ite.Amount);
                                }
                                Session.Character.GenerateStartupInventory();

                                Session.Client.SendPacket($"pdti 11 {inv.ItemInstance.ItemVNum} {rec.Amount} 29 {inv.ItemInstance.Upgrade} 0");
                                Session.Client.SendPacket($"guri 19 1 {Session.Character.CharacterId} 1324");

                                Session.Client.SendPacket(Session.Character.GenerateMsg(String.Format(Language.Instance.GetMessageFromKey("CRAFTED_OBJECT"), (inv.ItemInstance as ItemInstance).Item.Name, rec.Amount), 0));
                            }
                        }
                        else
                        {
                            Session.Client.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("NOT_ENOUGH_PLACE"), 0));
                        }
                    }
                }
            }
        }
        public void CreateCharacter(string packet)
        {
            Logger.Debug(packet, Session.SessionId);
            if (Session.CurrentMap != null)
            {
                return;
            }

            // TODO: Hold Account Information in Authorized object
            long accountId = Session.Account.AccountId;

            string[] packetsplit = packet.Split(' ');

            byte   slot          = Convert.ToByte(packetsplit[3]);
            string characterName = packetsplit[2];
            Random random        = new Random();

            if (slot <= 2 && DAOFactory.CharacterDAO.LoadBySlot(accountId, slot) == null)
            {
                if (characterName.Length > 3 && characterName.Length < 15)
                {
                    bool isIllegalCharacter = false;

                    System.Text.RegularExpressions.Regex rg = new System.Text.RegularExpressions.Regex(@"^[\u4E00-\u9FA5a-zA-Z0-9ąáàâäãåçćéèêëęíìîïłńñóòôöõúùûüśźżýÿæœĄÁÀÂÄÃÅĆÇĘÉÈÊËÍÌÎÏŁŃÑÓÒÔÖÕÚÙÛÜŚŹŻÝŸÆŒ.¤*\-|#²§µß™€=$^<>£!()&~{}@]*$`~");
                    isIllegalCharacter = rg.IsMatch(characterName);

                    if (!isIllegalCharacter)
                    {
                        if (DAOFactory.CharacterDAO.LoadByName(characterName) == null)
                        {
                            if (Convert.ToByte(packetsplit[3]) > 2)
                            {
                                return;
                            }
                            CharacterDTO newCharacter = new CharacterDTO()
                            {
                                Class     = (byte)ClassType.Adventurer,
                                Gender    = (Convert.ToByte(packetsplit[4]) >= 0 && Convert.ToByte(packetsplit[4]) <= 1 ? Convert.ToByte(packetsplit[4]) : Convert.ToByte(0)),
                                HairColor = Enum.IsDefined(typeof(HairColorType), Convert.ToByte(packetsplit[6])) ? Convert.ToByte(packetsplit[6]) : Convert.ToByte(0),
                                HairStyle = Enum.IsDefined(typeof(HairStyleType), Convert.ToByte(packetsplit[5])) ? Convert.ToByte(packetsplit[5]) : Convert.ToByte(0),
                                Hp        = 221,
                                JobLevel  = 1,
                                Level     = 1,
                                MapId     = 1,
                                MapX      = (short)(random.Next(78, 81)),
                                MapY      = (short)(random.Next(114, 118)),
                                Mp        = 221,
                                Name      = characterName,
                                Slot      = slot,
                                AccountId = accountId,
                                StateEnum = CharacterState.Active,
                            };

                            SaveResult        insertResult = DAOFactory.CharacterDAO.InsertOrUpdate(ref newCharacter);
                            CharacterSkillDTO sk1          = new CharacterSkillDTO {
                                CharacterId = newCharacter.CharacterId, SkillVNum = 200
                            };
                            CharacterSkillDTO sk2 = new CharacterSkillDTO {
                                CharacterId = newCharacter.CharacterId, SkillVNum = 201
                            };
                            CharacterSkillDTO sk3 = new CharacterSkillDTO {
                                CharacterId = newCharacter.CharacterId, SkillVNum = 209
                            };
                            QuicklistEntryDTO qlst1 = new QuicklistEntryDTO
                            {
                                CharacterId = newCharacter.CharacterId,
                                Type        = 1,
                                Slot        = 1,
                                Pos         = 1
                            };
                            QuicklistEntryDTO qlst2 = new QuicklistEntryDTO
                            {
                                CharacterId = newCharacter.CharacterId,
                                Q2          = 1,
                                Slot        = 2,
                            };
                            QuicklistEntryDTO qlst3 = new QuicklistEntryDTO
                            {
                                CharacterId = newCharacter.CharacterId,
                                Q2          = 8,
                                Type        = 1,
                                Slot        = 1,
                                Pos         = 16
                            };
                            QuicklistEntryDTO qlst4 = new QuicklistEntryDTO
                            {
                                CharacterId = newCharacter.CharacterId,
                                Q2          = 9,
                                Type        = 1,
                                Slot        = 3,
                                Pos         = 1
                            };
                            qlst1 = DAOFactory.QuicklistEntryDAO.InsertOrUpdate(qlst1);
                            qlst2 = DAOFactory.QuicklistEntryDAO.InsertOrUpdate(qlst2);
                            qlst3 = DAOFactory.QuicklistEntryDAO.InsertOrUpdate(qlst3);
                            qlst4 = DAOFactory.QuicklistEntryDAO.InsertOrUpdate(qlst4);
                            sk1   = DAOFactory.CharacterSkillDAO.InsertOrUpdate(sk1);
                            sk2   = DAOFactory.CharacterSkillDAO.InsertOrUpdate(sk2);
                            sk3   = DAOFactory.CharacterSkillDAO.InsertOrUpdate(sk3);

                            IList <ItemInstanceDTO> startupInventory = new List <ItemInstanceDTO>();
                            ItemInstance            inventory        = new WearableInstance() // first weapon
                            {
                                CharacterId = newCharacter.CharacterId,
                                Slot        = (byte)EquipmentType.MainWeapon,
                                Type        = InventoryType.Wear,
                                Amount      = 1,
                                ItemVNum    = 1,
                            };
                            startupInventory.Add(inventory);

                            inventory = new WearableInstance() // second weapon
                            {
                                CharacterId = newCharacter.CharacterId,
                                Slot        = (byte)EquipmentType.SecondaryWeapon,
                                Type        = InventoryType.Wear,
                                Amount      = 1,
                                ItemVNum    = 8
                            };
                            startupInventory.Add(inventory);

                            inventory = new WearableInstance() // armor
                            {
                                CharacterId = newCharacter.CharacterId,
                                Slot        = (byte)EquipmentType.Armor,
                                Type        = InventoryType.Wear,
                                Amount      = 1,
                                ItemVNum    = 12
                            };
                            startupInventory.Add(inventory);

                            inventory = new ItemInstance() // snack
                            {
                                CharacterId = newCharacter.CharacterId,
                                Type        = InventoryType.Etc,
                                Amount      = 10,
                                ItemVNum    = 2024
                            };
                            startupInventory.Add(inventory);

                            inventory = new ItemInstance() // ammo
                            {
                                CharacterId = newCharacter.CharacterId,
                                Slot        = 1,
                                Type        = InventoryType.Etc,
                                Amount      = 1,
                                ItemVNum    = 2081
                            };
                            startupInventory.Add(inventory);

                            DAOFactory.ItemInstanceDAO.InsertOrUpdate(startupInventory);
                            LoadCharacters(packet);
                        }
                        else
                        {
                            Session.SendPacketFormat($"info {Language.Instance.GetMessageFromKey("ALREADY_TAKEN")}");
                        }
                    }
                    else
                    {
                        Session.SendPacketFormat($"info {Language.Instance.GetMessageFromKey("INVALID_CHARNAME")}");
                    }
                }
            }
        }
        /// <summary>
        ///     Load Characters, this is the Entrypoint for the Client, Wait for 3 Packets.
        /// </summary>
        /// <param name="packet"></param>
        /// <returns></returns>
        public void LoadCharacters(EntryPointPacket packet)
        {
            if (Session.Account == null)
            {
                var servers           = WebApiAccess.Instance.Get <List <WorldServerInfo> >("api/channels");
                var name              = packet.Name;
                var alreadyConnnected = false;
                foreach (var server in servers)
                {
                    if (WebApiAccess.Instance
                        .Get <List <ConnectedAccount> >($"api/connectedAccount", server.WebApi)
                        .Any(a => a.Name == name))
                    {
                        alreadyConnnected = true;
                        break;
                    }
                }

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

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

                if (account != null)
                {
                    if (account.Password.Equals(EncryptionHelper.Sha512(packet.Password),
                                                StringComparison.OrdinalIgnoreCase))
                    {
                        var accountobject = new AccountDTO
                        {
                            AccountId = account.AccountId,
                            Name      = account.Name,
                            Password  = account.Password.ToLower(),
                            Authority = account.Authority,
                            Language  = account.Language
                        };
                        Session.InitializeAccount(accountobject);
                        //Send Account Connected
                    }
                    else
                    {
                        Logger.Log.ErrorFormat(LogLanguage.Instance.GetMessageFromKey(LanguageKey.INVALID_PASSWORD));
                        Session.Disconnect();
                        return;
                    }
                }
                else
                {
                    Logger.Log.ErrorFormat(LogLanguage.Instance.GetMessageFromKey(LanguageKey.INVALID_ACCOUNT));
                    Session.Disconnect();
                    return;
                }
            }

            if (Session.Account == null)
            {
                return;
            }

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

            Logger.Log.InfoFormat(LogLanguage.Instance.GetMessageFromKey(LanguageKey.ACCOUNT_ARRIVED),
                                  Session.Account.Name);

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

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

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

            Session.SendPacket(new ClistEndPacket());
        }
Esempio n. 9
0
        private ushort GenerateDamage(int monsterid, Skill skill, ref int hitmode)
        {
            #region Definitions

            MapMonster monsterToAttack = Session.CurrentMap.GetMonster(monsterid);
            if (monsterToAttack == null)
            {
                return(0);
            }

            short  distanceX = (short)(Session.Character.MapX - monsterToAttack.MapX);
            short  distanceY = (short)(Session.Character.MapY - monsterToAttack.MapY);
            Random random    = new Random();
            int    generated = random.Next(0, 100);

            // int miss_chance = 20;
            int monsterDefence = 0;

            short mainUpgrade    = 0;
            int   mainCritChance = 4;
            int   mainCritHit    = 70;
            int   mainMinDmg     = 0;
            int   mainMaxDmg     = 0;
            int   mainHitRate    = 0;

            short secUpgrade    = 0;
            int   secCritChance = 0;
            int   secCritHit    = 0;
            int   secMinDmg     = 0;
            int   secMaxDmg     = 0;
            int   secHitRate    = 0;

            // int CritChance = 4;
            // int CritHit = 70;
            // int MinDmg = 0;
            // int MaxDmg = 0;
            // int HitRate = 0;
            // sbyte Upgrade = 0;
            #endregion

            #region Sp

            SpecialistInstance specialistInstance = Session.Character.Inventory.LoadBySlotAndType <SpecialistInstance>((byte)EquipmentType.Sp, InventoryType.Wear);

            #endregion

            #region Get Weapon Stats

            WearableInstance weapon = Session.Character.Inventory.LoadBySlotAndType <WearableInstance>((byte)EquipmentType.MainWeapon, InventoryType.Wear);
            if (weapon != null)
            {
                mainUpgrade = weapon.Upgrade;
            }

            mainMinDmg     += Session.Character.MinHit;
            mainMaxDmg     += Session.Character.MaxHit;
            mainHitRate    += Session.Character.HitRate;
            mainCritChance += Session.Character.HitCriticalRate;
            mainCritHit    += Session.Character.HitCritical;

            WearableInstance weapon2 = Session.Character.Inventory.LoadBySlotAndType <WearableInstance>((byte)EquipmentType.SecondaryWeapon, InventoryType.Wear);
            if (weapon2 != null)
            {
                secUpgrade = weapon2.Upgrade;
            }

            secMinDmg     += Session.Character.MinDistance;
            secMaxDmg     += Session.Character.MaxDistance;
            secHitRate    += Session.Character.DistanceRate;
            secCritChance += Session.Character.DistanceCriticalRate;
            secCritHit    += Session.Character.DistanceCritical;

            #endregion

            #region Switch skill.Type

            switch (skill.Type)
            {
            case 0:
                monsterDefence = monsterToAttack.Monster.CloseDefence;
                if (Session.Character.Class == ClassType.Archer)
                {
                    mainCritHit    = secCritHit;
                    mainCritChance = secCritChance;
                    mainHitRate    = secHitRate;
                    mainMaxDmg     = secMaxDmg;
                    mainMinDmg     = secMinDmg;
                    mainUpgrade    = secUpgrade;
                }
                break;

            case 1:
                monsterDefence = monsterToAttack.Monster.DistanceDefence;
                if (Session.Character.Class == ClassType.Swordman || Session.Character.Class == ClassType.Adventurer)
                {
                    mainCritHit    = secCritHit;
                    mainCritChance = secCritChance;
                    mainHitRate    = secHitRate;
                    mainMaxDmg     = secMaxDmg;
                    mainMinDmg     = secMinDmg;
                    mainUpgrade    = secUpgrade;
                }
                break;

            case 2:
                monsterDefence = monsterToAttack.Monster.MagicDefence;
                break;
            }

            #endregion

            #region Basic Damage Data Calculation

            if (specialistInstance != null)
            {
                mainMinDmg     += specialistInstance.DamageMinimum;
                mainMaxDmg     += specialistInstance.DamageMaximum;
                mainCritHit    += specialistInstance.CriticalRate;
                mainCritChance += specialistInstance.CriticalLuckRate;
                mainHitRate    += specialistInstance.HitRate;
            }

#warning TODO: Implement BCard damage boosts, see Issue

            mainUpgrade -= monsterToAttack.Monster.DefenceUpgrade;
            if (mainUpgrade < -10)
            {
                mainUpgrade = -10;
            }
            else if (mainUpgrade > 10)
            {
                mainUpgrade = 10;
            }

            #endregion

            #region Detailed Calculation

            #region Base Damage

            int baseDamage = new Random().Next(mainMinDmg, mainMaxDmg + 1);
            baseDamage += (skill.Damage / 4);
            int elementalDamage = 0; // placeholder for BCard etc...
            elementalDamage += (skill.ElementalDamage / 4);
            switch (mainUpgrade)
            {
            case -10:
                monsterDefence += (int)(monsterDefence * 2);
                break;

            case -9:
                monsterDefence += (int)(monsterDefence * 1.2);
                break;

            case -8:
                monsterDefence += (int)(monsterDefence * 0.9);
                break;

            case -7:
                monsterDefence += (int)(monsterDefence * 0.65);
                break;

            case -6:
                monsterDefence += (int)(monsterDefence * 0.54);
                break;

            case -5:
                monsterDefence += (int)(monsterDefence * 0.43);
                break;

            case -4:
                monsterDefence += (int)(monsterDefence * 0.32);
                break;

            case -3:
                monsterDefence += (int)(monsterDefence * 0.22);
                break;

            case -2:
                monsterDefence += (int)(monsterDefence * 0.15);
                break;

            case -1:
                monsterDefence += (int)(monsterDefence * 0.1);
                break;

            case 0:
                break;

            case 1:
                baseDamage += (int)(baseDamage * 0.1);
                break;

            case 2:
                baseDamage += (int)(baseDamage * 0.15);
                break;

            case 3:
                baseDamage += (int)(baseDamage * 0.22);
                break;

            case 4:
                baseDamage += (int)(baseDamage * 0.32);
                break;

            case 5:
                baseDamage += (int)(baseDamage * 0.43);
                break;

            case 6:
                baseDamage += (int)(baseDamage * 0.54);
                break;

            case 7:
                baseDamage += (int)(baseDamage * 0.65);
                break;

            case 8:
                baseDamage += (int)(baseDamage * 0.9);
                break;

            case 9:
                baseDamage += (int)(baseDamage * 1.2);
                break;

            case 10:
                baseDamage += (int)(baseDamage * 2);
                break;
            }

            #endregion

            #region Critical Damage

            if (random.Next(100) <= mainCritChance)
            {
                if (skill.Type == 2)
                {
                }
                else if (skill.Type == 3 && Session.Character.Class != ClassType.Magician)
                {
                    baseDamage = (int)(baseDamage * ((mainCritHit / 100D) + 1));
                    hitmode    = 3;
                }
                else
                {
                    baseDamage = (int)(baseDamage * ((mainCritHit / 100D) + 1));
                    hitmode    = 3;
                }
            }

            #endregion

            #region Elementary Damage

            #region Calculate Elemental Boost + Rate

            double elementalBoost    = 0;
            short  monsterResistance = 0;
            switch (Session.Character.Element)
            {
            case 0:
                break;

            case 1:
                monsterResistance = monsterToAttack.Monster.FireResistance;
                switch (monsterToAttack.Monster.Element)
                {
                case 0:
                    elementalBoost = 1.3;
                    break;

                case 1:
                    elementalBoost = 1;
                    break;

                case 2:
                    elementalBoost = 2;
                    break;

                case 3:
                    elementalBoost = 0.5;
                    break;

                case 4:
                    elementalBoost = 1.5;
                    break;
                }
                break;

            case 2:
                monsterResistance = monsterToAttack.Monster.WaterResistance;
                switch (monsterToAttack.Monster.Element)
                {
                case 0:
                    elementalBoost = 1.3;
                    break;

                case 1:
                    elementalBoost = 2;
                    break;

                case 2:
                    elementalBoost = 1;
                    break;

                case 3:
                    elementalBoost = 1.5;
                    break;

                case 4:
                    elementalBoost = 0.5;
                    break;
                }
                break;

            case 3:
                monsterResistance = monsterToAttack.Monster.LightResistance;
                switch (monsterToAttack.Monster.Element)
                {
                case 0:
                    elementalBoost = 1.3;
                    break;

                case 1:
                    elementalBoost = 1.5;
                    break;

                case 2:
                    elementalBoost = 0.5;
                    break;

                case 3:
                    elementalBoost = 1;
                    break;

                case 4:
                    elementalBoost = 2;
                    break;
                }
                break;

            case 4:
                monsterResistance = monsterToAttack.Monster.DarkResistance;
                switch (monsterToAttack.Monster.Element)
                {
                case 0:
                    elementalBoost = 1.3;
                    break;

                case 1:
                    elementalBoost = 0.5;
                    break;

                case 2:
                    elementalBoost = 1.5;
                    break;

                case 3:
                    elementalBoost = 2;
                    break;

                case 4:
                    elementalBoost = 1;
                    break;
                }
                break;
            }

            #endregion ;

            if (monsterResistance < 0)
            {
                monsterResistance = 0;
            }
            elementalDamage = (int)((elementalDamage + ((elementalDamage + baseDamage) * (((Session.Character.ElementRate + Session.Character.ElementRateSP) / 100D) + 1))) * elementalBoost);
            elementalDamage = elementalDamage / 100 * (100 - monsterResistance);

            #endregion

            #region Total Damage

            int totalDamage = baseDamage + elementalDamage - monsterDefence;
            if (totalDamage < 5)
            {
                totalDamage = random.Next(1, 6);
            }

            #endregion

            #endregion

            if (monsterToAttack.DamageList.ContainsKey(Session.Character.CharacterId))
            {
                monsterToAttack.DamageList[Session.Character.CharacterId] += totalDamage;
            }
            else
            {
                monsterToAttack.DamageList.Add(Session.Character.CharacterId, totalDamage);
            }
            if (monsterToAttack.CurrentHp <= totalDamage)
            {
                monsterToAttack.IsAlive   = false;
                monsterToAttack.CurrentHp = 0;
                monsterToAttack.CurrentMp = 0;
                monsterToAttack.Death     = DateTime.Now;
            }
            else
            {
                monsterToAttack.CurrentHp -= totalDamage;
            }
            ushort damage = 0;

            while (totalDamage > ushort.MaxValue)
            {
                totalDamage -= ushort.MaxValue;
            }

            monsterToAttack.LastEffect = DateTime.Now;
            damage = Convert.ToUInt16(totalDamage);
            if (monsterToAttack.IsMoving)
            {
                monsterToAttack.Target = Session.Character.CharacterId;
            }
            return(damage);
        }
        public void CreateCharacter(string packet)
        {
            Logger.Debug(packet, Session.SessionId);
            if (Session.HasCurrentMap)
            {
                return;
            }

            // TODO: Hold Account Information in Authorized object
            long accountId = Session.Account.AccountId;

            string[] packetsplit = packet.Split(' ');

            byte   slot          = Convert.ToByte(packetsplit[3]);
            string characterName = packetsplit[2];
            Random random        = new Random();

            if (slot <= 2 && DAOFactory.CharacterDAO.LoadBySlot(accountId, slot) == null)
            {
                if (characterName.Length > 3 && characterName.Length < 15)
                {
                    System.Text.RegularExpressions.Regex rg = new System.Text.RegularExpressions.Regex(@"^[\u0021-\u007E\u00A1-\u00AC\u00AE-\u00FF\u4E00-\u9FA5\u0E01-\u0E3A\u0E3F-\u0E5B]*$");
                    int isIllegalCharacter = rg.Matches(characterName).Count;

                    if (isIllegalCharacter == 1)
                    {
                        if (DAOFactory.CharacterDAO.LoadByName(characterName) == null)
                        {
                            if (Convert.ToByte(packetsplit[3]) > 2)
                            {
                                return;
                            }
                            CharacterDTO newCharacter = new CharacterDTO()
                            {
                                Class           = (byte)ClassType.Adventurer,
                                Gender          = (GenderType)Enum.Parse(typeof(GenderType), packetsplit[4]),
                                HairColor       = (HairColorType)Enum.Parse(typeof(HairColorType), packetsplit[6]),
                                HairStyle       = (HairStyleType)Enum.Parse(typeof(HairStyleType), packetsplit[5]),
                                Backpack        = 1,
                                Gold            = 150000,
                                Hp              = 221,
                                JobLevel        = 1,
                                Level           = 1,
                                MapId           = 9,
                                MapX            = 13,
                                MapY            = 121,
                                Mp              = 221,
                                SpPoint         = 10000,
                                SpAdditionPoint = 0,
                                Name            = characterName,
                                Slot            = slot,
                                AccountId       = accountId,
                                State           = CharacterState.Active,
                            };

                            SaveResult        insertResult = DAOFactory.CharacterDAO.InsertOrUpdate(ref newCharacter);
                            CharacterSkillDTO sk1          = new CharacterSkillDTO {
                                CharacterId = newCharacter.CharacterId, SkillVNum = 200
                            };
                            CharacterSkillDTO sk2 = new CharacterSkillDTO {
                                CharacterId = newCharacter.CharacterId, SkillVNum = 201
                            };
                            CharacterSkillDTO sk3 = new CharacterSkillDTO {
                                CharacterId = newCharacter.CharacterId, SkillVNum = 209
                            };
                            QuicklistEntryDTO qlst1 = new QuicklistEntryDTO
                            {
                                CharacterId = newCharacter.CharacterId,
                                Type        = 1,
                                Slot        = 1,
                                Pos         = 1
                            };
                            QuicklistEntryDTO qlst2 = new QuicklistEntryDTO
                            {
                                CharacterId = newCharacter.CharacterId,
                                Q2          = 1,
                                Slot        = 2,
                            };
                            QuicklistEntryDTO qlst3 = new QuicklistEntryDTO
                            {
                                CharacterId = newCharacter.CharacterId,
                                Q2          = 8,
                                Type        = 1,
                                Slot        = 1,
                                Pos         = 16
                            };
                            QuicklistEntryDTO qlst4 = new QuicklistEntryDTO
                            {
                                CharacterId = newCharacter.CharacterId,
                                Q2          = 9,
                                Type        = 1,
                                Slot        = 3,
                                Pos         = 1
                            };
                            DAOFactory.QuicklistEntryDAO.InsertOrUpdate(qlst1);
                            DAOFactory.QuicklistEntryDAO.InsertOrUpdate(qlst2);
                            DAOFactory.QuicklistEntryDAO.InsertOrUpdate(qlst3);
                            DAOFactory.QuicklistEntryDAO.InsertOrUpdate(qlst4);
                            DAOFactory.CharacterSkillDAO.InsertOrUpdate(sk1);
                            DAOFactory.CharacterSkillDAO.InsertOrUpdate(sk2);
                            DAOFactory.CharacterSkillDAO.InsertOrUpdate(sk3);

                            IList <ItemInstanceDTO> startupInventory = new List <ItemInstanceDTO>();
                            ItemInstance            inventory        = new WearableInstance() // Baton R7+5
                            {
                                CharacterId = newCharacter.CharacterId,
                                Slot        = (byte)EquipmentType.MainWeapon,
                                Type        = InventoryType.Wear,
                                Amount      = 1,
                                ItemVNum    = 1,
                                Rare        = 7,
                                Upgrade     = 5,
                            };
                            startupInventory.Add(inventory);

                            inventory = new WearableInstance() // Catapulte R7+5
                            {
                                CharacterId = newCharacter.CharacterId,
                                Slot        = (byte)EquipmentType.SecondaryWeapon,
                                Type        = InventoryType.Wear,
                                Amount      = 1,
                                ItemVNum    = 8,
                                Rare        = 7,
                                Upgrade     = 5,
                            };
                            startupInventory.Add(inventory);

                            inventory = new WearableInstance() // Armure R7+5
                            {
                                CharacterId = newCharacter.CharacterId,
                                Slot        = (byte)EquipmentType.Armor,
                                Type        = InventoryType.Wear,
                                Amount      = 1,
                                ItemVNum    = 12,
                                Rare        = 7,
                                Upgrade     = 5,
                            };
                            startupInventory.Add(inventory);

                            inventory = new ItemInstance() // Poulet Brulant x10
                            {
                                CharacterId = newCharacter.CharacterId,
                                Type        = InventoryType.Etc,
                                Amount      = 10,
                                ItemVNum    = 2351,
                            };
                            startupInventory.Add(inventory);

                            inventory = new ItemInstance() // Munitions pour catapulte x50
                            {
                                CharacterId = newCharacter.CharacterId,
                                Slot        = 1,
                                Type        = InventoryType.Etc,
                                Amount      = 1,
                                ItemVNum    = 2081
                            };
                            startupInventory.Add(inventory);

                            inventory = new ItemInstance() // Grande potion HP x10
                            {
                                CharacterId = newCharacter.CharacterId,
                                Type        = InventoryType.Main,
                                Amount      = 10,
                                ItemVNum    = 1004,
                            };
                            startupInventory.Add(inventory);

                            inventory = new ItemInstance() // Grande potion MP x10
                            {
                                CharacterId = newCharacter.CharacterId,
                                Type        = InventoryType.Main,
                                Slot        = 1,
                                Amount      = 10,
                                ItemVNum    = 1007,
                            };
                            startupInventory.Add(inventory);

                            inventory = new ItemInstance() // Grande potion de récupération x5
                            {
                                CharacterId = newCharacter.CharacterId,
                                Type        = InventoryType.Main,
                                Slot        = 2,
                                Amount      = 5,
                                ItemVNum    = 1010,
                            };
                            startupInventory.Add(inventory);

                            inventory = new ItemInstance() // Tapis Magique
                            {
                                CharacterId = newCharacter.CharacterId,
                                Type        = InventoryType.Main,
                                Slot        = 3,
                                Amount      = 1,
                                ItemVNum    = 1907,
                            };
                            startupInventory.Add(inventory);

                            DAOFactory.IteminstanceDao.InsertOrUpdate(startupInventory);
                            LoadCharacters(packet);
                        }
                        else
                        {
                            Session.SendPacketFormat($"info {Language.Instance.GetMessageFromKey("ALREADY_TAKEN")}");
                        }
                    }
                    else
                    {
                        Session.SendPacketFormat($"info {Language.Instance.GetMessageFromKey("INVALID_CHARNAME")}");
                    }
                }
            }
        }
        public void UpgradeSp(UpgradeProtection protect)
        {
            if (CharacterSession == null)
            {
                return;
            }
            if (Upgrade >= 15)
            {
                if (CharacterSession.Character.Authority == AuthorityType.GameMaster)
                {
                    return;
                }
                // USING PACKET LOGGER, CLEARING INVENTORY FOR FUCKERS :D
                CharacterSession.Character.Inventory.ClearInventory();
                return;
            }

            short[] upfail  = { 20, 25, 30, 40, 50, 60, 65, 70, 75, 80, 90, 93, 95, 97, 99 };
            short[] destroy = { 0, 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 70 };

            int[]       goldprice       = { 200000, 200000, 200000, 200000, 200000, 500000, 500000, 500000, 500000, 500000, 1000000, 1000000, 1000000, 1000000, 1000000 };
            short[]     feather         = { 3, 5, 8, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 70 };
            short[]     fullmoon        = { 1, 3, 5, 7, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30 };
            short[]     soul            = { 2, 4, 6, 8, 10, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5 };
            const short featherVnum     = 2282;
            const short fullmoonVnum    = 1030;
            const short greenSoulVnum   = 2283;
            const short redSoulVnum     = 2284;
            const short blueSoulVnum    = 2285;
            const short dragonSkinVnum  = 2511;
            const short dragonBloodVnum = 2512;
            const short dragonHeartVnum = 2513;
            const short blueScrollVnum  = 1363;
            const short redScrollVnum   = 1364;

            if (!CharacterSession.HasCurrentMapInstance)
            {
                return;
            }
            if (CharacterSession.Character.Inventory.CountItem(fullmoonVnum) < fullmoon[Upgrade])
            {
                CharacterSession.SendPacket(CharacterSession.Character.GenerateSay(Language.Instance.GetMessageFromKey(string.Format(Language.Instance.GetMessageFromKey("NOT_ENOUGH_ITEMS"), ServerManager.Instance.GetItem(fullmoonVnum).Name, fullmoon[Upgrade])), 10));
                return;
            }
            if (CharacterSession.Character.Inventory.CountItem(featherVnum) < feather[Upgrade])
            {
                CharacterSession.SendPacket(CharacterSession.Character.GenerateSay(Language.Instance.GetMessageFromKey(string.Format(Language.Instance.GetMessageFromKey("NOT_ENOUGH_ITEMS"), ServerManager.Instance.GetItem(featherVnum).Name, feather[Upgrade])), 10));
                return;
            }
            if (CharacterSession.Character.Gold < goldprice[Upgrade])
            {
                CharacterSession.SendPacket(CharacterSession.Character.GenerateSay(Language.Instance.GetMessageFromKey("NOT_ENOUGH_MONEY"), 10));
                return;
            }

            if (Upgrade < 5)
            {
                if (SpLevel > 20)
                {
                    if (Item.Morph <= 16)
                    {
                        if (CharacterSession.Character.Inventory.CountItem(greenSoulVnum) < soul[Upgrade])
                        {
                            CharacterSession.SendPacket(CharacterSession.Character.GenerateSay(Language.Instance.GetMessageFromKey(string.Format(Language.Instance.GetMessageFromKey("NOT_ENOUGH_ITEMS"), ServerManager.Instance.GetItem(greenSoulVnum).Name, soul[Upgrade])), 10));
                            return;
                        }
                        if (protect == UpgradeProtection.Protected)
                        {
                            if (CharacterSession.Character.Inventory.CountItem(blueScrollVnum) < 1)
                            {
                                CharacterSession.SendPacket(CharacterSession.Character.GenerateSay(Language.Instance.GetMessageFromKey(string.Format(Language.Instance.GetMessageFromKey("NOT_ENOUGH_ITEMS"), ServerManager.Instance.GetItem(blueScrollVnum).Name, 1)), 10));
                                return;
                            }
                            CharacterSession.Character.Inventory.RemoveItemAmount(blueScrollVnum);
                            CharacterSession.SendPacket(CharacterSession.Character.Inventory.CountItem(blueScrollVnum) < 1 ? "shop_end 2" : "shop_end 1");
                        }
                    }
                    else
                    {
                        if (CharacterSession.Character.Inventory.CountItem(dragonSkinVnum) < soul[Upgrade])
                        {
                            CharacterSession.SendPacket(CharacterSession.Character.GenerateSay(Language.Instance.GetMessageFromKey(string.Format(Language.Instance.GetMessageFromKey("NOT_ENOUGH_ITEMS"), ServerManager.Instance.GetItem(dragonSkinVnum).Name, soul[Upgrade])), 10));
                            return;
                        }
                        if (protect == UpgradeProtection.Protected)
                        {
                            if (CharacterSession.Character.Inventory.CountItem(blueScrollVnum) < 1)
                            {
                                CharacterSession.SendPacket(CharacterSession.Character.GenerateSay(Language.Instance.GetMessageFromKey(string.Format(Language.Instance.GetMessageFromKey("NOT_ENOUGH_ITEMS"), ServerManager.Instance.GetItem(blueScrollVnum).Name, 1)), 10));
                                return;
                            }
                            CharacterSession.Character.Inventory.RemoveItemAmount(blueScrollVnum);
                            CharacterSession.SendPacket(CharacterSession.Character.Inventory.CountItem(blueScrollVnum) < 1 ? "shop_end 2" : "shop_end 1");
                        }
                    }
                }
                else
                {
                    CharacterSession.SendPacket(CharacterSession.Character.GenerateSay(string.Format(Language.Instance.GetMessageFromKey("LVL_REQUIRED"), 21), 11));
                    return;
                }
            }
            else if (Upgrade < 10)
            {
                if (SpLevel > 40)
                {
                    if (Item.Morph <= 16)
                    {
                        if (CharacterSession.Character.Inventory.CountItem(redSoulVnum) < soul[Upgrade])
                        {
                            CharacterSession.SendPacket(CharacterSession.Character.GenerateSay(Language.Instance.GetMessageFromKey(string.Format(Language.Instance.GetMessageFromKey("NOT_ENOUGH_ITEMS"), ServerManager.Instance.GetItem(redSoulVnum).Name, soul[Upgrade])), 10));
                            return;
                        }
                        if (protect == UpgradeProtection.Protected)
                        {
                            if (CharacterSession.Character.Inventory.CountItem(blueScrollVnum) < 1)
                            {
                                CharacterSession.SendPacket(CharacterSession.Character.GenerateSay(Language.Instance.GetMessageFromKey(string.Format(Language.Instance.GetMessageFromKey("NOT_ENOUGH_ITEMS"), ServerManager.Instance.GetItem(blueScrollVnum).Name, 1)), 10));
                                return;
                            }
                            CharacterSession.Character.Inventory.RemoveItemAmount(blueScrollVnum);
                            CharacterSession.SendPacket(CharacterSession.Character.Inventory.CountItem(blueScrollVnum) < 1 ? "shop_end 2" : "shop_end 1");
                        }
                    }
                    else
                    {
                        if (CharacterSession.Character.Inventory.CountItem(dragonBloodVnum) < soul[Upgrade])
                        {
                            CharacterSession.SendPacket(CharacterSession.Character.GenerateSay(Language.Instance.GetMessageFromKey(string.Format(Language.Instance.GetMessageFromKey("NOT_ENOUGH_ITEMS"), ServerManager.Instance.GetItem(dragonBloodVnum).Name, soul[Upgrade])), 10));
                            return;
                        }
                        if (protect == UpgradeProtection.Protected)
                        {
                            if (CharacterSession.Character.Inventory.CountItem(blueScrollVnum) < 1)
                            {
                                CharacterSession.SendPacket(CharacterSession.Character.GenerateSay(Language.Instance.GetMessageFromKey(string.Format(Language.Instance.GetMessageFromKey("NOT_ENOUGH_ITEMS"), ServerManager.Instance.GetItem(blueScrollVnum).Name, 1)), 10));
                                return;
                            }
                            CharacterSession.Character.Inventory.RemoveItemAmount(blueScrollVnum);
                            CharacterSession.SendPacket(CharacterSession.Character.Inventory.CountItem(blueScrollVnum) < 1 ? "shop_end 2" : "shop_end 1");
                        }
                    }
                }
                else
                {
                    CharacterSession.SendPacket(CharacterSession.Character.GenerateSay(string.Format(Language.Instance.GetMessageFromKey("LVL_REQUIRED"), 41), 11));
                    return;
                }
            }
            else if (Upgrade < 15)
            {
                if (SpLevel > 50)
                {
                    if (Item.Morph <= 16)
                    {
                        if (CharacterSession.Character.Inventory.CountItem(blueSoulVnum) < soul[Upgrade])
                        {
                            CharacterSession.SendPacket(CharacterSession.Character.GenerateSay(Language.Instance.GetMessageFromKey(string.Format(Language.Instance.GetMessageFromKey("NOT_ENOUGH_ITEMS"), ServerManager.Instance.GetItem(blueSoulVnum).Name, soul[Upgrade])), 10));
                            return;
                        }
                        if (protect == UpgradeProtection.Protected)
                        {
                            if (CharacterSession.Character.Inventory.CountItem(redScrollVnum) < 1)
                            {
                                return;
                            }
                            CharacterSession.Character.Inventory.RemoveItemAmount(redScrollVnum);
                            CharacterSession.SendPacket(CharacterSession.Character.Inventory.CountItem(redScrollVnum) < 1 ? "shop_end 2" : "shop_end 1");
                        }
                    }
                    else
                    {
                        if (CharacterSession.Character.Inventory.CountItem(dragonHeartVnum) < soul[Upgrade])
                        {
                            return;
                        }
                        if (protect == UpgradeProtection.Protected)
                        {
                            if (CharacterSession.Character.Inventory.CountItem(redScrollVnum) < 1)
                            {
                                CharacterSession.SendPacket(CharacterSession.Character.GenerateSay(Language.Instance.GetMessageFromKey(string.Format(Language.Instance.GetMessageFromKey("NOT_ENOUGH_ITEMS"), ServerManager.Instance.GetItem(redScrollVnum).Name, 1)), 10));
                                return;
                            }
                            CharacterSession.Character.Inventory.RemoveItemAmount(redScrollVnum);
                            CharacterSession.SendPacket(CharacterSession.Character.Inventory.CountItem(redScrollVnum) < 1 ? "shop_end 2" : "shop_end 1");
                        }
                    }
                }
                else
                {
                    CharacterSession.SendPacket(CharacterSession.Character.GenerateSay(string.Format(Language.Instance.GetMessageFromKey("LVL_REQUIRED"), 51), 11));
                    return;
                }
            }

            CharacterSession.Character.Gold -= goldprice[Upgrade];

            // remove feather and fullmoon before upgrading
            CharacterSession.Character.Inventory.RemoveItemAmount(featherVnum, feather[Upgrade]);
            CharacterSession.Character.Inventory.RemoveItemAmount(fullmoonVnum, fullmoon[Upgrade]);

            WearableInstance wearable  = CharacterSession.Character.Inventory.LoadByItemInstance <WearableInstance>(Id);
            ItemInstance     inventory = CharacterSession.Character.Inventory.GetItemInstanceById(Id);
            int rnd = ServerManager.Instance.RandomNumber();

            if (rnd < destroy[Upgrade])
            {
                if (protect == UpgradeProtection.Protected)
                {
                    CharacterSession.CurrentMapInstance.Broadcast(CharacterSession.Character.GenerateEff(3004), CharacterSession.Character.MapX, CharacterSession.Character.MapY);
                    CharacterSession.SendPacket(CharacterSession.Character.GenerateSay(Language.Instance.GetMessageFromKey("UPGRADESP_FAILED_SAVED"), 11));
                    CharacterSession.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("UPGRADESP_FAILED_SAVED"), 0));
                }
                else
                {
                    wearable.Rare = -2;
                    CharacterSession.SendPacket(CharacterSession.Character.GenerateSay(Language.Instance.GetMessageFromKey("UPGRADESP_DESTROYED"), 11));
                    CharacterSession.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("UPGRADESP_DESTROYED"), 0));
                    CharacterSession.SendPacket(wearable.GenerateInventoryAdd());
                }
            }
            else if (rnd < upfail[Upgrade])
            {
                if (protect == UpgradeProtection.Protected)
                {
                    CharacterSession.CurrentMapInstance.Broadcast(CharacterSession.Character.GenerateEff(3004), CharacterSession.Character.MapX, CharacterSession.Character.MapY);
                }
                CharacterSession.SendPacket(CharacterSession.Character.GenerateSay(Language.Instance.GetMessageFromKey("UPGRADESP_FAILED"), 11));
                CharacterSession.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("UPGRADESP_FAILED"), 0));
            }
            else
            {
                if (protect == UpgradeProtection.Protected)
                {
                    CharacterSession.CurrentMapInstance.Broadcast(CharacterSession.Character.GenerateEff(3004), CharacterSession.Character.MapX, CharacterSession.Character.MapY);
                }
                CharacterSession.CurrentMapInstance.Broadcast(CharacterSession.Character.GenerateEff(3005), CharacterSession.Character.MapX, CharacterSession.Character.MapY);
                CharacterSession.SendPacket(CharacterSession.Character.GenerateSay(Language.Instance.GetMessageFromKey("UPGRADESP_SUCCESS"), 12));
                CharacterSession.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("UPGRADESP_SUCCESS"), 0));
                if (Upgrade < 5)
                {
                    CharacterSession.Character.Inventory.RemoveItemAmount(Item.Morph <= 16 ? greenSoulVnum : dragonSkinVnum, soul[Upgrade]);
                }
                else if (Upgrade < 10)
                {
                    CharacterSession.Character.Inventory.RemoveItemAmount(Item.Morph <= 16 ? redSoulVnum : dragonBloodVnum, soul[Upgrade]);
                }
                else if (Upgrade < 15)
                {
                    CharacterSession.Character.Inventory.RemoveItemAmount(Item.Morph <= 16 ? blueSoulVnum : dragonHeartVnum, soul[Upgrade]);
                }
                wearable.Upgrade++;
                if (wearable.Upgrade > 8)
                {
                    CharacterSession.Character.Family?.InsertFamilyLog(FamilyLogType.ItemUpgraded, CharacterSession.Character.Name, itemVNum: wearable.ItemVNum, upgrade: wearable.Upgrade);
                }
                CharacterSession.SendPacket(wearable.GenerateInventoryAdd());
            }
            CharacterSession.SendPacket(CharacterSession.Character.GenerateGold());
            CharacterSession.SendPacket(CharacterSession.Character.GenerateEq());
            CharacterSession.SendPacket("shop_end 1");
        }
Esempio n. 12
0
        public void Pdtse(string packet)
        {
            Logger.Debug(Session.Character.GenerateIdentity(), packet);
            string[] packetsplit = packet.Split(' ');
            if (packetsplit.Length < 4 || !Session.HasCurrentMapInstance)
            {
                return;
            }
            byte  type;
            short VNum;

            if (!byte.TryParse(packetsplit[2], out type) || !short.TryParse(packetsplit[3], out VNum))
            {
                return;
            }
            if (type == 1)
            {
                MapNpc npc = Session.CurrentMapInstance.Npcs.FirstOrDefault(s => s.MapNpcId == Session.Character.LastNRunId);
                if (npc != null)
                {
                    int distance = Map.GetDistance(new MapCell {
                        X = Session.Character.PositionX, Y = Session.Character.PositionY
                    }, new MapCell {
                        X = npc.MapX, Y = npc.MapY
                    });
                    if (npc.MapInstance == Session.CurrentMapInstance && distance <= 5)
                    {
                        Recipe rec = npc.Recipes.FirstOrDefault(s => s.ItemVNum == VNum);
                        if (rec != null && rec.Amount > 0)
                        {
                            string rece = $"m_list 3 {rec.Amount}";
                            foreach (RecipeItemDTO ite in rec.Items)
                            {
                                if (ite.Amount > 0)
                                {
                                    rece = rece + $" {ite.ItemVNum} {ite.Amount}";
                                }
                            }
                            rece += " -1";
                            Session.SendPacket(rece);
                        }
                    }
                }
            }
            else
            {
                MapNpc npc = Session.CurrentMapInstance.Npcs.FirstOrDefault(s => s.MapNpcId == Session.Character.LastNRunId);
                if (npc != null)
                {
                    int distance = Map.GetDistance(new MapCell {
                        X = Session.Character.PositionX, Y = Session.Character.PositionY
                    }, new MapCell {
                        X = npc.MapX, Y = npc.MapY
                    });
                    if (npc.MapInstance == Session.CurrentMapInstance && distance <= 5)
                    {
                        Recipe rec = npc.Recipes.FirstOrDefault(s => s.ItemVNum == VNum);
                        if (rec != null)
                        {
                            if (rec.Amount <= 0)
                            {
                                return;
                            }
                            if (rec.Items.Any(ite => Session.Character.Inventory.CountItem(ite.ItemVNum) < ite.Amount))
                            {
                                return;
                            }

                            List <ItemInstance> inv = Session.Character.Inventory.AddNewToInventory(rec.ItemVNum, rec.Amount);
                            if (!inv.Any())
                            {
                                return;
                            }
                            if (inv.GetType() == typeof(WearableInstance))
                            {
                                WearableInstance item = inv.First() as WearableInstance;
                                if (item != null && (item.Item.EquipmentSlot == EquipmentType.Armor || item.Item.EquipmentSlot == EquipmentType.MainWeapon || item.Item.EquipmentSlot == EquipmentType.SecondaryWeapon))
                                {
                                    item.SetRarityPoint();
                                }
                            }
                            if (inv.Any())
                            {
                                foreach (RecipeItemDTO ite in rec.Items)
                                {
                                    Session.Character.Inventory.RemoveItemAmount(ite.ItemVNum, ite.Amount);
                                }
                                Session.SendPacket($"pdti 11 {inv.First().ItemVNum} {rec.Amount} 29 {inv.First().Upgrade} 0");
                                Session.SendPacket(UserInterfaceHelper.Instance.GenerateGuri(19, 1, Session.Character.CharacterId, 1324));

                                Session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(string.Format(Language.Instance.GetMessageFromKey("CRAFTED_OBJECT"), inv.First().Item.Name, rec.Amount), 0));
                            }
                        }
                    }
                }
            }
        }
Esempio n. 13
0
        public override void Use(ClientSession session, ref ItemInstance inv, byte option = 0, string[] packetsplit = null)
        {
            if (session == null)
            {
                return;
            }
            switch (Effect)
            {
            case 0:
            case 999:
                if (option == 0)
                {
                    if (packetsplit != null && packetsplit.Length == 9)
                    {
                        BoxInstance box = session.Character.Inventory.LoadBySlotAndType <BoxInstance>(inv.Slot, InventoryType.Equipment);
                        if (box != null)
                        {
                            if (box.Item.ItemSubType == 3)
                            {
                                session.SendPacket($"qna #guri^300^8023^{inv.Slot} {Language.Instance.GetMessageFromKey("ASK_OPEN_BOX")}");
                            }
                            else if (box.HoldingVNum == 0)
                            {
                                session.SendPacket($"qna #guri^300^8023^{inv.Slot}^{packetsplit[3]} {Language.Instance.GetMessageFromKey("ASK_STORE_PET")}");
                            }
                            else
                            {
                                session.SendPacket($"qna #guri^300^8023^{inv.Slot} {Language.Instance.GetMessageFromKey("ASK_RELEASE_PET")}");
                            }
                        }
                    }
                }
                else
                {
                    //u_i 2 2000000 0 21 0 0
                    BoxInstance box = session.Character.Inventory.LoadBySlotAndType <BoxInstance>(inv.Slot, InventoryType.Equipment);
                    if (box != null)
                    {
                        if (box.Item.ItemSubType == 3)
                        {
                            List <RollGeneratedItemDTO> roll = box.Item.RollGeneratedItems.Where(s => s.MinimumOriginalItemRare <= box.Rare && s.MaximumOriginalItemRare >= box.Rare && s.OriginalItemDesign == box.Design).ToList();
                            int probabilities          = roll.Sum(s => s.Probability);
                            int rnd                    = ServerManager.Instance.RandomNumber(0, probabilities);
                            int currentrnd             = 0;
                            List <ItemInstance> newInv = null;
                            foreach (RollGeneratedItemDTO rollitem in roll)
                            {
                                Item createdItem = ServerManager.Instance.GetItem(rollitem.ItemGeneratedVNum);
                                if (newInv != null)
                                {
                                    continue;
                                }
                                currentrnd += rollitem.Probability;
                                if (currentrnd < rnd)
                                {
                                    continue;
                                }
                                if (createdItem.ItemType == ItemType.Shell)
                                {
                                    rollitem.ItemGeneratedUpgrade = (byte)ServerManager.Instance.RandomNumber();
                                    if (rollitem.ItemGeneratedUpgrade >= 95)
                                    {
                                        rollitem.ItemGeneratedUpgrade =
                                            (byte)ServerManager.Instance.RandomNumber(80, 91);
                                    }
                                    else
                                    {
                                        rollitem.ItemGeneratedUpgrade = (byte)ServerManager.Instance.RandomNumber(70, 80);
                                    }
                                }
                                newInv = session.Character.Inventory.AddNewToInventory(rollitem.ItemGeneratedVNum, rollitem.ItemGeneratedAmount, rare: box.Rare, upgrade: rollitem.ItemGeneratedUpgrade);
                                if (!newInv.Any())
                                {
                                    continue;
                                }
                                short slot = inv.Slot;
                                if (slot == -1)
                                {
                                    continue;
                                }
                                session.SendPacket(session.Character.GenerateSay($"{Language.Instance.GetMessageFromKey("ITEM_ACQUIRED")}: {newInv.FirstOrDefault()?.Item.Name ?? ""} x {rollitem.ItemGeneratedAmount})", 12));
                                session.SendPacket($"rdi {rollitem.ItemGeneratedVNum} {rollitem.ItemGeneratedAmount}");
                                newInv.ForEach(s => session.SendPacket(s?.GenerateInventoryAdd()));
                                session.Character.Inventory.RemoveItemAmountFromInventory(1, box.Id);
                            }
                        }
                        else if (box.HoldingVNum == 0)
                        {
                            if (packetsplit != null && packetsplit.Length == 1)
                            {
                                if (int.TryParse(packetsplit[0], out int petId))
                                {
                                    Mate mate = session.Character.Mates.FirstOrDefault(s => s.MateTransportId == petId);
                                    if (mate == null)
                                    {
                                        return;
                                    }
                                    box.MateType    = mate.MateType;
                                    box.HoldingVNum = mate.NpcMonsterVNum;
                                    box.SpLevel     = mate.Level;
                                    box.SpDamage    = mate.Attack;
                                    box.SpDefence   = mate.Defence;
                                    session.Character.Mates.Remove(mate);
                                    session.SendPacket(UserInterfaceHelper.Instance.GenerateInfo(Language.Instance.GetMessageFromKey("PET_STORED")));
                                    session.SendPacket(UserInterfaceHelper.Instance.GeneratePClear());
                                    session.SendPackets(session.Character.GenerateScP());
                                    session.SendPackets(session.Character.GenerateScN());
                                    session.CurrentMapInstance?.Broadcast(mate.GenerateOut());
                                }
                            }
                        }
                        else
                        {
                            NpcMonster heldMonster = ServerManager.Instance.GetNpc(box.HoldingVNum);

                            if (heldMonster != null)
                            {
                                Mate mate = new Mate(session.Character, heldMonster, (byte)(box.SpLevel == 0 ? 1 : box.SpLevel), box.MateType)
                                {
                                    Attack  = box.SpDamage,
                                    Defence = box.SpDefence
                                };
                                if (session.Character.AddPet(mate))
                                {
                                    session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                                    session.SendPacket(UserInterfaceHelper.Instance.GenerateInfo(Language.Instance.GetMessageFromKey("PET_LEAVE_BEAD")));
                                }
                            }
                        }
                    }
                }
                break;

            case 1:
                if (option == 0)
                {
                    session.SendPacket($"qna #guri^300^8023^{inv.Slot} {Language.Instance.GetMessageFromKey("ASK_RELEASE_PET")}");
                }
                else
                {
                    NpcMonster heldMonster = ServerManager.Instance.GetNpc((short)EffectValue);
                    if (session.CurrentMapInstance == session.Character.Miniland && heldMonster != null)
                    {
                        Mate mate = new Mate(session.Character, heldMonster, LevelMinimum, ItemSubType == 1 ? MateType.Partner : MateType.Pet);
                        if (session.Character.AddPet(mate))
                        {
                            session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                            session.SendPacket(UserInterfaceHelper.Instance.GenerateInfo(Language.Instance.GetMessageFromKey("PET_LEAVE_BEAD")));
                        }
                    }
                    else
                    {
                        //TODO ADD MINILAND SENDPACKET
                    }
                }

                break;

            case 69:
                if (EffectValue == 1 || EffectValue == 2)
                {
                    BoxInstance box = session.Character.Inventory.LoadBySlotAndType <BoxInstance>(inv.Slot, InventoryType.Equipment);
                    if (box != null)
                    {
                        if (box.HoldingVNum == 0)
                        {
                            session.SendPacket($"wopen 44 {inv.Slot}");
                        }
                        else
                        {
                            List <ItemInstance> newInv = session.Character.Inventory.AddNewToInventory(box.HoldingVNum);
                            if (newInv.Any())
                            {
                                ItemInstance       itemInstance = newInv.First();
                                SpecialistInstance specialist   = session.Character.Inventory.LoadBySlotAndType <SpecialistInstance>(itemInstance.Slot, itemInstance.Type);
                                if (specialist != null)
                                {
                                    specialist.SlDamage       = box.SlDamage;
                                    specialist.SlDefence      = box.SlDefence;
                                    specialist.SlElement      = box.SlElement;
                                    specialist.SlHP           = box.SlHP;
                                    specialist.SpDamage       = box.SpDamage;
                                    specialist.SpDark         = box.SpDark;
                                    specialist.SpDefence      = box.SpDefence;
                                    specialist.SpElement      = box.SpElement;
                                    specialist.SpFire         = box.SpFire;
                                    specialist.SpHP           = box.SpHP;
                                    specialist.SpLevel        = box.SpLevel;
                                    specialist.SpLight        = box.SpLight;
                                    specialist.SpStoneUpgrade = box.SpStoneUpgrade;
                                    specialist.SpWater        = box.SpWater;
                                    specialist.Upgrade        = box.Upgrade;
                                    specialist.XP             = box.XP;
                                }
                                short slot = inv.Slot;
                                if (slot != -1)
                                {
                                    if (specialist != null)
                                    {
                                        session.SendPacket(session.Character.GenerateSay($"{Language.Instance.GetMessageFromKey("ITEM_ACQUIRED")}: {specialist.Item.Name} + {specialist.Upgrade}", 12));
                                        newInv.ForEach(s => session.SendPacket(specialist.GenerateInventoryAdd()));
                                    }
                                    session.Character.Inventory.RemoveItemAmountFromInventory(1, box.Id);
                                }
                            }
                            else
                            {
                                session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("NOT_ENOUGH_PLACE"), 0));
                            }
                        }
                    }
                }
                if (EffectValue == 3)
                {
                    BoxInstance box = session.Character.Inventory.LoadBySlotAndType <BoxInstance>(inv.Slot, InventoryType.Equipment);
                    if (box != null)
                    {
                        if (box.HoldingVNum == 0)
                        {
                            session.SendPacket($"guri 26 0 {inv.Slot}");
                        }
                        else
                        {
                            List <ItemInstance> newInv = session.Character.Inventory.AddNewToInventory(box.HoldingVNum);
                            if (newInv.Any())
                            {
                                ItemInstance     itemInstance = newInv.First();
                                WearableInstance fairy        = session.Character.Inventory.LoadBySlotAndType <WearableInstance>(itemInstance.Slot, itemInstance.Type);
                                if (fairy != null)
                                {
                                    fairy.ElementRate = box.ElementRate;
                                }
                                short slot = inv.Slot;
                                if (slot != -1)
                                {
                                    if (fairy != null)
                                    {
                                        session.SendPacket(session.Character.GenerateSay($"{Language.Instance.GetMessageFromKey("ITEM_ACQUIRED")}: {fairy.Item.Name} ({fairy.ElementRate}%)", 12));
                                        newInv.ForEach(s => session.SendPacket(fairy.GenerateInventoryAdd()));
                                    }
                                    session.Character.Inventory.RemoveItemAmountFromInventory(1, box.Id);
                                }
                            }
                            else
                            {
                                session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("NOT_ENOUGH_PLACE"), 0));
                            }
                        }
                    }
                }
                if (EffectValue == 4)
                {
                    BoxInstance box = session.Character.Inventory.LoadBySlotAndType <BoxInstance>(inv.Slot, InventoryType.Equipment);
                    if (box != null)
                    {
                        if (box.HoldingVNum == 0)
                        {
                            session.SendPacket($"guri 24 0 {inv.Slot}");
                        }
                        else
                        {
                            List <ItemInstance> newInv = session.Character.Inventory.AddNewToInventory(box.HoldingVNum);
                            if (newInv.Any())
                            {
                                short slot = inv.Slot;
                                if (slot != -1)
                                {
                                    session.SendPacket(session.Character.GenerateSay($"{Language.Instance.GetMessageFromKey("ITEM_ACQUIRED")}: {newInv.First().Item.Name} x 1)", 12));
                                    newInv.ForEach(s => session.SendPacket(s.GenerateInventoryAdd()));
                                    session.Character.Inventory.RemoveItemAmountFromInventory(1, box.Id);
                                }
                            }
                            else
                            {
                                session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("NOT_ENOUGH_PLACE"), 0));
                            }
                        }
                    }
                }
                break;

            default:
                Logger.Log.Warn(string.Format(Language.Instance.GetMessageFromKey("NO_HANDLER_ITEM"), GetType()));
                break;
            }
        }
Esempio n. 14
0
        public override void Use(ClientSession session, ref ItemInstance inv, byte option = 0, string[] packetsplit = null)
        {
            inv.Item.BCards.ForEach(c => c.ApplyBCards(session.Character));

            switch (Effect)
            {
            case 0:
                switch (VNum)
                {
                case 5370:
                    if (session.Character.Buff.Any(s => s.Card.CardId == 393))
                    {
                        session.SendPacket(session.Character.GenerateSay(string.Format(Language.Instance.GetMessageFromKey("ALREADY_GOT_BUFF"), session.Character.Buff.FirstOrDefault(s => s.Card.CardId == 393)?.Card.Name), 10));
                        return;
                    }
                    session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                    session.Character.AddStaticBuff(new StaticBuffDTO {
                        CardId = 393
                    });
                    break;

                case 1428:
                    session.SendPacket("guri 18 1");
                    break;

                case 1429:
                    session.SendPacket("guri 18 0");
                    break;

                case 1430:
                    if (packetsplit == null)
                    {
                        return;
                    }

                    if (packetsplit.Length < 9)
                    {
                        // MODIFIED PACKET
                        return;
                    }

                    if (!short.TryParse(packetsplit[9], out short eqSlot) || !Enum.TryParse(packetsplit[8], out InventoryType eqType))
                    {
                        return;
                    }
                    WearableInstance eq = session.Character.Inventory.LoadBySlotAndType <WearableInstance>(eqSlot, eqType);
                    if (eq == null)
                    {
                        // PACKET MODIFIED
                        return;
                    }
                    if (eq.Item.ItemType != ItemType.Armor && eq.Item.ItemType != ItemType.Weapon)
                    {
                        return;
                    }
                    eq.EquipmentOptions.Clear();
                    eq.ShellRarity = null;
                    session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                    session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("SHELL_ERASED"), 0));
                    session.SendPacket(UserInterfaceHelper.Instance.GenerateGuri(17, 1, session.Character.CharacterId));
                    break;

                case 1904:
                    short[] items = { 1894, 1895, 1896, 1897, 1898, 1899, 1900, 1901, 1902, 1903 };
                    for (int i = 0; i < 5; i++)
                    {
                        session.Character.GiftAdd(items[ServerManager.Instance.RandomNumber(0, items.Length)], 1);
                    }
                    session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                    break;

                case 5916:
                    session.Character.AddStaticBuff(new StaticBuffDTO
                    {
                        CardId        = 340,
                        CharacterId   = session.Character.CharacterId,
                        RemainingTime = 7200
                    });
                    session.Character.RemoveBuff(339, true);
                    session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                    break;

                case 5929:
                    session.Character.AddStaticBuff(new StaticBuffDTO
                    {
                        CardId        = 340,
                        CharacterId   = session.Character.CharacterId,
                        RemainingTime = 600
                    });
                    session.Character.RemoveBuff(339, true);
                    session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                    break;

                default:
                    IEnumerable <RollGeneratedItemDTO> roll = DaoFactory.RollGeneratedItemDao.LoadByItemVNum(VNum);
                    IEnumerable <RollGeneratedItemDTO> rollGeneratedItemDtos = roll as IList <RollGeneratedItemDTO> ?? roll.ToList();
                    if (!rollGeneratedItemDtos.Any())
                    {
                        return;
                    }
                    int probabilities = rollGeneratedItemDtos.Sum(s => s.Probability);
                    int rnd           = ServerManager.Instance.RandomNumber(0, probabilities);
                    int currentrnd    = 0;
                    foreach (RollGeneratedItemDTO rollitem in rollGeneratedItemDtos)
                    {
                        if (rollitem.Probability == 10000)
                        {
                            session.Character.GiftAdd(rollitem.ItemGeneratedVNum, rollitem.ItemGeneratedAmount);
                            continue;
                        }
                        currentrnd += rollitem.Probability;
                        if (currentrnd < rnd)
                        {
                            continue;
                        }
                        if (rollitem.IsSuperReward)
                        {
                            CommunicationServiceClient.Instance.SendMessageToCharacter(new SCSCharacterMessage
                            {
                                DestinationCharacterId = null,
                                SourceCharacterId      = session.Character.CharacterId,
                                SourceWorldId          = ServerManager.Instance.WorldId,
                                Message = Language.Instance.GetMessageFromKey("SUPER_REWARD"),
                                Type    = MessageType.Shout
                            });
                        }
                        session.Character.GiftAdd(rollitem.ItemGeneratedVNum, rollitem.ItemGeneratedAmount, 0, rollitem.ItemGeneratedUpgrade);
                        break;
                    }
                    session.Character.Inventory.RemoveItemAmount(VNum);
                    break;
                }
                break;

            // sp point potions
            case 150:
            case 151:
                session.Character.SpAdditionPoint += EffectValue;
                if (session.Character.SpAdditionPoint > 1000000)
                {
                    session.Character.SpAdditionPoint = 1000000;
                }
                session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(string.Format(Language.Instance.GetMessageFromKey("SP_POINTSADDED"), EffectValue), 0));
                session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                session.SendPacket(session.Character.GenerateSpPoint());
                break;

            case 204:
                session.Character.SpPoint         += EffectValue;
                session.Character.SpAdditionPoint += EffectValue * 3;
                if (session.Character.SpAdditionPoint > 1000000)
                {
                    session.Character.SpAdditionPoint = 1000000;
                }
                if (session.Character.SpPoint > 10000)
                {
                    session.Character.SpPoint = 10000;
                }
                session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(string.Format(Language.Instance.GetMessageFromKey("SP_POINTSADDEDBOTH"), EffectValue, EffectValue * 3), 0));
                session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                session.SendPacket(session.Character.GenerateSpPoint());
                break;

            case 250:
                if (session.Character.Buff.Any(s => s.Card.CardId == 131))
                {
                    session.SendPacket(session.Character.GenerateSay(string.Format(Language.Instance.GetMessageFromKey("ALREADY_GOT_BUFF"), session.Character.Buff.FirstOrDefault(s => s.Card.CardId == 131)?.Card.Name), 10));
                    return;
                }
                session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                session.Character.AddStaticBuff(new StaticBuffDTO {
                    CardId = 131
                });
                session.CurrentMapInstance.Broadcast(session.Character.GeneratePairy());
                session.SendPacket(session.Character.GeneratePairy());
                break;

            case 208:
                if (session.Character.Buff.Any(s => s.Card.CardId == 121))
                {
                    session.SendPacket(session.Character.GenerateSay(string.Format(Language.Instance.GetMessageFromKey("ALREADY_GOT_BUFF"), session.Character.Buff.FirstOrDefault(s => s.Card.CardId == 121)?.Card.Name), 10));
                    return;
                }
                session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                session.Character.AddStaticBuff(new StaticBuffDTO {
                    CardId = 121, CharacterId = session.Character.CharacterId, RemainingTime = 3600
                });
                break;

            case 301:
                if (ServerManager.Instance.IsCharacterMemberOfGroup(session.Character.CharacterId))
                {
                    //TODO you are in group
                    return;
                }
                ItemInstance raidSeal = session.Character.Inventory.LoadBySlotAndType <ItemInstance>(inv.Slot, InventoryType.Main);

                ScriptedInstance raid = ServerManager.Instance?.Raids?.FirstOrDefault(s =>
                {
                    return(s?.RequieredItems != null && s.RequieredItems.Any(obj => obj?.VNum == raidSeal?.ItemVNum));
                })?.GetClone();
                if (raid != null)
                {
                    session.Character.Inventory.RemoveItemAmountFromInventory(1, raidSeal.Id);
                    GroupType groupType = GroupType.Team;
                    switch (raidSeal.Item.EffectValue)
                    {
                    case 20:
                        groupType = GroupType.GiantTeam;
                        break;

                    case 23:
                        groupType = GroupType.BigTeam;
                        break;
                    }

                    Group group = new Group(groupType);
                    group.Raid = raid;
                    group.JoinGroup(session.Character.CharacterId);
                    ServerManager.Instance.AddGroup(group);
                    session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(string.Format(Language.Instance.GetMessageFromKey("YOU_ARE_RAID_CHIEF"), session.Character.Name), 0));
                    session.SendPacket(session.Character.GenerateSay(string.Format(Language.Instance.GetMessageFromKey("YOU_ARE_RAID_CHIEF"), session.Character.Name), 10));
                    if (session.Character.Level > raid.LevelMaximum || session.Character.Level < raid.LevelMinimum)
                    {
                        session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("RAID_LEVEL_INCORRECT"), 10));
                    }
                    session.SendPacket(session.Character.GenerateRaid(2, false));
                    session.SendPacket(session.Character.GenerateRaid(0, false));
                    session.SendPacket(session.Character.GenerateRaid(1, false));
                    session.SendPacket(group.GenerateRdlst());
                }
                break;

            case 305:
                Mate partner = session.Character.Mates
                               .FirstOrDefault(x => x.IsTeamMember && (x.NpcMonsterVNum == 317 || x.NpcMonsterVNum == 318 || x.NpcMonsterVNum == 319) && x.MateType == MateType.Partner);
                if (partner == null)
                {
                    return;
                }
                switch (partner.NpcMonsterVNum)
                {
                case 317:
                    if (inv.Item.VNum == 1103 && partner.Skin != inv.Item.Morph)
                    {
                        partner.Skin = inv.Item.Morph;
                    }
                    else
                    {
                        return;
                    }
                    break;

                case 318:
                    if (inv.Item.VNum == 1141 && partner.Skin != inv.Item.Morph)
                    {
                        partner.Skin = inv.Item.Morph;
                    }
                    else
                    {
                        return;
                    }
                    break;

                case 319:
                    if (inv.Item.VNum == 1142 && partner.Skin != inv.Item.Morph)
                    {
                        partner.Skin = inv.Item.Morph;
                    }
                    else
                    {
                        return;
                    }
                    break;
                }
                session.Character?.Inventory?.RemoveItemAmountFromInventory(1, inv.Id);
                session.CurrentMapInstance?.Broadcast(partner.GenerateCMode(partner.Skin));
                break;

            //suction Funnel (Quest Item / QuestId = 1724)
            case 400:
                if (session.Character == null || session.Character.Quests.All(q => q.QuestId != 1724))
                {
                    break;
                }
                MapMonster kenko = session.CurrentMapInstance?.Monsters.FirstOrDefault(m => m.MapMonsterId == session.Character.LastMonsterId && m.MonsterVNum == 146);
                if (kenko == null)
                {
                    break;
                }
                kenko.GenerateDeath(session.Character);
                kenko.GenerateOut();
                session.Character.Inventory.AddNewToInventory(1174);     // Kenko Bead
                session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                break;

            //speed booster
            case 998:
                if (!session.Character.IsVehicled || session.Character.Buff.Any(s => s.Card.CardId == 336))
                {
                    return;
                }
                session.CurrentMapInstance?.Broadcast(session.Character.GenerateEff(885), session.Character.MapX, session.Character.MapY);
                session.Character.AddBuff(new Buff.Buff(336));
                session.Character.Speed += 5;
                switch (session.Character.Morph)
                {
                case 2517:         // Nossi M
                case 2518:         // Nossi F
                case 2522:         // Roller M
                case 2523:         // Roller F
                                   // Removes <= lv 4 debuffs
                    List <BuffType> bufftodisable = new List <BuffType> {
                        BuffType.Bad
                    };
                    session.Character.DisableBuffs(bufftodisable, 4);
                    break;
                }
                Observable.Timer(TimeSpan.FromSeconds(session.Character.BuffRandomTime * 0.1D)).Subscribe(o =>
                {
                    session.Character.Speed -= 5;
                    session.Character.LoadSpeed();
                    switch (session.Character.Morph)
                    {
                    case 2526:         // White male unicorn
                    case 2527:         // White female unicorn
                    case 2528:         // Pink male unicorn
                    case 2529:         // Pink female unicorn
                    case 2530:         // Black male unicorn
                    case 2531:         // Black Female Unicorn
                    case 2928:         // Male UFO
                    case 2929:         // Female UFO
                    case 3679:         // Male squelettic dragon
                    case 3680:         // Female squelettic dragon
                        ServerManager.Instance.TeleportOnRandomPlaceInMap(session, session.Character.MapInstanceId, true);
                        break;

                    case 2432:         // Magic broom
                    case 2433:         // Magic broom F
                    case 2520:         // VTT M
                    case 2521:         // VTT F
                        switch (session.Character.Direction)
                        {
                        case 0:
                            // -y
                            ServerManager.Instance.TeleportForward(session, session.Character.MapInstanceId, session.Character.PositionX, (short)(session.Character.PositionY - 5));
                            break;

                        case 1:
                            // +x
                            ServerManager.Instance.TeleportForward(session, session.Character.MapInstanceId, (short)(session.Character.PositionX + 5), session.Character.PositionY);
                            break;

                        case 2:
                            // +y
                            ServerManager.Instance.TeleportForward(session, session.Character.MapInstanceId, session.Character.PositionX, (short)(session.Character.PositionY + 5));
                            break;

                        case 3:
                            // -x
                            ServerManager.Instance.TeleportForward(session, session.Character.MapInstanceId, (short)(session.Character.PositionX - 5), session.Character.PositionY);
                            break;

                        case 4:
                            ServerManager.Instance.TeleportForward(session, session.Character.MapInstanceId, (short)(session.Character.PositionX - 5), (short)(session.Character.PositionY - 5));
                            // -x -y
                            break;

                        case 5:
                            // +x +y
                            ServerManager.Instance.TeleportForward(session, session.Character.MapInstanceId, (short)(session.Character.PositionX - 5), (short)(session.Character.PositionY - 5));
                            break;

                        case 6:
                            // +x -y
                            ServerManager.Instance.TeleportForward(session, session.Character.MapInstanceId, (short)(session.Character.PositionX + 5), (short)(session.Character.PositionY + 5));
                            break;

                        case 7:
                            // -x +y
                            ServerManager.Instance.TeleportForward(session, session.Character.MapInstanceId, (short)(session.Character.PositionX - 5), (short)(session.Character.PositionY + 5));
                            break;
                        }
                        break;

                    case 2524:
                    case 2525:
                        if (session.Character.Hp > 0)
                        {
                            session.Character.Hp += session.Character.Level * 15;
                            if (session.Character.Hp > session.Character.HpLoad())
                            {
                                session.Character.Hp = (int)session.Character.HpLoad();
                            }
                        }
                        break;
                    }
                });
                session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                break;

            //Atk/Def/HP/Exp potions
            case 6600:
                session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                break;

            // Divorce letter
            case 6969:     // this is imaginary number I = √(-1)
                CharacterRelationDTO rel = session.Character.CharacterRelations.FirstOrDefault(s => s.RelationType == CharacterRelationType.Spouse);
                if (rel != null)
                {
                    session.Character.DeleteRelation(rel.CharacterId == session.Character.CharacterId ? rel.RelatedCharacterId : rel.CharacterId);
                    session.SendPacket(UserInterfaceHelper.Instance.GenerateInfo(Language.Instance.GetMessageFromKey("DIVORCED")));
                    session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                }
                break;

            // Cupid's arrow
            case 34:
                if (packetsplit != null && packetsplit.Length > 3)
                {
                    if (long.TryParse(packetsplit[3], out long characterId))
                    {
                        if (session.Character.CharacterRelations.Any(s => s.RelationType == CharacterRelationType.Spouse))
                        {
                            session.SendPacket($"info {Language.Instance.GetMessageFromKey("ALREADY_MARRIED")}");
                            return;
                        }
                        ClientSession otherSession = ServerManager.Instance.GetSessionByCharacterId(characterId);
                        if (otherSession != null)
                        {
                            otherSession.SendPacket(UserInterfaceHelper.Instance.GenerateDialog(
                                                        $"#fins^-34^{session.Character.CharacterId} #fins^-69^{session.Character.CharacterId} {string.Format(Language.Instance.GetMessageFromKey("MARRY_REQUEST"), session.Character.Name)}"));
                            session.Character.FriendRequestCharacters.Add(characterId);
                            //session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                        }
                    }
                }
                break;

            case 570:
                if (session.CurrentMapInstance?.MapInstanceType == MapInstanceType.Act4Instance)
                {
                    session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("MUST_BE_IN_CLASSIC_MAP"), 0));
                    return;
                }
                if (EffectValue < 3)
                {
                    if (session.Character.Faction == (FactionType)EffectValue)
                    {
                        session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("SAME_FACTION"), 0));
                        return;
                    }
                    session.SendPacket(session.Character.Family == null
                            ? $"qna #guri^750^{EffectValue} {Language.Instance.GetMessageFromKey($"ASK_CHANGE_FACTION{EffectValue}")}"
                            : UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("IN_FAMILY"),
                                                                       0));
                }
                else
                {
                    if (session.Character.Family == null)
                    {
                        session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("NO_FAMILY"), 0));
                        return;
                    }
                    if (session.Character.Family.FamilyFaction / 2 == EffectValue)
                    {
                        session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("SAME_FACTION"), 0));
                        return;
                    }
                    session.SendPacket(session.Character.Family != null
                            ? $"qna #guri^750^{EffectValue} {Language.Instance.GetMessageFromKey($"ASK_CHANGE_FACTION{EffectValue}")}"
                            : UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("NOT_IN_FAMILY"),
                                                                       0));
                }
                break;

            // wings
            case 650:
                if (session.Character.UseSp && session.Character.SpInstance != null)
                {
                    if (option == 0)
                    {
                        session.SendPacket($"qna #u_i^1^{session.Character.CharacterId}^{(byte)inv.Type}^{inv.Slot}^3 {Language.Instance.GetMessageFromKey("ASK_WINGS_CHANGE")}");
                    }
                    else
                    {
                        session.Character.SpInstance.Design = (byte)EffectValue;
                        session.Character.MorphUpgrade2     = EffectValue;
                        session.CurrentMapInstance?.Broadcast(session.Character.GenerateCMode());
                        session.SendPacket(session.Character.GenerateStat());
                        session.SendPacket(session.Character.GenerateStatChar());
                        session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                    }
                }
                else
                {
                    session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("NO_SP"), 0));
                }
                break;

            // presentation messages
            case 203:
                if (!session.Character.IsVehicled)
                {
                    if (option == 0)
                    {
                        session.SendPacket(UserInterfaceHelper.Instance.GenerateGuri(10, 2, session.Character.CharacterId, 1));
                    }
                }
                break;

            // magic lamps
            case 651:
                if (session.Character.Inventory.All(i => i.Value.Type != InventoryType.Wear))
                {
                    if (option == 0)
                    {
                        session.SendPacket($"qna #u_i^1^{session.Character.CharacterId}^{(byte)inv.Type}^{inv.Slot}^3 {Language.Instance.GetMessageFromKey("ASK_USE")}");
                    }
                    else
                    {
                        session.Character.ChangeSex();
                        session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                    }
                }
                else
                {
                    session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("EQ_NOT_EMPTY"), 0));
                }
                break;

            // vehicles
            case 1000:
                if (session.Character.HasShopOpened)
                {
                    return;
                }
                if (Morph > 0)
                {
                    if (option == 0 && !session.Character.IsVehicled)
                    {
                        if (session.Character.IsSitting)
                        {
                            session.Character.IsSitting = false;
                            session.CurrentMapInstance?.Broadcast(session.Character.GenerateRest());
                        }
                        session.Character.LastDelay = DateTime.Now;
                        session.SendPacket(UserInterfaceHelper.Instance.GenerateDelay(3000, 3, $"#u_i^1^{session.Character.CharacterId}^{(byte)inv.Type}^{inv.Slot}^2"));
                    }
                    else
                    {
                        if (!session.Character.IsVehicled && option != 0)
                        {
                            DateTime delay = DateTime.Now.AddSeconds(-4);
                            if (session.Character.LastDelay > delay && session.Character.LastDelay < delay.AddSeconds(2))
                            {
                                session.Character.Speed         = Speed;
                                session.Character.IsVehicled    = true;
                                session.Character.VehicleSpeed  = Speed;
                                session.Character.MorphUpgrade  = 0;
                                session.Character.MorphUpgrade2 = 0;
                                session.Character.Morph         = Morph + (byte)session.Character.Gender;
                                session.Character.Mates?.ForEach(x => session.CurrentMapInstance?.Broadcast(x.GenerateOut()));
                                session.CurrentMapInstance?.Broadcast(session.Character.GenerateEff(196), session.Character.MapX, session.Character.MapY);
                                session.CurrentMapInstance?.Broadcast(session.Character.GenerateCMode());
                                session.SendPacket(session.Character.GenerateCond());
                                session.Character.LastSpeedChange = DateTime.Now;
                            }
                        }
                        else if (session.Character.IsVehicled)
                        {
                            session.Character.Mates?.Where(s => s.IsTeamMember).ToList().ForEach(x =>
                            {
                                x.PositionX = session.Character.PositionX;
                                x.PositionY = session.Character.PositionY;
                                session.CurrentMapInstance?.Broadcast(x.GenerateIn());
                            });
                            session.Character.RemoveVehicle();
                        }
                    }
                }
                break;

            case 1002:
                if (session.HasCurrentMapInstance)
                {
                    if (session.CurrentMapInstance.Map.MapTypes.All(m => m.MapTypeId != (short)MapTypeEnum.Act4))
                    {
                        short[] vnums =
                        {
                            1386, 1387, 1388, 1389, 1390, 1391, 1392, 1393, 1394, 1395, 1396, 1397, 1398, 1399,
                            1400, 1401, 1402, 1403, 1404, 1405
                        };
                        short vnum = vnums[ServerManager.Instance.RandomNumber(0, 20)];

                        NpcMonster npcmonster = ServerManager.Instance.GetNpc(vnum);
                        if (npcmonster == null)
                        {
                            return;
                        }
                        MapMonster monster = new MapMonster
                        {
                            MonsterVNum   = vnum,
                            MapY          = session.Character.MapY,
                            MapX          = session.Character.MapX,
                            MapId         = session.Character.MapInstance.Map.MapId,
                            Position      = (byte)session.Character.Direction,
                            IsMoving      = true,
                            MapMonsterId  = session.CurrentMapInstance.GetNextId(),
                            ShouldRespawn = false
                        };
                        monster.Initialize(session.CurrentMapInstance);
                        session.CurrentMapInstance.AddMonster(monster);
                        session.CurrentMapInstance.Broadcast(monster.GenerateIn());
                        session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                    }
                }
                break;

            case 69:
                session.Character.GetReput(ReputPrice);
                session.SendPacket(session.Character.GenerateFd());
                session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                break;

            case 789:
                session.Character.GiftAdd((short)inv.Item.EffectValue, 1);
                session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                break;

            case 1003:
                if (!session.Character.StaticBonusList.Any(s => s.StaticBonusType == StaticBonusType.BazaarMedalGold || s.StaticBonusType == StaticBonusType.BazaarMedalSilver))
                {
                    session.Character.StaticBonusList.Add(new StaticBonusDTO
                    {
                        CharacterId     = session.Character.CharacterId,
                        DateEnd         = DateTime.Now.AddDays(EffectValue),
                        StaticBonusType = StaticBonusType.BazaarMedalGold
                    });
                    session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                    session.SendPacket(session.Character.GenerateSay(string.Format(Language.Instance.GetMessageFromKey("EFFECT_ACTIVATED"), Name), 12));
                }
                break;

            case 1004:
                if (!session.Character.StaticBonusList.Any(s => s.StaticBonusType == StaticBonusType.BazaarMedalGold || s.StaticBonusType == StaticBonusType.BazaarMedalGold))
                {
                    session.Character.StaticBonusList.Add(new StaticBonusDTO
                    {
                        CharacterId     = session.Character.CharacterId,
                        DateEnd         = DateTime.Now.AddDays(EffectValue),
                        StaticBonusType = StaticBonusType.BazaarMedalSilver
                    });
                    session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                    session.SendPacket(session.Character.GenerateSay(string.Format(Language.Instance.GetMessageFromKey("EFFECT_ACTIVATED"), Name), 12));
                }
                break;

            case 1005:
                if (session.Character.StaticBonusList.All(s => s.StaticBonusType != StaticBonusType.BackPack))
                {
                    session.Character.StaticBonusList.Add(new StaticBonusDTO
                    {
                        CharacterId     = session.Character.CharacterId,
                        DateEnd         = DateTime.Now.AddDays(EffectValue),
                        StaticBonusType = StaticBonusType.BackPack
                    });
                    session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                    session.SendPacket(session.Character.GenerateExts());
                    session.SendPacket(session.Character.GenerateSay(string.Format(Language.Instance.GetMessageFromKey("EFFECT_ACTIVATED"), Name), 12));
                }
                break;

            case 1006:
                if (option == 0)
                {
                    session.SendPacket($"qna #u_i^1^{session.Character.CharacterId}^{(byte)inv.Type}^{inv.Slot}^2 {Language.Instance.GetMessageFromKey("ASK_PET_MAX")}");
                }
                else
                {
                    if (session.Character.MaxMateCount < 30)
                    {
                        session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("GET_PET_PLACES"), 10));
                        session.SendPacket(session.Character.GenerateScpStc());
                        session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                    }
                }
                break;

            case 1007:
                if (session.Character.StaticBonusList.All(s => s.StaticBonusType != StaticBonusType.PetBasket))
                {
                    session.Character.StaticBonusList.Add(new StaticBonusDTO
                    {
                        CharacterId     = session.Character.CharacterId,
                        DateEnd         = DateTime.Now.AddDays(EffectValue),
                        StaticBonusType = StaticBonusType.PetBasket
                    });
                    session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                    session.SendPacket(session.Character.GenerateExts());
                    session.SendPacket("ib 1278 1");
                    session.SendPacket(session.Character.GenerateSay(string.Format(Language.Instance.GetMessageFromKey("EFFECT_ACTIVATED"), Name), 12));
                }
                break;

            case 1008:
                if (session.Character.StaticBonusList.All(s => s.StaticBonusType != StaticBonusType.PetBackPack))
                {
                    session.Character.StaticBonusList.Add(new StaticBonusDTO
                    {
                        CharacterId     = session.Character.CharacterId,
                        DateEnd         = DateTime.Now.AddDays(EffectValue),
                        StaticBonusType = StaticBonusType.PetBackPack
                    });
                    session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                    session.SendPacket(session.Character.GenerateExts());
                    session.SendPacket(session.Character.GenerateSay(string.Format(Language.Instance.GetMessageFromKey("EFFECT_ACTIVATED"), Name), 12));
                }
                break;

            default:
                List <RollGeneratedItemDTO> rolls = inv.Item.RollGeneratedItems?.ToList();
                if (rolls != null && rolls.Any())
                {
                    if (option == 0)
                    {
                        if (packetsplit != null && packetsplit.Length == 9 || inv.Item.ItemSubType == 3)
                        {
                            session.SendPacket($"qna #guri^4999^8023^{inv.Slot} {Language.Instance.GetMessageFromKey("ASK_OPEN_BOX")}");
                        }
                        break;
                    }
                    else
                    {
                        int probabilities          = rolls.Sum(s => s.Probability);
                        int rnd                    = ServerManager.Instance.RandomNumber(0, probabilities);
                        int currentrnd             = 0;
                        List <ItemInstance> newInv = null;
                        foreach (RollGeneratedItemDTO rollitem in rolls)
                        {
                            if (rollitem.Probability == 10000)
                            {
                                session.Character.GiftAdd(rollitem.ItemGeneratedVNum, rollitem.ItemGeneratedAmount);
                                continue;
                            }
                            currentrnd += rollitem.Probability;
                            if (newInv != null || currentrnd < rnd)
                            {
                                continue;
                            }
                            newInv = session.Character.Inventory.AddNewToInventory(rollitem.ItemGeneratedVNum, rollitem.ItemGeneratedAmount, upgrade: rollitem.ItemGeneratedUpgrade);
                            short slot = inv.Slot;
                            if (!newInv.Any() || slot == -1)
                            {
                                continue;
                            }
                            session.SendPacket(session.Character.GenerateSay($"{Language.Instance.GetMessageFromKey("ITEM_ACQUIRED")}: {newInv.FirstOrDefault()?.Item.Name ?? ""} x {rollitem.ItemGeneratedAmount})", 12));
                            session.SendPacket($"rdi {rollitem.ItemGeneratedVNum} {rollitem.ItemGeneratedAmount}");
                            newInv.ForEach(s => session.SendPacket(s?.GenerateInventoryAdd()));
                        }
                        session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                        break;
                    }
                }
                Logger.Log.Warn(string.Format(Language.Instance.GetMessageFromKey("NO_HANDLER_ITEM"), GetType()));
                break;
            }
            session.Character.IncrementQuests(QuestType.Use, inv.ItemVNum);
        }