Jump to content

Recommended Posts

Posted (edited)

 

hello I wanted to add a second value of custom enchant value for a custom scroll or donor I tried it but when using the scroll it keeps using the common value of custom enchant value and I don't know how to make it work thanks anyway

 

 

 

 

enchant config:

 

Quote

# The value of enchanting
# For example: If CustomEnchantValue = 5 Sharpening will:
# From 0 till the +5, with +5 to +10, from +10 to +15, etc.
# Total: 15 for three to scroll
# Default: 1 
CustomEnchantValue = 5

CustomDayEnchantValue = 25

CustomNightEnchantValue = 30

 

 

 

 

RequestEnchantItem.java

 

Quote

    private static final int[] BRANCA_DAY_WEAPON_SCROLLS =
    {
        12021
    };
    
    private static final int[] BRANCA_DAY_ARMOR_SCROLLS =
    {
        12020
    };
    
    private static final int[] BRANCA_NIGHT_WEAPON_SCROLLS =
    {
        12023
    };
    
    private static final int[] BRANCA_NIGHT_ARMOR_SCROLLS =
    {
        12022
    };
    
    private static final int[] NORMAL_ARMOR_SCROLLS =
    {
        730,
        948,
        952,
        956,
        960
    };
    
    private static final int[] BLESSED_ARMOR_SCROLLS =
    {
        6570,
        6572,
        6574,
        6576,
        6578
    };
    
    private static final int[] CRYSTAL_ARMOR_SCROLLS =
    {
        732,
        950,
        954,
        958,
        962
    };
    
    private int _objectId;
    
    @Override
    protected void readImpl()
    {
        _objectId = readD();
    }
    
    @Override
    protected void runImpl()
    {
        L2PcInstance activeChar = getClient().getActiveChar();
        
        if (activeChar == null || _objectId == 0)
        {
            return;
        }
        
        if (!getClient().getFloodProtectors().getUseAugItem().tryPerformAction("use enchant item"))
        {
            LOG.info(activeChar.getName() + " tried flood on ITEM enchanter.");
            activeChar.setActiveEnchantItem(null);
            activeChar.sendPacket(ActionFailed.STATIC_PACKET);
            return;
        }
        
        if (activeChar.isSubmitingPin())
        {
            activeChar.sendMessage("Unable to do any action while PIN is not submitted");
            activeChar.sendPacket(ActionFailed.STATIC_PACKET);
            return;
        }
        
        if (activeChar.getActiveTradeList() != null)
        {
            activeChar.cancelActiveTrade();
            activeChar.sendMessage("Your trade canceled.");
            return;
        }
        
        // Fix enchant transactions
        if (activeChar.isProcessingTransaction())
        {
            activeChar.sendPacket(new SystemMessage(SystemMessageId.INAPPROPRIATE_ENCHANT_CONDITION));
            activeChar.setActiveEnchantItem(null);
            return;
        }
        
        if (activeChar.isOnline() == 0)
        {
            activeChar.setActiveEnchantItem(null);
            return;
        }
        
        L2ItemInstance item = activeChar.getInventory().getItemByObjectId(_objectId);
        L2ItemInstance scroll = activeChar.getActiveEnchantItem();
        activeChar.setActiveEnchantItem(null);
        
        if (item == null || scroll == null)
        {
            activeChar.setActiveEnchantItem(null);
            activeChar.sendPacket(SystemMessageId.ENCHANT_SCROLL_CANCELLED);
            activeChar.sendPacket(EnchantResult.CANCELLED);
            return;
        }
        
        handleAugmentScrolls(activeChar, item, scroll);
        
        // can't enchant rods and shadow items
        if (item.getItem().getItemType() == L2WeaponType.ROD || item.isShadowItem())
        {
            activeChar.sendPacket(new SystemMessage(SystemMessageId.INAPPROPRIATE_ENCHANT_CONDITION));
            activeChar.setActiveEnchantItem(null);
            return;
        }
        
        if (!Config.ENCHANT_HERO_WEAPON && item.getItemId() >= 6611 && item.getItemId() <= 6621)
        {
            activeChar.sendPacket(new SystemMessage(SystemMessageId.INAPPROPRIATE_ENCHANT_CONDITION));
            activeChar.setActiveEnchantItem(null);
            return;
        }
        
        if (item.isWear())
        {
            activeChar.setActiveEnchantItem(null);
            Util.handleIllegalPlayerAction(activeChar, "Player " + activeChar.getName() + " tried to enchant a weared Item", IllegalPlayerAction.PUNISH_KICK);
            return;
        }
        
        int itemType2 = item.getItem().getType2();
        boolean enchantItem = false;
        boolean blessedScroll = false;
        boolean crystalScroll = false;
        boolean BrancaDayScroll = false;
        boolean BrancaNightScroll = false;
        int crystalId = 0;
        
        switch (item.getItem().getCrystalType())
        {
            case L2Item.CRYSTAL_A:
                crystalId = 1461;
                switch (scroll.getItemId())
                {
                    case 729:
                    case 731:
                    case 6569:
                        if (itemType2 == L2Item.TYPE2_WEAPON)
                        {
                            enchantItem = true;
                        }
                        break;
                    case 730:
                    case 732:
                    case 6570:
                        if (itemType2 == L2Item.TYPE2_SHIELD_ARMOR || itemType2 == L2Item.TYPE2_ACCESSORY)
                        {
                            enchantItem = true;
                        }
                        break;
                }
                break;
            case L2Item.CRYSTAL_B:
                crystalId = 1460;
                switch (scroll.getItemId())
                {
                    case 947:
                    case 949:
                    case 6571:
                        if (itemType2 == L2Item.TYPE2_WEAPON)
                        {
                            enchantItem = true;
                        }
                        break;
                    case 948:
                    case 950:
                    case 6572:
                        if (itemType2 == L2Item.TYPE2_SHIELD_ARMOR || itemType2 == L2Item.TYPE2_ACCESSORY)
                        {
                            enchantItem = true;
                        }
                        break;
                }
                break;
            case L2Item.CRYSTAL_C:
                crystalId = 1459;
                switch (scroll.getItemId())
                {
                    case 951:
                    case 953:
                    case 6573:
                        if (itemType2 == L2Item.TYPE2_WEAPON)
                        {
                            enchantItem = true;
                        }
                        break;
                    case 952:
                    case 954:
                    case 6574:
                        if (itemType2 == L2Item.TYPE2_SHIELD_ARMOR || itemType2 == L2Item.TYPE2_ACCESSORY)
                        {
                            enchantItem = true;
                        }
                        break;
                }
                break;
            case L2Item.CRYSTAL_D:
                crystalId = 1458;
                switch (scroll.getItemId())
                {
                    case 955:
                    case 957:
                    case 6575:
                        if (itemType2 == L2Item.TYPE2_WEAPON)
                        {
                            enchantItem = true;
                        }
                        break;
                    case 956:
                    case 958:
                    case 6576:
                        if (itemType2 == L2Item.TYPE2_SHIELD_ARMOR || itemType2 == L2Item.TYPE2_ACCESSORY)
                        {
                            enchantItem = true;
                        }
                        break;
                }
                break;
            case L2Item.CRYSTAL_S:
                crystalId = 1462;
                switch (scroll.getItemId())
                {
                    case 959:
                    case 961:
                    case 6577:
                    case 12021:
                    case 12022:
                        if (itemType2 == L2Item.TYPE2_WEAPON)
                        {
                            enchantItem = true;
                        }
                        break;
                    case 960:
                    case 962:
                    case 6578:
                    case 12020:
                    case 12023:
                        if (itemType2 == L2Item.TYPE2_SHIELD_ARMOR || itemType2 == L2Item.TYPE2_ACCESSORY)
                        {
                            enchantItem = true;
                        }
                        break;
                }
                break;
        }
        
        if (!enchantItem)
        {
            return;
        }
        
        // Get the scroll type
        if (scroll.getItemId() >= 6569 && scroll.getItemId() <= 6578)
        {
            blessedScroll = true;
        }
        else if (scroll.getItemId() == 12020 || scroll.getItemId() == 12021)
        {
            BrancaDayScroll = true;
        }
        else if (scroll.getItemId() == 12022 || scroll.getItemId() == 12023)
        {
            BrancaNightScroll = true;
        }
        else
        {
            for (int crystalscroll : CRYSTAL_SCROLLS)
            {
                if (scroll.getItemId() == crystalscroll)
                {
                    crystalScroll = true;
                    break;
                }
            }
            
        }
        
        SystemMessage sm;
        int chance = 0;
        int maxEnchantLevel = 0;
        int minEnchantLevel = 0;
        
        if (item.getItem().getType2() == L2Item.TYPE2_WEAPON)
        {
            if (blessedScroll)
            {
                for (int blessedweaponscroll : BLESSED_WEAPON_SCROLLS)
                {
                    if (scroll.getItemId() == blessedweaponscroll)
                    {
                        if (item.getEnchantLevel() >= Config.BLESS_WEAPON_ENCHANT_LEVEL.size())
                        {
                            chance = Config.BLESS_WEAPON_ENCHANT_LEVEL.get(Config.BLESS_WEAPON_ENCHANT_LEVEL.size());
                        }
                        else
                        {
                            chance = Config.BLESS_WEAPON_ENCHANT_LEVEL.get(item.getEnchantLevel() + 1);
                        }
                        
                        if (Config.CUSTOM_ENCHANT_GRADES_SYSTEM)
                        {
                            switch (item.getItem().getCrystalType())
                            {
                                case L2Item.CRYSTAL_S:
                                    maxEnchantLevel = Config.BLESSED_ENCHANT_MAX_S;
                                    break;
                                case L2Item.CRYSTAL_A:
                                    maxEnchantLevel = Config.BLESSED_ENCHANT_MAX_A;
                                    break;
                                case L2Item.CRYSTAL_B:
                                    maxEnchantLevel = Config.BLESSED_ENCHANT_MAX_B;
                                    break;
                                case L2Item.CRYSTAL_C:
                                    maxEnchantLevel = Config.BLESSED_ENCHANT_MAX_C;
                                    break;
                                case L2Item.CRYSTAL_D:
                                    maxEnchantLevel = Config.BLESSED_ENCHANT_MAX_D;
                                    break;
                            }
                        }
                        
                        if (!Config.CUSTOM_ENCHANT_GRADES_SYSTEM)
                        {
                            maxEnchantLevel = Config.ENCHANT_WEAPON_MAX;
                            break;
                        }
                    }
                }
            }
            
            else if (BrancaDayScroll)
            {
                
                for (int scrollId : BRANCA_DAY_WEAPON_SCROLLS)
                {
                    if (scroll.getItemId() == scrollId)
                    {
                        if (item.getEnchantLevel() >= Config.DONATOR_DAY_WEAPON_ENCHANT_LEVEL.size())
                        {
                            chance = Config.DONATOR_DAY_WEAPON_ENCHANT_LEVEL.get(Config.DONATOR_DAY_WEAPON_ENCHANT_LEVEL.size());
                        }
                        else
                        {
                            chance = Config.DONATOR_DAY_WEAPON_ENCHANT_LEVEL.get(item.getEnchantLevel() + 1);
                        }
                        minEnchantLevel = Config.ENCHANT_DAY_WEAPON_MIN;
                        maxEnchantLevel = Config.ENCHANT_DAY_WEAPON_MAX;
                        break;
                    }
                }
            }
            
            else if (BrancaNightScroll)
            {
                
                for (int scrollId : BRANCA_NIGHT_WEAPON_SCROLLS)
                {
                    if (scroll.getItemId() == scrollId)
                    {
                        if (item.getEnchantLevel() >= Config.DONATOR_NIGHT_WEAPON_ENCHANT_LEVEL.size())
                        {
                            chance = Config.DONATOR_NIGHT_WEAPON_ENCHANT_LEVEL.get(Config.DONATOR_NIGHT_WEAPON_ENCHANT_LEVEL.size());
                        }
                        else
                        {
                            chance = Config.DONATOR_NIGHT_WEAPON_ENCHANT_LEVEL.get(item.getEnchantLevel() + 1);
                        }
                        minEnchantLevel = Config.ENCHANT_NIGHT_WEAPON_MIN;
                        maxEnchantLevel = Config.ENCHANT_NIGHT_WEAPON_MAX;
                        break;
                    }
                }
            }
            
            else if (crystalScroll)
            {
                for (int crystalweaponscroll : CRYSTAL_WEAPON_SCROLLS)
                {
                    if (scroll.getItemId() == crystalweaponscroll)
                    {
                        if (item.getEnchantLevel() >= Config.CRYSTAL_WEAPON_ENCHANT_LEVEL.size())
                        {
                            chance = Config.CRYSTAL_WEAPON_ENCHANT_LEVEL.get(Config.CRYSTAL_WEAPON_ENCHANT_LEVEL.size());
                        }
                        else
                        {
                            chance = Config.CRYSTAL_WEAPON_ENCHANT_LEVEL.get(item.getEnchantLevel() + 1);
                        }
                        
                        minEnchantLevel = Config.CRYSTAL_ENCHANT_MIN;
                        maxEnchantLevel = Config.CRYSTAL_ENCHANT_MAX;
                        
                        break;
                    }
                }
            }
            else
            { // normal scrolls
                for (int normalweaponscroll : NORMAL_WEAPON_SCROLLS)
                {
                    if (scroll.getItemId() == normalweaponscroll)
                    {
                        if (item.getEnchantLevel() >= Config.NORMAL_WEAPON_ENCHANT_LEVEL.size())
                        {
                            chance = Config.NORMAL_WEAPON_ENCHANT_LEVEL.get(Config.NORMAL_WEAPON_ENCHANT_LEVEL.size());
                        }
                        else
                        {
                            chance = Config.NORMAL_WEAPON_ENCHANT_LEVEL.get(item.getEnchantLevel() + 1);
                        }
                        
                        if (Config.CUSTOM_ENCHANT_GRADES_SYSTEM)
                        {
                            switch (item.getItem().getCrystalType())
                            {
                                case L2Item.CRYSTAL_S:
                                    maxEnchantLevel = Config.ENCHANT_MAX_S;
                                    break;
                                case L2Item.CRYSTAL_A:
                                    maxEnchantLevel = Config.ENCHANT_MAX_A;
                                    break;
                                case L2Item.CRYSTAL_B:
                                    maxEnchantLevel = Config.ENCHANT_MAX_B;
                                    break;
                                case L2Item.CRYSTAL_C:
                                    maxEnchantLevel = Config.ENCHANT_MAX_C;
                                    break;
                                case L2Item.CRYSTAL_D:
                                    maxEnchantLevel = Config.ENCHANT_MAX_D;
                                    break;
                            }
                        }
                        
                    }
                    else if (BrancaDayScroll)
                    {
                        
                        for (int scrollId : BRANCA_DAY_ARMOR_SCROLLS)
                        {
                            if (scroll.getItemId() == scrollId)
                            {
                                if (item.getEnchantLevel() >= Config.DONATOR_DAY_ARMOR_ENCHANT_LEVEL.size())
                                {
                                    chance = Config.DONATOR_DAY_ARMOR_ENCHANT_LEVEL.get(Config.DONATOR_DAY_ARMOR_ENCHANT_LEVEL.size());
                                }
                                else
                                {
                                    chance = Config.DONATOR_DAY_ARMOR_ENCHANT_LEVEL.get(item.getEnchantLevel() + 1);
                                }
                                minEnchantLevel = Config.ENCHANT_DAY_ARMOR_MIN;
                                maxEnchantLevel = Config.ENCHANT_DAY_ARMOR_MAX;
                                
                                break;
                            }
                        }
                        
                        if (!Config.CUSTOM_ENCHANT_GRADES_SYSTEM)
                        {
                            maxEnchantLevel = Config.ENCHANT_WEAPON_MAX;
                            break;
                        }
                    }
                }
            }
            
        }
        else if (item.getItem().getType2() == L2Item.TYPE2_SHIELD_ARMOR)
        {
            if (blessedScroll)
            {
                for (int blessedarmorscroll : BLESSED_ARMOR_SCROLLS)
                {
                    if (scroll.getItemId() == blessedarmorscroll)
                    {
                        if (item.getEnchantLevel() >= Config.BLESS_ARMOR_ENCHANT_LEVEL.size())
                        {
                            chance = Config.BLESS_ARMOR_ENCHANT_LEVEL.get(Config.BLESS_ARMOR_ENCHANT_LEVEL.size());
                        }
                        else
                        {
                            chance = Config.BLESS_ARMOR_ENCHANT_LEVEL.get(item.getEnchantLevel() + 1);
                        }
                        
                        if (Config.CUSTOM_ENCHANT_GRADES_SYSTEM)
                        {
                            switch (item.getItem().getCrystalType())
                            {
                                case L2Item.CRYSTAL_S:
                                    maxEnchantLevel = Config.BLESSED_ENCHANT_MAX_S;
                                    break;
                                case L2Item.CRYSTAL_A:
                                    maxEnchantLevel = Config.BLESSED_ENCHANT_MAX_A;
                                    break;
                                case L2Item.CRYSTAL_B:
                                    maxEnchantLevel = Config.BLESSED_ENCHANT_MAX_B;
                                    break;
                                case L2Item.CRYSTAL_C:
                                    maxEnchantLevel = Config.BLESSED_ENCHANT_MAX_C;
                                    break;
                                case L2Item.CRYSTAL_D:
                                    maxEnchantLevel = Config.BLESSED_ENCHANT_MAX_D;
                                    break;
                            }
                        }
                        
                        if (!Config.CUSTOM_ENCHANT_GRADES_SYSTEM)
                        {
                            maxEnchantLevel = Config.ENCHANT_ARMOR_MAX;
                            break;
                        }
                    }
                }
            }
            else if (crystalScroll)
            {
                for (int crystalarmorscroll : CRYSTAL_ARMOR_SCROLLS)
                {
                    if (scroll.getItemId() == crystalarmorscroll)
                    {
                        if (item.getEnchantLevel() >= Config.CRYSTAL_ARMOR_ENCHANT_LEVEL.size())
                        {
                            chance = Config.CRYSTAL_ARMOR_ENCHANT_LEVEL.get(Config.CRYSTAL_ARMOR_ENCHANT_LEVEL.size());
                        }
                        else
                        {
                            chance = Config.CRYSTAL_ARMOR_ENCHANT_LEVEL.get(item.getEnchantLevel() + 1);
                        }
                        
                        minEnchantLevel = Config.CRYSTAL_ENCHANT_MIN;
                        maxEnchantLevel = Config.CRYSTAL_ENCHANT_MAX;
                        
                        break;
                    }
                }
                
            }
            else
            { // normal scrolls
                for (int normalarmorscroll : NORMAL_ARMOR_SCROLLS)
                {
                    if (scroll.getItemId() == normalarmorscroll)
                    {
                        if (item.getEnchantLevel() >= Config.NORMAL_ARMOR_ENCHANT_LEVEL.size())
                        {
                            chance = Config.NORMAL_ARMOR_ENCHANT_LEVEL.get(Config.NORMAL_ARMOR_ENCHANT_LEVEL.size());
                        }
                        else
                        {
                            chance = Config.NORMAL_ARMOR_ENCHANT_LEVEL.get(item.getEnchantLevel() + 1);
                        }
                        
                        if (Config.CUSTOM_ENCHANT_GRADES_SYSTEM)
                        {
                            switch (item.getItem().getCrystalType())
                            {
                                case L2Item.CRYSTAL_S:
                                    maxEnchantLevel = Config.ENCHANT_MAX_S;
                                    break;
                                case L2Item.CRYSTAL_A:
                                    maxEnchantLevel = Config.ENCHANT_MAX_A;
                                    break;
                                case L2Item.CRYSTAL_B:
                                    maxEnchantLevel = Config.ENCHANT_MAX_B;
                                    break;
                                case L2Item.CRYSTAL_C:
                                    maxEnchantLevel = Config.ENCHANT_MAX_C;
                                    break;
                                case L2Item.CRYSTAL_D:
                                    maxEnchantLevel = Config.ENCHANT_MAX_D;
                                    break;
                            }
                        }
                        
                    }
                    else if (BrancaNightScroll)
                    {
                        
                        for (int scrollId : BRANCA_NIGHT_ARMOR_SCROLLS)
                        {
                            if (scroll.getItemId() == scrollId)
                            {
                                if (item.getEnchantLevel() >= Config.DONATOR_NIGHT_ARMOR_ENCHANT_LEVEL.size())
                                {
                                    chance = Config.DONATOR_NIGHT_ARMOR_ENCHANT_LEVEL.get(Config.DONATOR_NIGHT_ARMOR_ENCHANT_LEVEL.size());
                                }
                                else
                                {
                                    chance = Config.DONATOR_NIGHT_ARMOR_ENCHANT_LEVEL.get(item.getEnchantLevel() + 1);
                                }
                                minEnchantLevel = Config.ENCHANT_NIGHT_ARMOR_MIN;
                                maxEnchantLevel = Config.ENCHANT_NIGHT_ARMOR_MAX;
                                
                                break;
                            }
                        }
                        
                        if (!Config.CUSTOM_ENCHANT_GRADES_SYSTEM)
                        {
                            maxEnchantLevel = Config.ENCHANT_ARMOR_MAX;
                            break;
                        }
                    }
                }
                
            }
            
        }
        else if (item.getItem().getType2() == L2Item.TYPE2_ACCESSORY)
        {
            if (blessedScroll)
            {
                
                for (int blessedjewelscroll : BLESSED_ARMOR_SCROLLS)
                {
                    if (scroll.getItemId() == blessedjewelscroll)
                    {
                        if (item.getEnchantLevel() >= Config.BLESS_JEWELRY_ENCHANT_LEVEL.size())
                        {
                            chance = Config.BLESS_JEWELRY_ENCHANT_LEVEL.get(Config.BLESS_JEWELRY_ENCHANT_LEVEL.size());
                        }
                        else
                        {
                            chance = Config.BLESS_JEWELRY_ENCHANT_LEVEL.get(item.getEnchantLevel() + 1);
                        }
                        
                        if (Config.CUSTOM_ENCHANT_GRADES_SYSTEM)
                        {
                            switch (item.getItem().getCrystalType())
                            {
                                case L2Item.CRYSTAL_S:
                                    maxEnchantLevel = Config.BLESSED_ENCHANT_MAX_S;
                                    break;
                                case L2Item.CRYSTAL_A:
                                    maxEnchantLevel = Config.BLESSED_ENCHANT_MAX_A;
                                    break;
                                case L2Item.CRYSTAL_B:
                                    maxEnchantLevel = Config.BLESSED_ENCHANT_MAX_B;
                                    break;
                                case L2Item.CRYSTAL_C:
                                    maxEnchantLevel = Config.BLESSED_ENCHANT_MAX_C;
                                    break;
                                case L2Item.CRYSTAL_D:
                                    maxEnchantLevel = Config.BLESSED_ENCHANT_MAX_D;
                                    break;
                            }
                        }
                        
                        if (!Config.CUSTOM_ENCHANT_GRADES_SYSTEM)
                        {
                            maxEnchantLevel = Config.ENCHANT_JEWELRY_MAX;
                            break;
                        }
                    }
                }
                
            }
            else if (crystalScroll)
            {
                for (int crystaljewelscroll : CRYSTAL_ARMOR_SCROLLS)
                {
                    if (scroll.getItemId() == crystaljewelscroll)
                    {
                        if (item.getEnchantLevel() >= Config.CRYSTAL_JEWELRY_ENCHANT_LEVEL.size())
                        {
                            chance = Config.CRYSTAL_JEWELRY_ENCHANT_LEVEL.get(Config.CRYSTAL_JEWELRY_ENCHANT_LEVEL.size());
                        }
                        else
                        {
                            chance = Config.CRYSTAL_JEWELRY_ENCHANT_LEVEL.get(item.getEnchantLevel() + 1);
                        }
                        
                        minEnchantLevel = Config.CRYSTAL_ENCHANT_MIN;
                        maxEnchantLevel = Config.CRYSTAL_ENCHANT_MAX;
                        
                        break;
                    }
                }
            }
            else
            {
                for (int normaljewelscroll : NORMAL_ARMOR_SCROLLS)
                {
                    if (scroll.getItemId() == normaljewelscroll)
                    {
                        if (item.getEnchantLevel() >= Config.NORMAL_JEWELRY_ENCHANT_LEVEL.size())
                        {
                            chance = Config.NORMAL_JEWELRY_ENCHANT_LEVEL.get(Config.NORMAL_JEWELRY_ENCHANT_LEVEL.size());
                        }
                        else
                        {
                            chance = Config.NORMAL_JEWELRY_ENCHANT_LEVEL.get(item.getEnchantLevel() + 1);
                        }
                        
                        if (Config.CUSTOM_ENCHANT_GRADES_SYSTEM)
                        {
                            switch (item.getItem().getCrystalType())
                            {
                                case L2Item.CRYSTAL_S:
                                    maxEnchantLevel = Config.ENCHANT_MAX_S;
                                    break;
                                case L2Item.CRYSTAL_A:
                                    maxEnchantLevel = Config.ENCHANT_MAX_A;
                                    break;
                                case L2Item.CRYSTAL_B:
                                    maxEnchantLevel = Config.ENCHANT_MAX_B;
                                    break;
                                case L2Item.CRYSTAL_C:
                                    maxEnchantLevel = Config.ENCHANT_MAX_C;
                                    break;
                                case L2Item.CRYSTAL_D:
                                    maxEnchantLevel = Config.ENCHANT_MAX_D;
                                    break;
                            }
                        }
                        
                        if (!Config.CUSTOM_ENCHANT_GRADES_SYSTEM)
                        {
                            maxEnchantLevel = Config.ENCHANT_JEWELRY_MAX;
                            break;
                        }
                    }
                }
            }
            
        }
        
        if ((maxEnchantLevel != 0 && item.getEnchantLevel() >= maxEnchantLevel) || (item.getEnchantLevel()) < minEnchantLevel)
        {
            activeChar.sendPacket(new SystemMessage(SystemMessageId.INAPPROPRIATE_ENCHANT_CONDITION));
            return;
        }
        
        if (Config.SCROLL_STACKABLE)
        {
            scroll = activeChar.getInventory().destroyItem("Enchant", scroll.getObjectId(), 1, activeChar, item);
        }
        else
        {
            scroll = activeChar.getInventory().destroyItem("Enchant", scroll, activeChar, item);
        }
        
        if (scroll == null)
        {
            activeChar.sendPacket(new SystemMessage(SystemMessageId.NOT_ENOUGH_ITEMS));
            Util.handleIllegalPlayerAction(activeChar, "Player " + activeChar.getName() + " tried to enchant with a scroll he doesnt have", Config.DEFAULT_PUNISH);
            return;
        }
        
        if (item.getEnchantLevel() < Config.ENCHANT_SAFE_MAX || item.getItem().getBodyPart() == L2Item.SLOT_FULL_ARMOR && item.getEnchantLevel() < Config.ENCHANT_SAFE_MAX_FULL)
        {
            chance = 100;
        }
        
        int rndValue = Rnd.get(100);
        
        if (Config.ENABLE_DWARF_ENCHANT_BONUS && activeChar.getRace() == Race.dwarf)
        {
            if (activeChar.getLevel() >= Config.DWARF_ENCHANT_MIN_LEVEL)
            {
                rndValue -= Config.DWARF_ENCHANT_BONUS;
            }
        }
        
        Object aChance = item.fireEvent("calcEnchantChance", new Object[chance]);
        if (aChance != null)
        {
            chance = (Integer) aChance;
        }
        
        synchronized (item)
        {
            if (rndValue < chance)
            {
                if (item.getOwnerId() != activeChar.getObjectId())
                {
                    activeChar.sendPacket(new SystemMessage(SystemMessageId.INAPPROPRIATE_ENCHANT_CONDITION));
                    return;
                }
                
                if (item.getLocation() != L2ItemInstance.ItemLocation.INVENTORY && item.getLocation() != L2ItemInstance.ItemLocation.PAPERDOLL)
                {
                    activeChar.sendPacket(new SystemMessage(SystemMessageId.INAPPROPRIATE_ENCHANT_CONDITION));
                    return;
                }
                
                if (item.getEnchantLevel() == 0)
                {
                    sm = new SystemMessage(SystemMessageId.S1_SUCCESSFULLY_ENCHANTED);
                    sm.addItemName(item.getItemId());
                    activeChar.sendPacket(sm);
                }
                else
                {
                    sm = new SystemMessage(SystemMessageId.S1_S2_SUCCESSFULLY_ENCHANTED);
                    sm.addNumber(item.getEnchantLevel());
                    sm.addItemName(item.getItemId());
                    activeChar.sendPacket(sm);
                }
                
                item.setEnchantLevel(item.getEnchantLevel() + Config.CUSTOM_ENCHANT_VALUE);
                item.setEnchantLevel2(item.getEnchantLevel2() + Config.CUSTOM_DAY_ENCHANT_VALUE);
                item.setEnchantLevel3(item.getEnchantLevel3() + Config.CUSTOM_NIGHT_ENCHANT_VALUE);
                item.updateDatabase();
                
                if (activeChar.getAchievement().getCount(item.isWeapon() ? AchType.ENCHANT_WEAPON : AchType.ENCHANT_OTHER) < item.getEnchantLevel())
                {
                    activeChar.getAchievement().increase(item.isWeapon() ? AchType.ENCHANT_WEAPON : AchType.ENCHANT_OTHER, item.getEnchantLevel(), false, false);
                }
                
                activeChar.getAchievement().increase(AchType.ENCHANT_SUCCESS);
            }
            else
            {
                if (crystalScroll)
                {
                    sm = SystemMessage.sendString("Failed in Crystal Enchant. The enchant value of the item became: " + item.getEnchantLevel());
                    activeChar.sendPacket(sm);
                    activeChar.getAchievement().increase(AchType.ENCHANT_FAILED);
                }
                else if (blessedScroll)
                {
                    sm = new SystemMessage(SystemMessageId.BLESSED_ENCHANT_FAILED);
                    activeChar.sendPacket(sm);
                }
                else if (BrancaDayScroll)
                {
                    sm = SystemMessage.sendString("Failed in Custom Enchant. The enchant value of the item become " + Config.DONATOR_ENCHANT_AFTER_BREAK + ".");
                    activeChar.sendPacket(sm);
                }
                else if (BrancaNightScroll)
                {
                    sm = SystemMessage.sendString("Failed in Custom Enchant. The enchant value of the item become " + Config.DONATOR_ENCHANT_AFTER_BREAK + ".");
                    activeChar.sendPacket(sm);
                    
                    activeChar.getAchievement().increase(AchType.ENCHANT_FAILED);
                }
                else
                {
                    if (item.getEnchantLevel() > 0)
                    {
                        sm = new SystemMessage(SystemMessageId.ENCHANTMENT_FAILED_S1_S2_EVAPORATED);
                        sm.addNumber(item.getEnchantLevel());
                        sm.addItemName(item.getItemId());
                        activeChar.sendPacket(sm);
                    }
                    else
                    {
                        sm = new SystemMessage(SystemMessageId.ENCHANTMENT_FAILED_S1_EVAPORATED);
                        sm.addItemName(item.getItemId());
                        activeChar.sendPacket(sm);
                    }
                    activeChar.getAchievement().increase(AchType.ENCHANT_FAILED);
                }
                
                if (!blessedScroll && !crystalScroll && !BrancaDayScroll && !BrancaNightScroll)
                {
                    if (!Config.PROTECT_NORMAL_SCROLLS)
                    {
                        if (item.getEnchantLevel() > 0)
                        {
                            sm = new SystemMessage(SystemMessageId.EQUIPMENT_S1_S2_REMOVED);
                            sm.addNumber(item.getEnchantLevel());
                            sm.addItemName(item.getItemId());
                            activeChar.sendPacket(sm);
                        }
                        else
                        {
                            sm = new SystemMessage(SystemMessageId.S1_DISARMED);
                            sm.addItemName(item.getItemId());
                            activeChar.sendPacket(sm);
                        }
                        
                        if (item.isEquipped())
                        {
                            if (item.isAugmented())
                            {
                                item.getAugmentation().removeBoni(activeChar);
                            }
                            
                            L2ItemInstance[] unequiped = activeChar.getInventory().unEquipItemInSlotAndRecord(item.getEquipSlot());
                            
                            InventoryUpdate iu = new InventoryUpdate();
                            for (L2ItemInstance element : unequiped)
                            {
                                iu.addModifiedItem(element);
                            }
                            activeChar.sendPacket(iu);
                            
                            activeChar.broadcastUserInfo();
                        }
                        
                        int count = item.getCrystalCount() - (item.getItem().getCrystalCount() + 1) / 2;
                        if (count < 1)
                        {
                            count = 1;
                        }
                        
                        if (item.fireEvent("enchantFail", new Object[] {}) != null)
                        {
                            return;
                        }
                        
                        L2ItemInstance destroyItem = activeChar.getInventory().destroyItem("Enchant", item, activeChar, null);
                        if (destroyItem == null)
                        {
                            return;
                        }
                        
                        L2ItemInstance crystals = activeChar.getInventory().addItem("Enchant", crystalId, count, activeChar, destroyItem);
                        
                        sm = new SystemMessage(SystemMessageId.EARNED_S2_S1_S);
                        sm.addItemName(crystals.getItemId());
                        sm.addNumber(count);
                        activeChar.sendPacket(sm);
                        
                        if (!Config.FORCE_INVENTORY_UPDATE)
                        {
                            InventoryUpdate iu = new InventoryUpdate();
                            if (destroyItem.getCount() == 0)
                            {
                                iu.addRemovedItem(destroyItem);
                            }
                            else
                            {
                                iu.addModifiedItem(destroyItem);
                            }
                            iu.addItem(crystals);
                            activeChar.sendPacket(iu);
                        }
                        else
                        {
                            activeChar.sendPacket(new ItemList(activeChar, true));
                        }
                        
                        StatusUpdate su = new StatusUpdate(activeChar.getObjectId());
                        su.addAttribute(StatusUpdate.CUR_LOAD, activeChar.getCurrentLoad());
                        activeChar.sendPacket(su);
                        
                        activeChar.broadcastUserInfo();
                        
                        L2World world = L2World.getInstance();
                        world.removeObject(destroyItem);
                    }
                    else
                    {
                        item.setEnchantLevel(0);
                        item.updateDatabase();
                    }
                }
                else
                {
                    if (blessedScroll)
                    {
                        if (!Config.EXPLLOSIVE_CUSTOM)
                        {
                            item.setEnchantLevel(Config.BREAK_ENCHANT);
                            item.updateDatabase();
                        }
                        else
                        {
                            if (item.getEnchantLevel() >= 9)
                            {
                                item.setEnchantLevel(item.getEnchantLevel() - 5);
                            }
                            else
                            {
                                item.setEnchantLevel(4);
                            }
                            
                            item.updateDatabase();
                        }
                    }
                    else if (crystalScroll)
                    {
                        item.setEnchantLevel(item.getEnchantLevel());
                        item.updateDatabase();
                    }
                    else if (BrancaDayScroll)
                    {
                        item.setEnchantLevel2(Config.BREAK_ENCHANT);
                        item.updateDatabase();
                    }
                    else if (BrancaNightScroll)
                    {
                        item.setEnchantLevel3(Config.BREAK_ENCHANT);
                        item.updateDatabase();
                    }
                }
            }
        }
        
        StatusUpdate su = new StatusUpdate(activeChar.getObjectId());
        su.addAttribute(StatusUpdate.CUR_LOAD, activeChar.getCurrentLoad());
        activeChar.sendPacket(su);
        
        activeChar.sendPacket(new EnchantResult(item.getEnchantLevel()));
        activeChar.sendPacket(new ItemList(activeChar, false));
        activeChar.broadcastUserInfo();
    }
    
    private static void handleAugmentScrolls(L2PcInstance player, L2ItemInstance item, L2ItemInstance scroll)
    {
        // get scroll augment data
        L2AugmentScroll enchant = AugmentScrollData.getInstance().getScroll(scroll);
        if (enchant != null)
        {
            if (item.getItem().getType2() != L2Item.TYPE2_WEAPON)
            {
                player.sendMessage("This scroll can be used only on weapon.");
                player.setActiveEnchantItem(null);
                player.sendPacket(EnchantResult.CANCELLED);
                return;
            }
            
            if (item.getItem().getCrystalType() == L2Item.CRYSTAL_NONE || item.getItem().getCrystalType() == L2Item.CRYSTAL_D || item.getItem().getCrystalType() == L2Item.CRYSTAL_C)
            {
                player.sendMessage("You can't augment this grade item.");
                player.setActiveEnchantItem(null);
                player.sendPacket(EnchantResult.CANCELLED);
                return;
            }
            
            if (item.isHeroItem())
            {
                player.sendMessage("You can't augment hero item " + item.getItemName() + ".");
                player.setActiveEnchantItem(null);
                player.sendPacket(EnchantResult.CANCELLED);
                return;
            }
            
            if (item.isAugmented())
            {
                player.sendMessage("This item is already augmented.");
                player.setActiveEnchantItem(null);
                player.sendPacket(EnchantResult.CANCELLED);
                return;
            }
            
            if (item.getOwnerId() != player.getObjectId())
            {
                player.sendPacket(SystemMessageId.INAPPROPRIATE_ENCHANT_CONDITION);
                player.setActiveEnchantItem(null);
                player.sendPacket(EnchantResult.CANCELLED);
                return;
            }
            
            if (!player.destroyItemByItemId("", enchant.getAugmentScrollId(), 1, null, true))
            {
                return;
            }
            
            // unequip item
            if (item.isEquipped())
            {
                L2ItemInstance[] unequipped = player.getInventory().unEquipItemInSlotAndRecord(item.getLocationSlot());
                InventoryUpdate iu = new InventoryUpdate();
                
                for (L2ItemInstance itm : unequipped)
                {
                    iu.addModifiedItem(itm);
                }
                
                player.sendPacket(iu);
                player.broadcastUserInfo();
            }
            
            int skill = enchant.getAugmentSkillId();
            int level = enchant.getAugmentSkillLv();
            
            final L2Augmentation aug = AugmentationData.getInstance().generateAugmentationWithSkill(item, skill, level);
            item.setAugmentation(aug);
            
            InventoryUpdate iu = new InventoryUpdate();
            iu.addModifiedItem(item);
            player.sendPacket(iu);
            
            StatusUpdate su = new StatusUpdate(player.getObjectId());
            su.addAttribute(StatusUpdate.CUR_LOAD, player.getCurrentLoad());
            player.sendPacket(su);
            
            player.broadcastUserInfo();
            player.sendSkillList();
            player.setActiveEnchantItem(null);
            player.sendPacket(EnchantResult.CANCELLED);
            player.sendMessage("You successfully augmented the weapon.");
            player.sendPacket(new PlaySound("ItemSound3.sys_enchant_success"));
            return;
        }
    }
    
    @Override
    public String getType()
    {
        return "[C] 58 RequestEnchantItem";
    }
}
 

 

 

 

Edited by tensador27

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Posts

    • I genuinely admire your bravery - in an age where AI can whip up something better in under a minute, you still stubbornly try to sell these "projects" of yours on a forum that’s been clinically dead for years. That’s no longer determination, that’s digital archaeology. I just can’t tell whether you’re actually trying to make money, or simply testing how much we can endure before we ask an AI to generate you some actual talent.   And ofc AI will make it for free, $220 saved.
    • I’m glad I’m not the only one who appreciates Maxthor’s involvement in group gay orgies, he can’t be bothered to reply to messages, but covering the entire forum in gay lights is absolutely no issue for him. As for the project - the forum is packed with feedback from the testers, the lads are spending every spare moment fixing even the tiniest typo in an NPC’s text. I’ll share the links as soon as I get the green light. Edit: I forgot to add that the GM recruitment will begin once the links are released. Three people will be accepted, and they’ll work in a three-shift rotation so that there’s always a GM available online.
    • Added: a brand-new default dashboard template. You can now add multiple game/login server builds. Full support for running both PTS & L2J servers simultaneously, with switching between them. Payment systems: added OmegaPay and Pally (new PayPal-style API). Account history now stores everything: donations, items delivered to characters, referrals, transfers between game accounts, and coin transfers to another master account. Personal Promo Code System: you can create a promo code and assign it to a user or promoter. When donating, a player can enter this promo code to receive bonus coins, and the promo code owner also receives a bonus — all fully configurable in the admin panel.     Look demo site: demo
    • One of best project i play last few years
    • for me no  😕   https://files.fm/f/jewqgu9fkb
  • Topics

×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock