Browse Source

BETA: Fix for IndexOutOfBoundsException from [5092] and added "randomness" for long range skill.

Zoey76 13 years ago
parent
commit
8d072cf5c5

+ 7 - 2
L2J_Server_BETA/java/com/l2jserver/gameserver/ai/L2AttackableAI.java

@@ -1106,7 +1106,7 @@ public class L2AttackableAI extends L2CharacterAI implements Runnable
 			if (npc.hasLSkill() || npc.hasSSkill())
 			{
 				final FastList<L2Skill> shortRangeSkills = shortRangeSkillRender();
-				if (npc.hasSSkill() && dist2 <= 150 && Rnd.get(100) <= npc.getSSkillChance())
+				if (!shortRangeSkills.isEmpty() && npc.hasSSkill() && (dist2 <= 150) && Rnd.get(100) <= npc.getSSkillChance())
 				{
 					final L2Skill shortRangeSkill = shortRangeSkills.get(Rnd.get(shortRangeSkills.size()));
 					if ((shortRangeSkill != null) && cast(shortRangeSkill))
@@ -1123,8 +1123,13 @@ public class L2AttackableAI extends L2CharacterAI implements Runnable
 				}
 				
 				final FastList<L2Skill> longRangeSkills = longRangeSkillRender();
-				if (npc.hasLSkill() && dist2 > 150 && Rnd.get(100) <= npc.getLSkillChance())
+				if (!longRangeSkills.isEmpty() && npc.hasLSkill() && (dist2 > 150) && Rnd.get(100) <= npc.getLSkillChance())
 				{
+					final L2Skill longRangeSkill = longRangeSkills.get(Rnd.get(longRangeSkills.size()));
+					if ((longRangeSkill != null) && cast(longRangeSkill))
+					{
+						return;
+					}
 					for (L2Skill sk : longRangeSkills)
 					{
 						if ((sk != null) && cast(sk))

+ 0 - 182
L2J_Server_BETA/java/com/l2jserver/gameserver/model/DesireTable.java

@@ -1,182 +0,0 @@
-/*
- * $Header$
- *
- * $Author$
- * $Date$
- * $Revision$
- * $Log$
- * Revision 1.1.2.1  2005/04/08 08:03:40  luisantonioa
- * *** empty log message ***
- *
- * Revision 1.1  4/04/2005 17:15:07  luisantonioa
- * Created New Class
- *
- *
- * This program is free software: you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later
- * version.
- * 
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- * 
- * You should have received a copy of the GNU General Public License along with
- * this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package com.l2jserver.gameserver.model;
-
-import java.util.Map;
-
-import javolution.util.FastMap;
-
-/**
- * This class ...
- *
- * @version $Revision$ $Date$
- */
-
-public class DesireTable
-{
-	public static final DesireType[] DEFAULT_DESIRES = {DesireType.FEAR, DesireType.DISLIKE,
-		DesireType.HATE, DesireType.DAMAGE};
-	
-	public enum DesireType {
-		FEAR, DISLIKE, HATE, DAMAGE;
-	}
-	
-	static class DesireValue
-	{
-		private float _value;
-		
-		DesireValue()
-		{
-			this(0f);
-		}
-		
-		DesireValue(Float pValue)
-		{
-			_value = pValue;
-		}
-		
-		public void addValue(float pValue)
-		{
-			_value += pValue;
-		}
-		
-		public float getValue()
-		{
-			return _value;
-		}
-	}
-	
-	class Desires
-	{
-		private Map<DesireType, DesireValue> _desireTable;
-		
-		public Desires(DesireType... desireList)
-		{
-			_desireTable = new FastMap<DesireType, DesireValue>();
-			
-			for (DesireType desire : desireList)
-			{
-				_desireTable.put(desire, new DesireValue());
-			}
-		}
-		
-		public DesireValue getDesireValue(DesireType type)
-		{
-			return _desireTable.get(type);
-		}
-		
-		public void addValue(DesireType type, float value)
-		{
-			DesireValue temp = getDesireValue(type);
-			if (temp != null)
-			{
-				temp.addValue(value);
-			}
-		}
-		
-		public void createDesire(DesireType type)
-		{
-			_desireTable.put(type, new DesireValue());
-		}
-		
-		public void deleteDesire(DesireType type)
-		{
-			_desireTable.remove(type);
-		}
-	}
-	
-	private Map<L2Object, Desires> _objectDesireTable;
-	private Desires _generalDesires;
-	private DesireType[] _desireTypes;
-	
-	public DesireTable(DesireType... desireList)
-	{
-		_desireTypes = desireList;
-		_objectDesireTable = new FastMap<L2Object, Desires>();
-		_generalDesires = new Desires(_desireTypes);
-	}
-	
-	public float getDesireValue(DesireType type)
-	{
-		return _generalDesires.getDesireValue(type).getValue();
-	}
-	
-	public float getDesireValue(L2Object object, DesireType type)
-	{
-		Desires desireList = _objectDesireTable.get(object);
-		if (desireList == null) return 0f;
-		return desireList.getDesireValue(type).getValue();
-	}
-	
-	public void addDesireValue(DesireType type, float value)
-	{
-		_generalDesires.addValue(type, value);
-	}
-	
-	public void addDesireValue(L2Object object, DesireType type, float value)
-	{
-		Desires desireList = _objectDesireTable.get(object);
-		if (desireList != null) desireList.addValue(type, value);
-	}
-	
-	public void createDesire(DesireType type)
-	{
-		_generalDesires.createDesire(type);
-	}
-	
-	public void deleteDesire(DesireType type)
-	{
-		_generalDesires.deleteDesire(type);
-	}
-	
-	public void createDesire(L2Object object, DesireType type)
-	{
-		Desires desireList = _objectDesireTable.get(object);
-		if (desireList != null) desireList.createDesire(type);
-	}
-	
-	public void deleteDesire(L2Object object, DesireType type)
-	{
-		Desires desireList = _objectDesireTable.get(object);
-		if (desireList != null) desireList.deleteDesire(type);
-	}
-	
-	public void addKnownObject(L2Object object)
-	{
-		if (object != null)
-		{
-			addKnownObject(object, DesireType.DISLIKE, DesireType.FEAR, DesireType.DAMAGE,
-					DesireType.HATE);
-		}
-	}
-	
-	public void addKnownObject(L2Object object, DesireType... desireList)
-	{
-		if (object != null) _objectDesireTable.put(object, new Desires(desireList));
-	}
-}