requestenchantitem.java
Code: Select all
package l2p.gameserver.clientpackets; import java.io.PrintStream;import java.util.logging.Logger;import l2p.Config;import l2p.extensions.multilang.CustomMessage;import l2p.gameserver.cache.Msg;import l2p.gameserver.model.L2Player;import l2p.gameserver.model.PcInventory;import l2p.gameserver.model.instances.L2ItemInstance;import l2p.gameserver.model.instances.L2ItemInstance.ItemLocation;import l2p.gameserver.network.L2GameClient;import l2p.gameserver.serverpackets.EnchantResult;import l2p.gameserver.serverpackets.InventoryUpdate;import l2p.gameserver.tables.ItemTable;import l2p.gameserver.templates.L2Item;import l2p.gameserver.templates.L2Item.Grade;import l2p.gameserver.templates.L2Weapon;import l2p.gameserver.templates.L2Weapon.WeaponType;import l2p.util.Log;import l2p.util.Rnd; public class RequestEnchantItem extends L2GameClientPacket{ protected static Logger _log = Logger.getLogger(RequestEnchantItem.class.getName()); private int _objectId; private int _unk; public void readImpl() { this._objectId = readD(); if (((L2GameClient)getClient()).isGraciaFinal()) { this._unk = readD(); System.out.println(getType() + " :: _unk = " + this._unk); } } public void runImpl() { label256: L2ItemInstance removedScroll; double chance; L2Player activeChar = ((L2GameClient)getClient()).getActiveChar(); if (activeChar == null) return; if ((activeChar.isOutOfControl()) || (activeChar.isActionsDisabled())) { activeChar.sendActionFailed(); return; } PcInventory inventory = activeChar.getInventory(); L2ItemInstance itemToEnchant = inventory.getItemByObjectId(Integer.valueOf(this._objectId)); L2ItemInstance scroll = activeChar.getEnchantScroll(); activeChar.setEnchantScroll(null); if ((itemToEnchant == null) || (scroll == null)) { activeChar.sendActionFailed(); return; } Log.add(activeChar.getName() + "|Trying to enchant|" + itemToEnchant.getItemId() + "|+" + itemToEnchant.getEnchantLevel() + "|" + itemToEnchant.getObjectId(), "enchants"); if (!(itemToEnchant.canBeEnchanted())) { activeChar.sendPacket(EnchantResult.CANCEL); activeChar.sendPacket(Msg.INAPPROPRIATE_ENCHANT_CONDITIONS); activeChar.sendActionFailed(); return; } if ((itemToEnchant.getLocation() != L2ItemInstance.ItemLocation.INVENTORY) && (itemToEnchant.getLocation() != L2ItemInstance.ItemLocation.PAPERDOLL)) { activeChar.sendPacket(Msg.INAPPROPRIATE_ENCHANT_CONDITIONS); activeChar.sendActionFailed(); return; } if (activeChar.getPrivateStoreType() != 0) { activeChar.sendPacket(EnchantResult.CANCEL); activeChar.sendPacket(Msg.YOU_CANNOT_PRACTICE_ENCHANTING_WHILE_OPERATING_A_PRIVATE_STORE_OR_PRIVATE_MANUFACTURING_WORKSHOP); activeChar.sendActionFailed(); return; } if (!(itemToEnchant.isStackable())) if ((scroll = inventory.getItemByObjectId(Integer.valueOf(scroll.getObjectId()))) != null) break label256; activeChar.sendPacket(EnchantResult.CANCEL); activeChar.sendActionFailed(); return; int crystalId = itemToEnchant.getEnchantCrystalId(scroll); if (crystalId == 0) { activeChar.sendPacket(EnchantResult.CANCEL); activeChar.sendPacket(Msg.INAPPROPRIATE_ENCHANT_CONDITIONS); activeChar.sendActionFailed(); return; } if (itemToEnchant.getEnchantLevel() >= Config.ENCHANT_MAX) { activeChar.sendPacket(EnchantResult.CANCEL); activeChar.sendMessage(new CustomMessage("l2p.gameserver.clientpackets.RequestEnchantItem.MaxLevel", activeChar)); activeChar.sendActionFailed(); return; } if (itemToEnchant.getOwnerId() != activeChar.getObjectId()) { activeChar.sendPacket(EnchantResult.CANCEL); activeChar.sendPacket(Msg.INAPPROPRIATE_ENCHANT_CONDITIONS); activeChar.sendActionFailed(); return; } synchronized (inventory) { removedScroll = inventory.destroyItem(scroll.getObjectId(), 1L, true); } if (removedScroll == null) { activeChar.sendPacket(EnchantResult.CANCEL); activeChar.sendActionFailed(); return; } int itemType = itemToEnchant.getItem().getType2(); int safeEnchantLevel = (itemToEnchant.getItem().getBodyPart() == 32768) ? Config.SAFE_ENCHANT_FULL_BODY : Config.SAFE_ENCHANT_COMMON; if (itemToEnchant.getEnchantLevel() < safeEnchantLevel) { chance = 100.0D; } else if (itemType == 0) { chance = Config.ENCHANT_CHANCE_WEAPON; } else if (itemType == 1) { chance = Config.ENCHANT_CHANCE_ARMOR; } else if (itemType == 2) { chance = Config.ENCHANT_CHANCE_ACCESSORY; } else { System.out.println("WTF? Request to enchant " + itemToEnchant.getItemId()); activeChar.sendPacket(EnchantResult.CANCEL); activeChar.sendActionFailed(); activeChar.sendPacket(Msg.SYSTEM_ERROR); activeChar.getInventory().addItem(removedScroll); return; } if ((scroll.getItemId() >= 22006) && (scroll.getItemId() <= 22017)) chance += 10.0D; else if ((scroll.getItemId() >= 22018) && (scroll.getItemId() <= 22021)) chance = 100.0D; if (Config.ALT_ENCHANT_FORMULA) { int enchlvl = itemToEnchant.getEnchantLevel(); L2Item.Grade crystaltype = itemToEnchant.getItem().getCrystalType(); if ((itemType == 0) && (itemToEnchant.getItemType() == L2Weapon.WeaponType.DUAL)) ++safeEnchantLevel; if (enchlvl < safeEnchantLevel) { chance = 100.0D; } else if (enchlvl > 11) { chance = 1.0D; } else { if (itemType == 0) { L2Weapon wepToEnchant = (L2Weapon)itemToEnchant.getItem(); boolean magewep = (itemType == 0) && (crystaltype.cry >= 1459) && (wepToEnchant.getPDamage() - wepToEnchant.getMDamage() <= wepToEnchant.getPDamage() * 0.4D); chance = Config.ALT_ENCHANT_CHANCE_MAGE_W; if ((itemToEnchant.getItem().getBodyPart() == 16384) && (itemToEnchant.getItem().getItemType() == L2Weapon.WeaponType.BLUNT) && (!(magewep))) chance -= Config.PENALTY_TO_TWOHANDED_BLUNTS; } else { chance = Config.ALT_ENCHANT_CHANCE_ARMOR; } int DeltaChance = 15; for (int i = safeEnchantLevel; i < enchlvl; ++i) { if (i == safeEnchantLevel + 2) DeltaChance -= 5; if (i == safeEnchantLevel + 6) DeltaChance -= 5; chance -= DeltaChance; } int Delta2 = 5; for (int in = 0; in < crystaltype.ordinal(); ++in) { if (in == 1459) Delta2 -= 5; if (in == 1460) Delta2 -= 5; if (in == 1461) Delta2 -= 2; if (in == 1462) --Delta2; } chance += Delta2; if (scroll.isBlessedEnchantScroll()) chance += 2.0D; if (chance < 1.0D) chance = 1.0D; } } if (Rnd.chance(chance)) { itemToEnchant.setEnchantLevel(itemToEnchant.getEnchantLevel() + 1); itemToEnchant.updateDatabase(); activeChar.sendPacket(new InventoryUpdate().addModifiedItem(itemToEnchant)); Log.add(activeChar.getName() + "|Successfully enchanted|" + itemToEnchant.getItemId() + "|to+" + itemToEnchant.getEnchantLevel() + "|" + chance, "enchants"); Log.LogItem(activeChar, Integer.valueOf(925), itemToEnchant); activeChar.sendPacket(EnchantResult.SUCESS); } else { Log.add(activeChar.getName() + "|Failed to enchant|" + itemToEnchant.getItemId() + "|+" + itemToEnchant.getEnchantLevel() + "|" + chance, "enchants"); if (scroll.isBlessedEnchantScroll()) { itemToEnchant.setEnchantLevel(0); activeChar.sendPacket(new InventoryUpdate().addModifiedItem(itemToEnchant)); activeChar.sendPacket(Msg.FAILED_IN_BLESSED_ENCHANT_THE_ENCHANT_VALUE_OF_THE_ITEM_BECAME_0); activeChar.sendPacket(EnchantResult.CANCEL); } else { if (itemToEnchant.isEquipped()) { activeChar.getInventory().unEquipItemInSlot(itemToEnchant.getEquipSlot()); } L2ItemInstance destroyedItem = inventory.destroyItem(itemToEnchant.getObjectId(), 1L, true); if (destroyedItem == null) { _log.warning("failed to destroy " + itemToEnchant.getObjectId() + " after unsuccessful enchant attempt by char " + activeChar.getName()); activeChar.sendActionFailed(); return; } L2ItemInstance crystalsToAdd = ItemTable.getInstance().createItem(crystalId); int count = (int)(itemToEnchant.getItem().getCrystalCount() * 0.87D); if (destroyedItem.getEnchantLevel() > 3) count = (int)(count + itemToEnchant.getItem().getCrystalCount() * 0.25D * (destroyedItem.getEnchantLevel() - 3)); if (count < 1) count = 1; crystalsToAdd.setCount(count); activeChar.getInventory().addItem(crystalsToAdd); Log.LogItem(activeChar, Integer.valueOf(926), itemToEnchant); Log.LogItem(activeChar, Integer.valueOf(959), crystalsToAdd); activeChar.sendPacket(new EnchantResult(1, crystalsToAdd.getItemId(), count)); activeChar.refreshExpertisePenalty(); activeChar.refreshOverloaded(); } } activeChar.setEnchantScroll(null); activeChar.sendChanges(); }}
config.java
Code: Select all
ALT_ENCHANT_FORMULA = getBooleanProperty(otherSettings, "AltEnchantFormulaForPvPServers", false); ALT_ENCHANT_CHANCE_W = getIntProperty(otherSettings, "EChanceWeapon", 80); ALT_ENCHANT_CHANCE_MAGE_W = getIntProperty(otherSettings, "EChanceMageWeapon", 80); ALT_ENCHANT_CHANCE_ARMOR = getIntProperty(otherSettings, "EChanceArmor", 80); PENALTY_TO_TWOHANDED_BLUNTS = getIntProperty(otherSettings, "PenaltyforEChanceToHandBlunt", 18); ENCHANT_CHANCE_WEAPON = getIntProperty(otherSettings, "EnchantChance", 66); ENCHANT_CHANCE_ARMOR = getIntProperty(otherSettings, "EnchantChanceArmor", ENCHANT_CHANCE_WEAPON); ENCHANT_CHANCE_ACCESSORY = getIntProperty(otherSettings, "EnchantChanceAccessory", ENCHANT_CHANCE_ARMOR); ENCHANT_CHANCE_CRYSTAL_WEAPON = getIntProperty(otherSettings, "EnchantChanceCrystal", 66); ENCHANT_CHANCE_CRYSTAL_ARMOR = getIntProperty(otherSettings, "EnchantChanceCrystalArmor", ENCHANT_CHANCE_CRYSTAL_WEAPON); ENCHANT_CHANCE_CRYSTAL_ACCESSORY = getIntProperty(otherSettings, "EnchantChanceCrystalAccessory", ENCHANT_CHANCE_CRYSTAL_ARMOR); SAFE_ENCHANT_COMMON = getIntProperty(otherSettings, "SafeEnchantCommon", 3); SAFE_ENCHANT_FULL_BODY = getIntProperty(otherSettings, "SafeEnchantFullBody", 4); ENCHANT_MAX = getByteProperty(otherSettings, "EnchantMax", 20);
can you help me do this for l2jserver?)