Exemple #1
0
        /// <summary>
        ///  guri packet
        /// </summary>
        /// <param name="guriPacket"></param>
        public void Guri(GuriPacket guriPacket)
        {
            if (guriPacket == null)
            {
                return;
            }
            if (guriPacket.Type == 10 && guriPacket.Data >= 973 && guriPacket.Data <= 999 && !Session.Character.EmoticonsBlocked)
            {
                if (guriPacket.User != null && Convert.ToInt64(guriPacket.User.Value) == Session.Character.CharacterId)
                {
                    Session.CurrentMapInstance?.Broadcast(Session, Session.Character.GenerateEff(guriPacket.Data + 4099), ReceiverType.AllNoEmoBlocked);
                }
                else
                {
                    Mate mate = Session.Character.Mates.FirstOrDefault(s => guriPacket.User != null && s.MateTransportId == Convert.ToInt32(guriPacket.User.Value));
                    if (mate != null)
                    {
                        Session.CurrentMapInstance?.Broadcast(Session, mate.GenerateEff(guriPacket.Data + 4099), ReceiverType.AllNoEmoBlocked);
                    }
                }
            }
            else
            {
                switch (guriPacket.Type)
                {
                // SHELL IDENTIFYING
                case 204:
                    if (guriPacket.User == null)
                    {
                        // WRONG PACKET
                        return;
                    }

                    InventoryType    inventoryType = (InventoryType)guriPacket.Argument;
                    ItemInstance     pearls        = Session.Character.Inventory.FirstOrDefault(s => s.Value.ItemVNum == 1429).Value;
                    WearableInstance shell         = (WearableInstance)Session.Character.Inventory.LoadBySlotAndType((short)guriPacket.User.Value, inventoryType);

                    if (pearls == null)
                    {
                        // USING PACKET LOGGER
                        return;
                    }

                    if (shell.EquipmentOptions.Any())
                    {
                        // ALREADY IDENTIFIED
                        Session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("SHELL_ALREADY_IDENTIFIED"), 0));
                        return;
                    }

                    if (!ShellGeneratorHelper.Instance.ShellTypes.TryGetValue(shell.ItemVNum, out byte shellType))
                    {
                        // SHELL TYPE NOT IMPLEMENTED
                        return;
                    }

                    if (shellType != 8 && shellType != 9)
                    {
                        if (shell.Upgrade < 50 || shell.Upgrade > 90)
                        {
                            return;
                        }
                    }

                    if (shellType == 8 || shellType == 9)
                    {
                        switch (shell.Upgrade)
                        {
                        case 25:
                        case 30:
                        case 40:
                        case 55:
                        case 60:
                        case 65:
                        case 70:
                        case 75:
                        case 80:
                        case 85:
                            break;

                        default:
                            Session.Character.Inventory.RemoveItemAmountFromInventory(1, shell.Id);
                            Session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("STOP_SPAWNING_BROKEN_SHELL"), 0));
                            return;
                        }
                    }

                    int perlsNeeded = shell.Upgrade / 10 + shell.Rare;

                    if (Session.Character.Inventory.CountItem(pearls.ItemVNum) < perlsNeeded)
                    {
                        // NOT ENOUGH PEARLS
                        return;
                    }

                    List <EquipmentOptionDTO> shellOptions = ShellGeneratorHelper.Instance.GenerateShell(shellType, shell.Rare, shell.Upgrade);

                    if (!shellOptions.Any())
                    {
                        Session.Character.Inventory.RemoveItemAmountFromInventory(1, shell.Id);
                        Session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("STOP_SPAWNING_BROKEN_SHELL"), 0));
                        return;
                    }

                    shell.EquipmentOptions.AddRange(shellOptions);

                    Session.Character.Inventory.RemoveItemAmount(pearls.ItemVNum, perlsNeeded);
                    Session.CurrentMapInstance?.Broadcast(Session, Session.Character.GenerateEff(3006));
                    Session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("SHELL_IDENTIFIED"), 0));
                    break;

                case 205:
                    if (guriPacket.User == null)
                    {
                        return;
                    }
                    const int        perfumeVnum          = 1428;
                    InventoryType    perfumeInventoryType = (InventoryType)guriPacket.Argument;
                    WearableInstance eq = (WearableInstance)Session.Character.Inventory.LoadBySlotAndType((short)guriPacket.User.Value, perfumeInventoryType);

                    if (eq.BoundCharacterId == Session.Character.CharacterId)
                    {
                        // ALREADY YOURS
                        return;
                    }
                    if (eq.ShellRarity == null)
                    {
                        // NO SHELL APPLIED
                        return;
                    }

                    int perfumesNeeded = ShellGeneratorHelper.Instance.PerfumeFromItemLevelAndShellRarity(eq.Item.LevelMinimum, (byte)eq.ShellRarity.Value);
                    if (Session.Character.Inventory.CountItem(perfumeVnum) < perfumesNeeded)
                    {
                        // NOT ENOUGH PEARLS
                        return;
                    }

                    Session.Character.Inventory.RemoveItemAmount(perfumeVnum, perfumesNeeded);
                    eq.BoundCharacterId = Session.Character.CharacterId;
                    break;

                case 300:
                    if (guriPacket.Argument == 8023)
                    {
                        if (guriPacket.User == null)
                        {
                            return;
                        }
                        short        slot = (short)guriPacket.User.Value;
                        ItemInstance box  = Session.Character.Inventory.LoadBySlotAndType <BoxInstance>(slot, InventoryType.Equipment);
                        if (box != null)
                        {
                            if (guriPacket.Data > 0)
                            {
                                box.Item.Use(Session, ref box, 1, new[] { guriPacket.Data.ToString() });
                            }
                            else
                            {
                                box.Item.Use(Session, ref box, 1);
                            }
                        }
                    }
                    break;

                case 501:
                    if (ServerManager.Instance.IceBreakerInWaiting && IceBreaker.Map.Sessions.Count() < IceBreaker.MaxAllowedPlayers)
                    {
                        ServerManager.Instance.TeleportOnRandomPlaceInMap(Session, IceBreaker.Map.MapInstanceId);
                    }
                    break;

                case 502:
                    long?charid = guriPacket.User;
                    if (charid == null)
                    {
                        return;
                    }
                    ClientSession target = ServerManager.Instance.GetSessionByCharacterId(charid.Value);
                    IceBreaker.FrozenPlayers.Remove(target);
                    IceBreaker.AlreadyFrozenPlayers.Add(target);
                    target?.CurrentMapInstance?.Broadcast(
                        UserInterfaceHelper.Instance.GenerateMsg(string.Format(Language.Instance.GetMessageFromKey("ICEBREAKER_PLAYER_UNFROZEN"), target.Character?.Name), 0));
                    break;

                case 506:
                    if (ServerManager.Instance.EventInWaiting)
                    {
                        Session.Character.IsWaitingForEvent = true;
                    }
                    break;

                default:
                    if (guriPacket.Type == 199 && guriPacket.Argument == 2)
                    {
                        short[] listWingOfFriendship = { 2160, 2312, 10048 };
                        short   vnumToUse            = -1;
                        foreach (short vnum in listWingOfFriendship)
                        {
                            if (Session.Character.Inventory.CountItem(vnum) > 0)
                            {
                                vnumToUse = vnum;
                            }
                        }
                        if (vnumToUse != -1)
                        {
                            if (guriPacket.User == null)
                            {
                                return;
                            }
                            if (!long.TryParse(guriPacket.User.Value.ToString(), out long charId))
                            {
                                return;
                            }
                            ClientSession session = ServerManager.Instance.GetSessionByCharacterId(charId);
                            if (session != null)
                            {
                                if (Session.Character.IsFriendOfCharacter(charId))
                                {
                                    if (session.CurrentMapInstance.MapInstanceType == MapInstanceType.BaseMapInstance)
                                    {
                                        if (Session.Character.MapInstance.MapInstanceType != MapInstanceType.BaseMapInstance)
                                        {
                                            Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("CANT_USE_THAT"), 10));
                                            return;
                                        }
                                        short mapy  = session.Character.PositionY;
                                        short mapx  = session.Character.PositionX;
                                        short mapId = session.Character.MapInstance.Map.MapId;

                                        ServerManager.Instance.ChangeMap(Session.Character.CharacterId, mapId, mapx, mapy);
                                        Session.Character.Inventory.RemoveItemAmount(vnumToUse);
                                    }
                                    else
                                    {
                                        if (Session.Character.MapInstance.MapInstanceType == MapInstanceType.Act4Instance && session.Character.Faction == Session.Character.Faction)
                                        {
                                            short mapy  = session.Character.PositionY;
                                            short mapx  = session.Character.PositionX;
                                            Guid  mapId = session.CurrentMapInstance.MapInstanceId;

                                            ServerManager.Instance.ChangeMapInstance(Session.Character.CharacterId, mapId, mapx, mapy);
                                            Session.Character.Inventory.RemoveItemAmount(vnumToUse);
                                        }
                                        else
                                        {
                                            Session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("USER_ON_INSTANCEMAP"), 0));
                                        }
                                    }
                                }
                            }
                            else
                            {
                                Session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("USER_NOT_CONNECTED"), 0));
                            }
                        }
                        else
                        {
                            Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("NO_WINGS"), 10));
                        }
                    }
                    else
                    {
                        switch (guriPacket.Type)
                        {
                        case 400:
                            if (guriPacket.Argument != 0)
                            {
                                if (!Session.HasCurrentMapInstance)
                                {
                                    return;
                                }
                                MapNpc npc = Session.CurrentMapInstance.Npcs.FirstOrDefault(n => n.MapNpcId.Equals(guriPacket.Argument));
                                if (npc != null)
                                {
                                    NpcMonster mapobject = ServerManager.Instance.GetNpc(npc.NpcVNum);

                                    int rateDrop = ServerManager.Instance.DropRate;
                                    int delay    = (int)Math.Round((3 + mapobject.RespawnTime / 1000d) * Session.Character.TimesUsed);
                                    delay = delay > 11 ? 8 : delay;
                                    if (Session.Character.LastMapObject.AddSeconds(delay) < DateTime.Now)
                                    {
                                        if (mapobject.Drops.Any(s => s.MonsterVNum != null))
                                        {
                                            if (mapobject.VNumRequired > 10 && Session.Character.Inventory.CountItem(mapobject.VNumRequired) < mapobject.AmountRequired)
                                            {
                                                Session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("NOT_ENOUGH_ITEM"), 0));
                                                return;
                                            }
                                        }
                                        Random  random       = new Random();
                                        double  randomAmount = ServerManager.Instance.RandomNumber() * random.NextDouble();
                                        DropDTO drop         = mapobject.Drops.FirstOrDefault(s => s.MonsterVNum == npc.NpcVNum);
                                        if (drop != null)
                                        {
                                            if (npc.NpcVNum == 2004 && npc.IsOut == false)
                                            {
                                                ItemInstance newInv = Session.Character.Inventory.AddNewToInventory(drop.ItemVNum).FirstOrDefault();
                                                if (newInv == null)
                                                {
                                                    return;
                                                }
                                                Session.CurrentMapInstance.Broadcast(npc.GenerateOut());
                                                Session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(
                                                                       string.Format(Language.Instance.GetMessageFromKey("RECEIVED_ITEM"), newInv.Item.Name), 0));
                                                Session.SendPacket(Session.Character.GenerateSay(string.Format(Language.Instance.GetMessageFromKey("RECEIVED_ITEM"), newInv.Item.Name), 11));
                                                return;
                                            }
                                            int dropChance = drop.DropChance;
                                            if (randomAmount <= (double)dropChance * rateDrop / 5000.000)
                                            {
                                                short        vnum   = drop.ItemVNum;
                                                ItemInstance newInv = Session.Character.Inventory.AddNewToInventory(vnum).FirstOrDefault();
                                                Session.Character.LastMapObject = DateTime.Now;
                                                Session.Character.TimesUsed++;
                                                if (Session.Character.TimesUsed >= 4)
                                                {
                                                    Session.Character.TimesUsed = 0;
                                                }
                                                if (newInv != null)
                                                {
                                                    Session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(
                                                                           string.Format(Language.Instance.GetMessageFromKey("RECEIVED_ITEM"), newInv.Item.Name), 0));
                                                    Session.SendPacket(Session.Character.GenerateSay(string.Format(Language.Instance.GetMessageFromKey("RECEIVED_ITEM"), newInv.Item.Name),
                                                                                                     11));
                                                }
                                                else
                                                {
                                                    Session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("NOT_ENOUGH_PLACE"), 0));
                                                }
                                            }
                                            else
                                            {
                                                Session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("TRY_FAILED"), 0));
                                            }
                                        }
                                    }
                                    else
                                    {
                                        Session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(
                                                               string.Format(Language.Instance.GetMessageFromKey("TRY_FAILED_WAIT"),
                                                                             (int)(Session.Character.LastMapObject.AddSeconds(delay) - DateTime.Now).TotalSeconds), 0));
                                    }
                                }
                            }
                            break;

                        case 710:
                            if (guriPacket.Value != null)
                            {
                                // MapNpc npc = Session.CurrentMapInstance.Npcs.FirstOrDefault(n =>
                                // n.MapNpcId.Equals(Convert.ToInt16(guriPacket.Data)); NpcMonster mapObject
                                // = ServerManager.Instance.GetNpc(npc.NpcVNum); teleport free
                            }
                            break;

                        case 750:
                            if (!guriPacket.User.HasValue)
                            {
                                const short baseVnum = 1623;
                                if (short.TryParse(guriPacket.Argument.ToString(), out short faction))
                                {
                                    if (Session.Character.Inventory.CountItem(baseVnum + faction) > 0)
                                    {
                                        Session.Character.Faction = (FactionType)faction;
                                        Session.Character.Inventory.RemoveItemAmount(baseVnum + faction);
                                        Session.SendPacket("scr 0 0 0 0 0 0 0");
                                        Session.SendPacket(Session.Character.GenerateFaction());
                                        Session.SendPacket(Session.Character.GenerateEff(4799 + faction));
                                        Session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey($"GET_PROTECTION_POWER_{faction}"), 0));
                                    }
                                }
                            }
                            break;

                        case 2:
                            Session.CurrentMapInstance?.Broadcast(UserInterfaceHelper.Instance.GenerateGuri(2, 1, Session.Character.CharacterId), Session.Character.PositionX,
                                                                  Session.Character.PositionY);
                            break;

                        case 4:
                            const int speakerVNum = 2173;
                            const int petnameVNum = 2157;
                            switch (guriPacket.Argument)
                            {
                            case 1:
                                Mate mate = Session.Character.Mates.FirstOrDefault(s => s.MateTransportId == guriPacket.Data);
                                if (guriPacket.Value.Length > 15)
                                {
                                    Session.SendPacket(UserInterfaceHelper.Instance.GenerateInfo(Language.Instance.GetMessageFromKey("NEW_NAME_PET_MAX_LENGTH")));
                                    return;
                                }
                                if (mate != null)
                                {
                                    mate.Name = guriPacket.Value;
                                    Session.CurrentMapInstance.Broadcast(mate.GenerateOut());
                                    Session.CurrentMapInstance.Broadcast(mate.GenerateIn());
                                    Session.SendPacket(UserInterfaceHelper.Instance.GenerateInfo(Language.Instance.GetMessageFromKey("NEW_NAME_PET")));
                                    Session.SendPacket(Session.Character.GeneratePinit());
                                    Session.SendPackets(Session.Character.GeneratePst());
                                    Session.SendPackets(Session.Character.GenerateScP());
                                    Session.Character.Inventory.RemoveItemAmount(petnameVNum);
                                }
                                break;

                            case 2:
                                int presentationVNum = Session.Character.Inventory.CountItem(1117) > 0 ? 1117 : (Session.Character.Inventory.CountItem(9013) > 0 ? 9013 : -1);
                                if (presentationVNum != -1)
                                {
                                    string message = string.Empty;

                                    // message = $" ";
                                    string[] valuesplit = guriPacket.Value.Split(' ');
                                    message = valuesplit.Aggregate(message, (current, t) => current + t + "^");
                                    message = message.Substring(0, message.Length - 1);             // Remove the last ^
                                    message = message.Trim();
                                    if (message.Length > 60)
                                    {
                                        message = message.Substring(0, 60);
                                    }

                                    Session.Character.Biography = message;
                                    Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("INTRODUCTION_SET"), 10));
                                    Session.Character.Inventory.RemoveItemAmount(presentationVNum);
                                }
                                break;

                            case 3:
                                if (Session.Character.Inventory.CountItem(speakerVNum) > 0)
                                {
                                    if (Session.Character == null || guriPacket.Value == null)
                                    {
                                        return;
                                    }
                                    string   message    = $"<{Language.Instance.GetMessageFromKey("SPEAKER")}> [{Session.Character.Name}]:";
                                    string[] valuesplit = guriPacket.Value.Split(' ');
                                    message = valuesplit.Aggregate(message, (current, t) => current + t + " ");
                                    if (message.Length > 120)
                                    {
                                        message = message.Substring(0, 120);
                                    }

                                    message = message.Trim();

                                    if (Session.Character.IsMuted())
                                    {
                                        Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("SPEAKER_CANT_BE_USED"), 10));
                                        return;
                                    }
                                    Session.Character.Inventory.RemoveItemAmount(speakerVNum);
                                    ServerManager.Instance.Broadcast(Session.Character.GenerateSay(message, 13));
                                    LogHelper.Instance.InsertChatLog(ChatType.Speaker, Session.Character.CharacterId, message, Session.IpAddress);
                                }
                                break;
                            }

                            // presentation message

                            // Speaker
                            break;

                        default:
                            if (guriPacket.Type == 199 && guriPacket.Argument == 1)
                            {
                                if (guriPacket.User != null && long.TryParse(guriPacket.User.Value.ToString(), out long charId))
                                {
                                    if (!Session.Character.IsFriendOfCharacter(charId))
                                    {
                                        Session.SendPacket(Language.Instance.GetMessageFromKey("CHARACTER_NOT_IN_FRIENDLIST"));
                                        return;
                                    }
                                    Session.SendPacket(UserInterfaceHelper.Instance.GenerateDelay(3000, 4, $"#guri^199^2^{guriPacket.User.Value}"));
                                }
                            }
                            else
                            {
                                switch (guriPacket.Type)
                                {
                                case 201:
                                    if (Session.Character.StaticBonusList.Any(s => s.StaticBonusType == StaticBonusType.PetBasket))
                                    {
                                        Session.SendPacket(Session.Character.GenerateStashAll());
                                    }
                                    break;

                                case 202:
                                    Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("PARTNER_BACKPACK"), 10));
                                    Session.SendPacket(Session.Character.GeneratePStashAll());
                                    break;

                                default:
                                    if (guriPacket.Type == 208 && guriPacket.Argument == 0)
                                    {
                                        if (guriPacket.User != null && short.TryParse(guriPacket.User.Value.ToString(), out short pearlSlot) &&
                                            short.TryParse(guriPacket.Value, out short mountSlot))
                                        {
                                            ItemInstance mount = Session.Character.Inventory.LoadBySlotAndType <ItemInstance>(mountSlot, InventoryType.Main);
                                            BoxInstance  pearl = Session.Character.Inventory.LoadBySlotAndType <BoxInstance>(pearlSlot, InventoryType.Equipment);
                                            if (mount != null && pearl != null)
                                            {
                                                pearl.HoldingVNum = mount.ItemVNum;
                                                Session.Character.Inventory.RemoveItemAmountFromInventory(1, mount.Id);
                                            }
                                        }
                                    }
                                    else if (guriPacket.Type == 209 && guriPacket.Argument == 0)
                                    {
                                        if (guriPacket.User != null && short.TryParse(guriPacket.User.Value.ToString(), out short pearlSlot) &&
                                            short.TryParse(guriPacket.Value, out short mountSlot))
                                        {
                                            WearableInstance fairy = Session.Character.Inventory.LoadBySlotAndType <WearableInstance>(mountSlot, InventoryType.Equipment);
                                            BoxInstance      pearl = Session.Character.Inventory.LoadBySlotAndType <BoxInstance>(pearlSlot, InventoryType.Equipment);
                                            if (fairy != null && pearl != null)
                                            {
                                                pearl.HoldingVNum = fairy.ItemVNum;
                                                pearl.ElementRate = fairy.ElementRate;
                                                Session.Character.Inventory.RemoveItemAmountFromInventory(1, fairy.Id);
                                            }
                                        }
                                    }
                                    else if (guriPacket.Type == 203 && guriPacket.Argument == 0)
                                    {
                                        // SP points initialization
                                        int[] listPotionResetVNums = { 1366, 1427, 5115, 9040 };
                                        int   vnumToUse            = -1;
                                        foreach (int vnum in listPotionResetVNums)
                                        {
                                            if (Session.Character.Inventory.CountItem(vnum) > 0)
                                            {
                                                vnumToUse = vnum;
                                            }
                                        }
                                        if (vnumToUse != -1)
                                        {
                                            if (Session.Character.UseSp)
                                            {
                                                SpecialistInstance specialistInstance =
                                                    Session.Character.Inventory.LoadBySlotAndType <SpecialistInstance>((byte)EquipmentType.Sp, InventoryType.Wear);
                                                if (specialistInstance != null)
                                                {
                                                    specialistInstance.SlDamage  = 0;
                                                    specialistInstance.SlDefence = 0;
                                                    specialistInstance.SlElement = 0;
                                                    specialistInstance.SlHP      = 0;

                                                    specialistInstance.DamageMinimum        = 0;
                                                    specialistInstance.DamageMaximum        = 0;
                                                    specialistInstance.HitRate              = 0;
                                                    specialistInstance.CriticalLuckRate     = 0;
                                                    specialistInstance.CriticalRate         = 0;
                                                    specialistInstance.DefenceDodge         = 0;
                                                    specialistInstance.DistanceDefenceDodge = 0;
                                                    specialistInstance.ElementRate          = 0;
                                                    specialistInstance.DarkResistance       = 0;
                                                    specialistInstance.LightResistance      = 0;
                                                    specialistInstance.FireResistance       = 0;
                                                    specialistInstance.WaterResistance      = 0;
                                                    specialistInstance.CriticalDodge        = 0;
                                                    specialistInstance.CloseDefence         = 0;
                                                    specialistInstance.DistanceDefence      = 0;
                                                    specialistInstance.MagicDefence         = 0;
                                                    specialistInstance.HP = 0;
                                                    specialistInstance.MP = 0;

                                                    Session.Character.Inventory.RemoveItemAmount(vnumToUse);
                                                    Session.Character.Inventory.DeleteFromSlotAndType((byte)EquipmentType.Sp, InventoryType.Wear);
                                                    Session.Character.Inventory.AddToInventoryWithSlotAndType(specialistInstance, InventoryType.Wear, (byte)EquipmentType.Sp);
                                                    Session.SendPacket(Session.Character.GenerateCond());
                                                    Session.SendPacket(specialistInstance.GenerateSlInfo());
                                                    Session.SendPacket(Session.Character.GenerateLev());
                                                    Session.SendPacket(Session.Character.GenerateStatChar());
                                                    Session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("POINTS_RESET"), 0));
                                                }
                                            }
                                            else
                                            {
                                                Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("TRANSFORMATION_NEEDED"), 10));
                                            }
                                        }
                                        else
                                        {
                                            Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("NOT_ENOUGH_POINTS"), 10));
                                        }
                                    }
                                    break;
                                }
                            }
                            break;
                        }
                    }
                    break;
                }
            }
        }
        /// <summary>
        /// sl packet
        /// </summary>
        /// <param name="spTransformPacket"></param>
        public void SpTransform(SpTransformPacket spTransformPacket)
        {
            SpecialistInstance specialistInstance = Session.Character.Inventory.LoadBySlotAndType <SpecialistInstance>((byte)EquipmentType.Sp, PocketType.Wear);

            if (spTransformPacket.Type == 10)
            {
                //TODO set points
            }
            else
            {
                if (Session.Character.IsSitting)
                {
                    return;
                }

                if (specialistInstance == null)
                {
                    Session.SendPacket(new MsgPacket
                    {
                        Message = Language.Instance.GetMessageFromKey(LanguageKey.NO_SP, Session.Account.Language)
                    });

                    return;
                }

                if (Session.Character.IsVehicled)
                {
                    Session.SendPacket(new MsgPacket
                    {
                        Message = Language.Instance.GetMessageFromKey(LanguageKey.REMOVE_VEHICLE, Session.Account.Language)
                    });
                    return;
                }

                double currentRunningSeconds = (SystemTime.Now() - Session.Character.LastSp).TotalSeconds;

                if (Session.Character.UseSp)
                {
                    Session.Character.LastSp = SystemTime.Now();
                    Session.Character.RemoveSp();
                }
                else
                {
                    if (Session.Character.SpPoint == 0 && Session.Character.SpAdditionPoint == 0)
                    {
                        Session.SendPacket(new MsgPacket
                        {
                            Message = Language.Instance.GetMessageFromKey(LanguageKey.SP_NOPOINTS, Session.Account.Language)
                        });
                        return;
                    }
                    if (currentRunningSeconds >= Session.Character.SpCooldown)
                    {
                        if (spTransformPacket.Type == 1)
                        {
                            Session.Character.ChangeSp();
                        }
                        else
                        {
                            Session.SendPacket(new DelayPacket
                            {
                                Type   = 3,
                                Delay  = 5000,
                                Packet = new SpTransformPacket {
                                    Type = 1
                                }
                            });
                            Session.Character.MapInstance.Sessions.SendPacket(new GuriPacket
                            {
                                Type           = 2,
                                Argument       = 1,
                                VisualEntityId = Session.Character.CharacterId
                            });
                        }
                    }
                    else
                    {
                        Session.SendPacket(new MsgPacket
                        {
                            Message = string.Format(Language.Instance.GetMessageFromKey(LanguageKey.SP_INLOADING,
                                                                                        Session.Account.Language), Session.Character.SpCooldown - (int)Math.Round(currentRunningSeconds))
                        });
                    }
                }
            }
        }
        public override void Use(ClientSession session, ref ItemInstance inv, byte option = 0, string[] packetsplit = null)
        {
            switch (Effect)
            {
            default:
                bool delay = false;
                if (option == 255)
                {
                    delay  = true;
                    option = 0;
                }
                Mate mate = null;
                if (option != 0)
                {
                    mate = session.Character.Mates.FirstOrDefault(s => s.MateType == MateType.Partner && s.PetId == (option - 1));
                }
                short         slot      = inv.Slot;
                InventoryType equipment = InventoryType.Wear;
                switch (option)
                {
                case 1:
                    equipment = InventoryType.FirstPartnerInventory;
                    break;

                case 2:
                    equipment = InventoryType.SecondPartnerInventory;
                    break;

                case 3:
                    equipment = InventoryType.ThirdPartnerInventory;
                    break;
                }

                InventoryType itemToWearType = inv.Type;

                if (inv == null)
                {
                    return;
                }

                if (ItemValidTime > 0 && !inv.IsBound)
                {
                    inv.ItemDeleteTime = DateTime.Now.AddSeconds(ItemValidTime);
                }

                if (!inv.IsBound)
                {
                    switch (inv.Item.Effect)
                    {
                    case 790:         // Tarot
                    case 932:         // Attack amulet
                    case 933:         // defense amulet
                        inv.BoundCharacterId = session.Character.CharacterId;
                        break;
                    }

                    if (!delay && (EquipmentSlot == EquipmentType.Fairy && (MaxElementRate == 70 || MaxElementRate == 80) || EquipmentSlot == EquipmentType.CostumeHat || EquipmentSlot == EquipmentType.CostumeSuit || EquipmentSlot == EquipmentType.WeaponSkin))
                    {
                        session.SendPacket($"qna #u_i^1^{session.Character.CharacterId}^{(byte)itemToWearType}^{slot}^1 {Language.Instance.GetMessageFromKey("ASK_BIND")}");
                        return;
                    }
                    if (delay)
                    {
                        inv.BoundCharacterId = session.Character.CharacterId;
                    }
                }

                double timeSpanSinceLastSpUsage = (DateTime.Now - Process.GetCurrentProcess().StartTime.AddSeconds(-50)).TotalSeconds - session.Character.LastSp;

                if (EquipmentSlot == EquipmentType.Sp && inv.Rare == -2)
                {
                    session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("CANT_EQUIP_DESTROYED_SP"), 0));
                    return;
                }

                if (option == 0)
                {
                    if (EquipmentSlot == EquipmentType.Sp && timeSpanSinceLastSpUsage <= session.Character.SpCooldown && session.Character.Inventory.LoadBySlotAndType <SpecialistInstance>((byte)EquipmentType.Sp, InventoryType.Specialist) != null)
                    {
                        session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(string.Format(Language.Instance.GetMessageFromKey("SP_INLOADING"), session.Character.SpCooldown - (int)Math.Round(timeSpanSinceLastSpUsage)), 0));
                        return;
                    }

                    if (ItemType != ItemType.Weapon && ItemType != ItemType.Armor && ItemType != ItemType.Fashion && ItemType != ItemType.Jewelery && ItemType != ItemType.Specialist ||
                        LevelMinimum > (IsHeroic ? session.Character.HeroLevel : session.Character.Level) || Sex != 0 && Sex != (byte)session.Character.Gender + 1 ||
                        ItemType != ItemType.Jewelery && EquipmentSlot != EquipmentType.Boots && EquipmentSlot != EquipmentType.Gloves && (Class >> (byte)session.Character.Class & 1) != 1)
                    {
                        session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("BAD_EQUIPMENT"), 10));
                        return;
                    }

                    if (session.Character.UseSp)
                    {
                        SpecialistInstance sp = session.Character.Inventory.LoadBySlotAndType <SpecialistInstance>((byte)EquipmentType.Sp, equipment);

                        if (sp != null && sp.Item.Element != 0 && EquipmentSlot == EquipmentType.Fairy && Element != sp.Item.Element && Element != sp.Item.SecondaryElement)
                        {
                            session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("BAD_FAIRY"), 0));
                            return;
                        }
                    }

                    if (ItemType == ItemType.Weapon || ItemType == ItemType.Armor)
                    {
                        if (inv.BoundCharacterId.HasValue && inv.BoundCharacterId.Value != session.Character.CharacterId)
                        {
                            session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("BAD_EQUIPMENT"), 10));
                            return;
                        }
                    }

                    if (session.Character.UseSp && EquipmentSlot == EquipmentType.Sp)
                    {
                        session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("SP_BLOCKED"), 10));
                        return;
                    }

                    if (session.Character.JobLevel < LevelJobMinimum)
                    {
                        session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("LOW_JOB_LVL"), 10));
                        return;
                    }
                }
                else if (mate != null)
                {
                    if (mate.Level < LevelMinimum)
                    {
                        session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("BAD_EQUIPMENT"), 10));
                        return;
                    }
                    switch (EquipmentSlot)
                    {
                    case EquipmentType.Armor:
                        if (ItemSubType == 4)
                        {
                            mate.ArmorInstance = inv;
                            break;
                        }
                        else
                        {
                            goto default;
                        }

                    case EquipmentType.MainWeapon:
                        if (ItemSubType == 12)
                        {
                            mate.WeaponInstance = inv;
                            break;
                        }
                        else
                        {
                            goto default;
                        }

                    case EquipmentType.Gloves:
                        mate.GlovesInstance = inv;
                        break;

                    case EquipmentType.Boots:
                        mate.BootsInstance = inv;
                        break;

                    case EquipmentType.Sp:
                        if (ItemSubType == 4)
                        {
                            mate.SpInstance = inv;
                            break;
                        }
                        else
                        {
                            goto default;
                        }

                    default:
                        session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("BAD_EQUIPMENT"), 10));
                        return;
                    }
                }

                ItemInstance currentlyEquippedItem = session.Character.Inventory.LoadBySlotAndType((short)EquipmentSlot, equipment);

                if (currentlyEquippedItem == null)
                {
                    // move from equipment to wear
                    session.Character.Inventory.MoveInInventory(inv.Slot, itemToWearType, equipment);
                    session.SendPacket(UserInterfaceHelper.Instance.GenerateInventoryRemove(itemToWearType, slot));
                }
                else
                {
                    // move from wear to equipment and back
                    session.Character.Inventory.MoveInInventory(currentlyEquippedItem.Slot, equipment, itemToWearType, inv.Slot);
                    session.SendPacket(currentlyEquippedItem.GenerateInventoryAdd());
                    session.Character.BattleEntity.StaticBcards.RemoveWhere(o => o.ItemVNum != currentlyEquippedItem.ItemVNum, out ConcurrentBag <BCard> eqBcards);
                    session.Character.BattleEntity.StaticBcards = eqBcards;
                }
                inv.Item.BCards.ForEach(s => session.Character.BattleEntity.StaticBcards.Add(s));

                if (inv is WearableInstance wearableInstance)
                {
                    SpecialistInstance specialistInstance = session.Character.Inventory.LoadBySlotAndType <SpecialistInstance>((byte)EquipmentType.Sp, InventoryType.Wear);

                    if (wearableInstance.EquipmentOptions != null)
                    {
                        switch (wearableInstance.Item.ItemType)
                        {
                        case ItemType.Armor:
                        case ItemType.Weapon:
                        case ItemType.Jewelery:
                            switch (wearableInstance.Slot)
                            {
                            case (byte)EquipmentType.Armor:
                                session.Character.Inventory.Armor = wearableInstance;
                                EquipmentOptionHelper.Instance.ShellToBCards(wearableInstance.EquipmentOptions, wearableInstance.ItemVNum)
                                .ForEach(s => session.Character.BattleEntity.StaticBcards.Add(s));
                                break;

                            case (byte)EquipmentType.MainWeapon:
                                session.Character.Inventory.PrimaryWeapon = wearableInstance;
                                EquipmentOptionHelper.Instance.ShellToBCards(wearableInstance.EquipmentOptions, wearableInstance.ItemVNum)
                                .ForEach(s => session.Character.BattleEntity.StaticBcards.Add(s));
                                specialistInstance?.RestorePoints(session, specialistInstance);
                                break;

                            case (byte)EquipmentType.SecondaryWeapon:
                                session.Character.Inventory.SecondaryWeapon = wearableInstance;
                                EquipmentOptionHelper.Instance.ShellToBCards(wearableInstance.EquipmentOptions, wearableInstance.ItemVNum)
                                .ForEach(s => session.Character.BattleEntity.StaticBcards.Add(s));
                                specialistInstance?.RestorePoints(session, specialistInstance);
                                break;

                            case (byte)EquipmentType.Ring:
                            case (byte)EquipmentType.Necklace:
                            case (byte)EquipmentType.Bracelet:
                                EquipmentOptionHelper.Instance.CellonToBCards(wearableInstance.EquipmentOptions, wearableInstance.ItemVNum)
                                .ForEach(s => session.Character.BattleEntity.StaticBcards.Add(s));
                                break;
                            }
                            break;
                        }
                    }
                }

                if (option == 0)
                {
                    session.SendPacket(session.Character.GenerateStatChar());
                    session.CurrentMapInstance?.Broadcast(session.Character.GenerateEq());
                    session.SendPacket(session.Character.GenerateEquipment());
                    session.CurrentMapInstance?.Broadcast(session.Character.GeneratePairy());

                    switch (EquipmentSlot)
                    {
                    case EquipmentType.Fairy:
                        WearableInstance fairy = session.Character.Inventory.LoadBySlotAndType <WearableInstance>((byte)EquipmentType.Fairy, equipment);
                        session.SendPacket(session.Character.GenerateSay(string.Format(Language.Instance.GetMessageFromKey("FAIRYSTATS"), fairy.XP, CharacterHelper.LoadFairyXpData(fairy.ElementRate + fairy.Item.ElementRate)), 10));
                        break;

                    case EquipmentType.Amulet:
                        session.SendPacket(session.Character.GenerateEff(39));
                        break;
                    }
                }
                else if (mate != null)
                {
                    session.SendPacket(mate.GenerateScPacket());
                }
                break;
            }
        }
        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()));
            }
        }
Exemple #5
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 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;
            }
        }