Selaa lähdekoodia

BETA: Skill Trees fixes and improvements:
* Game server shouldn't crash if skill trees folder isn't present.
* Unhardcoding Race check for skills, previously work for Dwarvens.
* Fixed validators for enchanted Transfer skills and Race specific Fishing Skills.
* Using Race enum instead of Race Id in L2SkillLearn.

Zoey76 13 vuotta sitten
vanhempi
sitoutus
f57928f7f7

+ 13 - 7
L2J_Server_BETA/java/com/l2jserver/gameserver/datatables/SkillTreesData.java

@@ -147,8 +147,13 @@ public final class SkillTreesData
 	 */
 	private boolean loadFiles()
 	{
-		File folder = new File(Config.DATAPACK_ROOT, "data/skillTrees/");
-		File[] listOfFiles = folder.listFiles(new XMLFilter());
+		final File folder = new File(Config.DATAPACK_ROOT, "data/skillTrees/");
+		if (!folder.exists())
+		{
+			_log.warning(getClass().getSimpleName() + ": Folder " + folder.getAbsolutePath() + " doesn't exist!");
+			return false;
+		}
+		final File[] listOfFiles = folder.listFiles(new XMLFilter());
 		for (File f : listOfFiles)
 		{
 			loadSkillTree(f);
@@ -643,10 +648,11 @@ public final class SkillTreesData
 		}
 		
 		final L2Skill[] oldSkills = player.getAllSkills();
+		final Race playerRace = player.getRace();
 		for (L2SkillLearn temp : skills.values())
 		{
-			// If skill is Dwarven only and player is not Dwarven.
-			if ((temp.getRaces() != null) && Util.contains(temp.getRaces(), 4) && !player.hasDwarvenCraft())
+			// If skill is Race specific and the player's race isn't allowed, skip it.
+			if ((temp.getRaces() != null) && !Util.contains(temp.getRaces(), playerRace))
 			{
 				continue;
 			}
@@ -1117,7 +1123,7 @@ public final class SkillTreesData
 		{
 			for (L2SkillLearn s : _fishingSkillTree.values())
 			{
-				if ((s.getRaces() != null) && Util.contains(s.getRaces(), r.ordinal()))
+				if ((s.getRaces() != null) && Util.contains(s.getRaces(), r))
 				{
 					list.add(SkillTable.getSkillHashCode(s.getSkillId(), s.getSkillLevel()));
 				}
@@ -1125,7 +1131,7 @@ public final class SkillTreesData
 			
 			for (L2SkillLearn s : _transformSkillTree.values())
 			{
-				if ((s.getRaces() != null) && Util.contains(s.getRaces(), r.ordinal()))
+				if ((s.getRaces() != null) && Util.contains(s.getRaces(), r))
 				{
 					list.add(SkillTable.getSkillHashCode(s.getSkillId(), s.getSkillLevel()));
 				}
@@ -1225,7 +1231,7 @@ public final class SkillTreesData
 		}
 		
 		// Exclude Transfer Skills from this check.
-		if (getTransferSkill(skill.getId(), skill.getLevel(), player.getClassId()) != null)
+		if (getTransferSkill(skill.getId(), Math.min(skill.getLevel(), maxLvl), player.getClassId()) != null)
 		{
 			return true;
 		}

+ 14 - 7
L2J_Server_BETA/java/com/l2jserver/gameserver/model/L2SkillLearn.java

@@ -18,6 +18,7 @@ import java.util.logging.Logger;
 
 import com.l2jserver.Config;
 import com.l2jserver.gameserver.model.base.ClassId;
+import com.l2jserver.gameserver.model.base.Race;
 import com.l2jserver.gameserver.templates.StatsSet;
 
 /**
@@ -34,7 +35,7 @@ public final class L2SkillLearn
 	private final boolean _autoGet;
 	private final int _levelUpSp;
 	private final int[][] _itemsIdCount;
-	private final int[] _races;
+	private final Race[] _races;
 	private final int[] _preReqSkillIdLvl;
 	private final int _socialClass;
 	private final boolean _residenceSkill;
@@ -44,7 +45,7 @@ public final class L2SkillLearn
 	private final boolean _learnedByFS;
 	
 	/**
-	 * Constructor for L2SkillLearn. 
+	 * Constructor for L2SkillLearn.
 	 * @param set the set with the L2SkillLearn data.
 	 */
 	public L2SkillLearn(StatsSet set)
@@ -64,8 +65,8 @@ public final class L2SkillLearn
 			{
 				try
 				{
-					_itemsIdCount[i][0] = Integer.parseInt(itemIdCount.split(",")[0]);//Id
-					_itemsIdCount[i][1] = Integer.parseInt(itemIdCount.split(",")[1]);//Count
+					_itemsIdCount[i][0] = Integer.parseInt(itemIdCount.split(",")[0]);// Id
+					_itemsIdCount[i][1] = Integer.parseInt(itemIdCount.split(",")[1]);// Count
 					i++;
 				}
 				catch (Exception e)
@@ -80,7 +81,13 @@ public final class L2SkillLearn
 		}
 		if (!set.getString("race", "").isEmpty())
 		{
-			_races = set.getIntegerArray("race");
+			final int[] allowedRaces = set.getIntegerArray("race");
+			final int totalRaces = allowedRaces.length;
+			_races = new Race[totalRaces];
+			for (int i = 0; i < totalRaces; i++)
+			{
+				_races[i] = Race.values()[allowedRaces[i]];
+			}
 		}
 		else
 		{
@@ -199,7 +206,7 @@ public final class L2SkillLearn
 	/**
 	 * @return the array with the races that can acquire this skill.
 	 */
-	public int[] getRaces()
+	public Race[] getRaces()
 	{
 		return _races;
 	}
@@ -237,7 +244,7 @@ public final class L2SkillLearn
 	}
 	
 	/**
-	 * @return the array with Sub-Class conditions, amount of subclasses and level. 
+	 * @return the array with Sub-Class conditions, amount of subclasses and level.
 	 */
 	public int[][] getSubClassConditions()
 	{