Bläddra i källkod

Will increasing verbosity against senseless stats values fix itself the well-known !ArrayIndexOutOfBoundException? Make your bet!

DrHouse 15 år sedan
förälder
incheckning
d9acd19f85

+ 7 - 6
L2_GameServer/java/net/sf/l2j/gameserver/datatables/NpcTable.java

@@ -33,6 +33,7 @@ import net.sf.l2j.gameserver.model.L2DropData;
 import net.sf.l2j.gameserver.model.L2MinionData;
 import net.sf.l2j.gameserver.model.L2Skill;
 import net.sf.l2j.gameserver.model.base.ClassId;
+import net.sf.l2j.gameserver.skills.Formulas;
 import net.sf.l2j.gameserver.skills.Stats;
 import net.sf.l2j.gameserver.templates.StatsSet;
 import net.sf.l2j.gameserver.templates.chars.L2NpcTemplate;
@@ -353,12 +354,12 @@ public class NpcTable
 			npcDat.set("baseRunSpd", NpcData.getInt("runspd"));
 			
 			// constants, until we have stats in DB
-			npcDat.set("baseSTR", NpcData.getInt("str"));
-			npcDat.set("baseCON", NpcData.getInt("con"));
-			npcDat.set("baseDEX", NpcData.getInt("dex"));
-			npcDat.set("baseINT", NpcData.getInt("int"));
-			npcDat.set("baseWIT", NpcData.getInt("wit"));
-			npcDat.set("baseMEN", NpcData.getInt("men"));
+			npcDat.safeSet("baseSTR", NpcData.getInt("str"), 0, Formulas.MAX_STAT_VALUE, "Loading npc template id: "+NpcData.getInt("idTemplate"));
+			npcDat.safeSet("baseCON", NpcData.getInt("con"), 0, Formulas.MAX_STAT_VALUE, "Loading npc template id: "+NpcData.getInt("idTemplate"));
+			npcDat.safeSet("baseDEX", NpcData.getInt("dex"), 0, Formulas.MAX_STAT_VALUE, "Loading npc template id: "+NpcData.getInt("idTemplate"));
+			npcDat.safeSet("baseINT", NpcData.getInt("int"), 0, Formulas.MAX_STAT_VALUE, "Loading npc template id: "+NpcData.getInt("idTemplate"));
+			npcDat.safeSet("baseWIT", NpcData.getInt("wit"), 0, Formulas.MAX_STAT_VALUE, "Loading npc template id: "+NpcData.getInt("idTemplate"));
+			npcDat.safeSet("baseMEN", NpcData.getInt("men"), 0, Formulas.MAX_STAT_VALUE, "Loading npc template id: "+NpcData.getInt("idTemplate"));
 			
 			npcDat.set("baseHpMax", NpcData.getInt("hp"));
 			npcDat.set("baseCpMax", 0);

+ 25 - 0
L2_GameServer/java/net/sf/l2j/gameserver/templates/StatsSet.java

@@ -15,6 +15,10 @@
 package net.sf.l2j.gameserver.templates;
 
 import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import net.sf.l2j.Config;
 
 import javolution.util.FastMap;
 
@@ -26,6 +30,7 @@ import javolution.util.FastMap;
  */
 public final class StatsSet  {
 
+	private static final Logger _log = Logger.getLogger(StatsSet.class.getName());
 	private final Map<String, Object> _set = new FastMap<String, Object>();
 
 	/**
@@ -462,6 +467,26 @@ public final class StatsSet  {
 	{
 		_set.put(name, value);
 	}
+	
+	/**
+	 * Safe version of "set". Expected values are within [min, max[<br>
+	 * Add the int hold in param "value" for the key "name".
+	 * 
+	 * @param name : String designating the key in the set
+	 * @param value : int corresponding to the value associated with the key
+	 */
+	public void safeSet(String name, int value, int min, int max, String reference)
+	{
+		if (min <= max && (value < min || value >= max))
+		{
+			if (Config.ASSERT)
+				throw new AssertionError("Incorrect value: "+value+"for: "+name+ "Ref: "+ reference);
+			
+			_log.log(Level.SEVERE, "Incorrect value: "+value+"for: "+name+ "Ref: "+ reference);
+		}
+		
+		set(name, value);
+	}
 
 	/**
 	 * Add the double hold in param "value" for the key "name"