Prechádzať zdrojové kódy

BETA: One more item enchanting rework:
* Moving package model.enchant to model.items.enchant
* Separated logic of EnchantItem into AbstractEnchantItem
* Renamed EnchantItem to EnchantSupportItem as it was meant to be.
* Fixed InventoryUpdate when using support item it wasn't updated.
* Suggested by: jurchiks

Rumen Nikiforov 11 rokov pred
rodič
commit
060d97a532

+ 5 - 12
L2J_Server_BETA/java/com/l2jserver/gameserver/datatables/EnchantItemData.java

@@ -27,8 +27,8 @@ import org.w3c.dom.Node;
 
 import com.l2jserver.gameserver.engines.DocumentParser;
 import com.l2jserver.gameserver.model.StatsSet;
-import com.l2jserver.gameserver.model.enchant.EnchantItem;
-import com.l2jserver.gameserver.model.enchant.EnchantScroll;
+import com.l2jserver.gameserver.model.items.enchant.EnchantSupportItem;
+import com.l2jserver.gameserver.model.items.enchant.EnchantScroll;
 import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
 
 /**
@@ -38,7 +38,7 @@ import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
 public class EnchantItemData extends DocumentParser
 {
 	public static final Map<Integer, EnchantScroll> _scrolls = new HashMap<>();
-	public static final Map<Integer, EnchantItem> _supports = new HashMap<>();
+	public static final Map<Integer, EnchantSupportItem> _supports = new HashMap<>();
 	
 	/**
 	 * Instantiates a new enchant item data.
@@ -113,14 +113,7 @@ public class EnchantItemData extends DocumentParser
 						
 						try
 						{
-							final EnchantItem item = new EnchantItem(set);
-							for (Node cd = d.getFirstChild(); cd != null; cd = cd.getNextSibling())
-							{
-								if ("item".equalsIgnoreCase(cd.getNodeName()))
-								{
-									item.addItem(parseInteger(cd.getAttributes(), "id"));
-								}
-							}
+							final EnchantSupportItem item = new EnchantSupportItem(set);
 							_supports.put(item.getId(), item);
 						}
 						catch (NullPointerException e)
@@ -152,7 +145,7 @@ public class EnchantItemData extends DocumentParser
 	 * @param item the item
 	 * @return enchant template for support item
 	 */
-	public final EnchantItem getSupportItem(L2ItemInstance item)
+	public final EnchantSupportItem getSupportItem(L2ItemInstance item)
 	{
 		return _supports.get(item.getId());
 	}

+ 3 - 3
L2J_Server_BETA/java/com/l2jserver/gameserver/datatables/EnchantItemGroupsData.java

@@ -26,11 +26,11 @@ import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
 
 import com.l2jserver.gameserver.engines.DocumentParser;
-import com.l2jserver.gameserver.model.enchant.EnchantItemGroup;
-import com.l2jserver.gameserver.model.enchant.EnchantRateItem;
-import com.l2jserver.gameserver.model.enchant.EnchantScrollGroup;
 import com.l2jserver.gameserver.model.holders.RangeChanceHolder;
 import com.l2jserver.gameserver.model.items.L2Item;
+import com.l2jserver.gameserver.model.items.enchant.EnchantItemGroup;
+import com.l2jserver.gameserver.model.items.enchant.EnchantRateItem;
+import com.l2jserver.gameserver.model.items.enchant.EnchantScrollGroup;
 import com.l2jserver.gameserver.util.Util;
 
 /**

+ 19 - 36
L2J_Server_BETA/java/com/l2jserver/gameserver/model/enchant/EnchantItem.java → L2J_Server_BETA/java/com/l2jserver/gameserver/model/items/enchant/AbstractEnchantItem.java

@@ -16,10 +16,8 @@
  * 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 com.l2jserver.gameserver.model.enchant;
+package com.l2jserver.gameserver.model.items.enchant;
 
-import java.util.ArrayList;
-import java.util.List;
 import java.util.logging.Logger;
 
 import com.l2jserver.gameserver.datatables.ItemTable;
@@ -33,9 +31,9 @@ import com.l2jserver.gameserver.util.Util;
 /**
  * @author UnAfraid
  */
-public class EnchantItem
+public abstract class AbstractEnchantItem
 {
-	protected static final Logger _log = Logger.getLogger(EnchantItem.class.getName());
+	protected static final Logger _log = Logger.getLogger(AbstractEnchantItem.class.getName());
 	
 	private static final L2ItemType[] ENCHANT_TYPES = new L2ItemType[]
 	{
@@ -50,13 +48,11 @@ public class EnchantItem
 	};
 	
 	private final int _id;
-	protected boolean _isWeapon;
 	private final int _grade;
 	private final int _maxEnchantLevel;
 	private final double _bonusRate;
-	private List<Integer> _itemIds;
 	
-	public EnchantItem(StatsSet set)
+	public AbstractEnchantItem(StatsSet set)
 	{
 		_id = set.getInteger("id");
 		if (getItem() == null)
@@ -67,7 +63,6 @@ public class EnchantItem
 		{
 			throw new IllegalAccessError();
 		}
-		_isWeapon = getItem().getItemType() == L2EtcItemType.SCRL_INC_ENCHANT_PROP_WP;
 		_grade = ItemTable._crystalTypes.get(set.getString("targetGrade", "none"));
 		_maxEnchantLevel = set.getInteger("maxEnchant", 65535);
 		_bonusRate = set.getDouble("bonusRate", 0);
@@ -108,55 +103,43 @@ public class EnchantItem
 	/**
 	 * @return {@code true} if scroll is for weapon, {@code false} for armor
 	 */
-	public boolean isWeapon()
-	{
-		return _isWeapon;
-	}
+	public abstract boolean isWeapon();
 	
 	/**
-	 * Enforces current scroll to use only those items as possible items to enchant
-	 * @param id
+	 * @return the maximum enchant level that this scroll/item can be used with
 	 */
-	public final void addItem(int id)
+	public int getMaxEnchantLevel()
 	{
-		if (_itemIds == null)
-		{
-			_itemIds = new ArrayList<>();
-		}
-		_itemIds.add(id);
+		return _maxEnchantLevel;
 	}
 	
 	/**
-	 * @param enchantItem
-	 * @return {@code true} if current item is valid to be enchanted, {@code false} otherwise
+	 * @param itemToEnchant the item to be enchanted
+	 * @param supportItem
+	 * @return {@code true} if this support item can be used with the item to be enchanted, {@code false} otherwise
 	 */
-	public final boolean isValid(L2ItemInstance enchantItem)
+	public boolean isValid(L2ItemInstance itemToEnchant, EnchantSupportItem supportItem)
 	{
-		if (enchantItem == null)
-		{
-			return false;
-		}
-		else if (enchantItem.isEnchantable() == 0)
+		if (itemToEnchant == null)
 		{
 			return false;
 		}
-		else if (!isValidItemType(enchantItem.getItem().getType2()))
+		else if (itemToEnchant.isEnchantable() == 0)
 		{
 			return false;
 		}
-		else if ((_maxEnchantLevel != 0) && (enchantItem.getEnchantLevel() >= _maxEnchantLevel))
+		else if (!isValidItemType(itemToEnchant.getItem().getType2()))
 		{
 			return false;
 		}
-		else if (_grade != enchantItem.getItem().getItemGradeSPlus())
+		else if ((_maxEnchantLevel != 0) && (itemToEnchant.getEnchantLevel() >= _maxEnchantLevel))
 		{
 			return false;
 		}
-		else if ((_itemIds != null) && !_itemIds.contains(enchantItem.getId()))
+		else if (_grade != itemToEnchant.getItem().getItemGradeSPlus())
 		{
 			return false;
 		}
-		
 		return true;
 	}
 	
@@ -168,11 +151,11 @@ public class EnchantItem
 	{
 		if (type2 == L2Item.TYPE2_WEAPON)
 		{
-			return _isWeapon;
+			return isWeapon();
 		}
 		else if ((type2 == L2Item.TYPE2_SHIELD_ARMOR) || (type2 == L2Item.TYPE2_ACCESSORY))
 		{
-			return !_isWeapon;
+			return !isWeapon();
 		}
 		return false;
 	}

+ 1 - 1
L2J_Server_BETA/java/com/l2jserver/gameserver/model/enchant/EnchantItemGroup.java → L2J_Server_BETA/java/com/l2jserver/gameserver/model/items/enchant/EnchantItemGroup.java

@@ -16,7 +16,7 @@
  * 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 com.l2jserver.gameserver.model.enchant;
+package com.l2jserver.gameserver.model.items.enchant;
 
 import java.util.ArrayList;
 import java.util.List;

+ 1 - 1
L2J_Server_BETA/java/com/l2jserver/gameserver/model/enchant/EnchantRateItem.java → L2J_Server_BETA/java/com/l2jserver/gameserver/model/items/enchant/EnchantRateItem.java

@@ -16,7 +16,7 @@
  * 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 com.l2jserver.gameserver.model.enchant;
+package com.l2jserver.gameserver.model.items.enchant;
 
 import com.l2jserver.gameserver.model.items.L2Item;
 

+ 1 - 1
L2J_Server_BETA/java/com/l2jserver/gameserver/model/enchant/EnchantResultType.java → L2J_Server_BETA/java/com/l2jserver/gameserver/model/items/enchant/EnchantResultType.java

@@ -16,7 +16,7 @@
  * 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 com.l2jserver.gameserver.model.enchant;
+package com.l2jserver.gameserver.model.items.enchant;
 
 /**
  * @author UnAfraid

+ 39 - 13
L2J_Server_BETA/java/com/l2jserver/gameserver/model/enchant/EnchantScroll.java → L2J_Server_BETA/java/com/l2jserver/gameserver/model/items/enchant/EnchantScroll.java

@@ -16,8 +16,10 @@
  * 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 com.l2jserver.gameserver.model.enchant;
+package com.l2jserver.gameserver.model.items.enchant;
 
+import java.util.HashSet;
+import java.util.Set;
 import java.util.logging.Level;
 
 import com.l2jserver.gameserver.datatables.EnchantItemGroupsData;
@@ -33,11 +35,13 @@ import com.l2jserver.util.Rnd;
 /**
  * @author UnAfraid
  */
-public final class EnchantScroll extends EnchantItem
+public final class EnchantScroll extends AbstractEnchantItem
 {
+	private final boolean _isWeapon;
 	private final boolean _isBlessed;
 	private final boolean _isSafe;
 	private final int _scrollGroupId;
+	private Set<Integer> _items;
 	
 	public EnchantScroll(StatsSet set)
 	{
@@ -50,6 +54,12 @@ public final class EnchantScroll extends EnchantItem
 		_isSafe = (type == L2EtcItemType.ANCIENT_CRYSTAL_ENCHANT_AM) || (type == L2EtcItemType.ANCIENT_CRYSTAL_ENCHANT_WP);
 	}
 	
+	@Override
+	public boolean isWeapon()
+	{
+		return _isWeapon;
+	}
+	
 	/**
 	 * @return {@code true} for blessed scrolls (enchanted item will remain on failure), {@code false} otherwise
 	 */
@@ -75,30 +85,46 @@ public final class EnchantScroll extends EnchantItem
 	}
 	
 	/**
-	 * @param enchantItem
-	 * @param supportItem
-	 * @return {@code true} if current scroll is valid to be used with support item, {@code false} otherwise
+	 * Enforces current scroll to use only those items as possible items to enchant
+	 * @param itemId
 	 */
-	public boolean isValid(L2ItemInstance enchantItem, EnchantItem supportItem)
+	public void addItem(int itemId)
 	{
-		if ((supportItem != null))
+		if (_items == null)
+		{
+			_items = new HashSet<>();
+		}
+		_items.add(itemId);
+	}
+	
+	/**
+	 * @param itemToEnchant the item to be enchanted
+	 * @param supportItem the support item used when enchanting (can be null)
+	 * @return {@code true} if this scroll can be used with the specified support item and the item to be enchanted, {@code false} otherwise
+	 */
+	@Override
+	public boolean isValid(L2ItemInstance itemToEnchant, EnchantSupportItem supportItem)
+	{
+		if ((_items != null) && !_items.contains(itemToEnchant.getId()))
+		{
+			return false;
+		}
+		else if ((supportItem != null))
 		{
-			// blessed scrolls can't use support items
 			if (isBlessed())
 			{
 				return false;
 			}
-			if (!supportItem.isValid(enchantItem))
+			else if (!supportItem.isValid(itemToEnchant, supportItem))
 			{
 				return false;
 			}
-			else if (supportItem.isWeapon() != _isWeapon)
+			else if (supportItem.isWeapon() != isWeapon())
 			{
 				return false;
 			}
 		}
-		
-		return super.isValid(enchantItem);
+		return super.isValid(itemToEnchant, supportItem);
 	}
 	
 	/**
@@ -129,7 +155,7 @@ public final class EnchantScroll extends EnchantItem
 	 * @param supportItem
 	 * @return the total chance for success rate of this scroll
 	 */
-	public EnchantResultType calculateSuccess(L2PcInstance player, L2ItemInstance enchantItem, EnchantItem supportItem)
+	public EnchantResultType calculateSuccess(L2PcInstance player, L2ItemInstance enchantItem, EnchantSupportItem supportItem)
 	{
 		if (!isValid(enchantItem, supportItem))
 		{

+ 1 - 1
L2J_Server_BETA/java/com/l2jserver/gameserver/model/enchant/EnchantScrollGroup.java → L2J_Server_BETA/java/com/l2jserver/gameserver/model/items/enchant/EnchantScrollGroup.java

@@ -16,7 +16,7 @@
  * 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 com.l2jserver.gameserver.model.enchant;
+package com.l2jserver.gameserver.model.items.enchant;
 
 import java.util.ArrayList;
 import java.util.Collections;

+ 42 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/model/items/enchant/EnchantSupportItem.java

@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2004-2013 L2J Server
+ * 
+ * This file is part of L2J Server.
+ * 
+ * L2J Server 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.
+ * 
+ * L2J Server 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 com.l2jserver.gameserver.model.items.enchant;
+
+import com.l2jserver.gameserver.model.StatsSet;
+import com.l2jserver.gameserver.model.items.type.L2EtcItemType;
+
+/**
+ * @author UnAfraid
+ */
+public final class EnchantSupportItem extends AbstractEnchantItem
+{
+	private final boolean _isWeapon;
+	
+	public EnchantSupportItem(StatsSet set)
+	{
+		super(set);
+		_isWeapon = getItem().getItemType() == L2EtcItemType.SCRL_INC_ENCHANT_PROP_WP;
+	}
+	
+	@Override
+	public boolean isWeapon()
+	{
+		return _isWeapon;
+	}
+}

+ 47 - 54
L2J_Server_BETA/java/com/l2jserver/gameserver/network/clientpackets/RequestEnchantItem.java

@@ -27,11 +27,11 @@ import com.l2jserver.gameserver.datatables.EnchantItemData;
 import com.l2jserver.gameserver.datatables.SkillTable;
 import com.l2jserver.gameserver.model.L2World;
 import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
-import com.l2jserver.gameserver.model.enchant.EnchantItem;
-import com.l2jserver.gameserver.model.enchant.EnchantResultType;
-import com.l2jserver.gameserver.model.enchant.EnchantScroll;
 import com.l2jserver.gameserver.model.items.L2Armor;
 import com.l2jserver.gameserver.model.items.L2Item;
+import com.l2jserver.gameserver.model.items.enchant.EnchantResultType;
+import com.l2jserver.gameserver.model.items.enchant.EnchantScroll;
+import com.l2jserver.gameserver.model.items.enchant.EnchantSupportItem;
 import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
 import com.l2jserver.gameserver.model.skills.L2Skill;
 import com.l2jserver.gameserver.network.SystemMessageId;
@@ -49,7 +49,7 @@ public final class RequestEnchantItem extends L2GameClientPacket
 	
 	private static final String _C__5F_REQUESTENCHANTITEM = "[C] 5F RequestEnchantItem";
 	
-	private int _objectId = 0;
+	private int _objectId;
 	private int _supportId;
 	
 	@Override
@@ -62,8 +62,7 @@ public final class RequestEnchantItem extends L2GameClientPacket
 	@Override
 	protected void runImpl()
 	{
-		L2PcInstance activeChar = getClient().getActiveChar();
-		
+		final L2PcInstance activeChar = getClient().getActiveChar();
 		if ((activeChar == null) || (_objectId == 0))
 		{
 			return;
@@ -82,7 +81,7 @@ public final class RequestEnchantItem extends L2GameClientPacket
 			return;
 		}
 		
-		final L2ItemInstance item = activeChar.getInventory().getItemByObjectId(_objectId);
+		L2ItemInstance item = activeChar.getInventory().getItemByObjectId(_objectId);
 		L2ItemInstance scroll = activeChar.getInventory().getItemByObjectId(activeChar.getActiveEnchantItemId());
 		L2ItemInstance support = activeChar.getInventory().getItemByObjectId(activeChar.getActiveEnchantSupportItemId());
 		
@@ -102,7 +101,7 @@ public final class RequestEnchantItem extends L2GameClientPacket
 		}
 		
 		// template for support item, if exist
-		EnchantItem supportTemplate = null;
+		EnchantSupportItem supportTemplate = null;
 		if (support != null)
 		{
 			if (support.getObjectId() != _supportId)
@@ -156,6 +155,7 @@ public final class RequestEnchantItem extends L2GameClientPacket
 			}
 		}
 		
+		final InventoryUpdate iu = new InventoryUpdate();
 		synchronized (item)
 		{
 			// last validation check
@@ -166,6 +166,7 @@ public final class RequestEnchantItem extends L2GameClientPacket
 				activeChar.sendPacket(new EnchantResult(2, 0, 0));
 				return;
 			}
+			
 			final EnchantResultType resultType = scrollTemplate.calculateSuccess(activeChar, item, supportTemplate);
 			switch (resultType)
 			{
@@ -220,7 +221,7 @@ public final class RequestEnchantItem extends L2GameClientPacket
 						}
 					}
 					
-					if ((it instanceof L2Armor) && (item.getEnchantLevel() == 4) && activeChar.getInventory().getItemByObjectId(item.getObjectId()).isEquipped())
+					if ((item.isArmor()) && (item.getEnchantLevel() == 4) && item.isEquipped())
 					{
 						enchant4Skill = ((L2Armor) it).getEnchant4Skill();
 						if (enchant4Skill != null)
@@ -274,7 +275,6 @@ public final class RequestEnchantItem extends L2GameClientPacket
 							}
 							
 							L2ItemInstance[] unequiped = activeChar.getInventory().unEquipItemInSlotAndRecord(item.getLocationSlot());
-							InventoryUpdate iu = new InventoryUpdate();
 							for (L2ItemInstance itm : unequiped)
 							{
 								iu.addModifiedItem(itm);
@@ -317,8 +317,8 @@ public final class RequestEnchantItem extends L2GameClientPacket
 								count = 1;
 							}
 							
-							L2ItemInstance destroyItem = activeChar.getInventory().destroyItem("Enchant", item, activeChar, null);
-							if (destroyItem == null)
+							item = activeChar.getInventory().destroyItem("Enchant", item, activeChar, null);
+							if (item == null)
 							{
 								// unable to destroy item, cheater ?
 								Util.handleIllegalPlayerAction(activeChar, "Unable to delete item on enchant failure from player " + activeChar.getName() + ", possible cheater !", Config.DEFAULT_PUNISH);
@@ -341,10 +341,11 @@ public final class RequestEnchantItem extends L2GameClientPacket
 								return;
 							}
 							
+							L2World.getInstance().removeObject(item);
 							L2ItemInstance crystals = null;
 							if (crystalId != 0)
 							{
-								crystals = activeChar.getInventory().addItem("Enchant", crystalId, count, activeChar, destroyItem);
+								crystals = activeChar.getInventory().addItem("Enchant", crystalId, count, activeChar, item);
 								
 								SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.EARNED_S2_S1_S);
 								sm.addItemName(crystals);
@@ -354,39 +355,12 @@ public final class RequestEnchantItem extends L2GameClientPacket
 							
 							if (!Config.FORCE_INVENTORY_UPDATE)
 							{
-								InventoryUpdate iu = new InventoryUpdate();
-								if (destroyItem.getCount() == 0)
-								{
-									iu.addRemovedItem(destroyItem);
-								}
-								else
-								{
-									iu.addModifiedItem(destroyItem);
-								}
-								
 								if (crystals != null)
 								{
 									iu.addItem(crystals);
 								}
-								
-								if (scroll.getCount() == 0)
-								{
-									iu.addRemovedItem(scroll);
-								}
-								else
-								{
-									iu.addModifiedItem(scroll);
-								}
-								
-								activeChar.sendPacket(iu);
-							}
-							else
-							{
-								activeChar.sendPacket(new ItemList(activeChar, true));
 							}
 							
-							L2World world = L2World.getInstance();
-							world.removeObject(destroyItem);
 							if (crystalId == 0)
 							{
 								activeChar.sendPacket(new EnchantResult(4, 0, 0));
@@ -418,26 +392,45 @@ public final class RequestEnchantItem extends L2GameClientPacket
 			final StatusUpdate su = new StatusUpdate(activeChar);
 			su.addAttribute(StatusUpdate.CUR_LOAD, activeChar.getCurrentLoad());
 			activeChar.sendPacket(su);
-			
-			final InventoryUpdate iu = new InventoryUpdate();
-			if (scroll.getCount() == 0)
+			if (!Config.FORCE_INVENTORY_UPDATE)
 			{
-				iu.addRemovedItem(scroll);
+				if (scroll.getCount() == 0)
+				{
+					iu.addRemovedItem(scroll);
+				}
+				else
+				{
+					iu.addModifiedItem(scroll);
+				}
+				
+				if (item.getCount() == 0)
+				{
+					iu.addRemovedItem(item);
+				}
+				else
+				{
+					iu.addModifiedItem(item);
+				}
+				
+				if (support != null)
+				{
+					if (support.getCount() == 0)
+					{
+						iu.addRemovedItem(support);
+					}
+					else
+					{
+						iu.addModifiedItem(support);
+					}
+				}
+				
+				activeChar.sendPacket(iu);
 			}
 			else
 			{
-				iu.addModifiedItem(scroll);
+				activeChar.sendPacket(new ItemList(activeChar, true));
 			}
 			
-			if (item.getCount() == 0)
-			{
-				iu.addRemovedItem(item);
-			}
-			else
-			{
-				iu.addModifiedItem(item);
-			}
-			activeChar.sendPacket(iu);
 			activeChar.broadcastUserInfo();
 			activeChar.setActiveEnchantItemId(L2PcInstance.ID_NONE);
 		}

+ 32 - 24
L2J_Server_BETA/java/com/l2jserver/gameserver/network/clientpackets/RequestExTryToPutEnchantSupportItem.java

@@ -20,7 +20,8 @@ package com.l2jserver.gameserver.network.clientpackets;
 
 import com.l2jserver.gameserver.datatables.EnchantItemData;
 import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
-import com.l2jserver.gameserver.model.enchant.EnchantItem;
+import com.l2jserver.gameserver.model.items.enchant.EnchantScroll;
+import com.l2jserver.gameserver.model.items.enchant.EnchantSupportItem;
 import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
 import com.l2jserver.gameserver.network.SystemMessageId;
 import com.l2jserver.gameserver.network.serverpackets.ExPutEnchantSupportItemResult;
@@ -45,32 +46,39 @@ public class RequestExTryToPutEnchantSupportItem extends L2GameClientPacket
 	@Override
 	protected void runImpl()
 	{
-		L2PcInstance activeChar = getClient().getActiveChar();
-		if (activeChar != null)
+		final L2PcInstance activeChar = getClient().getActiveChar();
+		if (activeChar == null)
 		{
-			if (activeChar.isEnchanting())
+			return;
+		}
+		
+		if (activeChar.isEnchanting())
+		{
+			final L2ItemInstance item = activeChar.getInventory().getItemByObjectId(_enchantObjectId);
+			final L2ItemInstance scroll = activeChar.getInventory().getItemByObjectId(activeChar.getActiveEnchantItemId());
+			final L2ItemInstance support = activeChar.getInventory().getItemByObjectId(_supportObjectId);
+			
+			if ((item == null) || (scroll == null) || (support == null))
+			{
+				// message may be custom
+				activeChar.sendPacket(SystemMessageId.INAPPROPRIATE_ENCHANT_CONDITION);
+				activeChar.setActiveEnchantSupportItemId(L2PcInstance.ID_NONE);
+				return;
+			}
+			
+			final EnchantScroll scrollTemplate = EnchantItemData.getInstance().getEnchantScroll(scroll);
+			final EnchantSupportItem supportTemplate = EnchantItemData.getInstance().getSupportItem(support);
+			
+			if ((scrollTemplate == null) || (supportTemplate == null) || !scrollTemplate.isValid(item, supportTemplate))
 			{
-				L2ItemInstance item = activeChar.getInventory().getItemByObjectId(_enchantObjectId);
-				L2ItemInstance support = activeChar.getInventory().getItemByObjectId(_supportObjectId);
-				
-				if ((item == null) || (support == null))
-				{
-					return;
-				}
-				
-				EnchantItem supportTemplate = EnchantItemData.getInstance().getSupportItem(support);
-				
-				if ((supportTemplate == null) || !supportTemplate.isValid(item))
-				{
-					// message may be custom
-					activeChar.sendPacket(SystemMessageId.INAPPROPRIATE_ENCHANT_CONDITION);
-					activeChar.setActiveEnchantSupportItemId(L2PcInstance.ID_NONE);
-					activeChar.sendPacket(new ExPutEnchantSupportItemResult(0));
-					return;
-				}
-				activeChar.setActiveEnchantSupportItemId(support.getObjectId());
-				activeChar.sendPacket(new ExPutEnchantSupportItemResult(_supportObjectId));
+				// message may be custom
+				activeChar.sendPacket(SystemMessageId.INAPPROPRIATE_ENCHANT_CONDITION);
+				activeChar.setActiveEnchantSupportItemId(L2PcInstance.ID_NONE);
+				activeChar.sendPacket(new ExPutEnchantSupportItemResult(0));
+				return;
 			}
+			activeChar.setActiveEnchantSupportItemId(support.getObjectId());
+			activeChar.sendPacket(new ExPutEnchantSupportItemResult(_supportObjectId));
 		}
 	}
 	

+ 7 - 9
L2J_Server_BETA/java/com/l2jserver/gameserver/network/clientpackets/RequestExTryToPutEnchantTargetItem.java

@@ -22,7 +22,7 @@ import java.util.logging.Level;
 
 import com.l2jserver.gameserver.datatables.EnchantItemData;
 import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
-import com.l2jserver.gameserver.model.enchant.EnchantScroll;
+import com.l2jserver.gameserver.model.items.enchant.EnchantScroll;
 import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
 import com.l2jserver.gameserver.network.SystemMessageId;
 import com.l2jserver.gameserver.network.serverpackets.ExPutEnchantTargetItemResult;
@@ -34,7 +34,7 @@ public class RequestExTryToPutEnchantTargetItem extends L2GameClientPacket
 {
 	private static final String _C__D0_4C_REQUESTEXTRYTOPUTENCHANTTARGETITEM = "[C] D0:4C RequestExTryToPutEnchantTargetItem";
 	
-	private int _objectId = 0;
+	private int _objectId;
 	
 	@Override
 	protected void readImpl()
@@ -45,8 +45,7 @@ public class RequestExTryToPutEnchantTargetItem extends L2GameClientPacket
 	@Override
 	protected void runImpl()
 	{
-		L2PcInstance activeChar = getClient().getActiveChar();
-		
+		final L2PcInstance activeChar = getClient().getActiveChar();
 		if ((_objectId == 0) || (activeChar == null))
 		{
 			return;
@@ -57,16 +56,15 @@ public class RequestExTryToPutEnchantTargetItem extends L2GameClientPacket
 			return;
 		}
 		
-		L2ItemInstance item = activeChar.getInventory().getItemByObjectId(_objectId);
-		L2ItemInstance scroll = activeChar.getInventory().getItemByObjectId(activeChar.getActiveEnchantItemId());
-		
+		final L2ItemInstance item = activeChar.getInventory().getItemByObjectId(_objectId);
+		final L2ItemInstance scroll = activeChar.getInventory().getItemByObjectId(activeChar.getActiveEnchantItemId());
 		if ((item == null) || (scroll == null))
 		{
 			return;
 		}
 		
-		EnchantScroll scrollTemplate = EnchantItemData.getInstance().getEnchantScroll(scroll);
-		if ((scrollTemplate == null) || !scrollTemplate.isValid(item))
+		final EnchantScroll scrollTemplate = EnchantItemData.getInstance().getEnchantScroll(scroll);
+		if ((scrollTemplate == null) || !scrollTemplate.isValid(item, null))
 		{
 			activeChar.sendPacket(SystemMessageId.DOES_NOT_FIT_SCROLL_CONDITIONS);
 			activeChar.setActiveEnchantItemId(L2PcInstance.ID_NONE);