Browse Source

Items which has element bonus not handled by skill will shown in item description.

Gigiikun 15 years ago
parent
commit
79aa74f4b4

+ 15 - 3
L2_GameServer/java/com/l2jserver/gameserver/model/L2ItemInstance.java

@@ -990,21 +990,33 @@ public final class L2ItemInstance extends L2Object
 
 	public byte getAttackElementType()
 	{
-		if (isWeapon() && _elementals != null)
+		if (!isWeapon())
+			return -2;
+		else if (getItem().getElementals() != null)
+			return getItem().getElementals().getElement();
+		else if (_elementals != null)
 			return _elementals.getElement();
 		return -2;
 	}
 
 	public int getAttackElementPower()
 	{
-		if (isWeapon() && _elementals != null)
+		if (!isWeapon())
+			return 0;
+		else if (getItem().getElementals() != null)
+			return getItem().getElementals().getValue();
+		else if (_elementals != null)
 			return _elementals.getValue();
 		return 0;
 	}
 
 	public int getElementDefAttr(byte element)
 	{
-		if (isArmor() && _elementals != null && _elementals.getElement() == element)
+		if (!isArmor())
+			return 0;
+		else if (getItem().getElementals() != null && getItem().getElementals().getElement() == element)
+			return getItem().getElementals().getValue();
+		else if (_elementals != null && _elementals.getElement() == element)
 			return _elementals.getValue();
 		return 0;
 	}

+ 2 - 1
L2_GameServer/java/com/l2jserver/gameserver/network/clientpackets/RequestExEnchantItemAttribute.java

@@ -99,7 +99,8 @@ public class RequestExEnchantItemAttribute extends L2GameClientPacket
 			item.getItem().getItemGradeSPlus() != L2Item.CRYSTAL_S || item.getItem().getBodyPart() == L2Item.SLOT_BACK ||
 			item.getItem().getBodyPart() == L2Item.SLOT_R_BRACELET || item.getItem().getBodyPart() == L2Item.SLOT_UNDERWEAR ||
 			item.getItem().getBodyPart() == L2Item.SLOT_BELT || item.getItem().getBodyPart() == L2Item.SLOT_NECK ||
-			item.getItem().getBodyPart() == L2Item.SLOT_R_EAR || item.getItem().getBodyPart() == L2Item.SLOT_R_FINGER)
+			item.getItem().getBodyPart() == L2Item.SLOT_R_EAR || item.getItem().getBodyPart() == L2Item.SLOT_R_FINGER ||
+			item.getItem().getElementals() != null)
 		{
 			player.sendPacket(new SystemMessage(SystemMessageId.ELEMENTAL_ENHANCE_REQUIREMENT_NOT_SUFFICIENT));
 			player.setActiveEnchantAttrItem(null);

+ 54 - 0
L2_GameServer/java/com/l2jserver/gameserver/templates/item/L2Item.java

@@ -16,8 +16,10 @@ package com.l2jserver.gameserver.templates.item;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.logging.Logger;
 
 import com.l2jserver.Config;
+import com.l2jserver.gameserver.model.Elementals;
 import com.l2jserver.gameserver.model.L2Effect;
 import com.l2jserver.gameserver.model.L2ItemInstance;
 import com.l2jserver.gameserver.model.L2Object;
@@ -168,6 +170,7 @@ public abstract class L2Item
 	@SuppressWarnings("unchecked")
 	protected final Enum _type;
 	
+	protected Elementals _elementals = null;
 	protected FuncTemplate[] _funcTemplates;
 	protected EffectTemplate[] _effectTemplates;
 	protected L2Skill[] _skills;
@@ -176,6 +179,8 @@ public abstract class L2Item
 	protected static final Func[] _emptyFunctionSet = new Func[0];
 	protected static final L2Effect[] _emptyEffectSet = new L2Effect[0];
 	
+	protected static final Logger _log = Logger.getLogger(L2Item.class.getName());
+	
 	/**
 	 * Constructor of the L2Item that fill class variables.<BR><BR>
 	 * <U><I>Variables filled :</I></U><BR>
@@ -393,6 +398,28 @@ public abstract class L2Item
 		return _name;
 	}
 	
+	/**
+	 * Returns the base elemental of the item
+	 * @return Elementals
+	 */
+	public final Elementals getElementals()
+	{
+		return _elementals;
+	}
+
+	/**
+	 * Sets the base elemental of the item
+	 */
+	public final void setElementals(Elementals element)
+	{
+		if (_elementals != null)
+		{
+			_log.warning("Item " + getName() + "(" + getItemId() + ") has more than one element definition!");
+			return;
+		}
+		_elementals = element;
+	}
+
 	/**
 	 * Return the part of the body used with the item.
 	 * @return int
@@ -663,6 +690,33 @@ public abstract class L2Item
 	 */
 	public void attach(FuncTemplate f)
 	{
+		switch(f.stat)
+		{
+			case FIRE_RES:
+			case FIRE_POWER:
+				setElementals(new Elementals(Elementals.FIRE, (int) f.lambda.calc(null)));
+				break;
+			case WATER_RES:
+			case WATER_POWER:
+				setElementals(new Elementals(Elementals.WATER, (int) f.lambda.calc(null)));
+				break;
+			case WIND_RES:
+			case WIND_POWER:
+				setElementals(new Elementals(Elementals.WIND, (int) f.lambda.calc(null)));
+				break;
+			case EARTH_RES:
+			case EARTH_POWER:
+				setElementals(new Elementals(Elementals.EARTH, (int) f.lambda.calc(null)));
+				break;
+			case HOLY_RES:
+			case HOLY_POWER:
+				setElementals(new Elementals(Elementals.HOLY, (int) f.lambda.calc(null)));
+				break;
+			case DARK_RES:
+			case DARK_POWER:
+				setElementals(new Elementals(Elementals.DARK, (int) f.lambda.calc(null)));
+				break;
+		}
 		// If _functTemplates is empty, create it and add the FuncTemplate f in it
 		if (_funcTemplates == null)
 		{