Jump to content
  • 0

Enchant Configs Messed up??


Question

Posted

 

 

Hello i have this abstractEnchantPacket & configs working without errors but i think are messed up..

With 60% enchant ratios in blessed and they take the ratio of crystal scrolls (90%) somehow.. (tested)

What is messed up here?

/*
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */
package net.sf.l2j.gameserver.network.clientpackets;

import java.util.HashMap;
import java.util.Map;

import net.sf.l2j.Config;
import net.sf.l2j.gameserver.model.item.instance.ItemInstance;
import net.sf.l2j.gameserver.model.item.kind.Item;
import net.sf.l2j.gameserver.model.item.kind.Weapon;
import net.sf.l2j.gameserver.model.item.type.CrystalType;
import net.sf.l2j.gameserver.model.item.type.WeaponType;

public abstract class AbstractEnchantPacket extends L2GameClientPacket
{
	public static final Map<Integer, EnchantScroll> _scrolls = new HashMap<>();
	
	public static final class EnchantScroll
	{
		protected final boolean _isWeapon;
		protected final CrystalType _grade;
		private final boolean _isBlessed;
		private final boolean _isCrystal;
		
		public EnchantScroll(boolean wep, boolean bless, boolean crystal, CrystalType type)
		{
			_isWeapon = wep;
			_grade = type;
			_isBlessed = bless;
			_isCrystal = crystal;
		}
		
		/**
		 * @param enchantItem : The item to enchant.
		 * @return true if support item can be used for this item
		 */
		public final boolean isValid(ItemInstance enchantItem)
		{
			if (enchantItem == null)
				return false;
			
			// checking scroll type and configured maximum enchant level
			switch (enchantItem.getItem().getType2())
			{
				case Item.TYPE2_WEAPON:
					if (!_isWeapon || (Config.ENCHANT_MAX_WEAPON > 0 && enchantItem.getEnchantLevel() >= Config.ENCHANT_MAX_WEAPON))
						return false;
					break;
				
				case Item.TYPE2_SHIELD_ARMOR:
				case Item.TYPE2_ACCESSORY:
					if (_isWeapon || (Config.ENCHANT_MAX_ARMOR > 0 && enchantItem.getEnchantLevel() >= Config.ENCHANT_MAX_ARMOR))
						return false;
					break;
				
				default:
					return false;
			}
			
			// check for crystal type
			if (_grade != enchantItem.getItem().getCrystalType())
				return false;
			
			return true;
		}
		
		/**
		 * @return true if item is a blessed scroll.
		 */
		public final boolean isBlessed()
		{
			return _isBlessed;
		}
		
		/**
		 * @return true if item is a crystal scroll.
		 */
		public final boolean isCrystal()
		{
			return _isCrystal;
		}
		
		/**
		 * Regarding enchant system :<br>
		 * <br>
		 * <u>Weapons</u>
		 * <ul>
		 * <li>magic weapons has chance of 40% until +15 and 20% from +15 and higher. There is no upper limit, there is no dependance on current enchant level.</li>
		 * <li>non magic weapons has chance of 70% until +15 and 35% from +15 and higher. There is no upper limit, there is no dependance on current enchant level.</li>
		 * </ul>
		 * <u>Armors</u>
		 * <ul>
		 * <li>non fullbody armors (jewelry, upper armor, lower armor, boots, gloves, helmets and shirts) has chance of 2/3 for +4, 1/3 for +5, 1/4 for +6, ...., 1/18 +20. If you've made a +20 armor, chance to make it +21 will be equal to zero (0%).</li>
		 * <li>full body armors has a chance of 1/1 for +4, 2/3 for +5, 1/3 for +6, ..., 1/17 for +20. If you've made a +20 armor, chance to make it +21 will be equal to zero (0%).</li>
		 * </ul>
		 * @param enchantItem : The item to enchant.
		 * @return the enchant chance under double format (0.7 / 0.35 / 0.44324...).
		 */
		public final double getChance(ItemInstance enchantItem)
		{
			if (!isValid(enchantItem))
				return -1;
			
			boolean fullBody = enchantItem.getItem().getBodyPart() == Item.SLOT_FULL_ARMOR;
			if (enchantItem.getEnchantLevel() < Config.ENCHANT_SAFE_MAX || (fullBody && enchantItem.getEnchantLevel() < Config.ENCHANT_SAFE_MAX_FULL))
				return 1;
			
			double chance = 0;
			
			// Armor formula : 0.66^(current-2), chance is lower and lower for each enchant.
            if (isBlessed())
            {
                if (enchantItem.isArmor())
                    chance = Math.pow(Config.ENCHANT_CHANCE_ARMOR_BLESSED, (enchantItem.getEnchantLevel() - 2));
                // Weapon formula is 70% for fighter weapon, 40% for mage weapon. Special rates after +14.
                else if (enchantItem.isWeapon())
                {
                    if (((Weapon) enchantItem.getItem()).isMagical())
                        chance = (enchantItem.getEnchantLevel() > 14) ? Config.ENCHANT_CHANCE_WEAPON_MAGIC_15PLUS_BLESSED : Config.ENCHANT_CHANCE_WEAPON_MAGIC_BLESSED;
                    else
                        chance = (enchantItem.getEnchantLevel() > 14) ? Config.ENCHANT_CHANCE_WEAPON_NONMAGIC_15PLUS_BLESSED : Config.ENCHANT_CHANCE_WEAPON_NONMAGIC_BLESSED;
                }
            }
            else if (isCrystal())
            {
                if (enchantItem.isArmor())
                    chance = Math.pow(Config.ENCHANT_CHANCE_ARMOR_CRYSTAL, (enchantItem.getEnchantLevel() - 2));
                // Weapon formula is 70% for fighter weapon, 40% for mage weapon. Special rates after +14.
                else if (enchantItem.isWeapon())
                {
                    if (((Weapon) enchantItem.getItem()).isMagical())
                        chance = (enchantItem.getEnchantLevel() > 14) ? Config.ENCHANT_CHANCE_WEAPON_MAGIC_15PLUS_CRYSTAL : Config.ENCHANT_CHANCE_WEAPON_MAGIC_CRYSTAL;
                    else
                        chance = (enchantItem.getEnchantLevel() > 14) ? Config.ENCHANT_CHANCE_WEAPON_NONMAGIC_15PLUS_CRYSTAL : Config.ENCHANT_CHANCE_WEAPON_NONMAGIC_CRYSTAL;
                }
            }
            else
            {
                if (enchantItem.isArmor())
                    chance = Math.pow(Config.ENCHANT_CHANCE_ARMOR, (enchantItem.getEnchantLevel() - 2));
                // Weapon formula is 70% for fighter weapon, 40% for mage weapon. Special rates after +14.
                else if (enchantItem.isWeapon())
                {
                    if (((Weapon) enchantItem.getItem()).isMagical())
                        chance = (enchantItem.getEnchantLevel() > 14) ? Config.ENCHANT_CHANCE_WEAPON_MAGIC_15PLUS : Config.ENCHANT_CHANCE_WEAPON_MAGIC;
                    else
                        chance = (enchantItem.getEnchantLevel() > 14) ? Config.ENCHANT_CHANCE_WEAPON_NONMAGIC_15PLUS : Config.ENCHANT_CHANCE_WEAPON_NONMAGIC;
                }
            }
			
			return chance;
		}
	}
	
	/**
	 * Format : itemId, (isWeapon, isBlessed, isCrystal, grade)<br>
	 * Allowed items IDs must be sorted by ascending order.
	 */
	static
	{
		// Scrolls: Enchant Weapon
		_scrolls.put(729, new EnchantScroll(true, false, false, CrystalType.A));
		_scrolls.put(947, new EnchantScroll(true, false, false, CrystalType.B));
		_scrolls.put(951, new EnchantScroll(true, false, false, CrystalType.C));
		_scrolls.put(955, new EnchantScroll(true, false, false, CrystalType.D));
		_scrolls.put(959, new EnchantScroll(true, false, false, CrystalType.S));
		
		// Scrolls: Enchant Armor
		_scrolls.put(730, new EnchantScroll(false, false, false, CrystalType.A));
		_scrolls.put(948, new EnchantScroll(false, false, false, CrystalType.B));
		_scrolls.put(952, new EnchantScroll(false, false, false, CrystalType.C));
		_scrolls.put(956, new EnchantScroll(false, false, false, CrystalType.D));
		_scrolls.put(960, new EnchantScroll(false, false, false, CrystalType.S));
		
		// Blessed Scrolls: Enchant Weapon
		_scrolls.put(6569, new EnchantScroll(true, true, false, CrystalType.A));
		_scrolls.put(6571, new EnchantScroll(true, true, false, CrystalType.B));
		_scrolls.put(6573, new EnchantScroll(true, true, false, CrystalType.C));
		_scrolls.put(6575, new EnchantScroll(true, true, false, CrystalType.D));
		_scrolls.put(6577, new EnchantScroll(true, true, false, CrystalType.S));
		
		// Blessed Scrolls: Enchant Armor
		_scrolls.put(6570, new EnchantScroll(false, true, false, CrystalType.A));
		_scrolls.put(6572, new EnchantScroll(false, true, false, CrystalType.B));
		_scrolls.put(6574, new EnchantScroll(false, true, false, CrystalType.C));
		_scrolls.put(6576, new EnchantScroll(false, true, false, CrystalType.D));
		_scrolls.put(6578, new EnchantScroll(false, true, false, CrystalType.S));
		
		// Crystal Scrolls: Enchant Weapon
		_scrolls.put(731, new EnchantScroll(true, false, true, CrystalType.A));
		_scrolls.put(949, new EnchantScroll(true, false, true, CrystalType.B));
		_scrolls.put(953, new EnchantScroll(true, false, true, CrystalType.C));
		_scrolls.put(957, new EnchantScroll(true, false, true, CrystalType.D));
		_scrolls.put(961, new EnchantScroll(true, false, true, CrystalType.S));
		
		// Crystal Scrolls: Enchant Armor
		_scrolls.put(732, new EnchantScroll(false, false, true, CrystalType.A));
		_scrolls.put(950, new EnchantScroll(false, false, true, CrystalType.B));
		_scrolls.put(954, new EnchantScroll(false, false, true, CrystalType.C));
		_scrolls.put(958, new EnchantScroll(false, false, true, CrystalType.D));
		_scrolls.put(962, new EnchantScroll(false, false, true, CrystalType.S));
	}
	
	/**
	 * @param scroll The instance of item to make checks on.
	 * @return enchant template for scroll.
	 */
	protected static final EnchantScroll getEnchantScroll(ItemInstance scroll)
	{
		return _scrolls.get(scroll.getItemId());
	}
	
	/**
	 * @param item The instance of item to make checks on.
	 * @return true if item can be enchanted.
	 */
	protected static final boolean isEnchantable(ItemInstance item)
	{
		if (item.isHeroItem() || item.isShadowItem() || item.isEtcItem() || item.getItem().getItemType() == WeaponType.FISHINGROD)
			return false;
		
		// only equipped items or in inventory can be enchanted
		if (item.getLocation() != ItemInstance.ItemLocation.INVENTORY && item.getLocation() != ItemInstance.ItemLocation.PAPERDOLL)
			return false;
		
		return true;
	}
}
    /** Enchant */
    public static double ENCHANT_CHANCE_WEAPON_MAGIC_BLESSED;
    public static double ENCHANT_CHANCE_WEAPON_MAGIC_15PLUS_BLESSED;
    public static double ENCHANT_CHANCE_WEAPON_NONMAGIC_BLESSED;
    public static double ENCHANT_CHANCE_WEAPON_NONMAGIC_15PLUS_BLESSED;
    public static double ENCHANT_CHANCE_ARMOR_BLESSED;
    public static double ENCHANT_CHANCE_WEAPON_MAGIC_CRYSTAL;
    public static double ENCHANT_CHANCE_WEAPON_MAGIC_15PLUS_CRYSTAL;
    public static double ENCHANT_CHANCE_WEAPON_NONMAGIC_CRYSTAL;
    public static double ENCHANT_CHANCE_WEAPON_NONMAGIC_15PLUS_CRYSTAL;
    public static double ENCHANT_CHANCE_ARMOR_CRYSTAL;
    public static double ENCHANT_CHANCE_WEAPON_MAGIC;
    public static double ENCHANT_CHANCE_WEAPON_MAGIC_15PLUS;
    public static double ENCHANT_CHANCE_WEAPON_NONMAGIC;
    public static double ENCHANT_CHANCE_WEAPON_NONMAGIC_15PLUS;
    public static double ENCHANT_CHANCE_ARMOR;
    public static int ENCHANT_MAX_WEAPON;
    public static int ENCHANT_MAX_ARMOR;
    public static int ENCHANT_SAFE_MAX;
    public static int ENCHANT_SAFE_MAX_FULL;
		ENCHANT_CHANCE_WEAPON_MAGIC = players.getProperty("EnchantChanceMagicWeapon", 0.4);
		ENCHANT_CHANCE_WEAPON_MAGIC_15PLUS = players.getProperty("EnchantChanceMagicWeapon15Plus", 0.2);
		ENCHANT_CHANCE_WEAPON_NONMAGIC = players.getProperty("EnchantChanceNonMagicWeapon", 0.7);
		ENCHANT_CHANCE_WEAPON_NONMAGIC_15PLUS = players.getProperty("EnchantChanceNonMagicWeapon15Plus", 0.35);
		ENCHANT_CHANCE_ARMOR_BLESSED = players.getProperty("EnchantChanceArmorBlessed", 0.66);
		ENCHANT_CHANCE_WEAPON_MAGIC_BLESSED = players.getProperty("EnchantChanceMagicWeaponBlessed", 0.4);
		ENCHANT_CHANCE_WEAPON_MAGIC_15PLUS_BLESSED = players.getProperty("EnchantChanceMagicWeapon15PlusBlessed", 0.2);
		ENCHANT_CHANCE_WEAPON_NONMAGIC_BLESSED = players.getProperty("EnchantChanceNonMagicWeaponBlessed", 0.7);
		ENCHANT_CHANCE_WEAPON_NONMAGIC_15PLUS_BLESSED = players.getProperty("EnchantChanceNonMagicWeapon15PlusBlessed", 0.35);
		ENCHANT_CHANCE_ARMOR_CRYSTAL = players.getProperty("EnchantChanceArmorCrystal", 0.66);
		ENCHANT_CHANCE_WEAPON_MAGIC_CRYSTAL = players.getProperty("EnchantChanceMagicWeaponCrystal", 0.4);
		ENCHANT_CHANCE_WEAPON_MAGIC_15PLUS_CRYSTAL = players.getProperty("EnchantChanceMagicWeapon15PlusCrystal", 0.2);
		ENCHANT_CHANCE_WEAPON_NONMAGIC_CRYSTAL = players.getProperty("EnchantChanceNonMagicWeaponCrystal", 0.7);
		ENCHANT_CHANCE_WEAPON_NONMAGIC_15PLUS_CRYSTAL = players.getProperty("EnchantChanceNonMagicWeapon15PlusCrystal", 0.35);

 

2 answers to this question

Recommended Posts

  • 0
Posted (edited)

What you mean (tested)? make your blessed condition like this

if (isBlessed())
{
	if (enchantItem.isArmor())
		chance = Math.pow(Config.ENCHANT_CHANCE_ARMOR_BLESSED, (enchantItem.getEnchantLevel() - 2));
	
	// Weapon formula is 70% for fighter weapon, 40% for mage weapon. Special rates after +14.
	else if (enchantItem.isWeapon())
	{
		if (((Weapon) enchantItem.getItem()).isMagical())
			chance = (enchantItem.getEnchantLevel() > 14) ? Config.ENCHANT_CHANCE_WEAPON_MAGIC_15PLUS_BLESSED : Config.ENCHANT_CHANCE_WEAPON_MAGIC_BLESSED;
		else
			chance = (enchantItem.getEnchantLevel() > 14) ? Config.ENCHANT_CHANCE_WEAPON_NONMAGIC_15PLUS_BLESSED : Config.ENCHANT_CHANCE_WEAPON_NONMAGIC_BLESSED;
	}
	System.out.println("Config chance: " + chance);
}

I think you will solve your problem (if any) by urself.

 

Edited by melron

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

    • Forum Post:   🛡️ L2Genesis Closed Beta — Test With Us, Launch With Exclusive Rewards Join the community: https://discord.gg/mcuHsQzNCm Website: https://l2genesis.com/ Join Beta: https://cbt.l2genesis.com/     Hey everyone, We're L2Genesis — an Interlude Classic server being built with one core belief: every player matters. Not just the top clans, not just the donators — everyone. We've spent months developing, refining, and listening to community feedback. Now we're opening up our Closed Beta and we need your help to make sure this server launches rock-solid. Registration is open for one week only — after that, the doors close. Every tester who puts in the work walks into launch day with exclusive rewards that won't be available again.     Why Genesis? We're not rushing to open doors and hope for the best. We're building a community-first server where player feedback directly shapes the final product. No pay-to-win, no shortcuts — just a clean Interlude experience with thoughtful quality-of-life improvements. If you've been burned by servers that promise the world and deliver a cash shop, this one's for you. What you can expect to see on our server: - x4 rate - Player buff trade shop - Crystallization shop - Arena mode for FUN PvP     Closed Beta Rewards Rewards are tied to real participation — no freebies for just showing up. 🥉 Tier 1 The test server runs at x100 rates with a gear shop, so you won't be grinding for days just to start testing. Requirements: Register, level to S-grade, complete 3rd profession, and join one of the organized beta clans.   Launch Rewards: - Exclusive "Genesis Start" Discord rank - Beta Box — unique hat (won't be available after launch) + big-head potions, fireworks & more   Optional: Participate in the Bug Hunt for additional rewards (details below). You will have one week from CBT server launch to complete Tier 1 🥇 Tier 2 Requirements: Complete Tier 1 + participate in at least 3 events like Clan Wars, Siege and others, they will be stated during CBT in Discord. Launch Rewards: - Everything from Tier 1 - 1 Month of VIP status — quality-of-life perks handed to you for free on day one     🐛 Bug Hunt — Bonus Rewards Throughout the beta we're running a Bug Hunt — find and report bugs to earn 1 Genesis Coin (donation currency) for every confirmed bug. We'll share full details and focus areas once you're in.     Get Involved This is your chance to shape a server before it launches, not complain about it after. The testers who show up now are the ones who'll feel the difference on day one — and they'll have the exclusive rewards to prove it. Sign Up for beta test and drop in to Discord, and let's build something worth logging into. Even if you're not ready to test but you're a veteran L2 player — join the community anyway. Your experience and perspective are worth a lot to us. See you in Aden.  
    • l2jlucera the source code is not public and is not for sale. If you're going to use L2jMobius or L2jAcis, you need to know how to program or have a basic understanding, and you can ask for help from a bot, which usually won't be 100% helpful. Or you can pay a programmer to do the work for you.  
    • You need for sure some knowledge to make a good start and dont get scammed.
    • https://l2jmobiusdevclon.pp.ua/index.php
    • I’ve been juggling different promo tools myself, and having variety in one spot really cuts the hassle. Also, I’ve been using Social Media People Insights to get a quick read on who I’m dealing with online, and it’s saved me from a couple of sketchy collabs. Stuff like that pairs well with big SMM setups since you know you’re boosting the right connections.
  • Topics

×
×
  • Create New...

Important Information

This community uses essential cookies to function properly. Non-essential cookies and third-party services are used only with your consent. Read our Privacy Policy and We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue..