Inheritance: OpenNos.Data.ItemInstanceDTO
Ejemplo n.º 1
0
 public override void Use(ClientSession session, ref ItemInstance inv, bool delay = false, string[] packetsplit = null)
 {
     if ((DateTime.Now - session.Character.LastPotion).TotalMilliseconds < 750)
     {
         return;
     }
     else
     {
         session.Character.LastPotion = DateTime.Now;
     }
     switch (Effect)
     {
         default:
             if (session.Character.Hp == session.Character.HPLoad() && session.Character.Mp == session.Character.MPLoad())
             {
                 return;
             }
             if (session.Character.Hp <= 0)
             {
                 return;
             }
             session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
             if ((int)session.Character.HPLoad() - session.Character.Hp < Hp)
             {
                 session.CurrentMap?.Broadcast(session.Character.GenerateRc((int)session.Character.HPLoad() - session.Character.Hp));
             }
             else if ((int)session.Character.HPLoad() - session.Character.Hp > Hp)
             {
                 session.CurrentMap?.Broadcast(session.Character.GenerateRc(Hp));
             }
             session.Character.Mp += Mp;
             session.Character.Hp += Hp;
             if (session.Character.Mp > session.Character.MPLoad())
             {
                 session.Character.Mp = (int)session.Character.MPLoad();
             }
             if (session.Character.Hp > session.Character.HPLoad())
             {
                 session.Character.Hp = (int)session.Character.HPLoad();
             }
             if (inv.ItemVNum == 1242 || inv.ItemVNum == 5582)
             {
                 session.CurrentMap?.Broadcast(session.Character.GenerateRc((int)session.Character.HPLoad() - session.Character.Hp));
                 session.Character.Hp = (int)session.Character.HPLoad();
             }
             else if (inv.ItemVNum == 1243 || inv.ItemVNum == 5583)
             {
                 session.Character.Mp = (int)session.Character.MPLoad();
             }
             else if (inv.ItemVNum == 1244 || inv.ItemVNum == 5584)
             {
                 session.CurrentMap?.Broadcast(session.Character.GenerateRc((int)session.Character.HPLoad() - session.Character.Hp));
                 session.Character.Hp = (int)session.Character.HPLoad();
                 session.Character.Mp = (int)session.Character.MPLoad();
             }
             session.SendPacket(session.Character.GenerateStat());
             break;
     }
 }
Ejemplo n.º 2
0
 public override void Use(ClientSession session, ref ItemInstance inv, bool delay = false, string[] packetsplit = null)
 {
     if ((DateTime.Now - session.Character.LastPotion).TotalMilliseconds < 750)
     {
         return;
     }
     else
     {
         session.Character.LastPotion = DateTime.Now;
     }
     Item item = inv.Item;
     switch (Effect)
     {
         default:
             if (session.Character.Hp <= 0)
             {
                 return;
             }
             if (!session.Character.IsSitting)
             {
                 session.Character.Rest();
                 session.Character.SnackAmount = 0;
                 session.Character.SnackHp = 0;
                 session.Character.SnackMp = 0;
             }
             int amount = session.Character.SnackAmount;
             if (amount < 5)
             {
                 if (!session.Character.IsSitting)
                 {
                     return;
                 }
                 Thread workerThread = new Thread(() => Regenerate(session, item));
                 workerThread.Start();
                 session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
             }
             else
             {
                 if (session.Character.Gender == Domain.GenderType.Female)
                 {
                     session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("NOT_HUNGRY_FEMALE"), 1));
                 }
                 else
                 {
                     session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("NOT_HUNGRY_MALE"), 1));
                 }
             }
             if (amount == 0)
             {
                 if (!session.Character.IsSitting)
                 {
                     return;
                 }
                 Thread workerThread2 = new Thread(() => Sync(session, item));
                 workerThread2.Start();
             }
             break;
     }
 }
Ejemplo n.º 3
0
 public override void Use(ClientSession session, ref ItemInstance inv, bool delay = false, string[] packetsplit = null)
 {
     switch (Effect)
     {
         default:
             Logger.Log.Warn(String.Format(Language.Instance.GetMessageFromKey("NO_HANDLER_ITEM"), this.GetType().ToString()));
             break;
     }
 }
Ejemplo n.º 4
0
        public override void Use(ClientSession session, ref ItemInstance inv, byte Option = 0, string[] packetsplit = null)
        {
            switch (Effect)
            {
            case 0:
                if (Option == 0)
                {
                    if (packetsplit.Length == 9)
                    {
                        ItemInstance box = session.Character.Inventory.LoadBySlotAndType <ItemInstance>(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
                    ItemInstance box = session.Character.Inventory.LoadBySlotAndType <ItemInstance>(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;
                            foreach (RollGeneratedItemDTO rollitem in roll)
                            {
                                currentrnd += rollitem.Probability;
                                if (currentrnd >= rnd)
                                {
                                    Item  i       = ServerManager.Instance.GetItem(rollitem.ItemGeneratedVNum);
                                    sbyte rare    = 0;
                                    byte  upgrade = 0;
                                    if (i.ItemType == ItemType.Armor || i.ItemType == ItemType.Weapon || i.ItemType == ItemType.Shell)
                                    {
                                        rare = box.Rare;
                                    }
                                    if (i.ItemType == ItemType.Shell)
                                    {
                                        upgrade = (byte)ServerManager.Instance.RandomNumber(50, 81);
                                    }
                                    session.Character.GiftAdd(rollitem.ItemGeneratedVNum, rollitem.ItemGeneratedAmount, (byte)rare, upgrade);
                                    session.SendPacket($"rdi {rollitem.ItemGeneratedVNum} {rollitem.ItemGeneratedAmount}");
                                    session.Character.Inventory.RemoveItemFromInventory(box.Id);
                                    return;

                                    //newInv = session.Character.Inventory.AddNewToInventory(rollitem.ItemGeneratedVNum, amount: rollitem.ItemGeneratedAmount, Design: design, Rare: rare);
                                    //if (newInv.Count > 0)
                                    //{
                                    //    short Slot = inv.Slot;
                                    //    if (Slot != -1)
                                    //    {
                                    //        session.SendPacket(session.Character.GenerateSay(
                                    //            $"{Language.Instance.GetMessageFromKey("ITEM_ACQUIRED")}: {newInv.FirstOrDefault(s => s != null)?.Item?.Name} x {rollitem.ItemGeneratedAmount}",
                                    //            12));
                                    //        newInv.Where(s => s != null).ToList()
                                    //            .ForEach(s => session.SendPacket(s.GenerateInventoryAdd()));
                                    //        session.Character.Inventory
                                    //            .RemoveItemAmountFromInventory(box.Id);
                                    //    }
                                    //}
                                }
                            }
                        }
                        else if (box.HoldingVNum == 0)
                        {
                            if (packetsplit.Length == 1 && int.TryParse(packetsplit[0], out int PetId))
                            {
                                Mate mate = session.Character.Mates.Find(s => s.MateTransportId == PetId);
                                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, 1, MateType.Pet)
                                {
                                    Attack  = box.SpDamage,
                                    Defence = box.SpDefence
                                };
                                if (session.Character.AddPet(mate))
                                {
                                    session.Character.Inventory.RemoveItemFromInventory(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.RemoveItemFromInventory(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)
                {
                    ItemInstance box = session.Character.Inventory.LoadBySlotAndType <ItemInstance>(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.Count > 0)
                            {
                                ItemInstance itemInstance = newInv[0];
                                ItemInstance specialist   = session.Character.Inventory.LoadBySlotAndType <ItemInstance>(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.EquipmentSerialId = box.EquipmentSerialId;
                                    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.RemoveItemFromInventory(box.Id);
                                }
                            }
                            else
                            {
                                session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("NOT_ENOUGH_PLACE"), 0));
                            }
                        }
                    }
                }
                if (EffectValue == 3)
                {
                    ItemInstance box = session.Character.Inventory.LoadBySlotAndType <ItemInstance>(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.Count > 0)
                            {
                                ItemInstance itemInstance = newInv[0];
                                ItemInstance fairy        = session.Character.Inventory.LoadBySlotAndType <ItemInstance>(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.RemoveItemFromInventory(box.Id);
                                }
                            }
                            else
                            {
                                session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("NOT_ENOUGH_PLACE"), 0));
                            }
                        }
                    }
                }
                if (EffectValue == 4)
                {
                    ItemInstance box = session.Character.Inventory.LoadBySlotAndType <ItemInstance>(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.Count > 0)
                            {
                                short Slot = inv.Slot;
                                if (Slot != -1)
                                {
                                    session.SendPacket(session.Character.GenerateSay($"{Language.Instance.GetMessageFromKey("ITEM_ACQUIRED")}: {newInv[0].Item.Name} x 1)", 12));
                                    newInv.ForEach(s => session.SendPacket(s.GenerateInventoryAdd()));
                                    session.Character.Inventory.RemoveItemFromInventory(box.Id);
                                }
                            }
                            else
                            {
                                session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("NOT_ENOUGH_PLACE"), 0));
                            }
                        }
                    }
                }
                break;

            default:
                Logger.Warn(string.Format(Language.Instance.GetMessageFromKey("NO_HANDLER_ITEM"), GetType()));
                break;
            }
        }
Ejemplo n.º 5
0
        public override void Use(ClientSession session, ref ItemInstance inv, bool delay = false, string[] packetsplit = null)
        {
            if (Effect == 0)
            {
                if (EffectValue != 0)
                {
                    if (session.Character.IsSitting)
                    {
                        session.Character.IsSitting = false;
                        session.SendPacket(session.Character.GenerateRest());
                    }
                    session.SendPacket(session.Character.GenerateGuri(12, 1, EffectValue));
                }
                else if (EffectValue == 0)
                {
                    if (packetsplit != null)
                    {
                        byte  TypeEquip;
                        short SlotEquip;

                        if (byte.TryParse(packetsplit[8], out TypeEquip) && short.TryParse(packetsplit[9], out SlotEquip))
                        {
                            if (session.Character.IsSitting)
                            {
                                session.Character.IsSitting = false;
                                session.SendPacket(session.Character.GenerateRest());
                            }
                            if (delay)
                            {
                                bool isUsed = false;
                                switch (inv.ItemVNum)
                                {
                                case 1219:
                                    WearableInstance equip = session.Character.Inventory.LoadBySlotAndType <WearableInstance>(SlotEquip, (Domain.InventoryType)TypeEquip);
                                    if (equip != null && equip.IsFixed)
                                    {
                                        equip.IsFixed = false;
                                        session.SendPacket(session.Character.GenerateEff(3003));
                                        session.SendPacket(session.Character.GenerateGuri(17, 1, 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, (Domain.InventoryType)TypeEquip);
                                    if (specialist != null && specialist.Rare == -2)
                                    {
                                        specialist.Rare = 0;
                                        session.SendPacket(session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("SP_RESURRECTED"), 0));
                                        session.CurrentMapInstance?.Broadcast(session.Character.GenerateGuri(13, 1, 1), session.Character.MapX, session.Character.MapY);
                                        session.Character.SpPoint = 10000;
                                        if (session.Character.SpPoint > 10000)
                                        {
                                            session.Character.SpPoint = 10000;
                                        }
                                        session.SendPacket(session.Character.GenerateSpPoint());
                                        session.SendPacket(session.Character.GenerateInventoryAdd(specialist.ItemVNum, 1, (Domain.InventoryType)TypeEquip, SlotEquip, specialist.Rare, specialist.Design, specialist.Upgrade, 0));
                                        isUsed = true;
                                    }
                                    break;
                                }

                                switch (inv.ItemVNum)
                                {
                                case 9039:
                                    SpecialistInstance specialist = session.Character.Inventory.LoadBySlotAndType <SpecialistInstance>(SlotEquip, (Domain.InventoryType)TypeEquip);
                                    if (specialist != null && specialist.Rare == -2)
                                    {
                                        specialist.Rare = 0;
                                        session.SendPacket(session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("SP_RESURRECTED"), 0));
                                        session.CurrentMapInstance?.Broadcast(session.Character.GenerateGuri(13, 1, 1), session.Character.MapX, session.Character.MapY);
                                        session.Character.SpPoint = 10000;
                                        session.SendPacket(session.Character.GenerateSpPoint());
                                        session.SendPacket(session.Character.GenerateInventoryAdd(specialist.ItemVNum, 1, (Domain.InventoryType)TypeEquip, SlotEquip, specialist.Rare, specialist.Design, specialist.Upgrade, 0));
                                        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()));
            }
        }
        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)
                {
                    int isIllegalCharacter = 0;

                    System.Text.RegularExpressions.Regex rg = new System.Text.RegularExpressions.Regex(@"^[\u0021-\u007E\u00A1-\u00AC\u00AE-\u00FF\u4E00-\u9FA5\u0E01-\u0E3A\u0E3F-\u0E5B]*$");
                    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]),
                                Hp = 221,
                                JobLevel = 1,
                                Level = 1,
                                MapId = 1,
                                MapX = (short)(random.Next(78, 81)),
                                MapY = (short)(random.Next(114, 118)),
                                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
                            };
                            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")}");
                    }
                }
            }
        }
Ejemplo n.º 7
0
        public override void Use(ClientSession session, ref ItemInstance inv, byte Option = 0, string[] packetsplit = null)
        {
            if (session.Character.IsVehicled)
            {
                session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("CANT_DO_VEHICLED"), 10));
                return;
            }

            if (session.CurrentMapInstance.MapInstanceType == MapInstanceType.TalentArenaMapInstance)
            {
                return;
            }

            if (packetsplit == null)
            {
                return;
            }

            void releasePet(MateType mateType, Guid itemToRemoveId)
            {
                if (int.TryParse(packetsplit[3], out int mateTransportId))
                {
                    Mate mate = session.Character.Mates.Find(s => s.MateTransportId == mateTransportId && s.MateType == mateType);
                    if (mate != null)
                    {
                        if (!mate.IsTeamMember)
                        {
                            List <ItemInstance> mateInventory = mate.GetInventory();
                            if (mateInventory.Count > 0)
                            {
                                session.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("EQ_NOT_EMPTY"), 0));
                            }
                            else
                            {
                                session.Character.Mates.Remove(mate);
                                byte i = 0;
                                session.Character.Mates.Where(s => s.MateType == MateType.Partner).ToList().ForEach(s =>
                                {
                                    s.GetInventory().ForEach(item => item.Type = (InventoryType)(13 + i));
                                    s.PetId = i;
                                    i++;
                                });
                                session.SendPacket(UserInterfaceHelper.GenerateInfo(Language.Instance.GetMessageFromKey("PET_RELEASED")));
                                session.SendPacket(UserInterfaceHelper.GeneratePClear());
                                session.SendPackets(session.Character.GenerateScP());
                                session.SendPackets(session.Character.GenerateScN());
                                session.CurrentMapInstance?.Broadcast(mate.GenerateOut());
                                session.Character.Inventory.RemoveItemFromInventory(itemToRemoveId);
                            }
                        }
                        else
                        {
                            session.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("PET_IN_TEAM_UNRELEASABLE"), 0));
                        }
                    }
                }
            }

            if (BCards.Count > 0 && session.Character.MapInstance == session.Character.Miniland)
            {
                BCards.ForEach(c => c.ApplyBCards(session.Character.BattleEntity, session.Character.BattleEntity));
                session.Character.Inventory.RemoveItemFromInventory(inv.Id);
                return;
            }

            switch (Effect)
            {
            case 10:
                if (int.TryParse(packetsplit[3], out int mateTransportId))
                {
                    Mate mate = session.Character.Mates.Find(s => s.MateTransportId == mateTransportId);
                    if (mate == null || mate.MateType != MateType.Pet || mate.Loyalty >= 1000)
                    {
                        return;
                    }
                    mate.Loyalty += 100;
                    if (mate.Loyalty > 1000)
                    {
                        mate.Loyalty = 1000;
                    }
                    mate.GenerateXp(EffectValue);
                    session.SendPacket(mate.GenerateCond());
                    session.SendPacket(StaticPacketHelper.GenerateEff(UserType.Npc, mate.MateTransportId, 5002));
                    session.Character.Inventory.RemoveItemFromInventory(inv.Id);
                }
                break;

            case 11:
                if (int.TryParse(packetsplit[3], out mateTransportId))
                {
                    Mate mate = session.Character.Mates.Find(s => s.MateTransportId == mateTransportId);
                    if (mate == null || mate.MateType != MateType.Pet || mate.Level >= session.Character.Level - 5 || mate.Level + 1 > ServerManager.Instance.Configuration.MaxLevel)
                    {
                        return;
                    }
                    mate.Level++;
                    mate.Hp = mate.MaxHp;
                    mate.Mp = mate.MaxMp;
                    session.SendPacket($"say 2 {mate.MateTransportId} 0 " + Language.Instance.GetMessageFromKey("MATE_POWER_INCREASED"));
                    session.SendPackets(session.Character.GenerateScP());
                    session.CurrentMapInstance?.Broadcast(StaticPacketHelper.GenerateEff(UserType.Npc, mate.MateTransportId, 8), mate.PositionX, mate.PositionY);
                    session.CurrentMapInstance?.Broadcast(StaticPacketHelper.GenerateEff(UserType.Npc, mate.MateTransportId, 198), mate.PositionX, mate.PositionY);
                    session.Character.Inventory.RemoveItemFromInventory(inv.Id);
                }
                break;

            case 12:
                if (int.TryParse(packetsplit[3], out mateTransportId))
                {
                    Mate mate = session.Character.Mates.Find(s => s.MateTransportId == mateTransportId);
                    if (mate == null || mate.MateType != MateType.Partner || mate.Level >= session.Character.Level - 5 || mate.Level + 1 > ServerManager.Instance.Configuration.MaxLevel)
                    {
                        return;
                    }
                    mate.Level++;
                    mate.Hp = mate.MaxHp;
                    mate.Mp = mate.MaxMp;
                    session.SendPacket($"say 2 {mate.MateTransportId} 0 " + Language.Instance.GetMessageFromKey("MATE_POWER_INCREASED"));
                    session.SendPackets(session.Character.GenerateScN());
                    session.CurrentMapInstance?.Broadcast(StaticPacketHelper.GenerateEff(UserType.Npc, mate.MateTransportId, 8), mate.PositionX, mate.PositionY);
                    session.CurrentMapInstance?.Broadcast(StaticPacketHelper.GenerateEff(UserType.Npc, mate.MateTransportId, 198), mate.PositionX, mate.PositionY);
                    session.Character.Inventory.RemoveItemFromInventory(inv.Id);
                }
                break;

            case 13:
                if (int.TryParse(packetsplit[3], out mateTransportId) && session.Character.Mates.FirstOrDefault(s => s.MateTransportId == mateTransportId) is Mate pet)
                {
                    if (pet.MateType == MateType.Pet)
                    {
                        session.SendPacket(UserInterfaceHelper.GenerateGuri(10, 1, mateTransportId, 2));
                    }
                    else
                    {
                        session.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("CANT_CHANGE_PARTNER_NAME"), 0));
                    }
                }
                break;

            case 14:
                if (int.TryParse(packetsplit[3], out mateTransportId))
                {
                    if (session.Character.MapInstance == session.Character.Miniland)
                    {
                        Mate mate = session.Character.Mates.Find(s => s.MateTransportId == mateTransportId && s.MateType == MateType.Pet);
                        if (mate?.CanPickUp == false)
                        {
                            session.CurrentMapInstance.Broadcast(StaticPacketHelper.GenerateEff(UserType.Npc, mate.MateTransportId, 5));
                            session.CurrentMapInstance.Broadcast(StaticPacketHelper.GenerateEff(UserType.Npc, mate.MateTransportId, 5002));
                            session.SendPacket($"say 2 {mate.MateTransportId} 0 " + Language.Instance.GetMessageFromKey("PET_SMART"));
                            mate.CanPickUp = true;
                            session.SendPackets(session.Character.GenerateScP());
                            session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("PET_CAN_PICK_UP"), 10));
                            session.Character.Inventory.RemoveItemFromInventory(inv.Id);
                        }
                    }
                    else
                    {
                        session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("NOT_IN_MINILAND"), 12));
                    }
                }
                break;

            case 16:
                if (int.TryParse(packetsplit[3], out mateTransportId))
                {
                    Mate mate = session.Character.Mates.Find(s => s.MateTransportId == mateTransportId);
                    if (mate == null || mate.MateType != MateType.Pet || mate.Level == 1)
                    {
                        return;
                    }
                    mate.Level--;
                    mate.Hp = mate.MaxHp;
                    mate.Mp = mate.MaxMp;
                    session.SendPacket($"say 2 {mate.MateTransportId} 0 " + Language.Instance.GetMessageFromKey("MATE_POWER_DECREASED"));
                    session.SendPackets(session.Character.GenerateScP());
                    session.CurrentMapInstance?.Broadcast(StaticPacketHelper.GenerateEff(UserType.Npc, mate.MateTransportId, 198), mate.PositionX, mate.PositionY);
                    session.Character.Inventory.RemoveItemFromInventory(inv.Id);
                }
                break;

            case 17:
                if (int.TryParse(packetsplit[3], out mateTransportId))
                {
                    Mate mate = session.Character.Mates.Find(s => s.MateTransportId == mateTransportId);
                    if (mate?.IsSummonable == false)
                    {
                        mate.IsSummonable = true;
                        session.SendPackets(session.Character.GenerateScP());
                        session.SendPacket(session.Character.GenerateSay(string.Format(Language.Instance.GetMessageFromKey("PET_SUMMONABLE"), mate.Name), 10));
                        session.SendPacket(UserInterfaceHelper.GenerateMsg(string.Format(Language.Instance.GetMessageFromKey("PET_SUMMONABLE"), mate.Name), 0));
                        session.Character.Inventory.RemoveItemFromInventory(inv.Id);
                    }
                }
                break;

            case 18:
                if (int.TryParse(packetsplit[3], out mateTransportId))
                {
                    Mate mate = session.Character.Mates.Find(s => s.MateTransportId == mateTransportId);
                    if (mate == null || mate.MateType != MateType.Partner || mate.Level == 1)
                    {
                        return;
                    }
                    mate.Level--;
                    mate.Hp = mate.MaxHp;
                    mate.Mp = mate.MaxMp;
                    session.SendPacket($"say 2 {mate.MateTransportId} 0 " + Language.Instance.GetMessageFromKey("MATE_POWER_DECREASED"));
                    session.SendPackets(session.Character.GenerateScN());
                    session.CurrentMapInstance?.Broadcast(StaticPacketHelper.GenerateEff(UserType.Npc, mate.MateTransportId, 198), mate.PositionX, mate.PositionY);
                    session.Character.Inventory.RemoveItemFromInventory(inv.Id);
                }
                break;

            case 1000:
                releasePet(MateType.Pet, inv.Id);
                break;

            case 1001:
                releasePet(MateType.Partner, inv.Id);
                break;

            case 1339:
                int rndevolve = ServerManager.RandomNumber(0, 1000);
                if (rndevolve > 900)
                {
                    if (int.TryParse(packetsplit[3], out mateTransportId))
                    {
                        Mate mate = session.Character.Mates.Find(s => s.MateTransportId == mateTransportId);
                        if (mate == null)
                        {
                            session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("PICK_PET"), 10));
                            return;
                        }
                        if (mate.Level >= 30 && mate.NpcMonsterVNum == 649 && mate.IsTeamMember == true && mate.MateType == MateType.Pet)
                        {
                            mate.Level          = 1;
                            mate.NpcMonsterVNum = 650;
                            session.CurrentMapInstance.Broadcast(StaticPacketHelper.GenerateEff(UserType.Npc, mate.MateTransportId, 5));
                            session.CurrentMapInstance.Broadcast(StaticPacketHelper.GenerateEff(UserType.Npc, mate.MateTransportId, 5002));
                            session.SendPackets(session.Character.GenerateScP());
                            session.SendPackets(session.Character.GenerateScN());
                            session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("PET_EVOLED"), 10));
                            if (session?.Character != null)
                            {
                                if (session.Character.Miniland == session.Character.MapInstance)
                                {
                                    ServerManager.Instance.JoinMiniland(session, session);
                                }
                                else
                                {
                                    ServerManager.Instance.ChangeMapInstance(session.Character.CharacterId,
                                                                             session.Character.MapInstanceId, session.Character.PositionX, session.Character.PositionY,
                                                                             true);
                                    session.SendPacket(StaticPacketHelper.Cancel(2));
                                }
                            }
                        }
                        else
                        {
                            if (mate.Level >= 30 && mate.NpcMonsterVNum == 648 && mate.IsTeamMember == true && mate.MateType == MateType.Pet)
                            {
                                mate.Level          = 1;
                                mate.NpcMonsterVNum = 649;
                                session.CurrentMapInstance.Broadcast(StaticPacketHelper.GenerateEff(UserType.Npc, mate.MateTransportId, 5));
                                session.CurrentMapInstance.Broadcast(StaticPacketHelper.GenerateEff(UserType.Npc, mate.MateTransportId, 5002));
                                session.SendPackets(session.Character.GenerateScP());
                                session.SendPackets(session.Character.GenerateScN());
                                session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("PET_EVOLED"), 10));
                                if (session?.Character != null)
                                {
                                    if (session.Character.Miniland == session.Character.MapInstance)
                                    {
                                        ServerManager.Instance.JoinMiniland(session, session);
                                    }
                                    else
                                    {
                                        ServerManager.Instance.ChangeMapInstance(session.Character.CharacterId,
                                                                                 session.Character.MapInstanceId, session.Character.PositionX, session.Character.PositionY,
                                                                                 true);
                                        session.SendPacket(StaticPacketHelper.Cancel(2));
                                    }
                                }
                            }
                            else
                            {
                                if (mate.Level >= 30 && mate.NpcMonsterVNum == 651 && mate.IsTeamMember == true && mate.MateType == MateType.Pet)
                                {
                                    mate.Level          = 1;
                                    mate.NpcMonsterVNum = 652;
                                    session.CurrentMapInstance.Broadcast(StaticPacketHelper.GenerateEff(UserType.Npc, mate.MateTransportId, 5));
                                    session.CurrentMapInstance.Broadcast(StaticPacketHelper.GenerateEff(UserType.Npc, mate.MateTransportId, 5002));
                                    session.SendPackets(session.Character.GenerateScP());
                                    session.SendPackets(session.Character.GenerateScN());
                                    session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("PET_EVOLED"), 10));
                                    if (session?.Character != null)
                                    {
                                        if (session.Character.Miniland == session.Character.MapInstance)
                                        {
                                            ServerManager.Instance.JoinMiniland(session, session);
                                        }
                                        else
                                        {
                                            ServerManager.Instance.ChangeMapInstance(session.Character.CharacterId,
                                                                                     session.Character.MapInstanceId, session.Character.PositionX, session.Character.PositionY,
                                                                                     true);
                                            session.SendPacket(StaticPacketHelper.Cancel(2));
                                        }
                                    }
                                }
                                else
                                {
                                    if (mate.Level >= 30 && mate.NpcMonsterVNum == 652 && mate.IsTeamMember == true && mate.MateType == MateType.Pet)
                                    {
                                        mate.Level          = 1;
                                        mate.NpcMonsterVNum = 653;
                                        session.CurrentMapInstance.Broadcast(StaticPacketHelper.GenerateEff(UserType.Npc, mate.MateTransportId, 5));
                                        session.CurrentMapInstance.Broadcast(StaticPacketHelper.GenerateEff(UserType.Npc, mate.MateTransportId, 5002));
                                        session.SendPackets(session.Character.GenerateScP());
                                        session.SendPackets(session.Character.GenerateScN());
                                        session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("PET_EVOLED"), 10));
                                        if (session?.Character != null)
                                        {
                                            if (session.Character.Miniland == session.Character.MapInstance)
                                            {
                                                ServerManager.Instance.JoinMiniland(session, session);
                                            }
                                            else
                                            {
                                                ServerManager.Instance.ChangeMapInstance(session.Character.CharacterId,
                                                                                         session.Character.MapInstanceId, session.Character.PositionX, session.Character.PositionY,
                                                                                         true);
                                                session.SendPacket(StaticPacketHelper.Cancel(2));
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (mate.Level >= 30 && mate.NpcMonsterVNum == 660 && mate.IsTeamMember == true && mate.MateType == MateType.Pet)
                                        {
                                            mate.Level          = 1;
                                            mate.NpcMonsterVNum = 661;
                                            session.CurrentMapInstance.Broadcast(StaticPacketHelper.GenerateEff(UserType.Npc, mate.MateTransportId, 5));
                                            session.CurrentMapInstance.Broadcast(StaticPacketHelper.GenerateEff(UserType.Npc, mate.MateTransportId, 5002));
                                            session.SendPackets(session.Character.GenerateScP());
                                            session.SendPackets(session.Character.GenerateScN());
                                            session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("PET_EVOLED"), 10));
                                            if (session?.Character != null)
                                            {
                                                if (session.Character.Miniland == session.Character.MapInstance)
                                                {
                                                    ServerManager.Instance.JoinMiniland(session, session);
                                                }
                                                else
                                                {
                                                    ServerManager.Instance.ChangeMapInstance(session.Character.CharacterId,
                                                                                             session.Character.MapInstanceId, session.Character.PositionX, session.Character.PositionY,
                                                                                             true);
                                                    session.SendPacket(StaticPacketHelper.Cancel(2));
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if (mate.Level >= 30 && mate.NpcMonsterVNum == 661 && mate.IsTeamMember == true && mate.MateType == MateType.Pet)
                                            {
                                                mate.Level          = 1;
                                                mate.NpcMonsterVNum = 662;
                                                session.CurrentMapInstance.Broadcast(StaticPacketHelper.GenerateEff(UserType.Npc, mate.MateTransportId, 5));
                                                session.CurrentMapInstance.Broadcast(StaticPacketHelper.GenerateEff(UserType.Npc, mate.MateTransportId, 5002));
                                                session.SendPackets(session.Character.GenerateScP());
                                                session.SendPackets(session.Character.GenerateScN());
                                                session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("PET_EVOLED"), 10));
                                                if (session?.Character != null)
                                                {
                                                    if (session.Character.Miniland == session.Character.MapInstance)
                                                    {
                                                        ServerManager.Instance.JoinMiniland(session, session);
                                                    }
                                                    else
                                                    {
                                                        ServerManager.Instance.ChangeMapInstance(session.Character.CharacterId,
                                                                                                 session.Character.MapInstanceId, session.Character.PositionX, session.Character.PositionY,
                                                                                                 true);
                                                        session.SendPacket(StaticPacketHelper.Cancel(2));
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                if (mate.Level >= 30 && mate.NpcMonsterVNum == 657 && mate.IsTeamMember == true && mate.MateType == MateType.Pet)
                                                {
                                                    mate.Level          = 1;
                                                    mate.NpcMonsterVNum = 658;
                                                    session.CurrentMapInstance.Broadcast(StaticPacketHelper.GenerateEff(UserType.Npc, mate.MateTransportId, 5));
                                                    session.CurrentMapInstance.Broadcast(StaticPacketHelper.GenerateEff(UserType.Npc, mate.MateTransportId, 5002));
                                                    session.SendPackets(session.Character.GenerateScP());
                                                    session.SendPackets(session.Character.GenerateScN());
                                                    session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("PET_EVOLED"), 10));
                                                    if (session?.Character != null)
                                                    {
                                                        if (session.Character.Miniland == session.Character.MapInstance)
                                                        {
                                                            ServerManager.Instance.JoinMiniland(session, session);
                                                        }
                                                        else
                                                        {
                                                            ServerManager.Instance.ChangeMapInstance(session.Character.CharacterId,
                                                                                                     session.Character.MapInstanceId, session.Character.PositionX, session.Character.PositionY,
                                                                                                     true);
                                                            session.SendPacket(StaticPacketHelper.Cancel(2));
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    if (mate.Level >= 30 && mate.NpcMonsterVNum == 658 && mate.IsTeamMember == true && mate.MateType == MateType.Pet)
                                                    {
                                                        mate.Level          = 1;
                                                        mate.NpcMonsterVNum = 659;
                                                        session.CurrentMapInstance.Broadcast(StaticPacketHelper.GenerateEff(UserType.Npc, mate.MateTransportId, 5));
                                                        session.CurrentMapInstance.Broadcast(StaticPacketHelper.GenerateEff(UserType.Npc, mate.MateTransportId, 5002));
                                                        session.SendPackets(session.Character.GenerateScP());
                                                        session.SendPackets(session.Character.GenerateScN());
                                                        session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("PET_EVOLED"), 10));
                                                        if (session?.Character != null)
                                                        {
                                                            if (session.Character.Miniland == session.Character.MapInstance)
                                                            {
                                                                ServerManager.Instance.JoinMiniland(session, session);
                                                            }
                                                            else
                                                            {
                                                                ServerManager.Instance.ChangeMapInstance(session.Character.CharacterId,
                                                                                                         session.Character.MapInstanceId, session.Character.PositionX, session.Character.PositionY,
                                                                                                         true);
                                                                session.SendPacket(StaticPacketHelper.Cancel(2));
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        if (mate.Level >= 30 && mate.NpcMonsterVNum == 660 && mate.IsTeamMember == true && mate.MateType == MateType.Pet)
                                                        {
                                                            mate.Level          = 1;
                                                            mate.NpcMonsterVNum = 661;
                                                            session.CurrentMapInstance.Broadcast(StaticPacketHelper.GenerateEff(UserType.Npc, mate.MateTransportId, 5));
                                                            session.CurrentMapInstance.Broadcast(StaticPacketHelper.GenerateEff(UserType.Npc, mate.MateTransportId, 5002));
                                                            session.SendPackets(session.Character.GenerateScP());
                                                            session.SendPackets(session.Character.GenerateScN());
                                                            session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("PET_EVOLED"), 10));
                                                            if (session?.Character != null)
                                                            {
                                                                if (session.Character.Miniland == session.Character.MapInstance)
                                                                {
                                                                    ServerManager.Instance.JoinMiniland(session, session);
                                                                }
                                                                else
                                                                {
                                                                    ServerManager.Instance.ChangeMapInstance(session.Character.CharacterId,
                                                                                                             session.Character.MapInstanceId, session.Character.PositionX, session.Character.PositionY,
                                                                                                             true);
                                                                    session.SendPacket(StaticPacketHelper.Cancel(2));
                                                                }
                                                            }
                                                        }
                                                        else
                                                        {
                                                            if (mate.Level >= 30 && mate.NpcMonsterVNum == 988 && mate.IsTeamMember == true && mate.MateType == MateType.Pet)
                                                            {
                                                                mate.Level          = 1;
                                                                mate.NpcMonsterVNum = 416;
                                                                session.CurrentMapInstance.Broadcast(StaticPacketHelper.GenerateEff(UserType.Npc, mate.MateTransportId, 5));
                                                                session.CurrentMapInstance.Broadcast(StaticPacketHelper.GenerateEff(UserType.Npc, mate.MateTransportId, 5002));
                                                                session.SendPackets(session.Character.GenerateScP());
                                                                session.SendPackets(session.Character.GenerateScN());
                                                                session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("PET_EVOLED"), 10));
                                                                if (session?.Character != null)
                                                                {
                                                                    if (session.Character.Miniland == session.Character.MapInstance)
                                                                    {
                                                                        ServerManager.Instance.JoinMiniland(session, session);
                                                                    }
                                                                    else
                                                                    {
                                                                        ServerManager.Instance.ChangeMapInstance(session.Character.CharacterId,
                                                                                                                 session.Character.MapInstanceId, session.Character.PositionX, session.Character.PositionY,
                                                                                                                 true);
                                                                        session.SendPacket(StaticPacketHelper.Cancel(2));
                                                                    }
                                                                }
                                                            }
                                                            else
                                                            {
                                                                if (mate.Level >= 30 && mate.NpcMonsterVNum == 416 && mate.IsTeamMember == true && mate.MateType == MateType.Pet)
                                                                {
                                                                    mate.Level          = 1;
                                                                    mate.NpcMonsterVNum = 412;
                                                                    session.CurrentMapInstance.Broadcast(StaticPacketHelper.GenerateEff(UserType.Npc, mate.MateTransportId, 5));
                                                                    session.CurrentMapInstance.Broadcast(StaticPacketHelper.GenerateEff(UserType.Npc, mate.MateTransportId, 5002));
                                                                    session.SendPackets(session.Character.GenerateScP());
                                                                    session.SendPackets(session.Character.GenerateScN());
                                                                    session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("PET_EVOLED"), 10));
                                                                    if (session?.Character != null)
                                                                    {
                                                                        if (session.Character.Miniland == session.Character.MapInstance)
                                                                        {
                                                                            ServerManager.Instance.JoinMiniland(session, session);
                                                                        }
                                                                        else
                                                                        {
                                                                            ServerManager.Instance.ChangeMapInstance(session.Character.CharacterId,
                                                                                                                     session.Character.MapInstanceId, session.Character.PositionX, session.Character.PositionY,
                                                                                                                     true);
                                                                            session.SendPacket(StaticPacketHelper.Cancel(2));
                                                                        }
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    if (mate.Level >= 30 && mate.NpcMonsterVNum == 412 && mate.IsTeamMember == true && mate.MateType == MateType.Pet)
                                                                    {
                                                                        mate.Level          = 1;
                                                                        mate.NpcMonsterVNum = 414;
                                                                        session.CurrentMapInstance.Broadcast(StaticPacketHelper.GenerateEff(UserType.Npc, mate.MateTransportId, 5));
                                                                        session.CurrentMapInstance.Broadcast(StaticPacketHelper.GenerateEff(UserType.Npc, mate.MateTransportId, 5002));
                                                                        session.SendPackets(session.Character.GenerateScP());
                                                                        session.SendPackets(session.Character.GenerateScN());
                                                                        session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("PET_EVOLED"), 10));
                                                                        if (session?.Character != null)
                                                                        {
                                                                            if (session.Character.Miniland == session.Character.MapInstance)
                                                                            {
                                                                                ServerManager.Instance.JoinMiniland(session, session);
                                                                            }
                                                                            else
                                                                            {
                                                                                ServerManager.Instance.ChangeMapInstance(session.Character.CharacterId,
                                                                                                                         session.Character.MapInstanceId, session.Character.PositionX, session.Character.PositionY,
                                                                                                                         true);
                                                                                session.SendPacket(StaticPacketHelper.Cancel(2));
                                                                            }
                                                                        }
                                                                    }
                                                                    else
                                                                    {
                                                                    }
                                                                }
                                                            }
                                                        }
                                                        break;
                                                    }
                                                    break;
                                                }
                                                break;
                                            }
                                            break;
                                        }
                                        break;
                                    }
                                    break;
                                }
                                break;
                            }
                            break;
                        }
                        break;
                    }
                    else
                    {
                        session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("PET_NOT_EVOLED"), 10));
                    }
                    break;
                }
                else
                {
                    session.Character.Inventory.RemoveItemFromInventory(inv.Id);
                    session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("PET_NOT_EVOLED"), 10));
                }
                break;

            case 2137:
                int rnd = ServerManager.RandomNumber(0, 1000);
                {
                    if (int.TryParse(packetsplit[3], out mateTransportId))
                    {
                        Mate mate = session.Character.Mates.Find(s => s.MateTransportId == mateTransportId);
                        if (mate == null)
                        {
                            session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("PICK_PET"), 10));
                        }
                        else
                        if (mate.Defence <= 9 || mate.Attack <= 9)
                        {
                            if (rnd >= 600 && rnd <= 800)
                            {
                                mate.Attack++;
                                session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("ATTACK_PLUS"), 10));
                                session.CurrentMapInstance.Broadcast(StaticPacketHelper.GenerateEff(UserType.Player, session.Character.CharacterId, 3004), session.Character.MapX, session.Character.MapY);
                            }
                            else if (rnd >= 801 && rnd <= 1000)
                            {
                                mate.Defence++;
                                session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("DEF_PLUS"), 10));
                                session.CurrentMapInstance.Broadcast(StaticPacketHelper.GenerateEff(UserType.Player, session.Character.CharacterId, 3004), session.Character.MapX, session.Character.MapY);
                            }
                            else if (rnd <= 800 && rnd >= 400)
                            {
                                if (mate.Defence == 0)
                                {
                                    return;
                                }
                                else
                                {
                                    mate.Defence--;
                                    session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("DEF_MINUS"), 10));
                                    session.CurrentMapInstance.Broadcast(StaticPacketHelper.GenerateEff(UserType.Player, session.Character.CharacterId, 3005), session.Character.MapX, session.Character.MapY);
                                }
                            }
                            else if (rnd <= 399 && rnd >= 0)
                            {
                                if (mate.Attack == 0)
                                {
                                    return;
                                }
                                else
                                {
                                    mate.Attack--;
                                    session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("ATTACK_MINUS"), 10));
                                    session.CurrentMapInstance.Broadcast(StaticPacketHelper.GenerateEff(UserType.Player, session.Character.CharacterId, 3005), session.Character.MapX, session.Character.MapY);
                                }
                            }
                            else
                            {
                                return;
                            }
                        }
                        else
                        {
                            return;
                        }
                    }
                    else
                    {
                        return;
                    }
                    session.Character.Inventory.RemoveItemAmount(2079, 1);
                }
                break;

            default:
                Logger.Warn(string.Format(Language.Instance.GetMessageFromKey("NO_HANDLER_ITEM"), GetType(), VNum, Effect, EffectValue));
                break;
            }
        }
Ejemplo n.º 8
0
        public void UpgradeSp(ClientSession Session, UpgradeProtection protect)
        {
            short[] upsuccess = { 100, 100, 95, 90, 85, 80, 75, 70, 65, 60, 55, 50, 45, 40, 30 };
            short[] upfail    = { 20, 25, 25, 30, 35, 40, 40, 40, 40, 40, 45, 43, 40, 37, 29 };

            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 };
            short   featherVnum     = 2282;
            short   fullmoonVnum    = 1030;
            short   greenSoulVnum   = 2283;
            short   redSoulVnum     = 2284;
            short   blueSoulVnum    = 2285;
            short   dragonSkinVnum  = 2511;
            short   dragonBloodVnum = 2512;
            short   dragonHeartVnum = 2513;
            short   blueScrollVnum  = 1363;
            short   redScrollVnum   = 1364;

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

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

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

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

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

            if (rnd <= upfail[Upgrade])
            {
                if (protect == UpgradeProtection.Protected)
                {
                    Session.CurrentMap.Broadcast(Session.Character.GenerateEff(3004), Session.Character.MapX, Session.Character.MapY);
                }
                Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("UPGRADESP_FAILED"), 11));
                Session.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("UPGRADESP_FAILED"), 0));
            }
            else if (rnd <= upsuccess[Upgrade])
            {
                if (protect == UpgradeProtection.Protected)
                {
                    Session.CurrentMap.Broadcast(Session.Character.GenerateEff(3004), Session.Character.MapX, Session.Character.MapY);
                }
                Session.CurrentMap.Broadcast(Session.Character.GenerateEff(3005), Session.Character.MapX, Session.Character.MapY);
                Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("UPGRADESP_SUCCESS"), 12));
                Session.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("UPGRADESP_SUCCESS"), 0));
                wearable.Upgrade++;
                Session.SendPacket(Session.Character.GenerateInventoryAdd(ItemVNum, 1, inventory.Type, inventory.Slot, wearable.Rare, wearable.Design, wearable.Upgrade, SpStoneUpgrade));
            }
            else
            {
                if (protect == UpgradeProtection.Protected)
                {
                    Session.CurrentMap.Broadcast(Session.Character.GenerateEff(3004), Session.Character.MapX, Session.Character.MapY);
                    Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("UPGRADESP_FAILED_SAVED"), 11));
                    Session.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("UPGRADESP_FAILED_SAVED"), 0));
                }
                else
                {
                    wearable.Rare = -2;
                    Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("UPGRADESP_DESTROYED"), 11));
                    Session.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("UPGRADESP_DESTROYED"), 0));
                    Session.SendPacket(Session.Character.GenerateInventoryAdd(ItemVNum, 1, inventory.Type, inventory.Slot, wearable.Rare, wearable.Design, wearable.Upgrade, SpStoneUpgrade));
                }
            }
            Session.SendPacket(Session.Character.GenerateGold());
            Session.SendPacket(Session.Character.GenerateEq());
            Session.SendPacket("shop_end 1");
        }
Ejemplo n.º 9
0
        public override void Use(ClientSession session, ref ItemInstance inv, byte option = 0, string[] packetsplit = null)
        {
            switch (Effect)
            {
            // airwaves - eventitems
            case 0:
                if (ItemType == ItemType.Event)
                {
                    session.CurrentMapInstance?.Broadcast(session.Character.GenerateEff(EffectValue));
                    if (MappingHelper.Instance.GuriItemEffects.ContainsKey(EffectValue))
                    {
                        session.CurrentMapInstance?.Broadcast(UserInterfaceHelper.Instance.GenerateGuri(19, 1, session.Character.CharacterId, MappingHelper.Instance.GuriItemEffects[EffectValue]), session.Character.MapX, session.Character.MapY);
                    }
                    session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                }
                // APPLY SHELL ON EQUIPMENT
                if (inv.Item.ItemType == ItemType.Shell)
                {
                    if (!((WearableInstance)inv).EquipmentOptions.Any())
                    {
                        session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("SHELL_MUST_BE_IDENTIFIED"), 0));
                        return;
                    }
                    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;
                    }

                    if (!int.TryParse(packetsplit[6], out int requestType))
                    {
                        return;
                    }

                    WearableInstance shell = (WearableInstance)inv;
                    WearableInstance eq    = session.Character.Inventory.LoadBySlotAndType <WearableInstance>(eqSlot, eqType);

                    if (eq == null)
                    {
                        // PACKET MODIFIED
                        return;
                    }
                    if (eq.Item.ItemType != ItemType.Armor && shell.Item.ItemSubType == 1)
                    {
                        // ARMOR SHELL ONLY APPLY ON ARMORS
                        session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("SHELL_FOR_ARMOR_ONLY"), 0));
                        return;
                    }
                    if (eq.Item.ItemType != ItemType.Weapon && shell.Item.ItemSubType == 0)
                    {
                        // WEAPON SHELL ONLY APPLY ON WEAPONS
                        session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("SHELL_FOR_WEAPON_ONLY"), 0));
                        return;
                    }
                    switch (requestType)
                    {
                    case 0:
                        session.SendPacket(eq.EquipmentOptions.Any()
                                    ? $"qna #u_i^1^{session.Character.CharacterId}^{(short) inv.Type}^{inv.Slot}^1^1^{(short) eqType}^{eqSlot} {Language.Instance.GetMessageFromKey("ADD_OPTION_ON_STUFF_NOT_EMPTY")}"
                                    : $"qna #u_i^1^{session.Character.CharacterId}^{(short) inv.Type}^{inv.Slot}^1^1^{(short) eqType}^{eqSlot} {Language.Instance.GetMessageFromKey("ADD_OPTION_ON_STUFF")}");
                        break;

                    case 1:
                        if (shell.EquipmentOptions == null)
                        {
                            // SHELL NOT IDENTIFIED
                            return;
                        }
                        if (eq.BoundCharacterId != session.Character.CharacterId && eq.BoundCharacterId != null)
                        {
                            // NEED TO PERFUME STUFF BEFORE CHANGING SHELL
                            session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("NEED_PARFUM_TO_CHANGE_SHELL"), 0));
                            return;
                        }
                        if (eq.Rare < shell.Rare)
                        {
                            // RARITY TOO HIGH ON SHELL
                            session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("SHELL_RARITY_TOO_HIGH"), 0));
                            return;
                        }
                        if (eq.Item.LevelMinimum < shell.Upgrade)
                        {
                            // SHELL LEVEL TOO HIGH
                            session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("SHELL_LEVEL_TOO_HIGH"), 0));
                            return;
                        }

                        if (eq.EquipmentOptions?.Any() == true)
                        {
                            if (new Random().Next(100) >= 50)
                            {
                                // BREAK BECAUSE DIDN'T USE MAGIC ERASER
                                session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("SHELL_BROKEN"), 0));
                                session.Character.Inventory.RemoveItemAmountFromInventory(1, shell.Id);
                                return;
                            }
                        }
                        if (eq.EquipmentOptions == null)
                        {
                            eq.EquipmentOptions = new List <EquipmentOptionDTO>();
                        }

                        eq.EquipmentOptions.Clear();
                        foreach (EquipmentOptionDTO i in shell.EquipmentOptions)
                        {
                            session.SendPacket(UserInterfaceHelper.Instance.GenerateGuri(17, 1, session.Character.CharacterId));
                            session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("SHELL_OPTION_SET"), 0));
                            eq.EquipmentOptions.Add(i);
                        }

                        eq.BoundCharacterId = session.Character.CharacterId;
                        eq.ShellRarity      = shell.Rare;
                        session.Character.Inventory.RemoveItemAmountFromInventory(1, shell.Id);
                        break;
                    }
                }
                break;

            //respawn objects
            case 1:
                if (session.Character.MapInstance.MapInstanceType != MapInstanceType.BaseMapInstance)
                {
                    session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("CANT_USE_THAT"), 10));
                    return;
                }
                if (packetsplit != null && int.TryParse(packetsplit[2], out var type) && int.TryParse(packetsplit[3], out var secondaryType) && int.TryParse(packetsplit[4], out var inventoryType) && int.TryParse(packetsplit[5], out var slot))
                {
                    int packetType;
                    switch (EffectValue)
                    {
                    case 0:
                        if (option == 0)
                        {
                            session.SendPacket(UserInterfaceHelper.Instance.GenerateDialog($"#u_i^{type}^{secondaryType}^{inventoryType}^{slot}^1 #u_i^{type}^{secondaryType}^{inventoryType}^{slot}^2 {Language.Instance.GetMessageFromKey("WANT_TO_SAVE_POSITION")}"));
                        }
                        else
                        {
                            if (int.TryParse(packetsplit[6], out packetType))
                            {
                                switch (packetType)
                                {
                                case 1:
                                    session.SendPacket(UserInterfaceHelper.Instance.GenerateDelay(5000, 7, $"#u_i^{type}^{secondaryType}^{inventoryType}^{slot}^3"));
                                    break;

                                case 2:
                                    session.SendPacket(UserInterfaceHelper.Instance.GenerateDelay(5000, 7, $"#u_i^{type}^{secondaryType}^{inventoryType}^{slot}^4"));
                                    break;

                                case 3:
                                    session.Character.SetReturnPoint(session.Character.MapId, session.Character.MapX, session.Character.MapY);
                                    RespawnMapTypeDTO respawn = session.Character.Respawn;
                                    if (respawn.DefaultX != 0 && respawn.DefaultY != 0 && respawn.DefaultMapId != 0)
                                    {
                                        ServerManager.Instance.ChangeMap(session.Character.CharacterId, respawn.DefaultMapId, (short)(respawn.DefaultX + ServerManager.Instance.RandomNumber(-5, 5)), (short)(respawn.DefaultY + ServerManager.Instance.RandomNumber(-5, 5)));
                                    }
                                    session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                                    break;

                                case 4:
                                    RespawnMapTypeDTO respawnObj = session.Character.Respawn;
                                    if (respawnObj.DefaultX != 0 && respawnObj.DefaultY != 0 && respawnObj.DefaultMapId != 0)
                                    {
                                        ServerManager.Instance.ChangeMap(session.Character.CharacterId, respawnObj.DefaultMapId, (short)(respawnObj.DefaultX + ServerManager.Instance.RandomNumber(-5, 5)), (short)(respawnObj.DefaultY + ServerManager.Instance.RandomNumber(-5, 5)));
                                    }
                                    session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                                    break;
                                }
                            }
                        }
                        break;

                    case 1:
                        if (int.TryParse(packetsplit[6], out packetType))
                        {
                            RespawnMapTypeDTO respawn = session.Character.Return;
                            switch (packetType)
                            {
                            case 0:
                                if (respawn.DefaultX != 0 && respawn.DefaultY != 0 && respawn.DefaultMapId != 0)
                                {
                                    session.SendPacket(UserInterfaceHelper.Instance.GenerateRp(respawn.DefaultMapId, respawn.DefaultX, respawn.DefaultY, $"#u_i^{type}^{secondaryType}^{inventoryType}^{slot}^1"));
                                }
                                break;

                            case 1:
                                session.SendPacket(UserInterfaceHelper.Instance.GenerateDelay(5000, 7, $"#u_i^{type}^{secondaryType}^{inventoryType}^{slot}^2"));
                                break;

                            case 2:
                                if (respawn.DefaultX != 0 && respawn.DefaultY != 0 && respawn.DefaultMapId != 0)
                                {
                                    ServerManager.Instance.ChangeMap(session.Character.CharacterId, respawn.DefaultMapId, respawn.DefaultX, respawn.DefaultY);
                                }
                                session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                                break;
                            }
                        }
                        break;

                    case 2:
                        if (option == 0)
                        {
                            session.SendPacket(UserInterfaceHelper.Instance.GenerateDelay(5000, 7, $"#u_i^{type}^{secondaryType}^{inventoryType}^{slot}^1"));
                        }
                        else
                        {
                            ServerManager.Instance.JoinMiniland(session, session);
                            session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                        }
                        break;
                    }
                }
                break;

            // dyes or waxes
            case 10:
            case 11:
                if (!session.Character.IsVehicled)
                {
                    if (Effect == 10)
                    {
                        if (EffectValue == 99)
                        {
                            byte nextValue = (byte)ServerManager.Instance.RandomNumber(0, 127);
                            session.Character.HairColor = Enum.IsDefined(typeof(HairColorType), nextValue) ? (HairColorType)nextValue : 0;
                        }
                        else
                        {
                            session.Character.HairColor = Enum.IsDefined(typeof(HairColorType), (byte)EffectValue) ? (HairColorType)EffectValue : 0;
                        }
                    }
                    else
                    {
                        if (session.Character.Class == (byte)ClassType.Adventurer && EffectValue > 1)
                        {
                            session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("ADVENTURERS_CANT_USE"), 10));
                            return;
                        }
                        session.Character.HairStyle = Enum.IsDefined(typeof(HairStyleType), (byte)EffectValue) ? (HairStyleType)EffectValue : 0;
                    }
                    session.SendPacket(session.Character.GenerateEq());
                    session.CurrentMapInstance?.Broadcast(session, session.Character.GenerateIn());
                    session.CurrentMapInstance?.Broadcast(session, session.Character.GenerateGidx());
                    session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                }
                break;

            // dignity restoration
            case 14:
                if ((EffectValue == 100 || EffectValue == 200) && session.Character.Dignity < 100 && !session.Character.IsVehicled)
                {
                    session.Character.Dignity += EffectValue;
                    if (session.Character.Dignity > 100)
                    {
                        session.Character.Dignity = 100;
                    }
                    session.SendPacket(session.Character.GenerateFd());
                    session.SendPacket(session.Character.GenerateEff(49 - (byte)session.Character.Faction));
                    session.CurrentMapInstance?.Broadcast(session, session.Character.GenerateIn(), ReceiverType.AllExceptMe);
                    session.CurrentMapInstance?.Broadcast(session, session.Character.GenerateGidx(), ReceiverType.AllExceptMe);
                    session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                }
                else if (EffectValue == 2000 && session.Character.Dignity < 100 && !session.Character.IsVehicled)
                {
                    session.Character.Dignity = 100;
                    session.SendPacket(session.Character.GenerateFd());
                    session.SendPacket(session.Character.GenerateEff(49 - (byte)session.Character.Faction));
                    session.CurrentMapInstance?.Broadcast(session, session.Character.GenerateIn(), ReceiverType.AllExceptMe);
                    session.CurrentMapInstance?.Broadcast(session, session.Character.GenerateGidx(), ReceiverType.AllExceptMe);
                    session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                }
                break;

            // speakers
            case 15:
                if (!session.Character.IsVehicled)
                {
                    if (option == 0)
                    {
                        session.SendPacket(UserInterfaceHelper.Instance.GenerateGuri(10, 3, session.Character.CharacterId, 1));
                    }
                }
                break;

            // bubbles
            case 16:
                if (!session.Character.IsVehicled)
                {
                    if (option == 0)
                    {
                        session.SendPacket(UserInterfaceHelper.Instance.GenerateGuri(10, 4, session.Character.CharacterId, 1));
                    }
                }
                break;

            // wigs
            case 30:
                if (!session.Character.IsVehicled)
                {
                    WearableInstance wig = session.Character.Inventory.LoadBySlotAndType <WearableInstance>((byte)EquipmentType.Hat, InventoryType.Wear);
                    if (wig != null)
                    {
                        wig.Design = (byte)ServerManager.Instance.RandomNumber(0, 15);
                        session.SendPacket(session.Character.GenerateEq());
                        session.SendPacket(session.Character.GenerateEquipment());
                        session.CurrentMapInstance?.Broadcast(session, session.Character.GenerateIn());
                        session.CurrentMapInstance?.Broadcast(session, session.Character.GenerateGidx());
                        session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                    }
                    else
                    {
                        session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("NO_WIG"), 0));
                    }
                }
                break;

            //Raid stone
            case 300:
                if (session.Character.Group != null && session.Character.Group.GroupType != GroupType.Group && session.Character.Group.IsLeader(session) && session.CurrentMapInstance.Portals.Any(s => s.Type == (short)PortalType.Raid))
                {
                    Parallel.ForEach(session.Character.Group.Characters.Where(s => s.Character.Group?.GroupId == session.Character.Group?.GroupId), sess =>
                    {
                        ServerManager.Instance.TeleportOnRandomPlaceInMap(sess, session.CurrentMapInstance.MapInstanceId);
                    });
                    session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                }
                break;

            default:
                Logger.Log.Warn(string.Format(Language.Instance.GetMessageFromKey("NO_HANDLER_ITEM"), GetType()));
                break;
            }
        }
Ejemplo n.º 10
0
        public override void Use(ClientSession session, ref ItemInstance inv, bool delay = false, string[] packetsplit = null)
        {
            Random random = new Random();
            switch (Effect)
            {
                // airwaves - eventitems
                case 0:
                    if (this != null && this.ItemType == Domain.ItemType.Event)
                    {
                        session.CurrentMap?.Broadcast(session.Character.GenerateEff(EffectValue));
                        if (MappingHelper.GuriItemEffects.ContainsKey(EffectValue))
                        {
                            session.CurrentMap?.Broadcast(session.Character.GenerateGuri(19, 1, MappingHelper.GuriItemEffects[EffectValue]), session.Character.MapX, session.Character.MapY);
                        }
                        session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                    }
                    break;

                //respawn objects
                case 1:
                    int x1;
                    int x2;
                    int x3;
                    int x4;
                    int x5;
                    if (int.TryParse(packetsplit[2], out x1) && int.TryParse(packetsplit[3], out x2) && int.TryParse(packetsplit[4], out x3) && int.TryParse(packetsplit[5], out x4))
                    {
                        switch (EffectValue)
                        {
                            case 0:
                                if (!delay)
                                {
                                    session.SendPacket(session.Character.GenerateDialog($"#u_i^{x1}^{x2}^{x3}^{x4}^1 #u_i^{x1}^{x2}^{x3}^{x4}^2 {Language.Instance.GetMessageFromKey("WANT_TO_SAVE_POSITION")}"));
                                }
                                else
                                {
                                    if (int.TryParse(packetsplit[6], out x5))
                                    {
                                        switch (x5)
                                        {
                                            case 1:
                                                session.SendPacket(session.Character.GenerateDelay(5000, 7, $"#u_i^{x1}^{x2}^{x3}^{x4}^3"));
                                                break;

                                            case 2:
                                                session.SendPacket(session.Character.GenerateDelay(5000, 7, $"#u_i^{x1}^{x2}^{x3}^{x4}^4"));
                                                break;

                                            case 3:
                                                session.Character.SetReturnPoint(session.Character.MapId, session.Character.MapX, session.Character.MapY);
                                                RespawnMapTypeDTO resp = session.Character.Respawn;
                                                if (resp.DefaultX != 0 && resp.DefaultY != 0 && resp.DefaultMapId != 0)
                                                {
                                                    ServerManager.Instance.LeaveMap(session.Character.CharacterId);
                                                    Random rnd = new Random();
                                                    ServerManager.Instance.ChangeMap(session.Character.CharacterId, resp.DefaultMapId, (short)(resp.DefaultX + rnd.Next(-5, 5)), (short)(resp.DefaultY + rnd.Next(-5, 5)));
                                                }
                                                session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                                                break;

                                            case 4:
                                                RespawnMapTypeDTO respa = session.Character.Respawn;
                                                if (respa.DefaultX != 0 && respa.DefaultY != 0 && respa.DefaultMapId != 0)
                                                {
                                                    ServerManager.Instance.LeaveMap(session.Character.CharacterId);
                                                    Random rnd = new Random();
                                                    ServerManager.Instance.ChangeMap(session.Character.CharacterId, respa.DefaultMapId, (short)(respa.DefaultX + rnd.Next(-5, 5)), (short)(respa.DefaultY + rnd.Next(-5, 5)));
                                                }
                                                session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                                                break;
                                        }
                                    }
                                }
                                break;

                            case 1:
                                if (int.TryParse(packetsplit[6], out x5))
                                {
                                    RespawnMapTypeDTO resp = session.Character.Return;
                                    switch (x5)
                                    {
                                        case 0:
                                            if (resp.DefaultX != 0 && resp.DefaultY != 0 && resp.DefaultMapId != 0)
                                            {
                                                session.SendPacket(session.Character.GenerateRp(resp.DefaultMapId, resp.DefaultX, resp.DefaultY, $"#u_i^{x1}^{x2}^{x3}^{x4}^1"));
                                            }
                                            break;

                                        case 1:
                                            session.SendPacket(session.Character.GenerateDelay(5000, 7, $"#u_i^{x1}^{x2}^{x3}^{x4}^2"));
                                            break;

                                        case 2:
                                            if (resp.DefaultX != 0 && resp.DefaultY != 0 && resp.DefaultMapId != 0)
                                            {
                                                ServerManager.Instance.LeaveMap(session.Character.CharacterId);
                                                ServerManager.Instance.ChangeMap(session.Character.CharacterId, resp.DefaultMapId, resp.DefaultX, resp.DefaultY);
                                            }
                                            session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                                            break;
                                    }
                                }
                                break;
                        }
                    }
                    break;

                // dyes or waxes
                case 10:
                case 11:
                    if (this != null && !session.Character.IsVehicled)
                    {
                        if (Effect == 10)
                        {
                            if (EffectValue == 99)
                            {
                                byte nextValue = (byte)random.Next(0, 127);
                                session.Character.HairColor = Enum.IsDefined(typeof(HairColorType), (byte)nextValue) ? (HairColorType)nextValue : 0;
                            }
                            else
                            {
                                session.Character.HairColor = Enum.IsDefined(typeof(HairColorType), (byte)EffectValue) ? (HairColorType)EffectValue : 0;
                            }
                        }
                        else
                        {
                            if (session.Character.Class == (byte)ClassType.Adventurer && EffectValue > 1)
                            {
                                session.SendPacket(session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("ADVENTURERS_CANT_USE"), 10));
                                return;
                            }
                            else
                            {
                                session.Character.HairStyle = Enum.IsDefined(typeof(HairStyleType), (byte)EffectValue) ? (HairStyleType)EffectValue : 0;
                            }
                        }
                        session.SendPacket(session.Character.GenerateEq());
                        session.CurrentMap?.Broadcast(session, session.Character.GenerateIn(), ReceiverType.All);
                        session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                    }
                    break;

                // dignity restoration
                case 14:
                    if ((EffectValue == 100 || EffectValue == 200) && session.Character.Dignity < 100 && !session.Character.IsVehicled)
                    {
                        session.Character.Dignity += EffectValue;
                        if (session.Character.Dignity > 100)
                        {
                            session.Character.Dignity = 100;
                        }
                        session.SendPacket(session.Character.GenerateFd());
                        session.SendPacket(session.Character.GenerateEff(48));
                        session.CurrentMap?.Broadcast(session, session.Character.GenerateIn(), ReceiverType.AllExceptMe);
                        session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                    }
                    else if (EffectValue == 2000 && session.Character.Dignity < 100 && !session.Character.IsVehicled)
                    {
                        session.Character.Dignity = 100;
                        session.SendPacket(session.Character.GenerateFd());
                        session.SendPacket(session.Character.GenerateEff(48));
                        session.CurrentMap?.Broadcast(session, session.Character.GenerateIn(), ReceiverType.AllExceptMe);
                        session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                    }
                    break;

                // speakers
                case 15:
                    if (this != null && !session.Character.IsVehicled)
                    {
                        if (!delay)
                        {
                            session.SendPacket(session.Character.GenerateGuri(10, 3, 1));
                        }
                    }
                    break;

                // bubbles
                case 16:
                    if (this != null && !session.Character.IsVehicled)
                    {
                        if (!delay)
                        {
                            session.SendPacket(session.Character.GenerateGuri(10, 4, 1));
                        }
                    }
                    break;

                // wigs
                case 30:
                    if (this != null && !session.Character.IsVehicled)
                    {
                        WearableInstance wig = session.Character.Inventory.LoadBySlotAndType<WearableInstance>((byte)EquipmentType.Hat, InventoryType.Wear);
                        if (wig != null)
                        {
                            wig.Design = (byte)random.Next(0, 15);
                            session.SendPacket(session.Character.GenerateEq());
                            session.SendPacket(session.Character.GenerateEquipment());
                            session.CurrentMap?.Broadcast(session, session.Character.GenerateIn(), ReceiverType.All);
                            session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                        }
                        else
                        {
                            session.SendPacket(session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("NO_WIG"), 0));
                            return;
                        }
                    }
                    break;

                default:
                    Logger.Log.Warn(String.Format(Language.Instance.GetMessageFromKey("NO_HANDLER_ITEM"), this.GetType().ToString()));
                    break;
            }
        }
Ejemplo n.º 11
0
        public override void Use(ClientSession session, ref ItemInstance inv, byte Option = 0, string[] packetsplit = null)
        {
            if (session.Character.IsVehicled && Effect != 888)
            {
                session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("CANT_DO_VEHICLED"), 10));
                return;
            }

            if (inv.ItemVNum == 333 || inv.ItemVNum == 334) // Sealed Jajamaru Specialist Card & Sealed Princess Sakura Bead
            {
                return;
            }

            switch (Effect)
            {
            case 0:
                if (Option == 0)
                {
                    if (packetsplit?.Length == 9)
                    {
                        ItemInstance box = session.Character.Inventory.LoadBySlotAndType(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
                    ItemInstance box = session.Character.Inventory.LoadBySlotAndType(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.RandomNumber(0, probabilities);
                            int currentrnd    = 0;
                            foreach (RollGeneratedItemDTO rollitem in roll.OrderBy(s => ServerManager.RandomNumber()))
                            {
                                currentrnd += rollitem.Probability;
                                if (currentrnd >= rnd)
                                {
                                    Item  i       = ServerManager.GetItem(rollitem.ItemGeneratedVNum);
                                    sbyte rare    = 0;
                                    byte  upgrade = 0;
                                    if (i.ItemType == ItemType.Armor || i.ItemType == ItemType.Weapon || i.ItemType == ItemType.Shell || i.ItemType == ItemType.Box)
                                    {
                                        rare = box.Rare;
                                    }
                                    if (i.ItemType == ItemType.Shell)
                                    {
                                        if (rare < 1)
                                        {
                                            rare = 1;
                                        }
                                        else if (rare > 7)
                                        {
                                            rare = 7;
                                        }
                                        upgrade = (byte)ServerManager.RandomNumber(50, 81);
                                    }
                                    if (rollitem.IsRareRandom)
                                    {
                                        rnd = ServerManager.RandomNumber(0, 100);

                                        for (int j = ItemHelper.RareRate.Length - 1; j >= 0; j--)
                                        {
                                            if (rnd < ItemHelper.RareRate[j])
                                            {
                                                rare = (sbyte)j;
                                                break;
                                            }
                                        }
                                        if (rare < 1)
                                        {
                                            rare = 1;
                                        }
                                    }
                                    session.Character.GiftAdd(rollitem.ItemGeneratedVNum, rollitem.ItemGeneratedAmount, (byte)rare, upgrade, rollitem.ItemGeneratedDesign);
                                    session.SendPacket($"rdi {rollitem.ItemGeneratedVNum} {rollitem.ItemGeneratedAmount}");
                                    session.Character.Inventory.RemoveItemFromInventory(box.Id);
                                    return;
                                }
                            }
                        }
                        else if (box.HoldingVNum == 0)
                        {
                            if (packetsplit.Length == 1 && int.TryParse(packetsplit[0], out int PetId) && session.Character.Mates.Find(s => s.MateTransportId == PetId) is Mate mate)
                            {
                                if (ItemSubType == 0 && mate.MateType != MateType.Pet || ItemSubType == 1 && mate.MateType != MateType.Partner)
                                {
                                    return;
                                }
                                if (mate.MateType == MateType.Partner && mate.GetInventory().Count > 0)
                                {
                                    session.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("EQ_NOT_EMPTY"), 0));
                                    return;
                                }
                                box.HoldingVNum = mate.NpcMonsterVNum;
                                box.SpLevel     = mate.Level;
                                box.SpDamage    = mate.Attack;
                                box.SpDefence   = mate.Defence;
                                session.Character.Mates.Remove(mate);
                                if (mate.MateType == MateType.Partner)
                                {
                                    byte i = 0;
                                    session.Character.Mates.Where(s => s.MateType == MateType.Partner).ToList().ForEach(s =>
                                    {
                                        s.GetInventory().ForEach(item => item.Type = (InventoryType)(13 + i));
                                        s.PetId = i;
                                        i++;
                                    });
                                }
                                session.SendPacket(UserInterfaceHelper.GenerateInfo(Language.Instance.GetMessageFromKey("PET_STORED")));
                                session.SendPacket(UserInterfaceHelper.GeneratePClear());
                                session.SendPackets(session.Character.GenerateScP());
                                session.SendPackets(session.Character.GenerateScN());
                                session.CurrentMapInstance?.Broadcast(mate.GenerateOut());
                            }
                        }
                        else
                        {
                            NpcMonster heldMonster = ServerManager.GetNpcMonster(box.HoldingVNum);
                            if (heldMonster != null)
                            {
                                Mate mate = new Mate(session.Character, heldMonster, box.SpLevel, ItemSubType == 0 ? MateType.Pet : MateType.Partner)
                                {
                                    Attack  = box.SpDamage,
                                    Defence = box.SpDefence
                                };
                                if (session.Character.AddPet(mate))
                                {
                                    session.Character.Inventory.RemoveItemFromInventory(inv.Id);
                                    session.SendPacket(UserInterfaceHelper.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.GetNpcMonster((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.RemoveItemFromInventory(inv.Id);
                            session.SendPacket(UserInterfaceHelper.GenerateInfo(Language.Instance.GetMessageFromKey("PET_LEAVE_BEAD")));
                        }
                    }
                    else
                    {
                        session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("NOT_IN_MINILAND"), 12));
                    }
                }

                break;

            case 69:
                if (EffectValue == 1 || EffectValue == 2)
                {
                    ItemInstance box = session.Character.Inventory.LoadBySlotAndType(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.Count > 0)
                            {
                                ItemInstance itemInstance = newInv[0];
                                ItemInstance specialist   = session.Character.Inventory.LoadBySlotAndType(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.EquipmentSerialId = box.EquipmentSerialId;
                                    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.RemoveItemFromInventory(box.Id);
                                }
                            }
                            else
                            {
                                session.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("NOT_ENOUGH_PLACE"), 0));
                            }
                        }
                    }
                }
                if (EffectValue == 3)
                {
                    ItemInstance box = session.Character.Inventory.LoadBySlotAndType(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.Count > 0)
                            {
                                ItemInstance itemInstance = newInv[0];
                                ItemInstance fairy        = session.Character.Inventory.LoadBySlotAndType(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.RemoveItemFromInventory(box.Id);
                                }
                            }
                            else
                            {
                                session.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("NOT_ENOUGH_PLACE"), 0));
                            }
                        }
                    }
                }
                if (EffectValue == 4)
                {
                    ItemInstance box = session.Character.Inventory.LoadBySlotAndType(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.Count > 0)
                            {
                                short Slot = inv.Slot;
                                if (Slot != -1)
                                {
                                    session.SendPacket(session.Character.GenerateSay($"{Language.Instance.GetMessageFromKey("ITEM_ACQUIRED")} {newInv[0].Item.Name} x 1)", 12));
                                    newInv.ForEach(s => session.SendPacket(s.GenerateInventoryAdd()));
                                    session.Character.Inventory.RemoveItemFromInventory(box.Id);
                                }
                            }
                            else
                            {
                                session.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("NOT_ENOUGH_PLACE"), 0));
                            }
                        }
                    }
                }
                if (EffectValue == 5)
                {
                    ItemInstance box = session.Character.Inventory.LoadBySlotAndType(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.Count > 0)
                            {
                                short Slot = inv.Slot;
                                if (Slot != -1)
                                {
                                    session.SendPacket(session.Character.GenerateSay($"{Language.Instance.GetMessageFromKey("ITEM_ACQUIRED")} {newInv[0].Item.Name} x 1)", 12));
                                    newInv.ForEach(s => session.SendPacket(s.GenerateInventoryAdd()));
                                    session.Character.Inventory.RemoveItemFromInventory(box.Id);
                                }
                            }
                            else
                            {
                                session.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("NOT_ENOUGH_PLACE"), 0));
                            }
                        }
                    }
                }
                break;

            case 888:
                if (session.Character.IsVehicled)
                {
                    if (!session.Character.Buff.Any(s => s.Card.CardId == 336))
                    {
                        if (inv.ItemDeleteTime == null)
                        {
                            inv.ItemDeleteTime = DateTime.Now.AddHours(LevelMinimum);
                        }
                        session.Character.VehicleItem.BCards.ForEach(s => s.ApplyBCards(session.Character.BattleEntity, session.Character.BattleEntity));
                        session.CurrentMapInstance.Broadcast($"eff 1 {session.Character.CharacterId} 885");
                    }
                }
                break;

            case 4801:

                break;

            default:
                Logger.Warn(string.Format(Language.Instance.GetMessageFromKey("NO_HANDLER_ITEM"), GetType(), VNum, Effect, EffectValue));
                break;
            }
        }
Ejemplo n.º 12
0
        public override void Use(ClientSession session, ref ItemInstance inv, byte Option = 0, string[] packetsplit = null)
        {
            if (session.Character.IsVehicled)
            {
                session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("CANT_DO_VEHICLED"), 10));
                return;
            }

            if (session.CurrentMapInstance.MapInstanceType == Domain.MapInstanceType.TalentArenaMapInstance)
            {
                return;
            }

            switch (Effect)
            {
            case 10:
            {
                switch (EffectValue)
                {
                case 1:
                    if (session.Character.Inventory.CountItem(1036) < 1 || session.Character.Inventory.CountItem(1013) < 1)
                    {
                        return;
                    }
                    session.Character.Inventory.RemoveItemAmount(1036);
                    session.Character.Inventory.RemoveItemAmount(1013);
                    if (ServerManager.RandomNumber() < 25)
                    {
                        switch (ServerManager.RandomNumber(0, 2))
                        {
                        case 0:
                            session.Character.GiftAdd(1015, 1);
                            break;

                        case 1:
                            session.Character.GiftAdd(1016, 1);
                            break;
                        }
                    }
                    break;

                case 2:
                    if (session.Character.Inventory.CountItem(1038) < 1 || session.Character.Inventory.CountItem(1013) < 1)
                    {
                        return;
                    }
                    session.Character.Inventory.RemoveItemAmount(1038);
                    session.Character.Inventory.RemoveItemAmount(1013);
                    if (ServerManager.RandomNumber() < 25)
                    {
                        switch (ServerManager.RandomNumber(0, 4))
                        {
                        case 0:
                            session.Character.GiftAdd(1031, 1);
                            break;

                        case 1:
                            session.Character.GiftAdd(1032, 1);
                            break;

                        case 2:
                            session.Character.GiftAdd(1033, 1);
                            break;

                        case 3:
                            session.Character.GiftAdd(1034, 1);
                            break;
                        }
                    }
                    break;

                case 3:
                    if (session.Character.Inventory.CountItem(1037) < 1 || session.Character.Inventory.CountItem(1013) < 1)
                    {
                        return;
                    }
                    session.Character.Inventory.RemoveItemAmount(1037);
                    session.Character.Inventory.RemoveItemAmount(1013);
                    if (ServerManager.RandomNumber() < 25)
                    {
                        switch (ServerManager.RandomNumber(0, 17))
                        {
                        case 0:
                        case 1:
                        case 2:
                        case 3:
                        case 4:
                            session.Character.GiftAdd(1017, 1);
                            break;

                        case 5:
                        case 6:
                        case 7:
                        case 8:
                            session.Character.GiftAdd(1018, 1);
                            break;

                        case 9:
                        case 10:
                        case 11:
                            session.Character.GiftAdd(1019, 1);
                            break;

                        case 12:
                        case 13:
                            session.Character.GiftAdd(1020, 1);
                            break;

                        case 14:
                            session.Character.GiftAdd(1021, 1);
                            break;

                        case 15:
                            session.Character.GiftAdd(1022, 1);
                            break;

                        case 16:
                            session.Character.GiftAdd(1023, 1);
                            break;
                        }
                    }
                    break;
                }

                session.Character.GiftAdd(1014, (byte)ServerManager.RandomNumber(5, 11));
            }
            break;

            default:
                Logger.Warn(string.Format(Language.Instance.GetMessageFromKey("NO_HANDLER_ITEM"), GetType(), VNum, Effect, EffectValue));
                break;
            }
        }
Ejemplo n.º 13
0
        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.Find(s => s.MateType == MateType.Partner && s.PetId == Option - 1);
                    if (mate == null || mate.IsTemporalMate)
                    {
                        return;
                    }
                }
                short         slot      = inv.Slot;
                InventoryType equipment = InventoryType.Wear;
                if (Option > 0)
                {
                    equipment = (InventoryType)(12 + Option);
                }

                InventoryType itemToWearType = inv.Type;

                if (inv == null)
                {
                    return;
                }
                if (ItemValidTime > 0 && !inv.IsBound)
                {
                    inv.ItemDeleteTime = DateTime.Now.AddSeconds(ItemValidTime);
                }
                else if (!inv.IsBound && ItemType == ItemType.Jewelery && new int[] { 3951, 3952, 3953, 3954, 3955, 7427 }.Contains(EffectValue))
                {
                    inv.ItemDeleteTime = DateTime.Now.AddSeconds(3600);
                }
                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.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((byte)EquipmentType.Sp, InventoryType.Specialist) != null)
                    {
                        session.SendPacket(UserInterfaceHelper.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)
                    {
                        if (session.Character.Inventory.LoadBySlotAndType((byte)EquipmentType.Sp, equipment) is ItemInstance sp && sp.Item.Element != 0 && EquipmentSlot == EquipmentType.Fairy && Element != sp.Item.Element && Element != sp.Item.SecondaryElement)
                        {
                            session.SendPacket(UserInterfaceHelper.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 (inv.Item.EquipmentSlot == EquipmentType.MainWeapon || inv.Item.EquipmentSlot == EquipmentType.SecondaryWeapon || inv.Item.EquipmentSlot == EquipmentType.Armor)
                    {
                        switch (mate.Monster.AttackClass)
                        {
                        case 0:
                            if (inv.ItemVNum != 990 && inv.ItemVNum != 997)
                            {
                                session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("BAD_EQUIPMENT"), 10));
                                return;
                            }
                            break;

                        case 1:
                            if (inv.ItemVNum != 991 && inv.ItemVNum != 996)
                            {
                                session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("BAD_EQUIPMENT"), 10));
                                return;
                            }
                            break;

                        case 2:
                            if (inv.ItemVNum != 992 && inv.ItemVNum != 995)
                            {
                                session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("BAD_EQUIPMENT"), 10));
                                return;
                            }
                            break;
                        }
                    }

                    if (mate.Level < LevelMinimum)
                    {
                        session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("BAD_EQUIPMENT"), 10));
                        return;
                    }

                    Item partnerEquipment = ServerManager.GetItem(inv.ItemVNum);

                    bool isBadEquipment = false;

                    switch (partnerEquipment.EquipmentSlot)
                    {
                    case EquipmentType.MainWeapon:
                    {
                        if (partnerEquipment.ItemSubType != 12)
                        {
                            isBadEquipment = true;
                        }
                        else
                        {
                            mate.WeaponInstance = inv;
                        }
                    }
                    break;

                    case EquipmentType.Armor:
                    {
                        if (partnerEquipment.ItemSubType != 4)
                        {
                            isBadEquipment = true;
                        }
                        else
                        {
                            mate.ArmorInstance = inv;
                        }
                    }
                    break;

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

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

                    case EquipmentType.Sp:
                    {
                        if (mate.IsUsingSp)
                        {
                            return;
                        }

                        if (partnerEquipment.ItemSubType != 4 ||
                            !PartnerHelper.CanWearSp(mate.NpcMonsterVNum, inv.ItemVNum))
                        {
                            isBadEquipment = true;
                        }
                        else
                        {
                            if (!mate.CanUseSp())
                            {
                                int spRemainingCooldown = mate.GetSpRemainingCooldown();
                                session.SendPacket(session.Character.GenerateSay(string.Format(Language.Instance.GetMessageFromKey("STAY_TIME"), spRemainingCooldown), 11));
                                session.SendPacket($"psd {spRemainingCooldown}");
                                return;
                            }

                            mate.Sp = new PartnerSp(inv);
                        }
                    }
                    break;
                    }

                    if (isBadEquipment)
                    {
                        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
                {
                    Logger.LogUserEvent("EQUIPMENT_TAKEOFF", session.GenerateIdentity(), $"IIId: {currentlyEquippedItem.Id} ItemVnum: {currentlyEquippedItem.ItemVNum} Upgrade: {currentlyEquippedItem.Upgrade} Rare: {currentlyEquippedItem.Rare}");

                    // move from wear to equipment and back
                    session.Character.Inventory.MoveInInventory(currentlyEquippedItem.Slot, equipment, itemToWearType, inv.Slot);
                    session.SendPacket(currentlyEquippedItem.GenerateInventoryAdd());
                    session.Character.EquipmentBCards.RemoveAll(o => o.ItemVNum == currentlyEquippedItem.ItemVNum);
                }

                Logger.LogUserEvent("EQUIPMENT_WEAR", session.GenerateIdentity(), $"IIId: {inv.Id} ItemVnum: {inv.ItemVNum} Upgrade: {inv.Upgrade} Rare: {inv.Rare}");

                ScriptedInstance raid = ServerManager.Instance.Raids.FirstOrDefault(s => s.RequiredItems?.Any(obj => obj?.VNum == VNum) == true)?.Copy();
                if (raid?.DailyEntries > 0)
                {
                    var entries = raid.DailyEntries - session.Character.GeneralLogs.CountLinq(s => s.LogType == "InstanceEntry" && short.Parse(s.LogData) == raid.Id && s.Timestamp.Date == DateTime.Today);
                    session.SendPacket(session.Character.GenerateSay(string.Format(Language.Instance.GetMessageFromKey("INSTANCE_ENTRIES"), entries), 10));
                }

                if (mate == null)
                {
                    session.Character.EquipmentBCards.AddRange(inv.Item.BCards);

                    switch (inv.Item.ItemType)
                    {
                    case ItemType.Armor:
                        session.Character.ShellEffectArmor.Clear();

                        foreach (ShellEffectDTO dto in inv.ShellEffects)
                        {
                            session.Character.ShellEffectArmor.Add(dto);
                        }
                        break;

                    case ItemType.Weapon:
                        switch (inv.Item.EquipmentSlot)
                        {
                        case EquipmentType.MainWeapon:
                            session.Character.ShellEffectMain.Clear();

                            foreach (ShellEffectDTO dto in inv.ShellEffects)
                            {
                                session.Character.ShellEffectMain.Add(dto);
                            }
                            break;

                        case EquipmentType.SecondaryWeapon:
                            session.Character.ShellEffectSecondary.Clear();

                            foreach (ShellEffectDTO dto in inv.ShellEffects)
                            {
                                session.Character.ShellEffectSecondary.Add(dto);
                            }
                            break;
                        }
                        break;
                    }
                }
                else
                {
                    mate.BattleEntity.BCards.AddRange(inv.Item.BCards);
                }

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

                    if (EquipmentSlot == EquipmentType.Fairy)
                    {
                        ItemInstance fairy = session.Character.Inventory.LoadBySlotAndType((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));
                    }

                    if (EquipmentSlot == EquipmentType.Amulet)
                    {
                        session.SendPacket(StaticPacketHelper.GenerateEff(UserType.Player, session.Character.CharacterId, 39));
                        inv.BoundCharacterId = session.Character.CharacterId;
                        if (inv.ItemDeleteTime > DateTime.Now || inv.DurabilityPoint > 0)
                        {
                            session.Character.AddBuff(new Buff(62, session.Character.Level), session.Character.BattleEntity);
                        }
                    }
                }
                else if (mate != null)
                {
                    session.SendPacket(mate.GenerateScPacket());
                }
                break;
            }
        }
Ejemplo n.º 14
0
        public override void Use(ClientSession session, ref ItemInstance inv, byte Option = 0, string[] packetsplit = null)
        {
            if (session.Character.IsVehicled)
            {
                session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("CANT_DO_VEHICLED"), 10));
                return;
            }

            if ((DateTime.Now - session.Character.LastSnack).TotalMilliseconds < 500 && session.Character.SnackAmount > 4 || (DateTime.Now - session.Character.LastSnack).TotalMilliseconds < 500 && session.Character.SnackAmount <= 0)
            {
                session.SendPacket(session.Character.Gender == GenderType.Female
                                               ? session.Character.GenerateSay(Language.Instance.GetMessageFromKey("NOT_HUNGRY_FEMALE"), 1)
                                               : session.Character.GenerateSay(Language.Instance.GetMessageFromKey("NOT_HUNGRY_MALE"), 1));
                return;
            }

            if ((DateTime.Now - session.Character.LastSnack).TotalMilliseconds < 350 && session.Character.SnackAmount > 0 && session.Character.SnackAmount < 5)
            {
                return;
            }
            session.Character.LastSnack = DateTime.Now;

            if (session.CurrentMapInstance?.MapInstanceType != MapInstanceType.TalentArenaMapInstance && VNum == 2802)
            {
                return;
            }
            if (session.CurrentMapInstance.MapInstanceType == MapInstanceType.TalentArenaMapInstance && VNum != 2802)
            {
                return;
            }

            int amount = session.Character.SnackAmount;

            if (session.Character.SnackAmount < 0)
            {
                session.Character.SnackAmount = 0;
            }

            if (session.Character.SnackAmount < 0 || session.Character.SnackAmount > 5)
            {
                return;
            }

            Item item = inv.Item;

            switch (Effect)
            {
            default:
                if (session.Character.Hp <= 0)
                {
                    return;
                }
                if (item.BCards.Find(s => s.Type == 25) is BCard Buff)
                {
                    if (ServerManager.RandomNumber() < Buff.FirstData)
                    {
                        session.Character.AddBuff(new Buff((short)Buff.SecondData, session.Character.Level), session.Character.BattleEntity);
                    }
                    session.Character.Inventory.RemoveItemFromInventory(inv.Id);
                }
                else
                {
                    if (session.Character.SnackAmount < 0)
                    {
                        session.Character.SnackAmount = 0;
                    }
                    if (amount < 5)
                    {
                        Thread workerThread = new Thread(() => Regenerate(session, item));
                        workerThread.Start();
                        session.Character.Inventory.RemoveItemFromInventory(inv.Id);
                    }
                    else
                    {
                        session.SendPacket(session.Character.Gender == GenderType.Female
                                ? session.Character.GenerateSay(Language.Instance.GetMessageFromKey("NOT_HUNGRY_FEMALE"), 1)
                                : session.Character.GenerateSay(Language.Instance.GetMessageFromKey("NOT_HUNGRY_MALE"), 1));
                    }
                    if (amount == 0)
                    {
                        Thread workerThread2 = new Thread(() => Sync(session));
                        workerThread2.Start();
                    }
                }
                break;
            }
        }
Ejemplo n.º 15
0
        public void UpgradeItem(ClientSession Session, UpgradeMode mode, UpgradeProtection protection, bool isCommand = false)
        {
            if (this.Upgrade < 10)
            {
                short[] upsuccess = { 100, 100, 100, 95, 80, 60, 40, 30, 20, 11 };
                short[] upfix     = { 0, 0, 10, 15, 20, 20, 20, 20, 15, 10 };

                // short itempricevnum1 = 0; short itempricevnum2 = 0;
                int[]   goldprice = { 500, 1500, 3000, 10000, 30000, 80000, 150000, 400000, 700000, 1000000 };
                short[] cella     = { 20, 50, 80, 120, 160, 220, 280, 380, 480, 600 };
                short[] gem       = { 1, 1, 2, 2, 3, 1, 1, 2, 2, 3 };

                short  cellaVnum          = 1014;
                short  gemVnum            = 1015;
                short  gemFullVnum        = 1016;
                double reducedpricefactor = 0.5;
                short  normalScrollVnum   = 1218;
                short  goldScrollVnum     = 5369;

                if (this.IsFixed)
                {
                    Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("ITEM_IS_FIXED"), 10));
                    Session.SendPacket("shop_end 1");
                    return;
                }
                switch (mode)
                {
                case UpgradeMode.Free:
                    break;

                case UpgradeMode.Reduced:

                    // TODO: Reduced Item Amount
                    if (Session.Character.Gold < (long)(goldprice[this.Upgrade] * reducedpricefactor))
                    {
                        Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("NOT_ENOUGH_MONEY"), 10));
                        return;
                    }
                    if (Session.Character.Inventory.CountItem(cellaVnum) < cella[this.Upgrade] * reducedpricefactor)
                    {
                        Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey(String.Format("NOT_ENOUGH_ITEMS", ServerManager.GetItem(cellaVnum).Name, cella[this.Upgrade] * reducedpricefactor)), 10));
                        return;
                    }
                    if (protection == UpgradeProtection.Protected && !isCommand && Session.Character.Inventory.CountItem(goldScrollVnum) < 1)
                    {
                        Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey(String.Format("NOT_ENOUGH_ITEMS", ServerManager.GetItem(goldScrollVnum).Name, cella[this.Upgrade] * reducedpricefactor)), 10));
                        return;
                    }
                    if (this.Upgrade < 5)
                    {
                        if (Session.Character.Inventory.CountItem(gemVnum) < gem[this.Upgrade])
                        {
                            Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey(String.Format("NOT_ENOUGH_ITEMS", ServerManager.GetItem(gemVnum).Name, gem[this.Upgrade])), 10));
                            return;
                        }
                        Session.Character.Inventory.RemoveItemAmount(gemVnum, gem[this.Upgrade]);
                    }
                    else
                    {
                        if (Session.Character.Inventory.CountItem(gemFullVnum) < gem[this.Upgrade])
                        {
                            Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey(String.Format("NOT_ENOUGH_ITEMS", ServerManager.GetItem(gemFullVnum).Name, gem[this.Upgrade])), 10));
                            return;
                        }
                        Session.Character.Inventory.RemoveItemAmount(gemFullVnum, gem[this.Upgrade]);
                    }
                    if (protection == UpgradeProtection.Protected && !isCommand)
                    {
                        Session.Character.Inventory.RemoveItemAmount(goldScrollVnum);
                        Session.SendPacket("shop_end 2");
                    }
                    Session.Character.Gold -= (long)(goldprice[this.Upgrade] * reducedpricefactor);
                    Session.Character.Inventory.RemoveItemAmount(cellaVnum, (int)(cella[this.Upgrade] * reducedpricefactor));
                    Session.SendPacket(Session.Character.GenerateGold());
                    break;

                case UpgradeMode.Normal:

                    // TODO: Normal Item Amount
                    if (Session.Character.Inventory.CountItem(cellaVnum) < cella[this.Upgrade])
                    {
                        return;
                    }
                    if (Session.Character.Gold < goldprice[this.Upgrade])
                    {
                        Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("NOT_ENOUGH_MONEY"), 10));
                        return;
                    }
                    if (protection == UpgradeProtection.Protected && !isCommand && Session.Character.Inventory.CountItem(normalScrollVnum) < 1)
                    {
                        Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey(String.Format("NOT_ENOUGH_ITEMS", ServerManager.GetItem(normalScrollVnum).Name, 1)), 10));
                        return;
                    }
                    if (this.Upgrade < 5)
                    {
                        if (Session.Character.Inventory.CountItem(gemVnum) < gem[this.Upgrade])
                        {
                            Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey(String.Format("NOT_ENOUGH_ITEMS", ServerManager.GetItem(gemVnum).Name, gem[this.Upgrade])), 10));
                            return;
                        }
                        Session.Character.Inventory.RemoveItemAmount(gemVnum, (gem[this.Upgrade]));
                    }
                    else
                    {
                        if (Session.Character.Inventory.CountItem(gemFullVnum) < gem[this.Upgrade])
                        {
                            Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey(String.Format("NOT_ENOUGH_ITEMS", ServerManager.GetItem(gemFullVnum).Name, gem[this.Upgrade])), 10));
                            return;
                        }
                        Session.Character.Inventory.RemoveItemAmount(gemFullVnum, (gem[this.Upgrade]));
                    }
                    if (protection == UpgradeProtection.Protected && !isCommand)
                    {
                        Session.Character.Inventory.RemoveItemAmount(normalScrollVnum);
                        Session.SendPacket("shop_end 2");
                    }
                    Session.Character.Inventory.RemoveItemAmount(cellaVnum, (cella[this.Upgrade]));
                    Session.Character.Gold -= goldprice[this.Upgrade];
                    Session.SendPacket(Session.Character.GenerateGold());
                    break;
                }
                WearableInstance wearable  = Session.Character.Inventory.LoadByItemInstance <WearableInstance>(this.Id);
                ItemInstance     inventory = Session.Character.Inventory.GetItemInstanceById(this.Id);

                int rnd = _random.Next(100);

                if (rnd <= upfix[this.Upgrade])
                {
                    Session.CurrentMap.Broadcast(Session.Character.GenerateEff(3004), Session.Character.MapX, Session.Character.MapY);
                    wearable.IsFixed = true;
                    Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("UPGRADE_FIXED"), 11));
                    Session.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("UPGRADE_FIXED"), 0));
                }
                else if (rnd <= upsuccess[this.Upgrade])
                {
                    Session.CurrentMap.Broadcast(Session.Character.GenerateEff(3005), Session.Character.MapX, Session.Character.MapY);
                    Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("UPGRADE_SUCCESS"), 12));
                    Session.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("UPGRADE_SUCCESS"), 0));
                    wearable.Upgrade++;
                    Session.SendPacket(Session.Character.GenerateInventoryAdd(this.ItemVNum, 1, inventory.Type, inventory.Slot, wearable.Rare, 0, wearable.Upgrade, 0));
                }
                else
                {
                    if (protection == UpgradeProtection.None)
                    {
                        Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("UPGRADE_FAILED"), 11));
                        Session.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("UPGRADE_FAILED"), 0));
                        Session.Character.DeleteItemByItemInstanceId(this.Id);
                    }
                    else
                    {
                        Session.CurrentMap.Broadcast(Session.Character.GenerateEff(3004), Session.Character.MapX, Session.Character.MapY);
                        Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("SCROLL_PROTECT_USED"), 11));
                        Session.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("UPGRADE_FAILED_ITEM_SAVED"), 0));
                    }
                }
            }
            else
            {
                Session.CurrentMap.Broadcast(Session.Character.GenerateEff(3004), Session.Character.MapX, Session.Character.MapY);
                Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("SCROLL_PROTECT_USED"), 11));
                Session.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("UPGRADE_FAILED_ITEM_SAVED"), 0));
            }
            Session.SendPacket("shop_end 1");
        }
Ejemplo n.º 16
0
        public void RarifyItem(ClientSession Session, RarifyMode mode, RarifyProtection protection, bool isCommand = false)
        {
            double raren2              = 80;
            double raren1              = 70;
            double rare0               = 60;
            double rare1               = 40;
            double rare2               = 30;
            double rare3               = 15;
            double rare4               = 10;
            double rare5               = 5;
            double rare6               = 3;
            double rare7               = 1;
            short  goldprice           = 500;
            double reducedpricefactor  = 0.5;
            double reducedchancefactor = 1.1;
            byte   cella               = 5;
            int    cellaVnum           = 1014;
            int    scrollVnum          = 1218;

            int rnd;

            if (mode != RarifyMode.Drop || this.Item.ItemType == ItemType.Shell)
            {
                raren2 = 0;
                raren1 = 0;
                rare0  = 0;
                rnd    = _random.Next(0, 80);
            }
            else
            {
                rnd = _random.Next(0, 100);
            }
            if (protection == RarifyProtection.RedAmulet)
            {
                raren2 = raren1 * reducedchancefactor;
                raren1 = raren1 * reducedchancefactor;
                rare0  = rare0 * reducedchancefactor;
                rare1  = rare1 * reducedchancefactor;
                rare2  = rare2 * reducedchancefactor;
                rare3  = rare3 * reducedchancefactor;
                rare4  = rare4 * reducedchancefactor;
                rare5  = rare5 * reducedchancefactor;
                rare6  = rare6 * reducedchancefactor;
                rare7  = rare7 * reducedchancefactor;

                // rare8 = rare8 * reducedchancefactor;
            }
            switch (mode)
            {
            case RarifyMode.Free:
                break;

            case RarifyMode.Reduced:

                // TODO: Reduced Item Amount
                if (Session.Character.Gold < (long)(goldprice * reducedpricefactor))
                {
                    return;
                }
                if (Session.Character.Inventory.CountItem(cellaVnum) < cella * reducedpricefactor)
                {
                    return;
                }
                Session.Character.Inventory.RemoveItemAmount(cellaVnum, (int)(cella * reducedpricefactor));
                Session.Character.Gold -= (long)(goldprice * reducedpricefactor);
                Session.SendPacket(Session.Character.GenerateGold());
                break;

            case RarifyMode.Normal:

                // TODO: Normal Item Amount
                if (Session.Character.Gold < goldprice)
                {
                    return;
                }
                if (Session.Character.Inventory.CountItem(cellaVnum) < cella)
                {
                    return;
                }
                if (protection == RarifyProtection.Scroll && !isCommand && Session.Character.Inventory.CountItem(scrollVnum) < 1)
                {
                    return;
                }

                if (protection == RarifyProtection.Scroll && !isCommand)
                {
                    Session.Character.Inventory.RemoveItemAmount(scrollVnum);
                    Session.SendPacket("shop_end 2");
                }
                Session.Character.Gold -= goldprice;
                Session.Character.Inventory.RemoveItemAmount(cellaVnum, cella);
                Session.SendPacket(Session.Character.GenerateGold());
                break;
            }

            if (rnd <= rare7 && !(protection == RarifyProtection.Scroll && this.Rare >= 7))
            {
                if (mode != RarifyMode.Drop)
                {
                    Session.Character.NotifyRarifyResult(7);
                }

                this.Rare = 7;
                SetRarityPoint();
            }
            else if (rnd <= rare6 && !(protection == RarifyProtection.Scroll && this.Rare >= 6))
            {
                if (mode != RarifyMode.Drop)
                {
                    Session.Character.NotifyRarifyResult(6);
                }
                this.Rare = 6;
                SetRarityPoint();
            }
            else if (rnd <= rare5 && !(protection == RarifyProtection.Scroll && this.Rare >= 5))
            {
                if (mode != RarifyMode.Drop)
                {
                    Session.Character.NotifyRarifyResult(5);
                }
                this.Rare = 5;
                SetRarityPoint();
            }
            else if (rnd <= rare4 && !(protection == RarifyProtection.Scroll && this.Rare >= 4))
            {
                if (mode != RarifyMode.Drop)
                {
                    Session.Character.NotifyRarifyResult(4);
                }
                this.Rare = 4;
                SetRarityPoint();
            }
            else if (rnd <= rare3 && !(protection == RarifyProtection.Scroll && this.Rare >= 3))
            {
                if (mode != RarifyMode.Drop)
                {
                    Session.Character.NotifyRarifyResult(3);
                }
                this.Rare = 3;
                SetRarityPoint();
            }
            else if (rnd <= rare2 && !(protection == RarifyProtection.Scroll && this.Rare >= 2))
            {
                if (mode != RarifyMode.Drop)
                {
                    Session.Character.NotifyRarifyResult(2);
                }
                this.Rare = 2;
                SetRarityPoint();
            }
            else if (rnd <= rare1 && !(protection == RarifyProtection.Scroll && this.Rare >= 1))
            {
                if (mode != RarifyMode.Drop)
                {
                    Session.Character.NotifyRarifyResult(1);
                }
                this.Rare = 1;
                SetRarityPoint();
            }
            else if (rnd <= rare0 && !(protection == RarifyProtection.Scroll && this.Rare >= 0))
            {
                if (mode != RarifyMode.Drop)
                {
                    Session.Character.NotifyRarifyResult(0);
                }
                this.Rare = 0;
                SetRarityPoint();
            }
            else if (rnd <= raren1 && !(protection == RarifyProtection.Scroll && this.Rare >= -1))
            {
                if (mode != RarifyMode.Drop)
                {
                    Session.Character.NotifyRarifyResult(-1);
                }
                this.Rare = -1;
                SetRarityPoint();
            }
            else if (rnd <= raren2 && !(protection == RarifyProtection.Scroll && this.Rare >= -2))
            {
                if (mode != RarifyMode.Drop)
                {
                    Session.Character.NotifyRarifyResult(-2);
                }
                this.Rare = -2;
                SetRarityPoint();
            }
            else
            {
                if (mode != RarifyMode.Drop)
                {
                    if (protection == RarifyProtection.None)
                    {
                        Session.Character.DeleteItemByItemInstanceId(this.Id);
                        Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("RARIFY_FAILED"), 11));
                        Session.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("RARIFY_FAILED"), 0));
                    }
                    else
                    {
                        Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("RARIFY_FAILED_ITEM_SAVED"), 11));
                        Session.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("RARIFY_FAILED_ITEM_SAVED"), 0));
                        Session.CurrentMap.Broadcast(Session.Character.GenerateEff(3004), Session.Character.MapX, Session.Character.MapY);
                    }
                }
            }

            // don't place under else.
            if (mode != RarifyMode.Drop)
            {
                ItemInstance inventory = Session.Character.Inventory.GetItemInstanceById(this.Id);
                if (inventory != null)
                {
                    Session.SendPacket(Session.Character.GenerateInventoryAdd(this.ItemVNum, 1, inventory.Type, inventory.Slot, inventory.Rare, 0, inventory.Upgrade, 0));
                }
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// c_reg packet
        /// </summary>
        /// <param name="cRegPacket"></param>
        public void SellBazaar(CRegPacket cRegPacket)
        {
            if (ServerManager.Instance.InShutdown || Session.Character == null || Session.Character.InExchangeOrTrade)
            {
                return;
            }
            SpinWait.SpinUntil(() => !ServerManager.Instance.InBazaarRefreshMode);
            StaticBonusDTO medal = Session.Character.StaticBonusList.FirstOrDefault(s => s.StaticBonusType == StaticBonusType.BazaarMedalGold || s.StaticBonusType == StaticBonusType.BazaarMedalSilver);

            long price   = cRegPacket.Price * cRegPacket.Amount;
            long taxmax  = price > 100000 ? price / 200 : 500;
            long taxmin  = price >= 4000 ? (60 + (price - 4000) / 2000 * 30 > 10000 ? 10000 : 60 + (price - 4000) / 2000 * 30) : 50;
            long tax     = medal == null ? taxmax : taxmin;
            long maxGold = ServerManager.Instance.MaxGold;

            if (Session.Character.Gold < tax || cRegPacket.Amount <= 0 || Session.Character.ExchangeInfo != null && Session.Character.ExchangeInfo.ExchangeList.Any() || Session.Character.IsShopping)
            {
                return;
            }
            ItemInstance it = Session.Character.Inventory.LoadBySlotAndType(cRegPacket.Slot, cRegPacket.Inventory == 4 ? 0 : (InventoryType)cRegPacket.Inventory);

            if (it == null || !it.Item.IsSoldable || it.IsBound)
            {
                return;
            }
            if (Session.Character.Inventory.CountItemInAnInventory(InventoryType.Bazaar) > 10 * (medal == null ? 1 : 10))
            {
                Session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("LIMIT_EXCEEDED"), 0));
                return;
            }
            if (price > (medal == null ? 100000000 : maxGold))
            {
                Session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("PRICE_EXCEEDED"), 0));
                return;
            }
            if (cRegPacket.Price < 0)
            {
                return;
            }
            ItemInstance bazar = Session.Character.Inventory.AddIntoBazaarInventory(cRegPacket.Inventory == 4 ? 0 : (InventoryType)cRegPacket.Inventory, cRegPacket.Slot, cRegPacket.Amount);

            if (bazar == null)
            {
                return;
            }
            short duration;

            switch (cRegPacket.Durability)
            {
            case 1:
                duration = 24;
                break;

            case 2:
                duration = 168;
                break;

            case 3:
                duration = 360;
                break;

            case 4:
                duration = 720;
                break;

            default:
                return;
            }
            ItemInstanceDTO bazarDto = bazar;

            DAOFactory.IteminstanceDAO.InsertOrUpdate(ref bazarDto);

            BazaarItemDTO bazaarItem = new BazaarItemDTO
            {
                Amount         = bazar.Amount,
                DateStart      = DateTime.Now,
                Duration       = duration,
                IsPackage      = cRegPacket.IsPackage != 0,
                MedalUsed      = medal != null,
                Price          = cRegPacket.Price,
                SellerId       = Session.Character.CharacterId,
                ItemInstanceId = bazar.Id
            };

            DAOFactory.BazaarItemDAO.InsertOrUpdate(ref bazaarItem);
            if (bazar is WearableInstance wear)
            {
                wear.EquipmentOptions.ForEach(s => s.WearableInstanceId = bazar.Id);
                IEnumerable <EquipmentOptionDTO> equipmentOptionDtos = wear.EquipmentOptions;
                DAOFactory.EquipmentOptionDAO.InsertOrUpdate(equipmentOptionDtos);
            }
            ServerManager.Instance.BazaarRefresh(bazaarItem.BazaarItemId);

            Session.Character.Gold -= tax;
            Session.SendPacket(Session.Character.GenerateGold());

            Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("OBJECT_IN_BAZAAR"), 10));
            Session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("OBJECT_IN_BAZAAR"), 0));

            Session.SendPacket("rc_reg 1");
        }
Ejemplo n.º 18
0
        public override void Use(ClientSession session, ref ItemInstance inv, byte Option = 0, string[] packetsplit = null)
        {
            if (!session.HasCurrentMapInstance)
            {
                return;
            }

            if (session.Character.IsLaurenaMorph())
            {
                return;
            }

            if ((DateTime.Now - session.Character.LastPotion).TotalMilliseconds < (session.CurrentMapInstance.Map.MapTypes.OrderByDescending(s => s.PotionDelay).FirstOrDefault()?.PotionDelay ?? 750))
            {
                return;
            }

            if ((session.CurrentMapInstance.MapInstanceType.Equals(MapInstanceType.TalentArenaMapInstance) && VNum != 5935) ||
                session.CurrentMapInstance.MapInstanceType.Equals(MapInstanceType.IceBreakerInstance))
            {
                return;
            }

            if (session.CurrentMapInstance.MapInstanceType != MapInstanceType.TalentArenaMapInstance && VNum == 5935)
            {
                return;
            }

            if (ServerManager.Instance.ChannelId == 51 &&
                session.Character.MapId != 130 &&
                session.Character.MapId != 131 &&
                (session.Character.Group?.Raid == null || !session.Character.Group.Raid.InstanceBag.Lock) &&
                session.Character.MapInstance.MapInstanceType != MapInstanceType.Act4Berios &&
                session.Character.MapInstance.MapInstanceType != MapInstanceType.Act4Calvina &&
                session.Character.MapInstance.MapInstanceType != MapInstanceType.Act4Hatus &&
                session.Character.MapInstance.MapInstanceType != MapInstanceType.Act4Morcos &&
                (inv.ItemVNum == 1242 || inv.ItemVNum == 1243 || inv.ItemVNum == 1244 || inv.ItemVNum == 5582 || inv.ItemVNum == 5583 || inv.ItemVNum == 5584))
            {
                return;
            }

            session.Character.LastPotion = DateTime.Now;

            switch (Effect)
            {
            default:
            {
                bool hasPotionBeenUsed = false;

                int hpLoad = (int)session.Character.HPLoad();
                int mpLoad = (int)session.Character.MPLoad();

                if (session.Character.Hp > 0 &&
                    (session.Character.Hp < hpLoad || session.Character.Mp < mpLoad))
                {
                    hasPotionBeenUsed = true;

                    double buffRc = session.Character.GetBuff(BCardType.CardType.LeonaPassiveSkill, (byte)AdditionalTypes.LeonaPassiveSkill.IncreaseRecoveryItems)[0] / 100D;

                    int hpAmount = Hp + (int)(Hp * buffRc);
                    int mpAmount = Mp + (int)(Mp * buffRc);

                    if (session.Character.Hp + hpAmount > hpLoad)
                    {
                        hpAmount = hpLoad - session.Character.Hp;
                    }

                    if (session.Character.Mp + mpAmount > mpLoad)
                    {
                        mpAmount = mpLoad - session.Character.Mp;
                    }

                    bool convertRecoveryToDamage = ServerManager.RandomNumber() < session.Character.GetBuff(BCardType.CardType.DarkCloneSummon, (byte)AdditionalTypes.DarkCloneSummon.ConvertRecoveryToDamage)[0];

                    if (convertRecoveryToDamage)
                    {
                        session.CurrentMapInstance.Broadcast(session.Character.GenerateDm(hpAmount));

                        session.Character.Hp -= hpAmount;

                        if (session.Character.Hp < 1)
                        {
                            session.Character.Hp = 1;
                        }
                    }
                    else
                    {
                        session.CurrentMapInstance.Broadcast(session.Character.GenerateRc(hpAmount));

                        session.Character.Hp += hpAmount;
                    }

                    session.Character.Mp += mpAmount;

                    switch (inv.ItemVNum)
                    {
                    // Full HP Potion
                    case 1242:
                    case 5582:
                    {
                        if (convertRecoveryToDamage)
                        {
                            session.CurrentMapInstance.Broadcast(session.Character.GenerateDm(session.Character.Hp - 1));
                            session.Character.Hp = 1;
                        }
                        else
                        {
                            session.CurrentMapInstance.Broadcast(session.Character.GenerateRc(hpLoad - session.Character.Hp));
                            session.Character.Hp = hpLoad;
                        }
                    }
                    break;

                    // Full MP Potion
                    case 1243:
                    case 5583:
                    {
                        session.Character.Mp = mpLoad;
                    }
                    break;

                    // Full HP & MP Potion
                    case 1244:
                    case 5584:
                    case 9129:
                    {
                        if (convertRecoveryToDamage)
                        {
                            session.CurrentMapInstance.Broadcast(session.Character.GenerateDm(session.Character.Hp - 1));
                            session.Character.Hp = 1;
                        }
                        else
                        {
                            session.CurrentMapInstance.Broadcast(session.Character.GenerateRc(hpLoad - session.Character.Hp));
                            session.Character.Hp = hpLoad;
                        }

                        session.Character.Mp = mpLoad;
                    }
                    break;
                    }

                    session.SendPacket(session.Character.GenerateStat());
                }

                foreach (Mate mate in session.Character.Mates.Where(s => s.IsTeamMember && s.IsAlive))
                {
                    hpLoad = (int)mate.MaxHp;
                    mpLoad = (int)mate.MaxMp;

                    if (mate.Hp <= 0 || (mate.Hp == hpLoad && mate.Mp == mpLoad))
                    {
                        continue;
                    }

                    hasPotionBeenUsed = true;

                    int hpAmount = Hp;
                    int mpAmount = Mp;

                    if (mate.Hp + hpAmount > hpLoad)
                    {
                        hpAmount = hpLoad - (int)mate.Hp;
                    }

                    if (mate.Mp + mpAmount > mpLoad)
                    {
                        mpAmount = mpLoad - (int)mate.Mp;
                    }

                    mate.Hp += hpAmount;
                    mate.Mp += mpAmount;

                    session.CurrentMapInstance.Broadcast(mate.GenerateRc(hpAmount));

                    switch (inv.ItemVNum)
                    {
                    // Full HP Potion
                    case 1242:
                    case 5582:
                        session.CurrentMapInstance.Broadcast(mate.GenerateRc(hpLoad - (int)mate.Hp));
                        mate.Hp = hpLoad;
                        break;

                    // Full MP Potion
                    case 1243:
                    case 5583:
                        mate.Mp = mpLoad;
                        break;

                    // Full HP & MP Potion
                    case 1244:
                    case 5584:
                    case 9129:
                        session.CurrentMapInstance.Broadcast(mate.GenerateRc(hpLoad - (int)mate.Hp));
                        mate.Hp = hpLoad;
                        mate.Mp = mpLoad;
                        break;
                    }

                    session.SendPacket(mate.GenerateStatInfo());
                }

                if (session.Character.Mates.Any(m => m.IsTeamMember && m.IsAlive))
                {
                    session.SendPackets(session.Character.GeneratePst());
                }

                if (hasPotionBeenUsed)
                {
                    session.Character.Inventory.RemoveItemFromInventory(inv.Id);
                }
            }
            break;
            }
        }
Ejemplo n.º 19
0
        public MapItem PutItem(InventoryType type, short slot, byte amount, ref ItemInstance inv, ClientSession session)
        {
            Logger.Debug($"type: {type} slot: {slot} amount: {amount}", session.SessionId);
            Guid random2 = Guid.NewGuid();
            MapItem droppedItem = null;
            List<GridPos> Possibilities = new List<GridPos>();

            for (short x = -2; x < 3; x++)
            {
                for (short y = -2; y < 3; y++)
                {
                    Possibilities.Add(new GridPos() { x = x, y = y });
                }
            }

            short mapX = 0;
            short mapY = 0;
            bool niceSpot = false;
            foreach (GridPos possibilitie in Possibilities.OrderBy(s => _random.Next()))
            {
                mapX = (short)(session.Character.MapX + possibilitie.x);
                mapY = (short)(session.Character.MapY + possibilitie.y);
                if (!IsBlockedZone(mapX, mapY))
                {
                    niceSpot = true;
                    break;
                }
            }

            if (niceSpot)
            {
                if (amount > 0 && amount <= inv.Amount)
                {
                    ItemInstance newItemInstance = inv.DeepCopy();
                    newItemInstance.Id = random2;
                    newItemInstance.Amount = amount;
                    droppedItem = new CharacterMapItem(mapX, mapY, newItemInstance);

                    DroppedList[droppedItem.TransportId] = droppedItem;
                    inv.Amount -= amount;
                }
            }
            return droppedItem;
        }
Ejemplo n.º 20
0
        public override void Use(ClientSession session, ref ItemInstance inv, byte Option = 0, string[] packetsplit = null)
        {
            switch (Effect)
            {
            // airwaves - eventitems
            case 0:
                if (ItemType == ItemType.Event)
                {
                    session.CurrentMapInstance?.Broadcast(session.Character.GenerateEff(EffectValue));
                    if (MappingHelper.GuriItemEffects.ContainsKey(EffectValue))
                    {
                        session.CurrentMapInstance?.Broadcast(UserInterfaceHelper.Instance.GenerateGuri(19, 1, session.Character.CharacterId, MappingHelper.GuriItemEffects[EffectValue]), session.Character.MapX, session.Character.MapY);
                    }
                    session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                }
                break;

            //respawn objects
            case 1:
                if (session.Character.MapInstance.MapInstanceType != MapInstanceType.BaseMapInstance)
                {
                    session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("CANT_USE_THAT"), 10));
                    return;
                }
                int type, secondaryType, inventoryType, slot;
                if (packetsplit != null && int.TryParse(packetsplit[2], out type) && int.TryParse(packetsplit[3], out secondaryType) && int.TryParse(packetsplit[4], out inventoryType) && int.TryParse(packetsplit[5], out slot))
                {
                    int packetType;
                    switch (EffectValue)
                    {
                    case 0:
                        if (Option == 0)
                        {
                            session.SendPacket(UserInterfaceHelper.Instance.GenerateDialog($"#u_i^{type}^{secondaryType}^{inventoryType}^{slot}^1 #u_i^{type}^{secondaryType}^{inventoryType}^{slot}^2 {Language.Instance.GetMessageFromKey("WANT_TO_SAVE_POSITION")}"));
                        }
                        else
                        {
                            if (int.TryParse(packetsplit[6], out packetType))
                            {
                                switch (packetType)
                                {
                                case 1:
                                    session.SendPacket(UserInterfaceHelper.Instance.GenerateDelay(5000, 7, $"#u_i^{type}^{secondaryType}^{inventoryType}^{slot}^3"));
                                    break;

                                case 2:
                                    session.SendPacket(UserInterfaceHelper.Instance.GenerateDelay(5000, 7, $"#u_i^{type}^{secondaryType}^{inventoryType}^{slot}^4"));
                                    break;

                                case 3:
                                    session.Character.SetReturnPoint(session.Character.MapId, session.Character.MapX, session.Character.MapY);
                                    RespawnMapTypeDTO respawn = session.Character.Respawn;
                                    if (respawn.DefaultX != 0 && respawn.DefaultY != 0 && respawn.DefaultMapId != 0)
                                    {
                                        ServerManager.Instance.ChangeMap(session.Character.CharacterId, respawn.DefaultMapId, (short)(respawn.DefaultX + ServerManager.Instance.RandomNumber(-5, 5)), (short)(respawn.DefaultY + ServerManager.Instance.RandomNumber(-5, 5)));
                                    }
                                    session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                                    break;

                                case 4:
                                    RespawnMapTypeDTO respawnObj = session.Character.Respawn;
                                    if (respawnObj.DefaultX != 0 && respawnObj.DefaultY != 0 && respawnObj.DefaultMapId != 0)
                                    {
                                        ServerManager.Instance.ChangeMap(session.Character.CharacterId, respawnObj.DefaultMapId, (short)(respawnObj.DefaultX + ServerManager.Instance.RandomNumber(-5, 5)), (short)(respawnObj.DefaultY + ServerManager.Instance.RandomNumber(-5, 5)));
                                    }
                                    session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                                    break;
                                }
                            }
                        }
                        break;

                    case 1:
                        if (int.TryParse(packetsplit[6], out packetType))
                        {
                            RespawnMapTypeDTO respawn = session.Character.Return;
                            switch (packetType)
                            {
                            case 0:
                                if (respawn.DefaultX != 0 && respawn.DefaultY != 0 && respawn.DefaultMapId != 0)
                                {
                                    session.SendPacket(UserInterfaceHelper.Instance.GenerateRp(respawn.DefaultMapId, respawn.DefaultX, respawn.DefaultY, $"#u_i^{type}^{secondaryType}^{inventoryType}^{slot}^1"));
                                }
                                break;

                            case 1:
                                session.SendPacket(UserInterfaceHelper.Instance.GenerateDelay(5000, 7, $"#u_i^{type}^{secondaryType}^{inventoryType}^{slot}^2"));
                                break;

                            case 2:
                                if (respawn.DefaultX != 0 && respawn.DefaultY != 0 && respawn.DefaultMapId != 0)
                                {
                                    ServerManager.Instance.ChangeMap(session.Character.CharacterId, respawn.DefaultMapId, respawn.DefaultX, respawn.DefaultY);
                                }
                                session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                                break;
                            }
                        }
                        break;

                    case 2:
                        if (Option == 0)
                        {
                            session.SendPacket(UserInterfaceHelper.Instance.GenerateDelay(5000, 7, $"#u_i^{type}^{secondaryType}^{inventoryType}^{slot}^1"));
                        }
                        else
                        {
                            ServerManager.Instance.JoinMiniland(session, session);
                            session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                        }
                        break;
                    }
                }
                break;

            // dyes or waxes
            case 10:
            case 11:
                if (!session.Character.IsVehicled)
                {
                    if (Effect == 10)
                    {
                        if (EffectValue == 99)
                        {
                            byte nextValue = (byte)ServerManager.Instance.RandomNumber(0, 127);
                            session.Character.HairColor = Enum.IsDefined(typeof(HairColorType), nextValue) ? (HairColorType)nextValue : 0;
                        }
                        else
                        {
                            session.Character.HairColor = Enum.IsDefined(typeof(HairColorType), (byte)EffectValue) ? (HairColorType)EffectValue : 0;
                        }
                    }
                    else
                    {
                        if (session.Character.Class == (byte)ClassType.Adventurer && EffectValue > 1)
                        {
                            session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("ADVENTURERS_CANT_USE"), 10));
                            return;
                        }
                        session.Character.HairStyle = Enum.IsDefined(typeof(HairStyleType), (byte)EffectValue) ? (HairStyleType)EffectValue : 0;
                    }
                    session.SendPacket(session.Character.GenerateEq());
                    session.CurrentMapInstance?.Broadcast(session, session.Character.GenerateIn());
                    session.CurrentMapInstance?.Broadcast(session, session.Character.GenerateGidx());
                    session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                }
                break;

            // dignity restoration
            case 14:
                if ((EffectValue == 100 || EffectValue == 200) && session.Character.Dignity < 100 && !session.Character.IsVehicled)
                {
                    session.Character.Dignity += EffectValue;
                    if (session.Character.Dignity > 100)
                    {
                        session.Character.Dignity = 100;
                    }
                    session.SendPacket(session.Character.GenerateFd());
                    session.SendPacket(session.Character.GenerateEff(49 - session.Character.Faction));
                    session.CurrentMapInstance?.Broadcast(session, session.Character.GenerateIn(), ReceiverType.AllExceptMe);
                    session.CurrentMapInstance?.Broadcast(session, session.Character.GenerateGidx(), ReceiverType.AllExceptMe);
                    session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                }
                else if (EffectValue == 2000 && session.Character.Dignity < 100 && !session.Character.IsVehicled)
                {
                    session.Character.Dignity = 100;
                    session.SendPacket(session.Character.GenerateFd());
                    session.SendPacket(session.Character.GenerateEff(49 - session.Character.Faction));
                    session.CurrentMapInstance?.Broadcast(session, session.Character.GenerateIn(), ReceiverType.AllExceptMe);
                    session.CurrentMapInstance?.Broadcast(session, session.Character.GenerateGidx(), ReceiverType.AllExceptMe);
                    session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                }
                break;

            // speakers
            case 15:
                if (!session.Character.IsVehicled)
                {
                    if (Option == 0)
                    {
                        session.SendPacket(UserInterfaceHelper.Instance.GenerateGuri(10, 3, session.Character.CharacterId, 1));
                    }
                }
                break;

            // bubbles
            case 16:
                if (!session.Character.IsVehicled)
                {
                    if (Option == 0)
                    {
                        session.SendPacket(UserInterfaceHelper.Instance.GenerateGuri(10, 4, session.Character.CharacterId, 1));
                    }
                }
                break;

            // wigs
            case 30:
                if (!session.Character.IsVehicled)
                {
                    WearableInstance wig = session.Character.Inventory.LoadBySlotAndType <WearableInstance>((byte)EquipmentType.Hat, InventoryType.Wear);
                    if (wig != null)
                    {
                        wig.Design = (byte)ServerManager.Instance.RandomNumber(0, 15);
                        session.SendPacket(session.Character.GenerateEq());
                        session.SendPacket(session.Character.GenerateEquipment());
                        session.CurrentMapInstance?.Broadcast(session, session.Character.GenerateIn());
                        session.CurrentMapInstance?.Broadcast(session, session.Character.GenerateGidx());
                        session.Character.Inventory.RemoveItemAmountFromInventory(1, inv.Id);
                    }
                    else
                    {
                        session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("NO_WIG"), 0));
                    }
                }
                break;

            default:
                Logger.Log.Warn(string.Format(Language.Instance.GetMessageFromKey("NO_HANDLER_ITEM"), GetType()));
                break;
            }
        }
Ejemplo n.º 21
0
        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)
                {
                    if (session.Character.Mates.Count(s => s.MateType == MateType.Partner) == 1 && option == 2)
                    {
                        option = 1;
                    }

                    mate = session.Character.Mates.Find(s =>
                                                        s.MateType == MateType.Partner && s.PartnerSlot == (option - 1));
                }
                short         slot      = inv.Slot;
                InventoryType equipment = InventoryType.Wear;

                if (option >= 1 && option <= 12)
                {
                    equipment = (InventoryType)(option + 12);     // partner inventories
                }

                InventoryType itemToWearType = inv.Type;

                if (inv == null)
                {
                    return;
                }
                if (ItemValidTime > 0 && !inv.IsBound)
                {
                    inv.ItemDeleteTime = DateTime.UtcNow.AddSeconds(ItemValidTime);
                }
                if (!inv.IsBound)
                {
                    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.UtcNow - Process.GetCurrentProcess().StartTime.AddHours(-2).AddSeconds(-50)).TotalSeconds - session.Character.LastSp;

                if (EquipmentSlot == EquipmentType.Sp && inv.Rare == -2)
                {
                    session.SendPacket(UserInterfaceHelper.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((byte)EquipmentType.Sp, InventoryType.Specialist) != null)
                    {
                        session.SendPacket(UserInterfaceHelper.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) ||
                        (inv.BoundCharacterId != null && inv.BoundCharacterId != session.Character.CharacterId))
                    {
                        session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("BAD_EQUIPMENT"), 10));
                        return;
                    }

                    if (session.Character.UseSp && session.Character.Inventory.LoadBySlotAndType((byte)EquipmentType.Sp, equipment) is ItemInstance sp && sp.Item.Element != 0 && EquipmentSlot == EquipmentType.Fairy && Element != sp.Item.Element && Element != sp.Item.SecondaryElement)
                    {
                        session.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("BAD_FAIRY"), 0));
                        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 || mate.Level < inv.MinimumLevel)
                    {
                        session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("BAD_EQUIPMENT"), 10));
                        return;
                    }
                    var isRagnar   = mate.NpcMonsterVNum == 2603 || mate.NpcMonsterVNum == 2618;
                    var mateSpType = ServerManager.GetNpcMonster(mate.NpcMonsterVNum).SpecialistType;
                    var itemSpType = ServerManager.GetItem(VNum).SpecialistType;
                    switch (EquipmentSlot)
                    {
                    case EquipmentType.Armor:
                        if (ItemSubType == 4 && !inv.Item.IsHeroic && mateSpType == itemSpType)
                        {
                            mate.ArmorInstance = inv;
                            break;
                        }
                        else if (ItemSubType == 4 && isRagnar && !inv.Item.IsHeroic && itemSpType == PartnerSpecialistType.Close)
                        {
                            mate.ArmorInstance = inv;
                            break;
                        }
                        else
                        {
                            goto default;
                        }

                    case EquipmentType.MainWeapon:
                        if (ItemSubType == 12 && !inv.Item.IsHeroic && mateSpType == itemSpType)
                        {
                            mate.WeaponInstance = inv;
                            break;
                        }
                        else if (ItemSubType == 4 && isRagnar && !inv.Item.IsHeroic && itemSpType == PartnerSpecialistType.Close)
                        {
                            mate.WeaponInstance = inv;
                            break;
                        }
                        else
                        {
                            goto default;
                        }

                    case EquipmentType.Gloves:
                        if (!inv.Item.IsHeroic)
                        {
                            mate.GlovesInstance = inv;
                        }
                        else
                        {
                            goto default;
                        }
                        break;

                    case EquipmentType.Boots:
                        if (!inv.Item.IsHeroic)
                        {
                            mate.BootsInstance = inv;
                        }
                        else
                        {
                            goto default;
                        }
                        break;

                    case EquipmentType.Sp:
                        if (ItemSubType == 4 && mateSpType == itemSpType)
                        {
                            mate.SpInstance = inv;
                            break;
                        }
                        else if (ItemSubType == 4 && isRagnar && itemSpType == PartnerSpecialistType.RagnarOnly)
                        {
                            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
                {
                    GameLogger.Instance.LogEquipmentUnwear(ServerManager.Instance.ChannelId, session.Character.Name,
                                                           session.Character.CharacterId, currentlyEquippedItem);

                    // move from wear to equipment and back
                    session.Character.Inventory.MoveInInventory(currentlyEquippedItem.Slot, equipment, itemToWearType, inv.Slot);
                    session.SendPacket(currentlyEquippedItem.GenerateInventoryAdd());
                    session.Character.EquipmentBCards.RemoveAll(o => o.ItemVNum == currentlyEquippedItem.ItemVNum);
                }

                GameLogger.Instance.LogEquipmentWear(ServerManager.Instance.ChannelId, session.Character.Name,
                                                     session.Character.CharacterId, inv);

                session.Character.EquipmentBCards.AddRange(inv.Item.BCards);

                switch (inv.Item.ItemType)
                {
                case ItemType.Armor:
                    session.Character.ShellEffectArmor.Clear();

                    foreach (ShellEffectDTO dto in inv.ShellEffects)
                    {
                        session.Character.ShellEffectArmor.Add(dto);
                    }
                    break;

                case ItemType.Weapon:
                    switch (inv.Item.EquipmentSlot)
                    {
                    case EquipmentType.MainWeapon:
                        session.Character.ShellEffectMain.Clear();

                        foreach (ShellEffectDTO dto in inv.ShellEffects)
                        {
                            session.Character.ShellEffectMain.Add(dto);
                        }
                        break;

                    case EquipmentType.SecondaryWeapon:
                        session.Character.ShellEffectSecondary.Clear();

                        foreach (ShellEffectDTO dto in inv.ShellEffects)
                        {
                            session.Character.ShellEffectSecondary.Add(dto);
                        }
                        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());

                    if (EquipmentSlot == EquipmentType.Fairy)
                    {
                        ItemInstance fairy = session.Character.Inventory.LoadBySlotAndType((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));
                    }

                    if (EquipmentSlot == EquipmentType.Amulet)
                    {
                        session.SendPacket(StaticPacketHelper.GenerateEff(UserType.Player, session.Character.CharacterId, 39));
                        inv.BoundCharacterId = session.Character.CharacterId;
                    }
                }
                else if (mate != null)
                {
                    session.SendPacket(mate.GenerateScPacket());
                }
                break;
            }
        }
Ejemplo n.º 22
0
        public override void Use(ClientSession session, ref ItemInstance inv, byte option = 0, string[] packetsplit = null)
        {
            if ((DateTime.Now - session.Character.LastPotion).TotalMilliseconds < 750)
            {
                return;
            }
            session.Character.LastPotion = DateTime.Now;
            if (session.Character.Hp == session.Character.HPLoad() && session.Character.Mp == session.Character.MPLoad())
            {
                return;
            }
            if (session.Character.Hp <= 0)
            {
                return;
            }
            switch (VNum)
            {
            // Full HP
            case 1242:
            case 5582:
                if (session.CurrentMapInstance?.MapInstanceType != MapInstanceType.Act4Instance && session.CurrentMapInstance?.IsPvp != true)
                {
                    session.CurrentMapInstance?.Broadcast(session.Character.GenerateRc((int)session.Character.HPLoad() - session.Character.Hp));
                    session.Character.Hp = (int)session.Character.HPLoad();
                    foreach (Mate mate in session.Character.Mates.Where(m => m.IsTeamMember))
                    {
                        mate.Hp = mate.HpLoad();
                        session.CurrentMapInstance?.Broadcast(mate.GenerateRc(mate.HpLoad() - mate.Hp));
                    }
                }
                session.Character.Inventory.RemoveItemFromInventory(inv.Id);
                session.SendPacket(session.Character.GenerateStat());
                break;

            // Full MP
            case 1243:
            case 5583:
                if (session.CurrentMapInstance?.MapInstanceType != MapInstanceType.Act4Instance && session.CurrentMapInstance?.IsPvp != true)
                {
                    session.Character.Mp = (int)session.Character.MPLoad();
                    session.Character.Mates.Where(m => m.IsTeamMember).ToList().ForEach(m => m.Mp = m.MpLoad());
                }
                session.Character.Inventory.RemoveItemFromInventory(inv.Id);
                session.SendPacket(session.Character.GenerateStat());
                break;

            // Full Mp & Hp
            case 1244:
            case 5584:
                if (session.CurrentMapInstance?.MapInstanceType != MapInstanceType.Act4Instance && session.CurrentMapInstance?.IsPvp != true)
                {
                    session.CurrentMapInstance?.Broadcast(session.Character.GenerateRc((int)session.Character.HPLoad() - session.Character.Hp));
                    session.Character.Hp = (int)session.Character.HPLoad();
                    session.Character.Mp = (int)session.Character.MPLoad();
                }
                session.Character.Inventory.RemoveItemFromInventory(inv.Id);
                session.SendPacket(session.Character.GenerateStat());
                break;

            default:
                int hpHeal = session.Character.Hp + Hp > session.Character.HPLoad() ? (int)session.Character.HPLoad() - session.Character.Hp : Hp;
                session.CurrentMapInstance?.Broadcast(session.Character.GenerateRc(hpHeal));
                session.Character.Hp += hpHeal;
                session.Character.Mp += session.Character.Mp + Mp > session.Character.MPLoad() ? (int)session.Character.MPLoad() - session.Character.Mp : Mp;

                foreach (Mate mate in session.Character.Mates.Where(m => m.IsTeamMember))
                {
                    int mateHpHeal = mate.Hp + Hp > mate.HpLoad() ? mate.HpLoad() - mate.Hp : Hp;
                    mate.Hp += mateHpHeal;
                    mate.Mp += mate.Mp + Mp > mate.MpLoad() ? mate.MpLoad() : Mp;
                    session.CurrentMapInstance?.Broadcast(mate.GenerateRc(mateHpHeal));
                }
                session.Character.Inventory.RemoveItemFromInventory(inv.Id);
                session.SendPacket(session.Character.GenerateStat());
                break;
            }
        }
Ejemplo n.º 23
0
        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.Find(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)
                {
                    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((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)
                    {
                        ItemInstance sp = session.Character.Inventory.LoadBySlotAndType((byte)EquipmentType.Sp, equipment);

                        if (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 (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 ((EquipmentSlot != EquipmentType.Gloves &&
                         EquipmentSlot != EquipmentType.Boots) ||
                        LevelMinimum > mate.Level)
                    {
                        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
                {
                    Logger.LogUserEvent("EQUIPMENT_TAKEOFF", session.GenerateIdentity(), $"IIId: {currentlyEquippedItem.Id} ItemVnum: {currentlyEquippedItem.ItemVNum} Upgrade: {currentlyEquippedItem.Upgrade} Rare: {currentlyEquippedItem.Rare}");

                    // move from wear to equipment and back
                    session.Character.Inventory.MoveInInventory(currentlyEquippedItem.Slot, equipment, itemToWearType, inv.Slot);
                    session.SendPacket(currentlyEquippedItem.GenerateInventoryAdd());
                    session.Character.EquipmentBCards.RemoveAll(o => o.ItemVNum == currentlyEquippedItem.ItemVNum);
                }

                Logger.LogUserEvent("EQUIPMENT_WEAR", session.GenerateIdentity(), $"IIId: {inv.Id} ItemVnum: {inv.ItemVNum} Upgrade: {inv.Upgrade} Rare: {inv.Rare}");

                session.Character.EquipmentBCards.AddRange(inv.Item.BCards);

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

                    if (EquipmentSlot == EquipmentType.Fairy)
                    {
                        ItemInstance fairy = session.Character.Inventory.LoadBySlotAndType((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));
                    }

                    if (EquipmentSlot == EquipmentType.Amulet)
                    {
                        session.SendPacket(StaticPacketHelper.GenerateEff(UserType.Player, session.Character.CharacterId, 39));
                        inv.BoundCharacterId = session.Character.CharacterId;
                    }
                }
                else if (mate != null)
                {
                    session.SendPacket(mate.GenerateScPacket());
                }
                break;
            }
        }
Ejemplo n.º 24
0
        public override void Use(ClientSession session, ref ItemInstance Inv, bool DelayUsed = false, string[] packetsplit = null)
        {
            if ((DateTime.Now - session.Character.LastPotion).TotalMilliseconds < 750)
            {
                return;
            }
            else
            {
                session.Character.LastPotion = DateTime.Now;
            }
            Item item = Inv.Item;

            switch (Effect)
            {
            default:
                if (session.Character.Hp <= 0)
                {
                    return;
                }
                if (!session.Character.IsSitting)
                {
                    session.Character.Rest();
                    session.Character.SnackAmount = 0;
                    session.Character.SnackHp     = 0;
                    session.Character.SnackMp     = 0;
                }
                int amount = session.Character.SnackAmount;
                if (amount < 5)
                {
                    if (!session.Character.IsSitting)
                    {
                        return;
                    }
                    Thread workerThread = new Thread(() => Regenerate(session, item));
                    workerThread.Start();
                    Inv.Amount--;
                    if (Inv.Amount > 0)
                    {
                        session.SendPacket(session.Character.GenerateInventoryAdd(Inv.ItemVNum, Inv.Amount, Inv.Type, Inv.Slot, 0, 0, 0, 0));
                    }
                    else
                    {
                        session.Character.Inventory.DeleteFromSlotAndType(Inv.Slot, Inv.Type);
                        session.SendPacket(session.Character.GenerateInventoryAdd(1, 0, Inv.Type, Inv.Slot, 0, 0, 0, 0));
                    }
                }
                else
                {
                    if (session.Character.Gender == 1)
                    {
                        session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("NOT_HUNGRY_FEMALE"), 1));
                    }
                    else
                    {
                        session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("NOT_HUNGRY_MALE"), 1));
                    }
                }
                if (amount == 0)
                {
                    if (!session.Character.IsSitting)
                    {
                        return;
                    }
                    Thread workerThread2 = new Thread(() => Sync(session, item));
                    workerThread2.Start();
                }
                break;
            }
        }
Ejemplo n.º 25
0
        public void MoveItem(InventoryType type, short sourceSlot, byte amount, short destinationSlot, out Inventory sourceInventory, out Inventory destinationInventory)
        {
            Logger.Debug($"type: {type} sourceSlot: {sourceSlot} amount: {amount} destinationSlot: {destinationSlot}", Owner.Session.SessionId);

            // load source and destination slots
            sourceInventory      = LoadInventoryBySlotAndType(sourceSlot, type);
            destinationInventory = LoadInventoryBySlotAndType(destinationSlot, type);
            if (sourceInventory != null && amount <= sourceInventory.ItemInstance.Amount)
            {
                if (destinationInventory == null)
                {
                    if (sourceInventory.ItemInstance.Amount == amount)
                    {
                        sourceInventory.Slot = destinationSlot;
                    }
                    else
                    {
                        ItemInstance itemDest = (sourceInventory.ItemInstance as ItemInstance).DeepCopy();
                        sourceInventory.ItemInstance.Amount -= amount;
                        itemDest.Amount      = amount;
                        itemDest.Id          = Guid.NewGuid();
                        destinationInventory = AddToInventoryWithSlotAndType(itemDest, sourceInventory.Type, destinationSlot);
                    }
                }
                else
                {
                    if (destinationInventory.ItemInstance.ItemVNum == sourceInventory.ItemInstance.ItemVNum && sourceInventory.Type != 0)
                    {
                        if (destinationInventory.ItemInstance.Amount + amount > 99)
                        {
                            int saveItemCount = destinationInventory.ItemInstance.Amount;
                            destinationInventory.ItemInstance.Amount = 99;
                            sourceInventory.ItemInstance.Amount      = (byte)(saveItemCount + sourceInventory.ItemInstance.Amount - 99);
                        }
                        else
                        {
                            destinationInventory.ItemInstance.Amount += amount;
                            sourceInventory.ItemInstance.Amount      -= amount;

                            // item with amount of 0 should be removed
                            if (sourceInventory.ItemInstance.Amount == 0)
                            {
                                DeleteFromSlotAndType(sourceInventory.Slot, sourceInventory.Type);
                            }
                        }
                    }
                    else
                    {
                        // add and remove save inventory
                        destinationInventory      = TakeInventory(destinationInventory.Slot, destinationInventory.Type);
                        destinationInventory.Slot = sourceSlot;
                        sourceInventory           = TakeInventory(sourceInventory.Slot, sourceInventory.Type);
                        sourceInventory.Slot      = destinationSlot;
                        PutInventory(destinationInventory);
                        PutInventory(sourceInventory);
                    }
                }
            }
            sourceInventory      = LoadInventoryBySlotAndType(sourceSlot, type);
            destinationInventory = LoadInventoryBySlotAndType(destinationSlot, type);
        }
Ejemplo n.º 26
0
 //TODO: Convert to PacketDefinition
 public abstract void Use(ClientSession session, ref ItemInstance inv, byte Option = 0, string[] packetsplit = null);
Ejemplo n.º 27
0
        public override void Use(ClientSession session, ref ItemInstance inv, bool delay = false, string[] packetsplit = null)
        {
            switch (Effect)
            {
                default:
                    short slot = inv.Slot;
                    InventoryType itemToWearType = inv.Type;

                    if (inv == null)
                    {
                        return;
                    }
                    if (ItemValidTime > 0 && inv.IsBound)
                    {
                        inv.ItemDeleteTime = DateTime.Now.AddSeconds(ItemValidTime);
                    }
                    if (!inv.IsBound)
                    {
                        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;
                        }
                        else 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(session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("CANT_EQUIP_DESTROYED_SP"), 0));
                        return;
                    }

                    if (EquipmentSlot == EquipmentType.Sp && timeSpanSinceLastSpUsage <= session.Character.SpCooldown && session.Character.Inventory.LoadBySlotAndType<SpecialistInstance>((byte)EquipmentType.Sp, InventoryType.Specialist) != null)
                    {
                        session.SendPacket(session.Character.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, InventoryType.Wear);

                        if (sp.Item.Element != 0 && EquipmentSlot == EquipmentType.Fairy && Element != sp.Item.Element && Element != sp.Item.SecondaryElement)
                        {
                            session.SendPacket(session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("BAD_FAIRY"), 0));
                            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;
                    }

                    ItemInstance currentlyEquippedItem = session.Character.Inventory.LoadBySlotAndType((short)EquipmentSlot, InventoryType.Wear);
                    if (EquipmentSlot == EquipmentType.Amulet)
                    {
                        session.SendPacket(session.Character.GenerateEff(39));
                        inv.BoundCharacterId = session.Character.CharacterId;
                    }

                    if (currentlyEquippedItem == null)
                    {
                        // move from equipment to wear
                        session.Character.Inventory.MoveInInventory(inv.Slot, itemToWearType, InventoryType.Wear);
                        session.SendPacket(session.Character.GenerateInventoryAdd(-1, 0, itemToWearType, slot, 0, 0, 0, 0));
                        session.SendPacket(session.Character.GenerateStatChar());
                        session.CurrentMap?.Broadcast(session.Character.GenerateEq());
                        session.SendPacket(session.Character.GenerateEquipment());
                        session.CurrentMap?.Broadcast(session.Character.GeneratePairy());
                    }
                    else
                    {
                        // move from wear to equipment and back
                        session.Character.Inventory.MoveInInventory(currentlyEquippedItem.Slot, InventoryType.Wear, itemToWearType, inv.Slot);

                        session.SendPacket(session.Character.GenerateInventoryAdd(-1, 0, itemToWearType, slot, 0, 0, 0, 0));
                        session.SendPacket(session.Character.GenerateInventoryAdd(currentlyEquippedItem.ItemVNum, currentlyEquippedItem.Amount,
                            currentlyEquippedItem.Type, currentlyEquippedItem.Slot, currentlyEquippedItem.Rare, currentlyEquippedItem.Design, currentlyEquippedItem.Upgrade, (currentlyEquippedItem as SpecialistInstance)?.SpStoneUpgrade ?? (byte)0));

                        session.SendPacket(session.Character.GenerateStatChar());
                        session.CurrentMap?.Broadcast(session.Character.GenerateEq());
                        session.SendPacket(session.Character.GenerateEquipment());
                        session.CurrentMap?.Broadcast(session.Character.GeneratePairy());
                    }

                    if (EquipmentSlot == EquipmentType.Fairy)
                    {
                        WearableInstance fairy = session.Character.Inventory.LoadBySlotAndType<WearableInstance>((byte)EquipmentType.Fairy, InventoryType.Wear);
                        session.SendPacket(session.Character.GenerateSay(String.Format(Language.Instance.GetMessageFromKey("FAIRYSTATS"), fairy.XP, CharacterHelper.LoadFairyXPData(fairy.ElementRate + fairy.Item.ElementRate)), 10));
                    }
                    break;
            }
        }
Ejemplo n.º 28
0
        public BattleEntity(Character character, Skill skill)
        {
            Session          = character.Session;
            HpMax            = character.HPMax;
            MpMax            = character.MPMax;
            Buffs            = character.Buff.GetAllItems();
            BCards           = character.EquipmentBCards.GetAllItems();
            Level            = character.Level;
            EntityType       = EntityType.Player;
            DamageMinimum    = character.MinHit;
            DamageMaximum    = character.MaxHit;
            Hitrate          = character.HitRate;
            CritChance       = character.HitCriticalRate;
            CritRate         = character.HitCritical;
            Morale           = character.Level;
            FireResistance   = character.FireResistance;
            WaterResistance  = character.WaterResistance;
            LightResistance  = character.LightResistance;
            ShadowResistance = character.DarkResistance;
            PositionX        = character.PositionX;
            PositionY        = character.PositionY;

            ItemInstance weapon = null;

            if (skill != null)
            {
                switch (skill.Type)
                {
                case 0:
                    AttackType = AttackType.Melee;
                    if (character.Class == ClassType.Archer)
                    {
                        DamageMinimum = character.MinDistance;
                        DamageMaximum = character.MaxDistance;
                        Hitrate       = character.DistanceRate;
                        CritChance    = character.DistanceCriticalRate;
                        CritRate      = character.DistanceCritical;
                        weapon        = character.Inventory.LoadBySlotAndType((byte)EquipmentType.SecondaryWeapon, InventoryType.Wear);
                    }
                    else
                    {
                        weapon = character.Inventory.LoadBySlotAndType((byte)EquipmentType.MainWeapon, InventoryType.Wear);
                    }
                    break;

                case 1:
                    AttackType = AttackType.Range;
                    if (character.Class == ClassType.Adventurer || character.Class == ClassType.Swordman || character.Class == ClassType.Magician)
                    {
                        DamageMinimum = character.MinDistance;
                        DamageMaximum = character.MaxDistance;
                        Hitrate       = character.DistanceRate;
                        CritChance    = character.DistanceCriticalRate;
                        CritRate      = character.DistanceCritical;
                        weapon        = character.Inventory.LoadBySlotAndType((byte)EquipmentType.SecondaryWeapon, InventoryType.Wear);
                    }
                    else
                    {
                        weapon = character.Inventory.LoadBySlotAndType((byte)EquipmentType.MainWeapon, InventoryType.Wear);
                    }
                    break;

                case 2:
                    AttackType = AttackType.Magical;
                    weapon     = character.Inventory.LoadBySlotAndType((byte)EquipmentType.MainWeapon, InventoryType.Wear);
                    break;

                case 3:
                    weapon = character.Inventory.LoadBySlotAndType((byte)EquipmentType.MainWeapon, InventoryType.Wear);
                    switch (character.Class)
                    {
                    case ClassType.Adventurer:
                    case ClassType.Swordman:
                        AttackType = AttackType.Melee;
                        break;

                    case ClassType.Archer:
                        AttackType = AttackType.Range;
                        break;

                    case ClassType.Magician:
                        AttackType = AttackType.Magical;
                        break;
                    }
                    break;

                case 5:
                    AttackType = AttackType.Melee;
                    switch (character.Class)
                    {
                    case ClassType.Adventurer:
                    case ClassType.Swordman:
                    case ClassType.Magician:
                        weapon = character.Inventory.LoadBySlotAndType((byte)EquipmentType.MainWeapon, InventoryType.Wear);
                        break;

                    case ClassType.Archer:
                        weapon = character.Inventory.LoadBySlotAndType((byte)EquipmentType.SecondaryWeapon, InventoryType.Wear);
                        break;
                    }
                    break;
                }
            }
            else
            {
                weapon = character.Inventory.LoadBySlotAndType((byte)EquipmentType.SecondaryWeapon, InventoryType.Wear);
                switch (character.Class)
                {
                case ClassType.Adventurer:
                case ClassType.Swordman:
                    AttackType = AttackType.Melee;
                    break;

                case ClassType.Archer:
                    AttackType = AttackType.Range;
                    break;

                case ClassType.Magician:
                    AttackType = AttackType.Magical;
                    break;
                }
            }

            if (weapon != null)
            {
                AttackUpgrade       = weapon.Upgrade;
                WeaponDamageMinimum = weapon.DamageMinimum + weapon.Item.DamageMinimum;
                WeaponDamageMaximum = weapon.DamageMaximum + weapon.Item.DamageMinimum;

                ShellWeaponEffects = character.ShellEffectMain.ToList();
            }

            ItemInstance armor = character.Inventory.LoadBySlotAndType((byte)EquipmentType.Armor, InventoryType.Wear);

            if (armor != null)
            {
                DefenseUpgrade      = armor.Upgrade;
                ArmorMeleeDefense   = armor.CloseDefence + armor.Item.CloseDefence;
                ArmorRangeDefense   = armor.DistanceDefence + armor.Item.DistanceDefence;
                ArmorMagicalDefense = armor.MagicDefence + armor.Item.MagicDefence;

                ShellArmorEffects = character.ShellEffectArmor.ToList();
            }

            CellonOptions = Session.Character.CellonOptions.GetAllItems();

            MeleeDefense      = character.Defence - ArmorMeleeDefense;
            MeleeDefenseDodge = character.DefenceRate;
            RangeDefense      = character.DistanceDefence - ArmorRangeDefense;
            RangeDefenseDodge = character.DistanceDefenceRate;
            MagicalDefense    = character.MagicalDefence - ArmorMagicalDefense;
            Element           = character.Element;
            ElementRate       = character.ElementRate + character.ElementRateSP;
        }
Ejemplo n.º 29
0
        public override void Use(ClientSession Session, ref ItemInstance inventory, bool DelayUsed = false, string[] packetsplit = null)
        {
            switch (Effect)
            {
            // wings
            case 650:
                SpecialistInstance specialistInstance = Session.Character.Inventory.LoadBySlotAndType <SpecialistInstance>((byte)EquipmentType.Sp, InventoryType.Wear);
                if (Session.Character.UseSp && specialistInstance != null)
                {
                    if (!DelayUsed)
                    {
                        Session.SendPacket($"qna #u_i^1^{Session.Character.CharacterId}^{(byte)inventory.Type}^{inventory.Slot}^3 {Language.Instance.GetMessageFromKey("ASK_WINGS_CHANGE")}");
                    }
                    else
                    {
                        specialistInstance.Design       = (byte)EffectValue;
                        Session.Character.MorphUpgrade2 = EffectValue;
                        Session.CurrentMap?.Broadcast(Session.Character.GenerateCMode());
                        Session.SendPacket(Session.Character.GenerateStat());
                        Session.SendPacket(Session.Character.GenerateStatChar());

                        inventory.Amount--;
                        if (inventory.Amount > 0)
                        {
                            Session.SendPacket(Session.Character.GenerateInventoryAdd(inventory.ItemVNum, inventory.Amount, inventory.Type, inventory.Slot, 0, 0, 0, 0));
                        }
                        else
                        {
                            Session.Character.Inventory.DeleteFromSlotAndType(inventory.Slot, inventory.Type);
                            Session.SendPacket(Session.Character.GenerateInventoryAdd(-1, 0, inventory.Type, inventory.Slot, 0, 0, 0, 0));
                        }
                    }
                }
                else
                {
                    Session.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("NO_SP"), 0));
                }
                break;

            // magic lamps
            case 651:
                if (!Session.Character.Inventory.Where(i => i.Type == InventoryType.Wear).Any())
                {
                    if (!DelayUsed)
                    {
                        Session.SendPacket($"qna #u_i^1^{Session.Character.CharacterId}^{(byte)inventory.Type}^{inventory.Slot}^3 {Language.Instance.GetMessageFromKey("ASK_USE")}");
                    }
                    else
                    {
                        Session.Character.ChangeSex();
                        inventory.Amount--;
                        if (inventory.Amount > 0)
                        {
                            Session.SendPacket(Session.Character.GenerateInventoryAdd(inventory.ItemVNum, inventory.Amount, inventory.Type, inventory.Slot, 0, 0, 0, 0));
                        }
                        else
                        {
                            Session.Character.Inventory.DeleteFromSlotAndType(inventory.Slot, inventory.Type);
                            Session.SendPacket(Session.Character.GenerateInventoryAdd(-1, 0, inventory.Type, inventory.Slot, 0, 0, 0, 0));
                        }
                    }
                }
                else
                {
                    Session.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("EQ_NOT_EMPTY"), 0));
                }
                break;

            // vehicles
            case 1000:
                SpecialistInstance sp = Session.Character.Inventory.LoadBySlotAndType <SpecialistInstance>((byte)EquipmentType.Sp, InventoryType.Wear);
                if (!DelayUsed && !Session.Character.IsVehicled)
                {
                    if (Session.Character.IsSitting)
                    {
                        Session.Character.IsSitting = false;
                        Session.CurrentMap?.Broadcast(Session.Character.GenerateRest());
                    }
                    Session.SendPacket(Session.Character.GenerateDelay(3000, 3, $"#u_i^1^{Session.Character.CharacterId}^{(byte)inventory.Type}^{inventory.Slot}^2"));
                }
                else
                {
                    if (!Session.Character.IsVehicled)
                    {
                        Session.Character.IsVehicled    = true;
                        Session.Character.MorphUpgrade  = 0;
                        Session.Character.MorphUpgrade2 = 0;
                        Session.Character.Morph         = Morph + Session.Character.Gender;
                        Session.Character.Speed         = Speed;
                        Session.CurrentMap?.Broadcast(Session.Character.GenerateEff(196), Session.Character.MapX, Session.Character.MapY);
                        Session.CurrentMap?.Broadcast(Session.Character.GenerateCMode());
                        Session.SendPacket(Session.Character.GenerateCond());
                    }
                    else
                    {
                        Session.Character.RemoveVehicle();
                    }
                }
                break;

            default:
                Logger.Log.Warn(String.Format(Language.Instance.GetMessageFromKey("NO_HANDLER_ITEM"), this.GetType().ToString()));
                break;
            }
        }
Ejemplo n.º 30
0
 public CharacterMapItem(short x, short y, ItemInstance itemInstance) : base(x, y)
 {
     ItemInstance = itemInstance;
 }
Ejemplo n.º 31
0
        public override void Use(ClientSession session, ref ItemInstance inv, byte Option = 0, string[] packetsplit = null)
        {
            if (session.Character.IsVehicled)
            {
                session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("CANT_DO_VEHICLED"), 10));
                return;
            }

            if (session.CurrentMapInstance.MapInstanceType == MapInstanceType.TalentArenaMapInstance)
            {
                return;
            }

            if (inv.ItemVNum == 2539 || inv.ItemVNum == 10066)//Cuarry Bank Money Card
            {
                if (session.Character.MapInstance.MapInstanceType != MapInstanceType.NormalInstance || session.Character.MapInstance.MapInstanceType != MapInstanceType.BaseMapInstance)
                {
                    return;
                }

                session.Character.OpenBank();
                session.Character.Inventory.RemoveItemFromInventory(inv.Id);
            }

            switch (Effect)
            {
            // airwaves - eventitems
            case 0:
                if (inv.Item.ItemType == ItemType.Shell)
                {
                    if (!(inv).ShellEffects.Any())
                    {
                        session.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("SHELL_MUST_BE_IDENTIFIED"), 0));
                        return;
                    }

                    if (packetsplit?.Length < 9)
                    {
                        return;
                    }

                    if (!int.TryParse(packetsplit[6], out int requestType))
                    {
                        return;
                    }
                    if (!Enum.TryParse(packetsplit[8], out InventoryType eqType))
                    {
                        return;
                    }

                    if (inv.ShellEffects.Count != 0 && packetsplit?.Length > 9 && byte.TryParse(packetsplit[9], out byte islot))
                    {
                        ItemInstance wearable = session.Character.Inventory.LoadBySlotAndType(islot, InventoryType.Equipment);
                        if (wearable != null && (wearable.Item.ItemType == ItemType.Weapon || wearable.Item.ItemType == ItemType.Armor) && wearable.Item.LevelMinimum >= inv.Upgrade && wearable.Rare >= inv.Rare && !wearable.Item.IsHeroic)
                        {
                            switch (requestType)
                            {
                            case 0:
                                session.SendPacket(wearable.ShellEffects.Any()
                                            ? $"qna #u_i^1^{session.Character.CharacterId}^{(short)inv.Type}^{inv.Slot}^1^1^{(short)eqType}^{islot} {Language.Instance.GetMessageFromKey("ADD_OPTION_ON_STUFF_NOT_EMPTY")}"
                                            : $"qna #u_i^1^{session.Character.CharacterId}^{(short)inv.Type}^{inv.Slot}^1^1^{(short)eqType}^{islot} {Language.Instance.GetMessageFromKey("ADD_OPTION_ON_STUFF")}");
                                break;

                            case 1:

                                if (inv.ShellEffects == null)
                                {
                                    return;
                                }
                                if (wearable.BoundCharacterId != session.Character.CharacterId && wearable.BoundCharacterId != null)
                                {
                                    session.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("NEED_FRAGANCE"), 0));
                                    return;
                                }
                                if (wearable.Rare < inv.Rare)
                                {
                                    session.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("SHELL_RARITY_TOO_HIGH"), 0));
                                    return;
                                }
                                if (wearable.Item.LevelMinimum < inv.Upgrade)
                                {
                                    session.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("SHELL_LEVEL_TOO_HIGH"), 0));
                                    return;
                                }

                                bool weapon = false;
                                if ((inv.ItemVNum >= 565 && inv.ItemVNum <= 576) || (inv.ItemVNum >= 589 && inv.ItemVNum <= 598))
                                {
                                    weapon = true;
                                }
                                else if ((inv.ItemVNum >= 577 && inv.ItemVNum <= 588) || (inv.ItemVNum >= 656 && inv.ItemVNum <= 664) || inv.ItemVNum == 599)
                                {
                                    weapon = false;
                                }
                                else
                                {
                                    return;
                                }
                                if ((wearable.Item.ItemType == ItemType.Weapon && weapon) || (wearable.Item.ItemType == ItemType.Armor && !weapon))
                                {
                                    if (wearable.ShellEffects.Count > 0 && ServerManager.RandomNumber() < 50)
                                    {
                                        session.Character.DeleteItemByItemInstanceId(inv.Id);
                                        session.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("OPTION_FAIL"), 0));
                                        return;
                                    }
                                    wearable.BoundCharacterId = session.Character.CharacterId;
                                    wearable.ShellRarity      = inv.Rare;
                                    wearable.ShellEffects.Clear();
                                    DAOFactory.ShellEffectDAO.DeleteByEquipmentSerialId(wearable.EquipmentSerialId);
                                    wearable.ShellEffects.AddRange(inv.ShellEffects);
                                    if (wearable.EquipmentSerialId == Guid.Empty)
                                    {
                                        wearable.EquipmentSerialId = Guid.NewGuid();
                                    }
                                    DAOFactory.ShellEffectDAO.InsertOrUpdateFromList(wearable.ShellEffects, wearable.EquipmentSerialId);
                                    session.Character.DeleteItemByItemInstanceId(inv.Id);
                                    session.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("OPTION_SUCCESS"), 0));
                                }
                                if (ItemType == ItemType.Magical)
                                {
                                    switch (VNum)
                                    {
                                    // Bank Card
                                    case 2539:
                                    case 10066:
                                        if (session.Character.MapInstance.MapInstanceType != MapInstanceType.BaseMapInstance)
                                        {
                                            return;
                                        }

                                        session.Character.OpenBank();
                                        session.Character.Inventory.RemoveItemFromInventory(inv.Id);
                                        return;
                                    }
                                }
                                break;
                            }
                        }
                    }
                    return;
                }

                if (ItemType == ItemType.Event)
                {
                    session.CurrentMapInstance?.Broadcast(StaticPacketHelper.GenerateEff(UserType.Player, session.Character.CharacterId, EffectValue));
                    if (MappingHelper.GuriItemEffects.ContainsKey(EffectValue))
                    {
                        session.CurrentMapInstance?.Broadcast(UserInterfaceHelper.GenerateGuri(19, 1, session.Character.CharacterId, MappingHelper.GuriItemEffects[EffectValue]), session.Character.PositionX, session.Character.PositionY);
                    }
                    session.Character.Inventory.RemoveItemFromInventory(inv.Id);
                }
                break;

            //respawn objects
            case 1:
                if (session.Character.MapInstance.MapInstanceType != MapInstanceType.BaseMapInstance || session.Character.IsSeal)
                {
                    session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("CANT_USE_THAT"), 10));
                    return;
                }
                int type, secondaryType, inventoryType, slot;
                if (packetsplit?.Length > 6 && int.TryParse(packetsplit[2], out type) && int.TryParse(packetsplit[3], out secondaryType) && int.TryParse(packetsplit[4], out inventoryType) && int.TryParse(packetsplit[5], out slot))
                {
                    int packetType;
                    switch (EffectValue)
                    {
                    case 0:
                        if (inv.ItemVNum != 2070 && inv.ItemVNum != 10010 || (session.CurrentMapInstance.Map.MapTypes.Any(m => m.MapTypeId == (short)MapTypeEnum.Act51 || m.MapTypeId == (short)MapTypeEnum.Act52)))
                        {
                            return;
                        }
                        if (Option == 0)
                        {
                            if (ServerManager.Instance.ChannelId == 51)
                            {
                                session.SendPacket(UserInterfaceHelper.GenerateDialog($"#u_i^{type}^{secondaryType}^{inventoryType}^{slot}^2 #u_i^{type}^{secondaryType}^{inventoryType}^{slot}^0 {Language.Instance.GetMessageFromKey("WANT_TO_GO_BASE")}"));
                            }
                            else
                            {
                                session.SendPacket(UserInterfaceHelper.GenerateDialog($"#u_i^{type}^{secondaryType}^{inventoryType}^{slot}^1 #u_i^{type}^{secondaryType}^{inventoryType}^{slot}^2 {Language.Instance.GetMessageFromKey("WANT_TO_SAVE_POSITION")}"));
                            }
                        }
                        else if (int.TryParse(packetsplit[6], out packetType))
                        {
                            switch (packetType)
                            {
                            case 1:
                                session.SendPacket(UserInterfaceHelper.GenerateDelay(5000, 7, $"#u_i^{type}^{secondaryType}^{inventoryType}^{slot}^3"));
                                break;

                            case 2:
                                session.SendPacket(UserInterfaceHelper.GenerateDelay(5000, 7, $"#u_i^{type}^{secondaryType}^{inventoryType}^{slot}^4"));
                                break;

                            case 3:
                                session.Character.SetReturnPoint(session.Character.MapId, session.Character.MapX, session.Character.MapY);
                                RespawnMapTypeDTO respawn = session.Character.Respawn;
                                if (respawn.DefaultX != 0 && respawn.DefaultY != 0 && respawn.DefaultMapId != 0)
                                {
                                    MapCell mapCell = new MapCell();
                                    for (int i = 0; i < 5; i++)
                                    {
                                        mapCell.X = (short)(respawn.DefaultX + ServerManager.RandomNumber(-3, 3));
                                        mapCell.Y = (short)(respawn.DefaultY + ServerManager.RandomNumber(-3, 3));
                                        if (ServerManager.GetMapInstanceByMapId(respawn.DefaultMapId) is MapInstance GoToMap)
                                        {
                                            if (!GoToMap.Map.IsBlockedZone(mapCell.X, mapCell.Y))
                                            {
                                                break;
                                            }
                                        }
                                    }
                                    ServerManager.Instance.ChangeMap(session.Character.CharacterId, respawn.DefaultMapId, mapCell.X, mapCell.Y);
                                }
                                session.Character.Inventory.RemoveItemFromInventory(inv.Id);
                                break;

                            case 4:
                                RespawnMapTypeDTO respawnObj = session.Character.Respawn;
                                if (ServerManager.Instance.ChannelId == 51)
                                {
                                    respawnObj.DefaultMapId = (short)(129 + session.Character.Faction);
                                    respawnObj.DefaultX     = 41;
                                    respawnObj.DefaultY     = 42;
                                }
                                if (respawnObj.DefaultX != 0 && respawnObj.DefaultY != 0 && respawnObj.DefaultMapId != 0)
                                {
                                    MapCell mapCell = new MapCell();
                                    for (int i = 0; i < 5; i++)
                                    {
                                        mapCell.X = (short)(respawnObj.DefaultX + ServerManager.RandomNumber(-3, 3));
                                        mapCell.Y = (short)(respawnObj.DefaultY + ServerManager.RandomNumber(-3, 3));
                                        if (ServerManager.GetMapInstanceByMapId(respawnObj.DefaultMapId) is MapInstance GoToMap)
                                        {
                                            if (!GoToMap.Map.IsBlockedZone(mapCell.X, mapCell.Y))
                                            {
                                                break;
                                            }
                                        }
                                    }
                                    ServerManager.Instance.ChangeMap(session.Character.CharacterId, respawnObj.DefaultMapId, mapCell.X, mapCell.Y);
                                }
                                session.Character.Inventory.RemoveItemFromInventory(inv.Id);
                                break;
                            }
                        }
                        break;

                    case 1:
                        if (inv.ItemVNum != 2071 && inv.ItemVNum != 10011)
                        {
                            return;
                        }
                        if (int.TryParse(packetsplit[6], out packetType))
                        {
                            if (ServerManager.Instance.ChannelId == 51)
                            {
                                session.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("CANNOT_USE"), 10));
                                return;
                            }
                            RespawnMapTypeDTO respawn = session.Character.Return;
                            switch (packetType)
                            {
                            case 0:
                                if (respawn.DefaultX != 0 && respawn.DefaultY != 0 && respawn.DefaultMapId != 0)
                                {
                                    session.SendPacket(UserInterfaceHelper.GenerateRp(respawn.DefaultMapId, respawn.DefaultX, respawn.DefaultY, $"#u_i^{type}^{secondaryType}^{inventoryType}^{slot}^1"));
                                }
                                break;

                            case 1:
                                session.SendPacket(UserInterfaceHelper.GenerateDelay(5000, 7, $"#u_i^{type}^{secondaryType}^{inventoryType}^{slot}^2"));
                                break;

                            case 2:
                                if (respawn.DefaultX != 0 && respawn.DefaultY != 0 && respawn.DefaultMapId != 0)
                                {
                                    ServerManager.Instance.ChangeMap(session.Character.CharacterId, respawn.DefaultMapId, respawn.DefaultX, respawn.DefaultY);
                                }
                                session.Character.Inventory.RemoveItemFromInventory(inv.Id);
                                break;
                            }
                        }
                        break;

                    case 2:
                        if (inv.ItemVNum != 2072 && inv.ItemVNum != 10012)
                        {
                            return;
                        }
                        if (Option == 0)
                        {
                            session.SendPacket(UserInterfaceHelper.GenerateDelay(5000, 7, $"#u_i^{type}^{secondaryType}^{inventoryType}^{slot}^1"));
                        }
                        else
                        {
                            ServerManager.Instance.JoinMiniland(session, session);
                            session.Character.Inventory.RemoveItemFromInventory(inv.Id);
                        }
                        break;

                    case 4:
                        if (inv.ItemVNum != 2188 || session.Character.MapInstance.Map.MapTypes.Any(s => s.MapTypeId == (short)MapTypeEnum.Act4))
                        {
                            return;
                        }
                        if (Option == 0)
                        {
                            session.SendPacket(UserInterfaceHelper.GenerateDelay(5000, 7, $"#u_i^{type}^{secondaryType}^{inventoryType}^{slot}^1"));
                        }
                        else
                        {
                            ServerManager.Instance.ChangeMap(session.Character.CharacterId, 98, 28, 34);
                            session.Character.Inventory.RemoveItemFromInventory(inv.Id);
                        }
                        break;

                    case 5:
                        if (inv.ItemVNum != 2311 || ServerManager.Instance.ChannelId != 51)
                        {
                            return;
                        }
                        if (ServerManager.GetAllMapInstances().SelectMany(s => s.Monsters.ToList()).LastOrDefault(s => s.MonsterVNum == (short)session.Character.Faction + 964) is MapMonster flag)
                        {
                            if (Option == 0)
                            {
                                session.SendPacket(UserInterfaceHelper.GenerateDelay(5000, 7, $"#u_i^{type}^{secondaryType}^{inventoryType}^{slot}^1"));
                            }
                            else
                            {
                                ServerManager.Instance.ChangeMapInstance(session.Character.CharacterId, flag.MapInstance.MapInstanceId, flag.MapX, flag.MapY);
                                session.Character.Inventory.RemoveItemFromInventory(inv.Id);
                            }
                        }
                        break;

                    case 6:
                        if (inv.ItemVNum != 2384 || ServerManager.Instance.ChannelId == 51 || session.CurrentMapInstance.MapInstanceType != MapInstanceType.BaseMapInstance)
                        {
                            return;
                        }
                        if (Option == 0)
                        {
                            session.SendPacket(UserInterfaceHelper.GenerateDialog($"#u_i^{type}^{secondaryType}^{inventoryType}^{slot}^1 #u_i^{type}^{secondaryType}^{inventoryType}^{slot}^2 {Language.Instance.GetMessageFromKey("WANT_TO_SAVE_POSITION")}"));
                        }
                        else if (int.TryParse(packetsplit[6], out packetType))
                        {
                            switch (packetType)
                            {
                            case 1:
                                session.SendPacket(UserInterfaceHelper.GenerateDelay(5000, 7, $"#u_i^{type}^{secondaryType}^{inventoryType}^{slot}^3"));
                                break;

                            case 2:
                                session.SendPacket(UserInterfaceHelper.GenerateDelay(5000, 7, $"#u_i^{type}^{secondaryType}^{inventoryType}^{slot}^4"));
                                break;

                            case 3:
                                if (session.CurrentMapInstance.Map.MapTypes.Any(s => s.MapTypeId == (short)MapTypeEnum.Act51 || s.MapTypeId == (short)MapTypeEnum.Act52))
                                {
                                    session.Character.SetReturnPoint(session.Character.MapId, session.Character.MapX, session.Character.MapY);
                                    RespawnMapTypeDTO respawn = session.Character.Respawn;
                                    if (respawn.DefaultX != 0 && respawn.DefaultY != 0 && respawn.DefaultMapId != 0)
                                    {
                                        MapCell mapCell = new MapCell();
                                        for (int i = 0; i < 5; i++)
                                        {
                                            mapCell.X = (short)(respawn.DefaultX + ServerManager.RandomNumber(-3, 3));
                                            mapCell.Y = (short)(respawn.DefaultY + ServerManager.RandomNumber(-3, 3));
                                            if (ServerManager.GetMapInstanceByMapId(respawn.DefaultMapId) is MapInstance GoToMap)
                                            {
                                                if (!GoToMap.Map.IsBlockedZone(mapCell.X, mapCell.Y))
                                                {
                                                    break;
                                                }
                                            }
                                        }
                                        ServerManager.Instance.ChangeMap(session.Character.CharacterId, respawn.DefaultMapId, mapCell.X, mapCell.Y);
                                    }
                                    session.Character.Inventory.RemoveItemFromInventory(inv.Id);
                                }
                                else
                                {
                                    goto case 4;
                                }
                                break;

                            case 4:
                                MapInstance mapInstanceBackup = session.CurrentMapInstance;
                                session.CurrentMapInstance = ServerManager.GetMapInstanceByMapId(170);
                                RespawnMapTypeDTO respawnObj = session.Character.Respawn;
                                session.CurrentMapInstance = mapInstanceBackup;
                                if (ServerManager.Instance.ChannelId == 51)
                                {
                                    respawnObj.DefaultMapId = (short)(129 + session.Character.Faction);
                                    respawnObj.DefaultX     = 41;
                                    respawnObj.DefaultY     = 42;
                                }
                                if (respawnObj.DefaultX != 0 && respawnObj.DefaultY != 0 && respawnObj.DefaultMapId != 0)
                                {
                                    MapCell mapCell = new MapCell();
                                    for (int i = 0; i < 5; i++)
                                    {
                                        mapCell.X = (short)(respawnObj.DefaultX + ServerManager.RandomNumber(-3, 3));
                                        mapCell.Y = (short)(respawnObj.DefaultY + ServerManager.RandomNumber(-3, 3));
                                        if (ServerManager.GetMapInstanceByMapId(respawnObj.DefaultMapId) is MapInstance GoToMap)
                                        {
                                            if (!GoToMap.Map.IsBlockedZone(mapCell.X, mapCell.Y))
                                            {
                                                break;
                                            }
                                        }
                                    }
                                    ServerManager.Instance.ChangeMap(session.Character.CharacterId, respawnObj.DefaultMapId, mapCell.X, mapCell.Y);
                                }
                                session.Character.Inventory.RemoveItemFromInventory(inv.Id);
                                break;
                            }
                        }
                        break;
                    }
                }
                break;

            // dyes or waxes
            case 10:
            case 11:
                if (!session.Character.IsVehicled)
                {
                    if (Effect == 10)
                    {
                        if (EffectValue == 99)
                        {
                            byte nextValue = (byte)ServerManager.RandomNumber(0, 127);
                            session.Character.HairColor = Enum.IsDefined(typeof(HairColorType), nextValue) ? (HairColorType)nextValue : 0;
                        }
                        else
                        {
                            session.Character.HairColor = Enum.IsDefined(typeof(HairColorType), (byte)EffectValue) ? (HairColorType)EffectValue : 0;
                        }
                    }
                    else if (Effect == 11)
                    {
                        if (session.Character.Class == (byte)ClassType.Adventurer && EffectValue > 1)
                        {
                            session.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("ADVENTURERS_CANT_USE"), 10));
                            return;
                        }
                        if (session.Character.Gender != (GenderType)Sex && (VNum < 2130 || VNum > 2162) && (VNum < 10025 || VNum > 10026))
                        {
                            session.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("CANNOT_USE"), 10));
                            return;
                        }
                        session.Character.HairStyle = Enum.IsDefined(typeof(HairStyleType), (byte)EffectValue) ? (HairStyleType)EffectValue : 0;
                    }
                    else
                    {
                        if (session.Character.Class == (byte)ClassType.Adventurer && EffectValue > 1)
                        {
                            session.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("ADVENTURERS_CANT_USE"), 10));
                            return;
                        }
                        session.Character.HairStyle = Enum.IsDefined(typeof(HairStyleType), (byte)EffectValue) ? (HairStyleType)EffectValue : 0;
                    }
                    session.SendPacket(session.Character.GenerateEq());
                    session.CurrentMapInstance?.Broadcast(session, session.Character.GenerateIn());
                    session.CurrentMapInstance?.Broadcast(session, session.Character.GenerateGidx());
                    session.Character.Inventory.RemoveItemFromInventory(inv.Id);
                }
                break;

            // TS npcs health
            case 12:
                if (EffectValue > 0)
                {
                    if (session.Character.Timespace != null)
                    {
                        session.Character.MapInstance.GetBattleEntitiesInRange(new MapCell {
                            X = session.Character.PositionX, Y = session.Character.PositionY
                        }, 6)
                        .Where(s => (s.MapNpc != null || (s.Mate != null && s.Mate.IsTemporalMate)) && !session.Character.BattleEntity.CanAttackEntity(s)).ToList()
                        .ForEach(s =>
                        {
                            int health = EffectValue;
                            if (s.Hp + EffectValue > s.HpMax)
                            {
                                health = s.HpMax - s.Hp;
                            }
                            s.Hp += health;
                            session.Character.MapInstance.Broadcast(s.GenerateRc(health));
                            s.Mate?.Owner.Session.SendPacket(s.Mate.GenerateStatInfo());
                        });
                        session.Character.Inventory.RemoveItemFromInventory(inv.Id);
                        session.SendPacket(StaticPacketHelper.GenerateEff(UserType.Player, session.Character.CharacterId, 48));
                    }
                }
                break;

            // dignity restoration
            case 14:
                if ((EffectValue == 100 || EffectValue == 200) && session.Character.Dignity < 100 && !session.Character.IsVehicled)
                {
                    session.Character.Dignity += EffectValue;
                    if (session.Character.Dignity > 100)
                    {
                        session.Character.Dignity = 100;
                    }
                    session.SendPacket(session.Character.GenerateFd());
                    session.SendPacket(StaticPacketHelper.GenerateEff(UserType.Player, session.Character.CharacterId, 49 - (byte)session.Character.Faction));
                    session.CurrentMapInstance?.Broadcast(session, session.Character.GenerateIn(InEffect: 1), ReceiverType.AllExceptMe);
                    session.CurrentMapInstance?.Broadcast(session, session.Character.GenerateGidx(), ReceiverType.AllExceptMe);
                    session.Character.Inventory.RemoveItemFromInventory(inv.Id);
                }
                else if (EffectValue == 2000 && session.Character.Dignity < 100 && !session.Character.IsVehicled)
                {
                    session.Character.Dignity = 100;
                    session.SendPacket(session.Character.GenerateFd());
                    session.SendPacket(StaticPacketHelper.GenerateEff(UserType.Player, session.Character.CharacterId, 49 - (byte)session.Character.Faction));
                    session.CurrentMapInstance?.Broadcast(session, session.Character.GenerateIn(InEffect: 1), ReceiverType.AllExceptMe);
                    session.CurrentMapInstance?.Broadcast(session, session.Character.GenerateGidx(), ReceiverType.AllExceptMe);
                    session.Character.Inventory.RemoveItemFromInventory(inv.Id);
                }
                break;

            // speakers
            case 15:
                if (!session.Character.IsVehicled && Option == 0)
                {
                    session.SendPacket(UserInterfaceHelper.GenerateGuri(10, 3, session.Character.CharacterId, 1));
                }
                break;

            // bubbles
            case 16:
                if (!session.Character.IsVehicled && Option == 0)
                {
                    session.SendPacket(UserInterfaceHelper.GenerateGuri(10, 4, session.Character.CharacterId, 1));
                }
                break;

            // wigs
            case 30:
                if (!session.Character.IsVehicled)
                {
                    ItemInstance wig = session.Character.Inventory.LoadBySlotAndType((byte)EquipmentType.Hat, InventoryType.Wear);
                    if (wig != null)
                    {
                        wig.Design = (byte)ServerManager.RandomNumber(0, 15);
                        session.SendPacket(session.Character.GenerateEq());
                        session.SendPacket(session.Character.GenerateEquipment());
                        session.CurrentMapInstance?.Broadcast(session, session.Character.GenerateIn());
                        session.CurrentMapInstance?.Broadcast(session, session.Character.GenerateGidx());
                        session.Character.Inventory.RemoveItemFromInventory(inv.Id);
                    }
                    else
                    {
                        session.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("NO_WIG"), 0));
                    }
                }
                break;

            case 31:
                if (!session.Character.IsVehicled && session.Character.HairStyle == HairStyleType.Hair7)
                {
                    session.Character.HairStyle = HairStyleType.Hair8;
                    session.SendPacket(session.Character.GenerateEq());
                    session.CurrentMapInstance?.Broadcast(session, session.Character.GenerateIn());
                    session.CurrentMapInstance?.Broadcast(session, session.Character.GenerateGidx());
                    session.Character.Inventory.RemoveItemFromInventory(inv.Id);
                    // idk how it works yet but seems like all characters with this hairstyle have DarkPurple hair
                    //session.Character.HairColor = HairColorType.DarkPurple;
                }
                break;

            // Passive skills books
            case 99:
                if (session.Character.HeroLevel >= EffectValue)
                {
                    if (session.Character.AddSkill((short)(Sex + 1)))
                    {
                        session.SendPacket(session.Character.GenerateSki());
                        session.Character.Inventory.RemoveItemFromInventory(inv.Id);
                    }
                }
                else
                {
                    session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("LOW_HERO_LVL"), 10));
                }
                break;

            case 300:
                if (session.Character.Group != null && session.Character.Group.GroupType != GroupType.Group && session.Character.Group.IsLeader(session) && session.CurrentMapInstance.Portals.Any(s => s.Type == (short)PortalType.Raid))
                {
                    int delay = 0;
                    foreach (ClientSession sess in session.Character.Group.Sessions.GetAllItems())
                    {
                        Observable.Timer(TimeSpan.FromMilliseconds(delay)).Subscribe(o =>
                        {
                            if (sess?.Character != null && session?.CurrentMapInstance != null && session?.Character != null && sess.Character != session.Character)
                            {
                                ServerManager.Instance.TeleportOnRandomPlaceInMap(sess, session.CurrentMapInstance.MapInstanceId);
                            }
                        });
                        delay += 100;
                    }
                    session.Character.Inventory.RemoveItemFromInventory(inv.Id);
                }
                break;

            default:
                Logger.Warn(string.Format(Language.Instance.GetMessageFromKey("NO_HANDLER_ITEM"), GetType(), VNum, Effect, EffectValue));
                break;
            }
        }
Ejemplo n.º 32
0
        public override void Use(ClientSession Session, ref ItemInstance Inv, bool DelayUsed = false, string[] packetsplit = null)
        {
            Random random = new Random();

            switch (Effect)
            {
            // airwaves - eventitems
            case 0:
                if (this != null && this.ItemType == Domain.ItemType.Event)
                {
                    Session.CurrentMap?.Broadcast(Session.Character.GenerateEff(EffectValue));
                    if (MappingHelper.GuriItemEffects.ContainsKey(EffectValue))
                    {
                        Session.CurrentMap?.Broadcast(Session.Character.GenerateGuri(19, 1, MappingHelper.GuriItemEffects[EffectValue]));
                    }

                    Inv.Amount--;
                    if (Inv.Amount > 0)
                    {
                        Session.SendPacket(Session.Character.GenerateInventoryAdd(Inv.ItemVNum, Inv.Amount, Inv.Type, Inv.Slot, 0, 0, 0, 0));
                    }
                    else
                    {
                        Session.Character.Inventory.DeleteFromSlotAndType(Inv.Slot, Inv.Type);
                        Session.SendPacket(Session.Character.GenerateInventoryAdd(-1, 0, Inv.Type, Inv.Slot, 0, 0, 0, 0));
                    }
                }
                break;

            // dyes
            case 10:
                if (this != null && !Session.Character.IsVehicled)
                {
                    if (EffectValue == 99)
                    {
                        Session.Character.HairColor = (byte)random.Next(0, 127);
                    }
                    else
                    {
                        Session.Character.HairColor = (byte)EffectValue;
                    }
                    Session.SendPacket(Session.Character.GenerateEq());
                    Session.CurrentMap?.Broadcast(Session, Session.Character.GenerateIn(), ReceiverType.All);
                    Inv.Amount--;
                    if (Inv.Amount > 0)
                    {
                        Session.SendPacket(Session.Character.GenerateInventoryAdd(Inv.ItemVNum, Inv.Amount, Inv.Type, Inv.Slot, 0, 0, 0, 0));
                    }
                    else
                    {
                        Session.Character.Inventory.DeleteFromSlotAndType(Inv.Slot, Inv.Type);
                        Session.SendPacket(Session.Character.GenerateInventoryAdd(-1, 0, Inv.Type, Inv.Slot, 0, 0, 0, 0));
                    }
                }
                break;

            // waxes
            case 11:
                if (this != null && !Session.Character.IsVehicled)
                {
                    if (Session.Character.Class == (byte)ClassType.Adventurer && EffectValue > 1)
                    {
                        Session.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("ADVENTURERS_CANT_USE"), 10));
                    }
                    else
                    {
                        Session.Character.HairStyle = Session.Character.HairStyle != (byte)EffectValue ? (byte)EffectValue : (byte)1;
                        Session.SendPacket(Session.Character.GenerateEq());
                        Session.CurrentMap?.Broadcast(Session, Session.Character.GenerateIn(), ReceiverType.All);
                        Inv.Amount--;
                        if (Inv.Amount > 0)
                        {
                            Session.SendPacket(Session.Character.GenerateInventoryAdd(Inv.ItemVNum, Inv.Amount, Inv.Type, Inv.Slot, 0, 0, 0, 0));
                        }
                        else
                        {
                            Session.Character.Inventory.DeleteFromSlotAndType(Inv.Slot, Inv.Type);
                            Session.SendPacket(Session.Character.GenerateInventoryAdd(-1, 0, Inv.Type, Inv.Slot, 0, 0, 0, 0));
                        }
                    }
                }
                break;

            // dignity restoration
            case 14:
                if ((EffectValue == 100 || EffectValue == 200) && Session.Character.Dignity < 100 && !Session.Character.IsVehicled)
                {
                    Session.Character.Dignity += EffectValue;
                    if (Session.Character.Dignity > 100)
                    {
                        Session.Character.Dignity = 100;
                    }
                    Session.SendPacket(Session.Character.GenerateFd());
                    Session.SendPacket(Session.Character.GenerateEff(48));
                    Session.CurrentMap?.Broadcast(Session, Session.Character.GenerateIn(), ReceiverType.AllExceptMe);
                    Inv.Amount--;
                    if (Inv.Amount > 0)
                    {
                        Session.SendPacket(Session.Character.GenerateInventoryAdd(Inv.ItemVNum, Inv.Amount, Inv.Type, Inv.Slot, 0, 0, 0, 0));
                    }
                    else
                    {
                        Session.Character.Inventory.DeleteFromSlotAndType(Inv.Slot, Inv.Type);
                        Session.SendPacket(Session.Character.GenerateInventoryAdd(-1, 0, Inv.Type, Inv.Slot, 0, 0, 0, 0));
                    }
                }
                else if (EffectValue == 2000 && Session.Character.Dignity < 100 && !Session.Character.IsVehicled)
                {
                    Session.Character.Dignity = 100;
                    Session.SendPacket(Session.Character.GenerateFd());
                    Session.SendPacket(Session.Character.GenerateEff(48));
                    Session.CurrentMap?.Broadcast(Session, Session.Character.GenerateIn(), ReceiverType.AllExceptMe);
                    Inv.Amount--;
                    if (Inv.Amount > 0)
                    {
                        Session.SendPacket(Session.Character.GenerateInventoryAdd(Inv.ItemVNum, Inv.Amount, Inv.Type, Inv.Slot, 0, 0, 0, 0));
                    }
                    else
                    {
                        Session.Character.Inventory.DeleteFromSlotAndType(Inv.Slot, Inv.Type);
                        Session.SendPacket(Session.Character.GenerateInventoryAdd(-1, 0, Inv.Type, Inv.Slot, 0, 0, 0, 0));
                    }
                }
                break;

            // speakers
            case 15:
                if (this != null && !Session.Character.IsVehicled)
                {
                    if (!DelayUsed)
                    {
                        Session.SendPacket(Session.Character.GenerateGuri(10, 3, 1));
                    }
                }
                break;

            // bubbles
            case 16:
                if (this != null && !Session.Character.IsVehicled)
                {
                    if (!DelayUsed)
                    {
                        Session.SendPacket(Session.Character.GenerateGuri(10, 4, 1));
                    }
                }
                break;

            // wigs
            case 30:
                if (this != null && !Session.Character.IsVehicled)
                {
                    WearableInstance wig = Session.Character.Inventory.LoadBySlotAndType <WearableInstance>((byte)EquipmentType.Hat, InventoryType.Wear);
                    if (wig != null)
                    {
                        wig.Design = (byte)random.Next(0, 15);
                        Session.SendPacket(Session.Character.GenerateEq());
                        Session.SendPacket(Session.Character.GenerateEquipment());
                        Session.CurrentMap?.Broadcast(Session, Session.Character.GenerateIn(), ReceiverType.All);
                        Inv.Amount--;
                        if (Inv.Amount > 0)
                        {
                            Session.SendPacket(Session.Character.GenerateInventoryAdd(Inv.ItemVNum, Inv.Amount, Inv.Type, Inv.Slot, 0, 0, 0, 0));
                        }
                        else
                        {
                            Session.Character.Inventory.DeleteFromSlotAndType(Inv.Slot, Inv.Type);
                            Session.SendPacket(Session.Character.GenerateInventoryAdd(-1, 0, Inv.Type, Inv.Slot, 0, 0, 0, 0));
                        }
                    }
                    else
                    {
                        Session.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("NO_WIG"), 0));
                        return;
                    }
                }
                break;

            // presentation messages
            case 203:
                if (this != null && !Session.Character.IsVehicled)
                {
                    if (!DelayUsed)
                    {
                        Session.SendPacket(Session.Character.GenerateGuri(10, 2, 2));
                    }
                }
                break;

            default:
                Logger.Log.Warn(String.Format(Language.Instance.GetMessageFromKey("NO_HANDLER_ITEM"), this.GetType().ToString()));
                break;
            }
        }
Ejemplo n.º 33
0
        public override void Use(ClientSession session, ref ItemInstance inv, byte Option = 0, string[] packetsplit = null)
        {
            if (session.Character.IsVehicled)
            {
                session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("CANT_DO_VEHICLED"), 10));
                return;
            }

            if (session.CurrentMapInstance.MapInstanceType == MapInstanceType.TalentArenaMapInstance)
            {
                return;
            }

            if (packetsplit == null)
            {
                return;
            }

            void releasePet(MateType mateType, Guid itemToRemoveId)
            {
                if (int.TryParse(packetsplit[3], out int mateTransportId))
                {
                    Mate mate = session.Character.Mates.Find(s => s.MateTransportId == mateTransportId && s.MateType == mateType);
                    if (mate != null)
                    {
                        if (!mate.IsTeamMember)
                        {
                            session.Character.Mates.Remove(mate);
                            session.SendPacket(UserInterfaceHelper.GenerateInfo(Language.Instance.GetMessageFromKey("PET_RELEASED")));
                            session.SendPacket(UserInterfaceHelper.GeneratePClear());
                            session.SendPackets(session.Character.GenerateScP());
                            session.SendPackets(session.Character.GenerateScN());
                            session.CurrentMapInstance?.Broadcast(mate.GenerateOut());
                            session.Character.Inventory.RemoveItemFromInventory(itemToRemoveId);
                        }
                        else
                        {
                            session.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("PET_IN_TEAM_UNRELEASABLE"), 0));
                        }
                    }
                }
            }

            if (BCards.Count > 0 && session.Character.MapInstance == session.Character.Miniland)
            {
                BCards.ForEach(c => c.ApplyBCards(session.Character.BattleEntity, session.Character.BattleEntity));
                session.Character.Inventory.RemoveItemFromInventory(inv.Id);
                return;
            }

            switch (Effect)
            {
            case 10:
                if (int.TryParse(packetsplit[3], out int mateTransportId))
                {
                    Mate mate = session.Character.Mates.Find(s => s.MateTransportId == mateTransportId);
                    if (mate == null || mate.MateType != MateType.Pet || mate.Loyalty >= 1000)
                    {
                        return;
                    }
                    mate.Loyalty += 100;
                    if (mate.Loyalty > 1000)
                    {
                        mate.Loyalty = 1000;
                    }
                    mate.GenerateXp(EffectValue);
                    session.SendPacket(mate.GenerateCond());
                    session.SendPacket(StaticPacketHelper.GenerateEff(UserType.Npc, mate.MateTransportId, 5002));
                    session.Character.Inventory.RemoveItemFromInventory(inv.Id);
                }
                break;

            case 11:
                if (int.TryParse(packetsplit[3], out mateTransportId))
                {
                    Mate mate = session.Character.Mates.Find(s => s.MateTransportId == mateTransportId);
                    if (mate == null || mate.MateType != MateType.Pet || mate.Level >= session.Character.Level - 5 || mate.Level + 1 > ServerManager.Instance.Configuration.MaxLevel)
                    {
                        return;
                    }
                    mate.Level++;
                    session.CurrentMapInstance?.Broadcast(StaticPacketHelper.GenerateEff(UserType.Npc, mate.MateTransportId, 8), mate.PositionX, mate.PositionY);
                    session.CurrentMapInstance?.Broadcast(StaticPacketHelper.GenerateEff(UserType.Npc, mate.MateTransportId, 198), mate.PositionX, mate.PositionY);
                    session.Character.Inventory.RemoveItemFromInventory(inv.Id);
                }
                break;

            case 12:
                if (int.TryParse(packetsplit[3], out mateTransportId))
                {
                    Mate mate = session.Character.Mates.Find(s => s.MateTransportId == mateTransportId);
                    if (mate == null || mate.MateType != MateType.Partner || mate.Level >= session.Character.Level - 5 || mate.Level + 1 > ServerManager.Instance.Configuration.MaxLevel)
                    {
                        return;
                    }
                    mate.Level++;
                    session.CurrentMapInstance?.Broadcast(StaticPacketHelper.GenerateEff(UserType.Npc, mate.MateTransportId, 8), mate.PositionX, mate.PositionY);
                    session.CurrentMapInstance?.Broadcast(StaticPacketHelper.GenerateEff(UserType.Npc, mate.MateTransportId, 198), mate.PositionX, mate.PositionY);
                    session.Character.Inventory.RemoveItemFromInventory(inv.Id);
                }
                break;

            case 13:
                if (int.TryParse(packetsplit[3], out mateTransportId) && session.Character.Mates.FirstOrDefault(s => s.MateTransportId == mateTransportId) is Mate pet)
                {
                    if (pet.MateType == MateType.Pet)
                    {
                        session.SendPacket(UserInterfaceHelper.GenerateGuri(10, 1, mateTransportId, 2));
                    }
                    else
                    {
                        session.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("CANT_CHANGE_PARTNER_NAME"), 0));
                    }
                }
                break;

            case 14:
                if (int.TryParse(packetsplit[3], out mateTransportId))
                {
                    if (session.Character.MapInstance == session.Character.Miniland)
                    {
                        Mate mate = session.Character.Mates.Find(s => s.MateTransportId == mateTransportId && s.MateType == MateType.Pet);
                        if (mate?.CanPickUp == false)
                        {
                            session.CurrentMapInstance.Broadcast(StaticPacketHelper.GenerateEff(UserType.Npc, mate.MateTransportId, 5));
                            session.CurrentMapInstance.Broadcast(StaticPacketHelper.GenerateEff(UserType.Npc, mate.MateTransportId, 5002));
                            mate.CanPickUp = true;
                            session.SendPackets(session.Character.GenerateScP());
                            session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("PET_CAN_PICK_UP"), 10));
                            session.Character.Inventory.RemoveItemFromInventory(inv.Id);
                        }
                    }
                    else
                    {
                        session.SendPacket(session.Character.GenerateSay(Language.Instance.GetMessageFromKey("NOT_IN_MINILAND"), 12));
                    }
                }
                break;

            case 16:
                if (int.TryParse(packetsplit[3], out mateTransportId))
                {
                    Mate mate = session.Character.Mates.Find(s => s.MateTransportId == mateTransportId);
                    if (mate == null || mate.MateType != MateType.Pet || mate.Level == 1)
                    {
                        return;
                    }
                    mate.Level--;
                    session.Character.Inventory.RemoveItemFromInventory(inv.Id);
                }
                break;

            case 17:
                if (int.TryParse(packetsplit[3], out mateTransportId))
                {
                    Mate mate = session.Character.Mates.Find(s => s.MateTransportId == mateTransportId);
                    if (mate?.IsSummonable == false)
                    {
                        mate.IsSummonable = true;
                        session.SendPackets(session.Character.GenerateScP());
                        session.SendPacket(session.Character.GenerateSay(string.Format(Language.Instance.GetMessageFromKey("PET_SUMMONABLE"), mate.Name), 10));
                        session.SendPacket(UserInterfaceHelper.GenerateMsg(string.Format(Language.Instance.GetMessageFromKey("PET_SUMMONABLE"), mate.Name), 0));
                        session.Character.Inventory.RemoveItemFromInventory(inv.Id);
                    }
                }
                break;

            case 18:
                if (int.TryParse(packetsplit[3], out mateTransportId))
                {
                    Mate mate = session.Character.Mates.Find(s => s.MateTransportId == mateTransportId);
                    if (mate == null || mate.MateType != MateType.Partner || mate.Level == 1)
                    {
                        return;
                    }
                    mate.Level--;
                    session.Character.Inventory.RemoveItemFromInventory(inv.Id);
                }
                break;

            case 1000:
                releasePet(MateType.Pet, inv.Id);
                break;

            case 1001:
                releasePet(MateType.Partner, inv.Id);
                break;

            default:
                Logger.Warn(string.Format(Language.Instance.GetMessageFromKey("NO_HANDLER_ITEM"), GetType(), VNum, Effect, EffectValue));
                break;
            }
        }
Ejemplo n.º 34
0
        /// <summary>
        /// c_scalc packet
        /// </summary>
        /// <param name="cScalcPacket"></param>
        public void GetBazaar(CScalcPacket cScalcPacket)
        {
            if (ServerManager.Instance.InShutdown || Session.Character == null || Session.Character.InExchangeOrTrade)
            {
                return;
            }
            SpinWait.SpinUntil(() => !ServerManager.Instance.InBazaarRefreshMode);
            BazaarItemDTO bz = DAOFactory.BazaarItemDAO.FirstOrDefault(s => s.BazaarItemId == cScalcPacket.BazaarId);

            if (bz != null)
            {
                ItemInstance item = (ItemInstance)DAOFactory.IteminstanceDAO.FirstOrDefault(s => s.Id == bz.ItemInstanceId);
                if (item == null || bz.SellerId != Session.Character.CharacterId)
                {
                    return;
                }
                int  soldedamount = bz.Amount - item.Amount;
                long taxes        = bz.MedalUsed ? 0 : (long)(bz.Price * 0.10 * soldedamount);
                long price        = bz.Price * soldedamount - taxes;
                if (Session.Character.Inventory.CanAddItem(item.ItemVNum))
                {
                    if (Session.Character.Gold + price <= ServerManager.Instance.MaxGold)
                    {
                        Session.Character.Gold += price;
                        Session.SendPacket(Session.Character.GenerateGold());
                        Session.SendPacket(Session.Character.GenerateSay(string.Format(Language.Instance.GetMessageFromKey("REMOVE_FROM_BAZAAR"), price), 10));
                        if (item.Amount != 0)
                        {
                            ItemInstance newBz = item.DeepCopy();
                            newBz.Id   = Guid.NewGuid();
                            newBz.Type = newBz.Item.Type;
                            if (newBz is WearableInstance wear)
                            {
                                wear.EquipmentOptions.AddRange(DAOFactory.EquipmentOptionDAO.Where(s => s.WearableInstanceId == item.Id));
                                wear.EquipmentOptions.ForEach(s => s.WearableInstanceId = newBz.Id);
                            }
                            List <ItemInstance> newInv = Session.Character.Inventory.AddToInventory(newBz);
                        }
                        Session.SendPacket($"rc_scalc 1 {bz.Price} {bz.Amount - item.Amount} {bz.Amount} {taxes} {price + taxes}");

                        if (DAOFactory.BazaarItemDAO.FirstOrDefault(s => s.BazaarItemId == bz.BazaarItemId) != null)
                        {
                            DAOFactory.BazaarItemDAO.Delete(bz.BazaarItemId);
                        }

                        DAOFactory.IteminstanceDAO.Delete(item.Id);

                        ServerManager.Instance.BazaarRefresh(bz.BazaarItemId);
                    }
                    else
                    {
                        Session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("MAX_GOLD"), 0));
                        Session.SendPacket($"rc_scalc 1 {bz.Price} 0 {bz.Amount} 0 0");
                    }
                }
                else
                {
                    Session.SendPacket(UserInterfaceHelper.Instance.GenerateInfo(Language.Instance.GetMessageFromKey("NOT_ENOUGH_PLACE")));
                    Session.SendPacket($"rc_scalc 1 {bz.Price} 0 {bz.Amount} 0 0");
                }
            }
            else
            {
                Session.SendPacket("rc_scalc 1 0 0 0 0 0");
            }
        }
Ejemplo n.º 35
0
 public override void Use(ClientSession session, ref ItemInstance inv, byte Option = 0, string[] packetsplit = null)
 {
     if (!session.HasCurrentMapInstance)
     {
         return;
     }
     if ((DateTime.Now - session.Character.LastPotion).TotalMilliseconds < (session.CurrentMapInstance.Map.MapTypes.OrderByDescending(s => s.PotionDelay).FirstOrDefault()?.PotionDelay ?? 750))
     {
         return;
     }
     session.Character.LastPotion = DateTime.Now;
     switch (Effect)
     {
     default:
         if (session.Character.Hp == session.Character.HPLoad() && session.Character.Mp == session.Character.MPLoad())
         {
             return;
         }
         if (session.Character.Hp <= 0)
         {
             return;
         }
         session.Character.Inventory.RemoveItemFromInventory(inv.Id);
         if ((int)session.Character.HPLoad() - session.Character.Hp < Hp)
         {
             session.CurrentMapInstance?.Broadcast(session.Character.GenerateRc((int)session.Character.HPLoad() - session.Character.Hp));
         }
         else if ((int)session.Character.HPLoad() - session.Character.Hp > Hp)
         {
             session.CurrentMapInstance?.Broadcast(session.Character.GenerateRc(Hp));
         }
         session.Character.Mp += Mp;
         session.Character.Hp += Hp;
         if (session.Character.Mp > session.Character.MPLoad())
         {
             session.Character.Mp = (int)session.Character.MPLoad();
         }
         if (session.Character.Hp > session.Character.HPLoad())
         {
             session.Character.Hp = (int)session.Character.HPLoad();
         }
         if (ServerManager.Instance.ChannelId != 51 || session.Character.MapId == 130 || session.Character.MapId == 131)
         {
             if (inv.ItemVNum == 1242 || inv.ItemVNum == 5582)
             {
                 session.CurrentMapInstance?.Broadcast(session.Character.GenerateRc((int)session.Character.HPLoad() - session.Character.Hp));
                 session.Character.Hp = (int)session.Character.HPLoad();
             }
             else if (inv.ItemVNum == 1243 || inv.ItemVNum == 5583)
             {
                 session.Character.Mp = (int)session.Character.MPLoad();
             }
             else if (inv.ItemVNum == 1244 || inv.ItemVNum == 5584)
             {
                 session.CurrentMapInstance?.Broadcast(session.Character.GenerateRc((int)session.Character.HPLoad() - session.Character.Hp));
                 session.Character.Hp = (int)session.Character.HPLoad();
                 session.Character.Mp = (int)session.Character.MPLoad();
             }
         }
         session.SendPacket(session.Character.GenerateStat());
         break;
     }
 }
Ejemplo n.º 36
0
        /// <summary>
        /// c_buy packet
        /// </summary>
        /// <param name="cBuyPacket"></param>
        public void BuyBazaar(CBuyPacket cBuyPacket)
        {
            if (ServerManager.Instance.InShutdown || Session.Character == null || Session.Character.InExchangeOrTrade)
            {
                return;
            }
            BazaarItemDTO bz = DAOFactory.BazaarItemDAO.FirstOrDefault(s => s.BazaarItemId == cBuyPacket.BazaarId);

            if (bz != null && cBuyPacket.Amount > 0)
            {
                long price = cBuyPacket.Amount * bz.Price;

                if (Session.Character.Gold >= price)
                {
                    BazaarItemLink bzcree = new BazaarItemLink {
                        BazaarItem = bz
                    };
                    if (DAOFactory.CharacterDAO.FirstOrDefault(s => s.CharacterId == bz.SellerId && s.State == (byte)CharacterState.Active) != null)
                    {
                        bzcree.Owner = DAOFactory.CharacterDAO.FirstOrDefault(s => s.CharacterId.Equals(bz.SellerId) && s.State == (byte)CharacterState.Active)?.Name;
                        bzcree.Item  = (ItemInstance)DAOFactory.IteminstanceDAO.FirstOrDefault(s => s.Id == bz.ItemInstanceId);
                    }
                    if (cBuyPacket.Amount <= bzcree.Item.Amount)
                    {
                        if (!Session.Character.Inventory.CanAddItem(bzcree.Item.ItemVNum))
                        {
                            Session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("NOT_ENOUGH_PLACE"), 0));
                            return;
                        }

                        if (bzcree.Item == null)
                        {
                            return;
                        }
                        if (bz.IsPackage && cBuyPacket.Amount != bz.Amount)
                        {
                            return;
                        }
                        ItemInstanceDTO bzitemdto = DAOFactory.IteminstanceDAO.FirstOrDefault(s => s.Id == bzcree.BazaarItem.ItemInstanceId);
                        if (bzitemdto.Amount < cBuyPacket.Amount)
                        {
                            return;
                        }
                        bzitemdto.Amount       -= cBuyPacket.Amount;
                        Session.Character.Gold -= price;
                        Session.SendPacket(Session.Character.GenerateGold());
                        DAOFactory.IteminstanceDAO.InsertOrUpdate(ref bzitemdto);
                        ServerManager.Instance.BazaarRefresh(bzcree.BazaarItem.BazaarItemId);
                        Session.SendPacket($"rc_buy 1 {bzcree.Item.Item.VNum} {bzcree.Owner} {cBuyPacket.Amount} {cBuyPacket.Price} 0 0 0");
                        ItemInstance newBz = bzcree.Item.DeepCopy();
                        newBz.Id     = Guid.NewGuid();
                        newBz.Amount = cBuyPacket.Amount;
                        newBz.Type   = newBz.Item.Type;
                        if (newBz is WearableInstance wear)
                        {
                            wear.EquipmentOptions.ForEach(s => s.WearableInstanceId = newBz.Id);
                        }


                        List <ItemInstance> newInv = Session.Character.Inventory.AddToInventory(newBz);
                        if (newInv.Any())
                        {
                            Session.SendPacket(Session.Character.GenerateSay($"{Language.Instance.GetMessageFromKey("ITEM_ACQUIRED")}: { bzcree.Item.Item.Name} x {cBuyPacket.Amount}", 10));
                        }
                    }
                    else
                    {
                        Session.SendPacket(UserInterfaceHelper.Instance.GenerateModal(Language.Instance.GetMessageFromKey("STATE_CHANGED"), 1));
                    }
                }
                else
                {
                    Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("NOT_ENOUGH_MONEY"), 10));
                    Session.SendPacket(UserInterfaceHelper.Instance.GenerateModal(Language.Instance.GetMessageFromKey("NOT_ENOUGH_MONEY"), 1));
                }
            }
            else
            {
                Session.SendPacket(UserInterfaceHelper.Instance.GenerateModal(Language.Instance.GetMessageFromKey("STATE_CHANGED"), 1));
            }
        }
Ejemplo n.º 37
0
 public abstract void Use(ClientSession session, ref ItemInstance inv, bool delay = false, string[] packetsplit = null);
Ejemplo n.º 38
0
        public override void Use(ClientSession session, ref ItemInstance inv, bool delay = false, string[] packetsplit = null)
        {
            if (Effect == 0)
            {
                if (EffectValue != 0)
                {
                    if (session.Character.IsSitting)
                    {
                        session.Character.IsSitting = false;
                        session.SendPacket(session.Character.GenerateRest());
                    }
                    session.SendPacket(session.Character.GenerateGuri(12, 1, EffectValue));
                }
                else if (EffectValue == 0)
                {
                    if (packetsplit != null)
                    {
                        byte TypeEquip = 0;
                        short SlotEquip = -1;

                        if (byte.TryParse(packetsplit[8], out TypeEquip) && short.TryParse(packetsplit[9], out SlotEquip))
                        {
                            if (session.Character.IsSitting)
                            {
                                session.Character.IsSitting = false;
                                session.SendPacket(session.Character.GenerateRest());
                            }
                            if (delay)
                            {
                                bool isUsed = false;
                                switch (inv.ItemVNum)
                                {
                                    case 1219:
                                        WearableInstance equip = session.Character.Inventory.LoadBySlotAndType<WearableInstance>(SlotEquip, (Domain.InventoryType)TypeEquip);
                                        if (equip != null && equip.IsFixed)
                                        {
                                            equip.IsFixed = false;
                                            session.SendPacket(session.Character.GenerateEff(3003));
                                            session.SendPacket(session.Character.GenerateGuri(17, 1, 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, (Domain.InventoryType)TypeEquip);
                                        if (specialist != null && specialist.Rare == -2)
                                        {
                                            specialist.Rare = 0;
                                            session.SendPacket(session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("SP_RESURRECTED"), 0));
                                            session.CurrentMap?.Broadcast(session.Character.GenerateGuri(13, 1, 1), session.Character.MapX, session.Character.MapY);
                                            session.Character.SpPoint = 10000;
                                            if (session.Character.SpPoint > 10000)
                                            {
                                                session.Character.SpPoint = 10000;
                                            }
                                            session.SendPacket(session.Character.GenerateSpPoint());
                                            session.SendPacket(session.Character.GenerateInventoryAdd(specialist.ItemVNum, 1, (Domain.InventoryType)TypeEquip, SlotEquip, specialist.Rare, specialist.Design, specialist.Upgrade, 0));
                                            isUsed = true;
                                        }
                                        break;
                                }

                                switch (inv.ItemVNum)
                                {
                                    case 9039:
                                        SpecialistInstance specialist = session.Character.Inventory.LoadBySlotAndType<SpecialistInstance>(SlotEquip, (Domain.InventoryType)TypeEquip);
                                        if (specialist != null && specialist.Rare == -2)
                                        {
                                            specialist.Rare = 0;
                                            session.SendPacket(session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("SP_RESURRECTED"), 0));
                                            session.CurrentMap?.Broadcast(session.Character.GenerateGuri(13, 1, 1), session.Character.MapX, session.Character.MapY);
                                            session.Character.SpPoint = 10000;
                                            session.SendPacket(session.Character.GenerateSpPoint());
                                            session.SendPacket(session.Character.GenerateInventoryAdd(specialist.ItemVNum, 1, (Domain.InventoryType)TypeEquip, SlotEquip, specialist.Rare, specialist.Design, specialist.Upgrade, 0));
                                            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"), this.GetType().ToString()));
            }
        }
        public override void Use(ClientSession session, ref ItemInstance inv, bool delay = false, string[] packetsplit = null)
        {
            switch (Effect)
            {
            default:
                short         slot           = inv.Slot;
                InventoryType itemToWearType = inv.Type;

                if (inv == null)
                {
                    return;
                }
                if (ItemValidTime > 0 && inv.IsBound)
                {
                    inv.ItemDeleteTime = DateTime.Now.AddSeconds(ItemValidTime);
                }
                if (!inv.IsBound)
                {
                    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(session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("CANT_EQUIP_DESTROYED_SP"), 0));
                    return;
                }

                if (EquipmentSlot == EquipmentType.Sp && timeSpanSinceLastSpUsage <= session.Character.SpCooldown && session.Character.Inventory.LoadBySlotAndType <SpecialistInstance>((byte)EquipmentType.Sp, InventoryType.Specialist) != null)
                {
                    session.SendPacket(session.Character.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, InventoryType.Wear);

                    if (sp.Item.Element != 0 && EquipmentSlot == EquipmentType.Fairy && Element != sp.Item.Element && Element != sp.Item.SecondaryElement)
                    {
                        session.SendPacket(session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("BAD_FAIRY"), 0));
                        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;
                }

                ItemInstance currentlyEquippedItem = session.Character.Inventory.LoadBySlotAndType((short)EquipmentSlot, InventoryType.Wear);
                if (EquipmentSlot == EquipmentType.Amulet)
                {
                    session.SendPacket(session.Character.GenerateEff(39));
                    inv.BoundCharacterId = session.Character.CharacterId;
                }

                if (currentlyEquippedItem == null)
                {
                    // move from equipment to wear
                    session.Character.Inventory.MoveInInventory(inv.Slot, itemToWearType, InventoryType.Wear);
                    session.SendPacket(session.Character.GenerateInventoryAdd(-1, 0, itemToWearType, slot, 0, 0, 0, 0));
                    session.SendPacket(session.Character.GenerateStatChar());
                    session.CurrentMap?.Broadcast(session.Character.GenerateEq());
                    session.SendPacket(session.Character.GenerateEquipment());
                    session.CurrentMap?.Broadcast(session.Character.GeneratePairy());
                }
                else
                {
                    // move from wear to equipment and back
                    session.Character.Inventory.MoveInInventory(currentlyEquippedItem.Slot, InventoryType.Wear, itemToWearType, inv.Slot);

                    session.SendPacket(session.Character.GenerateInventoryAdd(-1, 0, itemToWearType, slot, 0, 0, 0, 0));
                    session.SendPacket(session.Character.GenerateInventoryAdd(currentlyEquippedItem.ItemVNum, currentlyEquippedItem.Amount,
                                                                              currentlyEquippedItem.Type, currentlyEquippedItem.Slot, currentlyEquippedItem.Rare, currentlyEquippedItem.Design, currentlyEquippedItem.Upgrade, (currentlyEquippedItem as SpecialistInstance)?.SpStoneUpgrade ?? (byte)0));

                    session.SendPacket(session.Character.GenerateStatChar());
                    session.CurrentMap?.Broadcast(session.Character.GenerateEq());
                    session.SendPacket(session.Character.GenerateEquipment());
                    session.CurrentMap?.Broadcast(session.Character.GeneratePairy());
                }

                if (EquipmentSlot == EquipmentType.Fairy)
                {
                    WearableInstance fairy = session.Character.Inventory.LoadBySlotAndType <WearableInstance>((byte)EquipmentType.Fairy, InventoryType.Wear);
                    session.SendPacket(session.Character.GenerateSay(string.Format(Language.Instance.GetMessageFromKey("FAIRYSTATS"), fairy.XP, CharacterHelper.LoadFairyXPData(fairy.ElementRate + fairy.Item.ElementRate)), 10));
                }
                break;
            }
        }