Browse Source

BETA: Item classes cleanup.

Rumen Nikiforov 12 years ago
parent
commit
0df4751b1b

+ 144 - 105
L2J_Server_BETA/java/com/l2jserver/gameserver/model/items/L2Item.java

@@ -17,7 +17,6 @@ package com.l2jserver.gameserver.model.items;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
-import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import javolution.util.FastList;
@@ -50,10 +49,7 @@ import com.l2jserver.util.StringUtil;
 
 /**
  * This class contains all informations concerning the item (weapon, armor, etc).<BR>
- * Mother class of :
- * <LI>L2Armor</LI>
- * <LI>L2EtcItem</LI>
- * <LI>L2Weapon</LI>
+ * Mother class of : <LI>L2Armor</LI> <LI>L2EtcItem</LI> <LI>L2Weapon</LI>
  * @version $Revision: 1.7.2.2.2.5 $ $Date: 2005/04/06 18:25:18 $
  */
 public abstract class L2Item
@@ -154,15 +150,36 @@ public abstract class L2Item
 	
 	private static final int[] crystalItemId =
 	{
-		0, 1458, 1459, 1460, 1461, 1462, 1462, 1462
+		0,
+		1458,
+		1459,
+		1460,
+		1461,
+		1462,
+		1462,
+		1462
 	};
 	private static final int[] crystalEnchantBonusArmor =
 	{
-		0, 11, 6, 11, 19, 25, 25, 25
+		0,
+		11,
+		6,
+		11,
+		19,
+		25,
+		25,
+		25
 	};
 	private static final int[] crystalEnchantBonusWeapon =
 	{
-		0, 90, 45, 67, 144, 250, 250, 250
+		0,
+		90,
+		45,
+		67,
+		144,
+		250,
+		250,
+		250
 	};
 	
 	private final int _itemId;
@@ -198,11 +215,11 @@ public abstract class L2Item
 	private final L2ActionType _defaultAction;
 	
 	protected int _type1; // needed for item list (inventory)
-	protected int _type2; // different lists for armor, weapon, etc	
+	protected int _type2; // different lists for armor, weapon, etc
 	protected Elementals[] _elementals = null;
 	protected FuncTemplate[] _funcTemplates;
 	protected EffectTemplate[] _effectTemplates;
-	protected List <Condition> _preConditions;
+	protected List<Condition> _preConditions;
 	private SkillHolder[] _skillHolder;
 	
 	protected static final Func[] _emptyFunctionSet = new Func[0];
@@ -211,10 +228,11 @@ public abstract class L2Item
 	private final List<Quest> _questEvents = new FastList<>();
 	private final int _useSkillDisTime;
 	private final int _reuseDelay;
-	private int _sharedReuseGroup;
+	private final int _sharedReuseGroup;
 	
 	/**
-	 * Constructor of the L2Item that fill class variables.<BR><BR>
+	 * Constructor of the L2Item that fill class variables.<BR>
+	 * <BR>
 	 * @param set : StatsSet corresponding to a set of couples (key,value) for description of the item
 	 */
 	protected L2Item(StatsSet set)
@@ -246,39 +264,55 @@ public abstract class L2Item
 		_freightable = set.getBool("is_freightable", false);
 		_is_oly_restricted = set.getBool("is_oly_restricted", false);
 		
-		//_immediate_effect - herb
+		// _immediate_effect - herb
 		_ex_immediate_effect = set.getBool("ex_immediate_effect", false);
 		
-		//used for custom type select
+		// used for custom type select
 		_defaultAction = set.getEnum("default_action", L2ActionType.class, L2ActionType.none);
 		_useSkillDisTime = set.getInteger("useSkillDisTime", 0);
 		_defaultEnchantLevel = set.getInteger("enchanted", 0);
 		_reuseDelay = set.getInteger("reuse_delay", 0);
 		_sharedReuseGroup = set.getInteger("shared_reuse_group", 0);
 		
-		//TODO cleanup + finish
+		// TODO cleanup + finish
 		String equip_condition = set.getString("equip_condition", null);
 		if (equip_condition != null)
 		{
-			//pet conditions
+			// pet conditions
 			ConditionLogicOr cond = new ConditionLogicOr();
 			if (equip_condition.contains("all_wolf_group"))
+			{
 				cond.add(new ConditionPetType(ALL_WOLF));
+			}
 			if (equip_condition.contains("hatchling_group"))
+			{
 				cond.add(new ConditionPetType(HATCHLING));
+			}
 			if (equip_condition.contains("strider"))
+			{
 				cond.add(new ConditionPetType(STRIDER));
+			}
 			if (equip_condition.contains("baby_pet_group"))
+			{
 				cond.add(new ConditionPetType(BABY));
+			}
 			if (equip_condition.contains("upgrade_baby_pet_group"))
+			{
 				cond.add(new ConditionPetType(IMPROVED_BABY));
+			}
 			if (equip_condition.contains("grown_up_wolf_group"))
+			{
 				cond.add(new ConditionPetType(GROWN_WOLF));
+			}
 			if (equip_condition.contains("item_equip_pet_group"))
+			{
 				cond.add(new ConditionPetType(ALL_PET));
+			}
 			
 			if (cond.conditions.length > 0)
+			{
 				attach(cond);
+			}
 		}
 		
 		String skills = set.getString("item_skill", null);
@@ -288,7 +322,7 @@ public abstract class L2Item
 			_skillHolder = new SkillHolder[skillsSplit.length];
 			int used = 0;
 			
-			for (int i = 0;i < skillsSplit.length;++ i)
+			for (int i = 0; i < skillsSplit.length; ++i)
 			{
 				try
 				{
@@ -296,27 +330,27 @@ public abstract class L2Item
 					int id = Integer.parseInt(skillSplit[0]);
 					int level = Integer.parseInt(skillSplit[1]);
 					
-			        if (id == 0)
-			        {
-			        	_log.info(StringUtil.concat("Ignoring item_skill(", skillsSplit[i], ") for item ", toString(), ". Skill id is 0!"));
-			        	continue;
-			        }
-			        
-			        if (level == 0)
-			        {
-			        	_log.info(StringUtil.concat("Ignoring item_skill(", skillsSplit[i], ") for item ", toString(), ". Skill level is 0!"));
-			        	continue;
-			        }
-			        
-			        _skillHolder[used] = new SkillHolder(id, level);
-			        ++ used;
+					if (id == 0)
+					{
+						_log.info(StringUtil.concat("Ignoring item_skill(", skillsSplit[i], ") for item ", toString(), ". Skill id is 0!"));
+						continue;
+					}
+					
+					if (level == 0)
+					{
+						_log.info(StringUtil.concat("Ignoring item_skill(", skillsSplit[i], ") for item ", toString(), ". Skill level is 0!"));
+						continue;
+					}
+					
+					_skillHolder[used] = new SkillHolder(id, level);
+					++used;
 				}
 				catch (Exception e)
 				{
 					_log.warning(StringUtil.concat("Failed to parse item_skill(", skillsSplit[i], ") for item ", toString(), "! Format: SkillId0-SkillLevel0[;SkillIdN-SkillLevelN]"));
 				}
 			}
-				
+			
 			// this is only loading? just don't leave a null or use a collection?
 			if (used != _skillHolder.length)
 			{
@@ -325,18 +359,10 @@ public abstract class L2Item
 				_skillHolder = skillHolder;
 			}
 		}
-
-		_common = (_itemId >= 11605 && _itemId <= 12361);
-		_heroItem = (_itemId >= 6611 && _itemId <= 6621) || (_itemId >= 9388 && _itemId <= 9390) || _itemId == 6842;
-		_pvpItem = (_itemId >= 10667 && _itemId <= 10835) || (_itemId >= 12852 && _itemId <= 12977) || (_itemId >= 14363 && _itemId <= 14525) || _itemId == 14528 || _itemId == 14529 || _itemId == 14558 || (_itemId >=15913 && _itemId <= 16024) || (_itemId >=16134 && _itemId <= 16147) || _itemId == 16149 || _itemId == 16151 || _itemId == 16153 || _itemId == 16155 || _itemId == 16157 || _itemId == 16159 || (_itemId >=16168 && _itemId <= 16176) || (_itemId >=16179 && _itemId <= 16220);
 		
-		if (this instanceof L2EtcItem)
-		{
-			if (_elementable)
-			{
-				_log.log(Level.WARNING, getClass().getSimpleName() + ": " + getItemId() + " " + getName() + " with element enabled");
-			}
-		}
+		_common = ((_itemId >= 11605) && (_itemId <= 12361));
+		_heroItem = ((_itemId >= 6611) && (_itemId <= 6621)) || ((_itemId >= 9388) && (_itemId <= 9390)) || (_itemId == 6842);
+		_pvpItem = ((_itemId >= 10667) && (_itemId <= 10835)) || ((_itemId >= 12852) && (_itemId <= 12977)) || ((_itemId >= 14363) && (_itemId <= 14525)) || (_itemId == 14528) || (_itemId == 14529) || (_itemId == 14558) || ((_itemId >= 15913) && (_itemId <= 16024)) || ((_itemId >= 16134) && (_itemId <= 16147)) || (_itemId == 16149) || (_itemId == 16151) || (_itemId == 16153) || (_itemId == 16155) || (_itemId == 16157) || (_itemId == 16159) || ((_itemId >= 16168) && (_itemId <= 16176)) || ((_itemId >= 16179) && (_itemId <= 16220));
 	}
 	
 	/**
@@ -352,7 +378,7 @@ public abstract class L2Item
 	{
 		return _equipReuseDelay;
 	}
-
+	
 	/**
 	 * Returns the duration of the item
 	 * @return int
@@ -432,7 +458,7 @@ public abstract class L2Item
 	 */
 	public final boolean isCrystallizable()
 	{
-		return _crystalType != L2Item.CRYSTAL_NONE && _crystalCount > 0;
+		return (_crystalType != L2Item.CRYSTAL_NONE) && (_crystalCount > 0);
 	}
 	
 	/**
@@ -454,7 +480,8 @@ public abstract class L2Item
 	}
 	
 	/**
-	 * Returns the grade of the item.<BR><BR>
+	 * Returns the grade of the item.<BR>
+	 * <BR>
 	 * <U><I>Concept :</I></U><BR>
 	 * In fact, this function returns the type of crystal of the item.
 	 * @return int
@@ -489,35 +516,41 @@ public abstract class L2Item
 	}
 	
 	/**
-	 * @param enchantLevel 
+	 * @param enchantLevel
 	 * @return the quantity of crystals for crystallization on specific enchant level
 	 */
 	public final int getCrystalCount(int enchantLevel)
 	{
 		if (enchantLevel > 3)
+		{
 			switch (_type2)
 			{
 				case TYPE2_SHIELD_ARMOR:
 				case TYPE2_ACCESSORY:
-					return _crystalCount + crystalEnchantBonusArmor[getCrystalType()] * (3 * enchantLevel - 6);
+					return _crystalCount + (crystalEnchantBonusArmor[getCrystalType()] * ((3 * enchantLevel) - 6));
 				case TYPE2_WEAPON:
-					return _crystalCount + crystalEnchantBonusWeapon[getCrystalType()] * (2 * enchantLevel - 3);
+					return _crystalCount + (crystalEnchantBonusWeapon[getCrystalType()] * ((2 * enchantLevel) - 3));
 				default:
 					return _crystalCount;
 			}
+		}
 		else if (enchantLevel > 0)
+		{
 			switch (_type2)
 			{
 				case TYPE2_SHIELD_ARMOR:
 				case TYPE2_ACCESSORY:
-					return _crystalCount + crystalEnchantBonusArmor[getCrystalType()] * enchantLevel;
+					return _crystalCount + (crystalEnchantBonusArmor[getCrystalType()] * enchantLevel);
 				case TYPE2_WEAPON:
-					return _crystalCount + crystalEnchantBonusWeapon[getCrystalType()] * enchantLevel;
+					return _crystalCount + (crystalEnchantBonusWeapon[getCrystalType()] * enchantLevel);
 				default:
 					return _crystalCount;
 			}
+		}
 		else
+		{
 			return _crystalCount;
+		}
 	}
 	
 	/**
@@ -541,7 +574,9 @@ public abstract class L2Item
 		for (Elementals elm : _elementals)
 		{
 			if (elm.getElement() == attribute)
+			{
 				return elm;
+			}
 		}
 		return null;
 	}
@@ -581,7 +616,8 @@ public abstract class L2Item
 	public final int getBodyPart()
 	{
 		return _bodyPart;
-	}	
+	}
+	
 	/**
 	 * @return the type 1 of the item.
 	 */
@@ -611,7 +647,7 @@ public abstract class L2Item
 	 */
 	public boolean isEquipable()
 	{
-		return getBodyPart() != 0 && !(getItemType() instanceof L2EtcItemType);
+		return (getBodyPart() != 0) && !(getItemType() instanceof L2EtcItemType);
 	}
 	
 	/**
@@ -619,7 +655,7 @@ public abstract class L2Item
 	 */
 	public final int getReferencePrice()
 	{
-		return (isConsumable() ? (int)(_referencePrice * Config.RATE_CONSUMABLE_COST) : _referencePrice);
+		return (isConsumable() ? (int) (_referencePrice * Config.RATE_CONSUMABLE_COST) : _referencePrice);
 	}
 	
 	/**
@@ -668,7 +704,7 @@ public abstract class L2Item
 	 */
 	public final int isEnchantable()
 	{
-		return Arrays.binarySearch(Config.ENCHANT_BLACKLIST, getItemId()) < 0 ?  _enchantable : 0;
+		return Arrays.binarySearch(Config.ENCHANT_BLACKLIST, getItemId()) < 0 ? _enchantable : 0;
 	}
 	
 	/**
@@ -706,16 +742,16 @@ public abstract class L2Item
 		return _pvpItem;
 	}
 	
-	public boolean isPotion() 
-	{ 
+	public boolean isPotion()
+	{
 		return (getItemType() == L2EtcItemType.POTION);
 	}
-
-	public boolean isElixir() 
-	{ 
+	
+	public boolean isElixir()
+	{
 		return (getItemType() == L2EtcItemType.ELIXIR);
 	}
-
+	
 	/**
 	 * Returns array of Func objects containing the list of functions used by the item
 	 * @param item : L2ItemInstance pointing out the item
@@ -724,8 +760,10 @@ public abstract class L2Item
 	 */
 	public Func[] getStatFuncs(L2ItemInstance item, L2Character player)
 	{
-		if (_funcTemplates == null || _funcTemplates.length == 0)
+		if ((_funcTemplates == null) || (_funcTemplates.length == 0))
+		{
 			return _emptyFunctionSet;
+		}
 		
 		ArrayList<Func> funcs = new ArrayList<>(_funcTemplates.length);
 		
@@ -739,7 +777,9 @@ public abstract class L2Item
 		{
 			f = t.getFunc(env, this); // skill is owner
 			if (f != null)
+			{
 				funcs.add(f);
+			}
 		}
 		
 		if (funcs.isEmpty())
@@ -757,8 +797,10 @@ public abstract class L2Item
 	 */
 	public L2Effect[] getEffects(L2ItemInstance item, L2Character player)
 	{
-		if (_effectTemplates == null || _effectTemplates.length == 0)
+		if ((_effectTemplates == null) || (_effectTemplates.length == 0))
+		{
 			return _emptyEffectSet;
+		}
 		
 		FastList<L2Effect> effects = FastList.newInstance();
 		
@@ -780,7 +822,9 @@ public abstract class L2Item
 		}
 		
 		if (effects.isEmpty())
+		{
 			return _emptyEffectSet;
+		}
 		
 		L2Effect[] result = effects.toArray(new L2Effect[effects.size()]);
 		FastList.recycle(effects);
@@ -791,28 +835,9 @@ public abstract class L2Item
 	 * Returns effects of skills associated with the item.
 	 * @param caster : L2Character pointing out the caster
 	 * @param target : L2Character pointing out the target
-	 * @return L2Effect[] : array of effects generated by the skill
-	 
-	public L2Effect[] getSkillEffects(L2Character caster, L2Character target)
-	{
-		if (_skills == null)
-			return _emptyEffectSet;
-		List<L2Effect> effects = new FastList<L2Effect>();
-		
-		for (L2Skill skill : _skills)
-		{
-			if (!skill.checkCondition(caster, target, true))
-				continue; // Skill condition not met
-				
-			if (target.getFirstEffect(skill.getId()) != null)
-				target.removeEffect(target.getFirstEffect(skill.getId()));
-			for (L2Effect e : skill.getEffects(caster, target))
-				effects.add(e);
-		}
-		if (effects.isEmpty())
-			return _emptyEffectSet;
-		return effects.toArray(new L2Effect[effects.size()]);
-	}
+	 * @return L2Effect[] : array of effects generated by the skill public L2Effect[] getSkillEffects(L2Character caster, L2Character target) { if (_skills == null) return _emptyEffectSet; List<L2Effect> effects = new FastList<L2Effect>(); for (L2Skill skill : _skills) { if
+	 *         (!skill.checkCondition(caster, target, true)) continue; // Skill condition not met if (target.getFirstEffect(skill.getId()) != null) target.removeEffect(target.getFirstEffect(skill.getId())); for (L2Effect e : skill.getEffects(caster, target)) effects.add(e); } if (effects.isEmpty())
+	 *         return _emptyEffectSet; return effects.toArray(new L2Effect[effects.size()]); }
 	 */
 	/**
 	 * Add the FuncTemplate f to the list of functions used with the item
@@ -820,7 +845,7 @@ public abstract class L2Item
 	 */
 	public void attach(FuncTemplate f)
 	{
-		switch(f.stat)
+		switch (f.stat)
 		{
 			case FIRE_RES:
 			case FIRE_POWER:
@@ -851,16 +876,16 @@ public abstract class L2Item
 		if (_funcTemplates == null)
 		{
 			_funcTemplates = new FuncTemplate[]
-			                                  {
-					f
-			                                  };
+			{
+				f
+			};
 		}
 		else
 		{
 			int len = _funcTemplates.length;
 			FuncTemplate[] tmp = new FuncTemplate[len + 1];
 			// Definition : arraycopy(array source, begins copy at this position of source, array destination, begins copy at this position in dest,
-			//						  number of components to be copied)
+			// number of components to be copied)
 			System.arraycopy(_funcTemplates, 0, tmp, 0, len);
 			tmp[len] = f;
 			_funcTemplates = tmp;
@@ -876,16 +901,16 @@ public abstract class L2Item
 		if (_effectTemplates == null)
 		{
 			_effectTemplates = new EffectTemplate[]
-			                                      {
-					effect
-			                                      };
+			{
+				effect
+			};
 		}
 		else
 		{
 			int len = _effectTemplates.length;
 			EffectTemplate[] tmp = new EffectTemplate[len + 1];
 			// Definition : arraycopy(array source, begins copy at this position of source, array destination, begins copy at this position in dest,
-			//						  number of components to be copied)
+			// number of components to be copied)
 			System.arraycopy(_effectTemplates, 0, tmp, 0, len);
 			tmp[len] = effect;
 			_effectTemplates = tmp;
@@ -895,9 +920,13 @@ public abstract class L2Item
 	public final void attach(Condition c)
 	{
 		if (_preConditions == null)
+		{
 			_preConditions = new FastList<>();
+		}
 		if (!_preConditions.contains(c))
+		{
 			_preConditions.add(c);
+		}
 	}
 	
 	public boolean hasSkills()
@@ -906,11 +935,7 @@ public abstract class L2Item
 	}
 	
 	/**
-	 * Method to retrive skills linked to this item
-	 *
-	 * armor and weapon: passive skills
-	 * etcitem: skills used on item use <-- ???
-	 *
+	 * Method to retrive skills linked to this item armor and weapon: passive skills etcitem: skills used on item use <-- ???
 	 * @return Skills linked to this item as SkillHolder[]
 	 */
 	public final SkillHolder[] getSkills()
@@ -921,30 +946,42 @@ public abstract class L2Item
 	public boolean checkCondition(L2Character activeChar, L2Object target, boolean sendMessage)
 	{
 		if (activeChar.isGM() && !Config.GM_ITEM_RESTRICTION)
+		{
 			return true;
+		}
 		
 		// Don't allow hero equipment and restricted items during Olympiad
 		if ((isOlyRestrictedItem() || isHeroItem()) && ((activeChar instanceof L2PcInstance) && activeChar.getActingPlayer().isInOlympiadMode()))
 		{
 			if (isEquipable())
+			{
 				activeChar.sendPacket(SystemMessageId.THIS_ITEM_CANT_BE_EQUIPPED_FOR_THE_OLYMPIAD_EVENT);
+			}
 			else
+			{
 				activeChar.sendPacket(SystemMessageId.THIS_ITEM_IS_NOT_AVAILABLE_FOR_THE_OLYMPIAD_EVENT);
+			}
 			return false;
 		}
 		
 		if (!isConditionAttached())
+		{
 			return true;
+		}
 		
 		Env env = new Env();
 		env.setCharacter(activeChar);
 		if (target instanceof L2Character)
+		{
 			env.setTarget((L2Character) target);
+		}
 		
 		for (Condition preCondition : _preConditions)
 		{
 			if (preCondition == null)
+			{
 				continue;
+			}
 			
 			if (!preCondition.test(env))
 			{
@@ -962,11 +999,13 @@ public abstract class L2Item
 					{
 						activeChar.sendMessage(msg);
 					}
-					else if (msgId !=0)
+					else if (msgId != 0)
 					{
 						SystemMessage sm = SystemMessage.getSystemMessage(msgId);
 						if (preCondition.isAddName())
+						{
 							sm.addItemName(_itemId);
+						}
 						activeChar.sendPacket(sm);
 					}
 				}
@@ -978,7 +1017,7 @@ public abstract class L2Item
 	
 	public boolean isConditionAttached()
 	{
-		return _preConditions != null && !_preConditions.isEmpty();
+		return (_preConditions != null) && !_preConditions.isEmpty();
 	}
 	
 	public boolean isQuestItem()
@@ -995,7 +1034,7 @@ public abstract class L2Item
 	{
 		return _is_oly_restricted || Config.LIST_OLY_RESTRICTED_ITEMS.contains(_itemId);
 	}
-
+	
 	/**
 	 * Returns the name of the item
 	 * @return String
@@ -1003,9 +1042,9 @@ public abstract class L2Item
 	@Override
 	public String toString()
 	{
-		return _name+"("+_itemId+")";
+		return _name + "(" + _itemId + ")";
 	}
-
+	
 	/**
 	 * @return the _ex_immediate_effect
 	 */
@@ -1013,7 +1052,7 @@ public abstract class L2Item
 	{
 		return _ex_immediate_effect;
 	}
-
+	
 	/**
 	 * @return the _default_action
 	 */

+ 6 - 1
L2J_Server_BETA/java/com/l2jserver/gameserver/model/items/L2WarehouseItem.java

@@ -41,7 +41,12 @@ public class L2WarehouseItem
 	private int _elemAtkPower = 0;
 	private final int[] _elemDefAttr =
 	{
-		0, 0, 0, 0, 0, 0
+		0,
+		0,
+		0,
+		0,
+		0,
+		0
 	};
 	private final int _time;
 	

+ 4 - 2
L2J_Server_BETA/java/com/l2jserver/gameserver/model/items/L2Weapon.java

@@ -450,14 +450,16 @@ public final class L2Weapon extends L2Item
 			return _emptyEffectSet;
 		}
 		
-		
 		final byte shld = Formulas.calcShldUse(caster, target, onCastSkill);
 		if (onCastSkill.isOffensive() && !Formulas.calcSkillSuccess(caster, target, onCastSkill, shld, false, false, false))
 		{
 			return _emptyEffectSet;
 		}
 		
-		L2Character[] targets = { target };
+		L2Character[] targets =
+		{
+			target
+		};
 		
 		// Launch the magic skill and calculate its effects
 		// Get the skill handler corresponding to the skill type