Forráskód Böngészése

Moving duped code from derived L2Item classes (thanks FBIagent, Zoey76 & UnAfraid) also added warnings in some configs to avoid people changing IPs where they shouldn't.

MELERIX 14 éve
szülő
commit
0904683c44

+ 1 - 50
L2J_Server/java/com/l2jserver/gameserver/templates/item/L2Armor.java

@@ -36,7 +36,6 @@ public final class L2Armor extends L2Item
 	private final int _avoidModifier;
 	private SkillHolder _enchant4Skill = null; // skill that activates when armor is enchanted +4
 	// private final String[] _skill;
-	private SkillHolder[] _skillHolder;
 	private L2ArmorType _type;
 	
 	/**
@@ -96,44 +95,7 @@ public final class L2Armor extends L2Item
 				if (id > 0 && level > 0)
 					_enchant4Skill = new SkillHolder(id, level);
 			}
-		}
-		
-		skill = set.getString("item_skill", null);
-		if (skill != null)
-		{
-			String[] skills = skill.split(";");
-			_skillHolder = new SkillHolder[skills.length];
-			byte iterator = 0;
-			for (String st : skills)
-			{
-				String[] info = st.split("-");
-				
-				if (info == null || info.length != 2)
-					continue;
-				
-				int id = 0;
-				int level = 0;
-				
-				try
-				{
-					id = Integer.parseInt(info[0]);
-					level = Integer.parseInt(info[1]);
-				}
-				catch (Exception nfe)
-				{
-					// Incorrect syntax, dont add new skill
-					_log.info(StringUtil.concat("> Couldnt parse ", st, " in armor skills! item ",this.toString()));
-					continue;
-				}
-				
-				// If skill can exist, add it
-				if (id > 0 && level > 0)
-				{
-					_skillHolder[iterator] = new SkillHolder(id, level);
-					iterator++;
-				}
-			}
-		}
+		}	
 	}
 	
 	/**
@@ -177,17 +139,6 @@ public final class L2Armor extends L2Item
 		return _enchant4Skill.getSkill();
 	}
 	
-	/**
-	 * Returns passive skill linked to that armor
-	 * @return
-	 */
-	@Override
-	public SkillHolder[] getSkills()
-	{
-		return _skillHolder;
-	}
-	
-	
 	/**
 	 * Returns array of Func objects containing the list of functions used by the armor
 	 * @param instance : L2ItemInstance pointing out the armor

+ 1 - 50
L2J_Server/java/com/l2jserver/gameserver/templates/item/L2EtcItem.java

@@ -19,7 +19,6 @@ import java.util.List;
 
 import com.l2jserver.gameserver.model.L2ExtractableProduct;
 import com.l2jserver.gameserver.model.itemcontainer.PcInventory;
-import com.l2jserver.gameserver.skills.SkillHolder;
 import com.l2jserver.gameserver.templates.StatsSet;
 import com.l2jserver.util.StringUtil;
 
@@ -32,8 +31,7 @@ public final class L2EtcItem  extends L2Item
 {
 	// private final String[] _skill;
 	private String _handler;
-	private SkillHolder[] _skillHolder;
-	private int _sharedReuseGroup;
+	private final int _sharedReuseGroup;
 	private L2EtcItemType _type;
 	private final boolean _isBlessed;
 	private final List<L2ExtractableProduct> _extractableItems;
@@ -73,43 +71,6 @@ public final class L2EtcItem  extends L2Item
 		else if (getItemId() == PcInventory.ADENA_ID || getItemId() == PcInventory.ANCIENT_ADENA_ID)
 			_type2 = L2Item.TYPE2_MONEY;
 		
-		String skill = set.getString("item_skill", null);
-		if (skill != null)
-		{
-			String[] skills = skill.split(";");
-			_skillHolder = new SkillHolder[skills.length];
-			byte iterator = 0;
-			for (String st : skills)
-			{
-				String[] info = st.split("-");
-				
-				if (info == null || info.length != 2)
-					continue;
-				
-				int id = 0;
-				int level = 0;
-				
-				try
-				{
-					id = Integer.parseInt(info[0]);
-					level = Integer.parseInt(info[1]);
-				}
-				catch (Exception nfe)
-				{
-					// Incorrect syntax, dont add new skill
-					_log.info(StringUtil.concat("> Couldnt parse ", st, " in etcitem skills! item ", this.toString()));
-					continue;
-				}
-				
-				// If skill can exist, add it
-				if (id > 0 && level > 0)
-				{
-					_skillHolder[iterator] = new SkillHolder(id, level);
-					iterator++;
-				}
-			}
-		}
-		
 		_handler = set.getString("handler", null);  // ! null !
 		_sharedReuseGroup = set.getInteger("shared_reuse_group", -1);
 		_isBlessed = set.getBool("blessed", false);
@@ -183,16 +144,6 @@ public final class L2EtcItem  extends L2Item
 		return getItemType().mask();
 	}
 	
-	/**
-	 * Returns skills linked to that EtcItem
-	 * @return
-	 */
-	@Override
-	public SkillHolder[] getSkills()
-	{
-		return _skillHolder;
-	}
-	
 	/**
 	 * Return handler name. null if no handler for item
 	 * @return String

+ 59 - 2
L2J_Server/java/com/l2jserver/gameserver/templates/item/L2Item.java

@@ -39,6 +39,7 @@ import com.l2jserver.gameserver.skills.funcs.Func;
 import com.l2jserver.gameserver.skills.funcs.FuncTemplate;
 import com.l2jserver.gameserver.templates.StatsSet;
 import com.l2jserver.gameserver.templates.effects.EffectTemplate;
+import com.l2jserver.util.StringUtil;
 
 /**
  * This class contains all informations concerning the item (weapon, armor, etc).<BR>
@@ -185,6 +186,7 @@ public abstract class L2Item
 	protected FuncTemplate[] _funcTemplates;
 	protected EffectTemplate[] _effectTemplates;
 	protected List <Condition> _preConditions;
+	private SkillHolder[] _skillHolder;
 	
 	protected static final Func[] _emptyFunctionSet = new Func[0];
 	protected static final L2Effect[] _emptyEffectSet = new L2Effect[0];
@@ -246,8 +248,52 @@ public abstract class L2Item
 			if (cond.conditions.length > 0)
 				attach(cond);
 		}
-
 		
+		String skills = set.getString("item_skill", null);
+		if (skills != null)
+		{
+			String[] skillsSplit = skills.split(";");
+			_skillHolder = new SkillHolder[skillsSplit.length];
+			int used = 0;
+			
+			for (int i = 0;i < skillsSplit.length;++ i)
+			{
+				try
+				{
+					String[] skillSplit = skillsSplit[i].split("-");
+					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;
+				}
+				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)
+			{
+				SkillHolder[] skillHolder = new SkillHolder[used];
+				System.arraycopy(_skillHolder, 0, skillHolder, 0, used);
+				_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);
@@ -782,7 +828,18 @@ public abstract class L2Item
 			_preConditions.add(c);
 	}
 	
-	public abstract SkillHolder[] getSkills();
+	/**
+	 * 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()
+	{
+		return _skillHolder;
+	}
 	
 	public boolean checkCondition(L2Character activeChar, L2Object target, boolean sendMessage)
 	{

+ 1 - 50
L2J_Server/java/com/l2jserver/gameserver/templates/item/L2Weapon.java

@@ -57,7 +57,6 @@ public final class L2Weapon extends L2Item
 	private SkillHolder _enchant4Skill = null; // skill that activates when item is enchanted +4 (for duals)
 	private final int _changeWeaponId;
 	// private final String[] _skill;
-	private SkillHolder[] _skillHolder;
 	
 	// Attached skills for Special Abilities
 	private SkillHolder _skillsOnCast;
@@ -95,45 +94,7 @@ public final class L2Weapon extends L2Item
 		_mpConsume = set.getInteger("mp_consume", 0);
 		_reuseDelay = set.getInteger("reuse_delay", 0);
 		
-		String skill = set.getString("item_skill", null);
-		if (skill != null)
-		{
-			String[] skills = skill.split(";");
-			_skillHolder = new SkillHolder[skills.length];
-			byte iterator = 0;
-			for (String st : skills)
-			{
-				String[] info = st.split("-");
-				
-				if (info == null || info.length != 2)
-					continue;
-				
-				int id = 0;
-				int level = 0;
-				
-				try
-				{
-					id = Integer.parseInt(info[0]);
-					level = Integer.parseInt(info[1]);
-				}
-				catch (Exception nfe)
-				{
-					// Incorrect syntax, dont add new skill
-					_log.info(StringUtil.concat("> Couldnt parse ", st, " in weapon skills! item ", this.toString()));
-					continue;
-				}
-				
-				// If skill can exist, add it
-				if (id > 0 && level > 0)
-				{
-					_skillHolder[iterator] = new SkillHolder(id, level);
-					iterator++;
-				}
-			}
-		}
-		
-		
-		skill = set.getString("enchant4_skill", null);
+		String skill = set.getString("enchant4_skill", null);
 		if (skill != null)
 		{
 			String[] info = skill.split("-");
@@ -297,16 +258,6 @@ public final class L2Weapon extends L2Item
 	{
 		return _mpConsume;
 	}
-
-	/**
-	 * Returns passive skill linked to that weapon
-	 * @return
-	 */
-	@Override
-	public SkillHolder[] getSkills()
-	{
-		return _skillHolder;
-	}
 	
 	/**
 	 * Returns skill that player get when has equiped weapon +4  or more  (for duals SA)

+ 6 - 2
L2J_Server/java/config/loginserver.properties

@@ -12,14 +12,18 @@
 # ---------------------------------------------------------------------------
 
 # Bind ip of the LoginServer, use * to bind on all available IPs
-# Default: *
+# WARNING: <u><b><font color="red">Please don't change default IPs here if you don't know what are you doing!</font></b></u>
+# WARNING: <u><b><font color="red">External/Internal IPs are now inside "ipconfig.xml" file.</font></b></u>
+# Default: * (0.0.0.0)
 LoginserverHostname = *
 
 # Default: 2106
 LoginserverPort = 2106
 
 # The address on which login will listen for GameServers, use * to bind on all available IPs
-# Default: *
+# WARNING: <u><b><font color="red">Please don't change default IPs here if you don't know what are you doing!</font></b></u>
+# WARNING: <u><b><font color="red">External/Internal IPs are now inside "ipconfig.xml" file.</font></b></u>
+# Default: * (0.0.0.0)
 LoginHostname = *
 
 # The port on which login will listen for GameServers

+ 4 - 3
L2J_Server/java/config/server.properties

@@ -10,11 +10,10 @@
 # ---------------------------------------------------------------------------
 # Networking
 # ---------------------------------------------------------------------------
-#
-# Note: External/Internal address definitions was moved to the ipconfig.xml
-#
 
 # Where's the Login server this gameserver should connect to
+# WARNING: <u><b><font color="red">Please don't change default IPs here if you don't know what are you doing!</font></b></u>
+# WARNING: <u><b><font color="red">External/Internal IPs are now inside "ipconfig.xml" file.</font></b></u>
 # Default: 127.0.0.1
 LoginHost = 127.0.0.1
 
@@ -23,6 +22,8 @@ LoginHost = 127.0.0.1
 LoginPort = 9014
 
 # Bind address for gameserver. You should not need to change it in most cases.
+# WARNING: <u><b><font color="red">Please don't change default IPs here if you don't know what are you doing!</font></b></u>
+# WARNING: <u><b><font color="red">External/Internal IPs are now inside "ipconfig.xml" file.</font></b></u>
 # Default: * (0.0.0.0)
 GameserverHostname = *