Example #1
0
        private static void RemovePetLevel(ref Mate mate, Guid idToRemove)
        {
            if (mate == null || mate.Level <= 1)
            {
                return;
            }

            mate.Level     -= 1;
            mate.Experience = 0;
            mate.Hp         = mate.HpLoad();
            mate.Mp         = mate.MpLoad();
            mate.Owner?.Session.SendPacket(mate.GenerateCond());
            mate.Owner?.Session.SendPacket(mate.GenerateScPacket());
            mate.Owner?.Session.CurrentMapInstance?.Broadcast(StaticPacketHelper.GenerateEff(UserType.Npc, mate.MateTransportId, 8), mate.PositionX, mate.PositionY);
            mate.Owner?.Session.CurrentMapInstance?.Broadcast(StaticPacketHelper.GenerateEff(UserType.Npc, mate.MateTransportId, 198), mate.PositionX, mate.PositionY);
            mate.Owner?.Session.Character.Inventory.RemoveItemFromInventory(idToRemove);
        }
Example #2
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.FirstOrDefault(s => s.MateType == MateType.Partner && s.PetId == (option - 1));
                }
                short         slot      = inv.Slot;
                InventoryType equipment = InventoryType.Wear;
                switch (option)
                {
                case 1:
                    equipment = InventoryType.FirstPartnerInventory;
                    break;

                case 2:
                    equipment = InventoryType.SecondPartnerInventory;
                    break;

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

                InventoryType itemToWearType = inv.Type;

                if (inv == null)
                {
                    return;
                }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                if (currentlyEquippedItem == null)
                {
                    // move from equipment to wear
                    session.Character.Inventory.MoveInInventory(inv.Slot, itemToWearType, equipment);
                    session.SendPacket(UserInterfaceHelper.Instance.GenerateInventoryRemove(itemToWearType, slot));
                }
                else
                {
                    // move from wear to equipment and back
                    session.Character.Inventory.MoveInInventory(currentlyEquippedItem.Slot, equipment, itemToWearType, inv.Slot);
                    session.SendPacket(currentlyEquippedItem.GenerateInventoryAdd());
                    session.Character.EquipmentBCards = session.Character.EquipmentBCards.Replace(o => o.ItemVNum != currentlyEquippedItem.ItemVNum);
                    switch (currentlyEquippedItem.Slot)
                    {
                    case (byte)EquipmentType.Armor:
                        session.Character.Inventory.Armor = null;
                        break;

                    case (byte)EquipmentType.MainWeapon:
                        session.Character.Inventory.PrimaryWeapon = null;
                        break;

                    case (byte)EquipmentType.SecondaryWeapon:
                        session.Character.Inventory.SecondaryWeapon = null;
                        break;
                    }
                }
                inv.Item.BCards.ForEach(s => session.Character.EquipmentBCards.Add(s));

                if (inv is WearableInstance wearableInstance)
                {
                    if (wearableInstance.EquipmentOptions != null)
                    {
                        switch (wearableInstance.Item.ItemType)
                        {
                        case ItemType.Armor:
                        case ItemType.Weapon:
                            switch (wearableInstance.Slot)
                            {
                            case (byte)EquipmentType.Armor:
                                session.Character.Inventory.Armor = wearableInstance;
                                break;

                            case (byte)EquipmentType.MainWeapon:
                                session.Character.Inventory.PrimaryWeapon = wearableInstance;
                                break;

                            case (byte)EquipmentType.SecondaryWeapon:
                                session.Character.Inventory.SecondaryWeapon = wearableInstance;
                                break;
                            }
                            EquipmentOptionHelper.Instance.ShellToBCards(wearableInstance.EquipmentOptions, wearableInstance.ItemVNum).ForEach(s => session.Character.EquipmentBCards.Add(s));
                            break;

                        case ItemType.Jewelery:
                            EquipmentOptionHelper.Instance.CellonToBCards(wearableInstance.EquipmentOptions, wearableInstance.ItemVNum).ForEach(s => session.Character.EquipmentBCards.Add(s));
                            break;
                        }
                    }
                }

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

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

                    case EquipmentType.Amulet:
                        session.SendPacket(session.Character.GenerateEff(39));
                        inv.BoundCharacterId = session.Character.CharacterId;
                        break;
                    }
                }
                else if (mate != null)
                {
                    session.SendPacket(mate.GenerateScPacket());
                }
                break;
            }
        }
Example #3
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.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)
                    {
                        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.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, 42));
                        inv.BoundCharacterId = session.Character.CharacterId;
                    }
                }
                else if (mate != null)
                {
                    session.SendPacket(mate.GenerateScPacket());
                }
                break;
            }
        }
        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;
            }
        }
Example #5
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;
            }
        }
Example #6
0
        public override void Use(ClientSession session, ref ItemInstance inv, byte option = 0, string[] packetsplit = null)
        {
            if (packetsplit == null)
            {
                return;
            }

            void ReleasePet(MateType mateType, Guid itemToRemoveId)
            {
                if (!int.TryParse(packetsplit[3], out int mateTransportId))
                {
                    return;
                }

                Mate mate = session.Character.Mates.Find(s => s.MateTransportId == mateTransportId && s.MateType == mateType);

                if (mate == null)
                {
                    return;
                }

                if (mate.MateType == MateType.Partner)
                {
                    if (mate.SpInstance != null || mate.GlovesInstance != null || mate.BootsInstance != null || mate.WeaponInstance != null || mate.ArmorInstance != null)
                    {
                        session.SendPacket(UserInterfaceHelper.GenerateInfo(Language.Instance.GetMessageFromKey("MUST_REMOVE_PARTNER_EQUIPMENT")));
                        return;
                    }
                }

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

            switch (Effect)
            {
            // loyalty & xp petfood
            case 10:
                if (int.TryParse(packetsplit[3], out var mateTransportId))
                {
                    Mate mate = session.Character.Mates.Find(s => s.MateTransportId == mateTransportId && s.MateType == MateType.Pet);

                    if (mate == null || mate.Loyalty >= 1000 || mate.MateType == MateType.Partner)
                    {
                        return;
                    }

                    mate.Loyalty = (short)(mate.Loyalty + 100 > 1000 ? 1000 : mate.Loyalty + 100);
                    mate.GenerateXp(EffectValue);
                    session.SendPacket(mate.GenerateScPacket());
                    mate.Owner?.Session.SendPacket(mate.GenerateCond());
                    mate.Owner?.Session.SendPacket(StaticPacketHelper.GenerateEff(UserType.Npc, mate.MateTransportId, 5));
                    mate.Owner?.Session.SendPacket(StaticPacketHelper.GenerateEff(UserType.Npc, mate.MateTransportId, 5002));
                    mate.Owner?.Session.SendPacket(mate.Owner.GenerateSay(Language.Instance.GetMessageFromKey("MATE_EATS_FOOD"), 10));
                    session.Character.Inventory.RemoveItemFromInventory(inv.Id);
                }
                break;

            case 11:
            case 12:
                if (int.TryParse(packetsplit[3], out mateTransportId))
                {
                    Mate mate = session.Character.Mates.Find(s => s.MateTransportId == mateTransportId && s.MateType == (Effect == 11 ? MateType.Pet : MateType.Partner));
                    AddPetLevel(ref mate, inv.Id);
                }
                break;

            case 13:
                if (int.TryParse(packetsplit[3], out mateTransportId) && session.Character.Mates.Any(s => s.MateTransportId == mateTransportId))
                {
                    session.SendPacket(UserInterfaceHelper.GenerateGuri(10, 1, mateTransportId, 2));
                }
                break;

            case 14:
                if (int.TryParse(packetsplit[3], out mateTransportId))
                {
                    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);
                    }
                }
                break;

            case 16:
                if (int.TryParse(packetsplit[3], out mateTransportId))
                {
                    Mate mate = session.Character.Mates.Find(s => s.MateTransportId == mateTransportId && s.MateType == MateType.Pet);
                    RemovePetLevel(ref mate, 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 && s.MateType == MateType.Partner);
                    RemovePetLevel(ref mate, inv.Id);
                }
                break;

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

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

            // Pet trainer
            case 10000:
                if (session.Character.MapInstance != session.Character.Miniland)
                {
                    session.SendPacket(UserInterfaceHelper.GenerateModal(Language.Instance.GetMessageFromKey("NOT_IN_MINILAND"), 1));
                    return;
                }

                var monster = new MapMonster
                {
                    MonsterVNum   = (short)EffectValue,
                    MapY          = session.Character.PositionY,
                    MapX          = session.Character.PositionX,
                    MapId         = session.Character.MapInstance.Map.MapId,
                    Position      = session.Character.Direction,
                    IsMoving      = true,
                    IsHostile     = true,
                    MapMonsterId  = session.CurrentMapInstance.GetNextMonsterId(),
                    IsMateTrainer = true,
                    ShouldRespawn = false
                };

                monster.Initialize(session.CurrentMapInstance);
                session.CurrentMapInstance.AddMonster(monster);
                session.CurrentMapInstance.Broadcast(monster.GenerateIn());
                session.Character.Inventory.RemoveItemAmount(inv.ItemVNum);
                monster.GetNearestOponent();
                break;

            default:
                Logger.Warn(string.Format(Language.Instance.GetMessageFromKey("NO_HANDLER_ITEM"), GetType(), VNum, Effect, EffectValue));
                break;
            }
        }