Browse Source

BETA: Misc fixes for [5146]
* Comments fixes and cleanup in Formulas.
* Fixed logger in Formulas.
* Comments fixes and cleanup in ConditionListener.
* BaseStats shouldn't NPE if statBonus.xml is not valid.

Zoey76 13 năm trước cách đây
mục cha
commit
db67cbecfc

+ 5 - 4
L2J_Server_BETA/java/com/l2jserver/gameserver/model/conditions/ConditionListener.java

@@ -15,14 +15,15 @@
 package com.l2jserver.gameserver.model.conditions;
 
 /**
- * The listener interface for receiving condition events. The class that is interested in processing a condition event implements this interface, and the object created with that class is registered with a component using the component's <code>addConditionListener<code> method. When
- * the condition event occurs, that object's appropriate
- * method is invoked.
+ * The listener interface for receiving condition events.<br>
+ * The class that is interested in processing a condition event implements this interface,<br>
+ * and the object created with that class is registered with a component using the component's<br>
+ * <code>addConditionListener<code> method.<br>
+ * When the condition event occurs, that object's appropriate method is invoked.
  * @author mkizub
  */
 public interface ConditionListener
 {
-	
 	/**
 	 * Notify changed.
 	 */

+ 58 - 40
L2J_Server_BETA/java/com/l2jserver/gameserver/model/stats/BaseStats.java

@@ -29,9 +29,7 @@ import com.l2jserver.Config;
 import com.l2jserver.gameserver.model.actor.L2Character;
 
 /**
- * 
  * @author DS
- *
  */
 public enum BaseStats
 {
@@ -43,7 +41,7 @@ public enum BaseStats
 	MEN(new MEN()),
 	NULL(new NULL());
 	
-	protected static final Logger _log = Logger.getLogger(BaseStats.class.getName());
+	private static final Logger _log = Logger.getLogger(BaseStats.class.getName());
 	
 	public static final int MAX_STAT_VALUE = 100;
 	
@@ -69,7 +67,9 @@ public enum BaseStats
 	public final double calcBonus(L2Character actor)
 	{
 		if (actor != null)
+		{
 			return _stat.calcBonus(actor);
+		}
 		
 		return 1;
 	}
@@ -80,9 +80,10 @@ public enum BaseStats
 		for (BaseStats s : values())
 		{
 			if (s.getValue().equalsIgnoreCase(name))
+			{
 				return s;
+			}
 		}
-		
 		throw new NoSuchElementException("Unknown name '" + name + "' for enum BaseStats");
 	}
 	
@@ -173,47 +174,64 @@ public enum BaseStats
 				_log.log(Level.WARNING, "[BaseStats] Could not parse file: " + e.getMessage(), e);
 			}
 			
-			String statName;
-			int val;
-			double bonus;
-			NamedNodeMap attrs;
-			for (Node list = doc.getFirstChild(); list != null; list = list.getNextSibling())
+			if (doc != null)
 			{
-				if ("list".equalsIgnoreCase(list.getNodeName()))
+				String statName;
+				int val;
+				double bonus;
+				NamedNodeMap attrs;
+				for (Node list = doc.getFirstChild(); list != null; list = list.getNextSibling())
 				{
-					for (Node stat = list.getFirstChild(); stat != null; stat = stat.getNextSibling())
+					if ("list".equalsIgnoreCase(list.getNodeName()))
 					{
-						statName = stat.getNodeName();
-						for (Node value = stat.getFirstChild(); value != null; value = value.getNextSibling())
+						for (Node stat = list.getFirstChild(); stat != null; stat = stat.getNextSibling())
 						{
-							if ("stat".equalsIgnoreCase(value.getNodeName()))
+							statName = stat.getNodeName();
+							for (Node value = stat.getFirstChild(); value != null; value = value.getNextSibling())
 							{
-								attrs = value.getAttributes();
-								try
-								{
-									val = Integer.parseInt(attrs.getNamedItem("value").getNodeValue());
-									bonus = Double.parseDouble(attrs.getNamedItem("bonus").getNodeValue());
-								}
-								catch (Exception e)
+								if ("stat".equalsIgnoreCase(value.getNodeName()))
 								{
-									_log.severe("[BaseStats] Invalid stats value: "+value.getNodeValue()+", skipping");
-									continue;
+									attrs = value.getAttributes();
+									try
+									{
+										val = Integer.parseInt(attrs.getNamedItem("value").getNodeValue());
+										bonus = Double.parseDouble(attrs.getNamedItem("bonus").getNodeValue());
+									}
+									catch (Exception e)
+									{
+										_log.severe("[BaseStats] Invalid stats value: " + value.getNodeValue() + ", skipping");
+										continue;
+									}
+									
+									if ("STR".equalsIgnoreCase(statName))
+									{
+										STRbonus[val] = bonus;
+									}
+									else if ("INT".equalsIgnoreCase(statName))
+									{
+										INTbonus[val] = bonus;
+									}
+									else if ("DEX".equalsIgnoreCase(statName))
+									{
+										DEXbonus[val] = bonus;
+									}
+									else if ("WIT".equalsIgnoreCase(statName))
+									{
+										WITbonus[val] = bonus;
+									}
+									else if ("CON".equalsIgnoreCase(statName))
+									{
+										CONbonus[val] = bonus;
+									}
+									else if ("MEN".equalsIgnoreCase(statName))
+									{
+										MENbonus[val] = bonus;
+									}
+									else
+									{
+										_log.severe("[BaseStats] Invalid stats name: " + statName + ", skipping");
+									}
 								}
-								
-								if ("STR".equalsIgnoreCase(statName))
-									STRbonus[val] = bonus;
-								else if ("INT".equalsIgnoreCase(statName))
-									INTbonus[val] = bonus;
-								else if ("DEX".equalsIgnoreCase(statName))
-									DEXbonus[val] = bonus;
-								else if ("WIT".equalsIgnoreCase(statName))
-									WITbonus[val] = bonus;
-								else if ("CON".equalsIgnoreCase(statName))
-									CONbonus[val] = bonus;
-								else if ("MEN".equalsIgnoreCase(statName))
-									MENbonus[val] = bonus;
-								else
-									_log.severe("[BaseStats] Invalid stats name: "+statName+", skipping");
 							}
 						}
 					}
@@ -222,7 +240,7 @@ public enum BaseStats
 		}
 		else
 		{
-			throw new Error("[BaseStats] File not found: "+file.getName());
+			throw new Error("[BaseStats] File not found: " + file.getName());
 		}
 	}
-}
+}

+ 31 - 60
L2J_Server_BETA/java/com/l2jserver/gameserver/model/stats/Formulas.java

@@ -70,12 +70,15 @@ import com.l2jserver.util.Rnd;
 import com.l2jserver.util.StringUtil;
 
 /**
- * Global calculations, can be modified by server admins
+ * Global calculations.
  */
 public final class Formulas
 {
-	/** Regen Task period */
-	protected static final Logger _log = Logger.getLogger(L2Character.class.getName());
+	private static final Logger _log = Logger.getLogger(Formulas.class.getName());
+	
+	/**
+	 * Regen Task period.
+	 */
 	private static final int HP_REGENERATE_PERIOD = 3000; // 3 secs
 	
 	public static final byte SHIELD_DEFENSE_FAILED = 0; // no shield defense
@@ -161,8 +164,7 @@ public final class Formulas
 		}
 		
 		/**
-		 * Constructor of the FuncMultRegenResting.<BR>
-		 * <BR>
+		 * Constructor of the FuncMultRegenResting.
 		 * @param pStat
 		 */
 		private FuncMultRegenResting(Stats pStat)
@@ -172,8 +174,7 @@ public final class Formulas
 		}
 		
 		/**
-		 * Calculate the modifier of the state concerned.<BR>
-		 * <BR>
+		 * Calculate the modifier of the state concerned.
 		 */
 		@Override
 		public void calc(Env env)
@@ -969,8 +970,7 @@ public final class Formulas
 	}
 	
 	/**
-	 * Return the period between 2 regeneration task (3s for L2Character, 5 min for L2DoorInstance).<BR>
-	 * <BR>
+	 * Return the period between 2 regeneration task (3s for L2Character, 5 min for L2DoorInstance).
 	 * @param cha
 	 * @return
 	 */
@@ -985,16 +985,11 @@ public final class Formulas
 	}
 	
 	/**
-	 * Return the standard NPC Calculator set containing ACCURACY_COMBAT and EVASION_RATE.<BR>
-	 * <BR>
-	 * <B><U> Concept</U> :</B><BR>
-	 * <BR>
-	 * A calculator is created to manage and dynamically calculate the effect of a character property (ex : MAX_HP, REGENERATE_HP_RATE...). In fact, each calculator is a table of Func object in which each Func represents a mathematic function : <BR>
-	 * <BR>
-	 * FuncAtkAccuracy -> Math.sqrt(_player.getDEX())*6+_player.getLevel()<BR>
-	 * <BR>
-	 * To reduce cache memory use, L2NPCInstances who don't have skills share the same Calculator set called <B>NPC_STD_CALCULATOR</B>.<BR>
-	 * <BR>
+	 * Return the standard NPC Calculator set containing ACCURACY_COMBAT and EVASION_RATE.
+	 * <B><U>Concept</U>:</B><br>
+	 * A calculator is created to manage and dynamically calculate the effect of a character property (ex : MAX_HP, REGENERATE_HP_RATE...). In fact, each calculator is a table of Func object in which each Func represents a mathematic function : <br>
+	 * FuncAtkAccuracy -> Math.sqrt(_player.getDEX())*6+_player.getLevel()<br>
+	 * To reduce cache memory use, L2NPCInstances who don't have skills share the same Calculator set called <B>NPC_STD_CALCULATOR</B>.<br>
 	 * @return
 	 */
 	public static Calculator[] getStdNPCCalculators()
@@ -1067,14 +1062,10 @@ public final class Formulas
 	}
 	
 	/**
-	 * Add basics Func objects to L2PcInstance and L2Summon.<BR>
-	 * <BR>
-	 * <B><U> Concept</U> :</B><BR>
-	 * <BR>
-	 * A calculator is created to manage and dynamically calculate the effect of a character property (ex : MAX_HP, REGENERATE_HP_RATE...). In fact, each calculator is a table of Func object in which each Func represents a mathematic function : <BR>
-	 * <BR>
-	 * FuncAtkAccuracy -> Math.sqrt(_player.getDEX())*6+_player.getLevel()<BR>
-	 * <BR>
+	 * Add basics Func objects to L2PcInstance and L2Summon.<br>
+	 * <B><U>Concept</U>:</B><br>
+	 * A calculator is created to manage and dynamically calculate the effect of a character property (ex : MAX_HP, REGENERATE_HP_RATE...). In fact, each calculator is a table of Func object in which each Func represents a mathematic function : <br>
+	 * FuncAtkAccuracy -> Math.sqrt(_player.getDEX())*6+_player.getLevel()<br>
 	 * @param cha L2PcInstance or L2Summon that must obtain basic Func objects
 	 */
 	public static void addFuncsToNewCharacter(L2Character cha)
@@ -1603,7 +1594,7 @@ public final class Formulas
 	}
 	
 	/**
-	 * Calculated damage caused by ATTACK of attacker on target, called separatly for each weapon, if dual-weapon is used.
+	 * Calculated damage caused by ATTACK of attacker on target, called separately for each weapon, if dual-weapon is used.
 	 * @param attacker player or NPC that makes ATTACK
 	 * @param target player or NPC, target of ATTACK
 	 * @param skill
@@ -1683,7 +1674,7 @@ public final class Formulas
 			}
 		}
 		
-		// defence modifier depending of the attacker weapon
+		// Defense modifier depending of the attacker weapon
 		L2Weapon weapon = attacker.getActiveWeaponItem();
 		Stats stat = null;
 		boolean isBow = false;
@@ -1738,9 +1729,6 @@ public final class Formulas
 				case ANCIENTSWORD:
 					stat = Stats.ANCIENT_WPN_VULN;
 					break;
-			/*
-			 * case PET: stat = Stats.PET_WPN_VULN; break;
-			 */
 			}
 		}
 		
@@ -1750,17 +1738,6 @@ public final class Formulas
 			stat = Stats.PET_WPN_VULN;
 		}
 		
-		/*
-		 * if (shld && !Config.ALT_GAME_SHIELD_BLOCKS) { defence += target.getShldDef(); }
-		 */
-		// if (!(attacker instanceof L2RaidBossInstance) &&
-		/*
-		 * if ((attacker instanceof L2NpcInstance || attacker instanceof L2SiegeGuardInstance)) { if (attacker instanceof L2RaidBossInstance) damage *= 1; // was 10 changed for temp fix // else // damage *= 2; // if (attacker instanceof L2NpcInstance || attacker instanceof L2SiegeGuardInstance){
-		 * //damage = damage * attacker.getSTR() * attacker.getAccuracy() * 0.05 / defence; // damage = damage * attacker.getSTR()* (attacker.getSTR() + attacker.getLevel()) * 0.025 / defence; // damage += _rnd.nextDouble() * damage / 10 ; }
-		 */
-		// else {
-		// if (skill == null)
-		
 		if (crit)
 		{
 			// Finally retail like formula
@@ -1777,17 +1754,10 @@ public final class Formulas
 		{
 			// get the vulnerability due to skills (buffs, passives, toggles, etc)
 			damage = target.calcStat(stat, damage, target, null);
-			/*
-			 * if (target instanceof L2Npc) { // get the natural vulnerability for the template damage *= ((L2Npc) target).getTemplate().getVulnerability(stat); }
-			 */
 		}
 		
 		// Weapon random damage
 		damage *= attacker.getRandomDamageMultiplier();
-		
-		// damage += Rnd.nextDouble() * damage / 10;
-		// damage += _rnd.nextDouble()* attacker.getRandomDamage(target);
-		// }
 		if ((shld > 0) && Config.ALT_GAME_SHIELD_BLOCKS)
 		{
 			damage -= target.getShldDef();
@@ -2400,10 +2370,10 @@ public final class Formulas
 	}
 	
 	/**
-	 * Returns true if hit missed (target evaded) Formula based on http://l2p.l2wh.com/nonskillattacks.html
+	 * Formula based on http://l2p.l2wh.com/nonskillattacks.html
 	 * @param attacker
 	 * @param target
-	 * @return
+	 * @return {@code true} if hit missed (target evaded), {@code false} otherwise.
 	 */
 	public static boolean calcHitMiss(L2Character attacker, L2Character target)
 	{
@@ -3514,30 +3484,32 @@ public final class Formulas
 	}
 	
 	/**
-	 * Calculate skill reflection according these three possibilities: <li>Reflect failed</li> <li>Mormal reflect (just effects). <U>Only possible for skilltypes: BUFF, REFLECT, HEAL_PERCENT, MANAHEAL_PERCENT, HOT, CPHOT, MPHOT</U></li> <li>vengEance reflect (100% damage reflected but damage is also
-	 * dealt to actor). <U>This is only possible for skills with skilltype PDAM, BLOW, CHARGEDAM, MDAM or DEATHLINK</U></li>
+	 * Calculate skill reflection according these three possibilities:<br>
+	 * <ul>
+	 * <li>Reflect failed</li>
+	 * <li>Mormal reflect (just effects). <U>Only possible for skilltypes: BUFF, REFLECT, HEAL_PERCENT, MANAHEAL_PERCENT, HOT, CPHOT, MPHOT</U></li>
+	 * <li>vengEance reflect (100% damage reflected but damage is also dealt to actor). <U>This is only possible for skills with skilltype PDAM, BLOW, CHARGEDAM, MDAM or DEATHLINK</U></li>
+	 * </ul>
 	 * @param target
 	 * @param skill
 	 * @return SKILL_REFLECTED_FAILED, SKILL_REFLECT_SUCCEED or SKILL_REFLECT_VENGEANCE
 	 */
 	public static byte calcSkillReflect(L2Character target, L2Skill skill)
 	{
-		/*
-		 * Neither some special skills (like hero debuffs...) or those skills ignoring resistances can be reflected
-		 */
+		// Neither some special skills (like hero debuffs...) or those skills ignoring resistances can be reflected
 		if (skill.ignoreResists() || !skill.canBeReflected())
 		{
 			return SKILL_REFLECT_FAILED;
 		}
 		
-		// only magic and melee skills can be reflected
+		// Only magic and melee skills can be reflected
 		if (!skill.isMagic() && ((skill.getCastRange() == -1) || (skill.getCastRange() > MELEE_ATTACK_RANGE)))
 		{
 			return SKILL_REFLECT_FAILED;
 		}
 		
 		byte reflect = SKILL_REFLECT_FAILED;
-		// check for non-reflected skilltypes, need additional retail check
+		// Check for non-reflected skilltypes, need additional retail check
 		switch (skill.getSkillType())
 		{
 			case BUFF:
@@ -3571,7 +3543,6 @@ public final class Formulas
 		}
 		
 		final double reflectChance = target.calcStat(skill.isMagic() ? Stats.REFLECT_SKILL_MAGIC : Stats.REFLECT_SKILL_PHYSIC, 0, null, skill);
-		
 		if (Rnd.get(100) < reflectChance)
 		{
 			reflect |= SKILL_REFLECT_SUCCEED;