Просмотр исходного кода

BETA: Misc fixes:
* Avoiding duplicated code using getActingPlayer(), by Tryskell.
* Avoiding getActiveChar() calls, instead using present reference.
* Using proper logger inheritance from AbstractAI.

Zoey76 13 лет назад
Родитель
Сommit
5d890540a3

+ 2 - 3
L2J_Server_BETA/java/com/l2jserver/gameserver/ai/AbstractAI.java

@@ -19,7 +19,6 @@ import static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_FOLLOW;
 import static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_IDLE;
 
 import java.util.concurrent.Future;
-import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import com.l2jserver.gameserver.GameTimeController;
@@ -47,7 +46,7 @@ import com.l2jserver.gameserver.taskmanager.AttackStanceTaskManager;
  */
 public abstract class AbstractAI implements Ctrl
 {
-	protected static final Logger _log = Logger.getLogger(AbstractAI.class.getName());
+	protected final Logger _log = Logger.getLogger(getClass().getName());
 	
 	private NextAction _nextAction;
 	
@@ -114,7 +113,7 @@ public abstract class AbstractAI implements Ctrl
 			}
 			catch (Exception e)
 			{
-				_log.log(Level.WARNING, "", e);
+				_log.warning(getClass().getSimpleName() + ": Error: " + e.getMessage());
 			}
 		}
 	}

+ 37 - 64
L2J_Server_BETA/java/com/l2jserver/gameserver/ai/L2AttackableAI.java

@@ -20,8 +20,6 @@ import static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_IDLE;
 
 import java.util.Collection;
 import java.util.concurrent.Future;
-import java.util.logging.Level;
-import java.util.logging.Logger;
 
 import javolution.util.FastList;
 
@@ -63,23 +61,25 @@ import com.l2jserver.util.Rnd;
  */
 public class L2AttackableAI extends L2CharacterAI implements Runnable
 {
-	private static final Logger _log = Logger.getLogger(L2AttackableAI.class.getName());
-	
 	private static final int RANDOM_WALK_RATE = 30; // confirmed
 	// private static final int MAX_DRIFT_RANGE = 300;
 	private static final int MAX_ATTACK_TIMEOUT = 1200; // int ticks, i.e. 2min
-	
-	/** The L2Attackable AI task executed every 1s (call onEvtThink method)*/
+	/**
+	 * The L2Attackable AI task executed every 1s (call onEvtThink method).
+	 */
 	private Future<?> _aiTask;
-	
-	/** The delay after which the attacked is stopped */
+	/**
+	 * The delay after which the attacked is stopped.
+	 */
 	private int _attackTimeout;
-	
-	/** The L2Attackable aggro counter */
+	/**
+	 * The L2Attackable aggro counter.
+	 */
 	private int _globalAggro;
-	
-	/** The flag used to indicate that a thinking action is in progress */
-	private boolean _thinking; // to prevent recursive thinking
+	/**
+	 * The flag used to indicate that a thinking action is in progress, to prevent recursive thinking.
+	 */
+	private boolean _thinking;
 	
 	private int timepass = 0;
 	private int chaostime = 0;
@@ -89,16 +89,13 @@ public class L2AttackableAI extends L2CharacterAI implements Runnable
 	int lastBuffTick;
 	
 	/**
-	 * Constructor of L2AttackableAI.<BR><BR>
-	 *
+	 * Constructor of L2AttackableAI.
 	 * @param accessor The AI accessor of the L2Character
-	 *
 	 */
 	public L2AttackableAI(L2Character.AIAccessor accessor)
 	{
 		super(accessor);
 		_skillrender = NpcTable.getInstance().getTemplate(getActiveChar().getTemplate().getNpcId());
-		//_selfAnalysis.init();
 		_attackTimeout = Integer.MAX_VALUE;
 		_globalAggro = -10; // 10 seconds timeout of ATTACK after respawn
 	}
@@ -143,9 +140,10 @@ public class L2AttackableAI extends L2CharacterAI implements Runnable
 	private boolean autoAttackCondition(L2Character target)
 	{
 		if (target == null || getActiveChar() == null)
+		{
 			return false;
-		
-		L2Attackable me = getActiveChar();
+		}
+		final L2Attackable me = getActiveChar();
 		
 		// Check if the target isn't invulnerable
 		if (target.isInvul())
@@ -173,10 +171,10 @@ public class L2AttackableAI extends L2CharacterAI implements Runnable
 				return false;
 		}
 		
-		// Check if the target is a L2PcInstance
-		if (target instanceof L2PcInstance)
+		// Gets the player if there is any.
+		final L2PcInstance player = target.getActingPlayer();
+		if (player != null)
 		{
-			final L2PcInstance player = target.getActingPlayer();
 			// Don't take the aggro if the GM has the access level below or equal to GM_DONT_TAKE_AGGRO
 			if (player.isGM() && !player.getAccessLevel().canTakeAggro())
 				return false;
@@ -203,48 +201,24 @@ public class L2AttackableAI extends L2CharacterAI implements Runnable
 				if (me instanceof L2RiftInvaderInstance && !DimensionalRiftManager.getInstance().getRoom(riftType, riftRoom).checkIfInZone(me.getX(), me.getY(), me.getZ()))
 					return false;
 			}
-			
-			//if (_selfAnalysis.cannotMoveOnLand && !target.isInsideZone(L2Character.ZONE_WATER))
-			//	return false;
 		}
 		
-		// Check if the target is a L2Summon
-		if (target instanceof L2Summon)
-		{
-			L2PcInstance owner = ((L2Summon) target).getOwner();
-			if (owner != null)
-			{
-				// Don't take the aggro if the GM has the access level below or equal to GM_DONT_TAKE_AGGRO
-				if (owner.isGM() && (owner.isInvul() || !owner.getAccessLevel().canTakeAggro()))
-					return false;
-				// Check if player is an ally (comparing mem addr)
-				if ("varka_silenos_clan".equals(me.getFactionId()) && owner.isAlliedWithVarka())
-					return false;
-				if ("ketra_orc_clan".equals(me.getFactionId()) && owner.isAlliedWithKetra())
-					return false;
-			}
-		}
 		// Check if the actor is a L2GuardInstance
-		if (getActiveChar() instanceof L2GuardInstance)
+		if (me instanceof L2GuardInstance)
 		{
-			
 			// Check if the L2PcInstance target has karma (=PK)
-			if (target instanceof L2PcInstance && ((L2PcInstance) target).getKarma() > 0)
-				// Los Check
-				return GeoData.getInstance().canSeeTarget(me, target);
-			
-			//if (target instanceof L2Summon)
-			//	return ((L2Summon)target).getKarma() > 0;
-			
+			if ((player != null) && player.getKarma() > 0)
+			{
+				return GeoData.getInstance().canSeeTarget(me, player); // Los Check
+			}
 			// Check if the L2MonsterInstance target is aggressive
 			if (target instanceof L2MonsterInstance && Config.GUARD_ATTACK_AGGRO_MOB)
 				return (((L2MonsterInstance) target).isAggressive() && GeoData.getInstance().canSeeTarget(me, target));
 			
 			return false;
 		}
-		else if (getActiveChar() instanceof L2FriendlyMobInstance)
-		{ // the actor is a L2FriendlyMobInstance
-			
+		else if (me instanceof L2FriendlyMobInstance)
+		{
 			// Check if the target isn't another L2Npc
 			if (target instanceof L2Npc)
 				return false;
@@ -258,23 +232,23 @@ public class L2AttackableAI extends L2CharacterAI implements Runnable
 		{
 			if (target instanceof L2Attackable)
 			{
-				if (getActiveChar().getEnemyClan() == null || ((L2Attackable) target).getClan() == null)
+				if (me.getEnemyClan() == null || ((L2Attackable) target).getClan() == null)
 					return false;
 				
-				if (!target.isAutoAttackable(getActiveChar()))
+				if (!target.isAutoAttackable(me))
 					return false;
 				
-				if (getActiveChar().getEnemyClan().equals(((L2Attackable) target).getClan()))
+				if (me.getEnemyClan().equals(((L2Attackable) target).getClan()))
 				{
-					if (getActiveChar().isInsideRadius(target, getActiveChar().getEnemyRange(), false, false))
+					if (me.isInsideRadius(target, me.getEnemyRange(), false, false))
 					{
-						return GeoData.getInstance().canSeeTarget(getActiveChar(), target);
+						return GeoData.getInstance().canSeeTarget(me, target);
 					}
 					return false;
 				}
-				if (getActiveChar().getIsChaos() > 0 && me.isInsideRadius(target, getActiveChar().getIsChaos(), false, false))
+				if (me.getIsChaos() > 0 && me.isInsideRadius(target, me.getIsChaos(), false, false))
 				{
-					if (getActiveChar().getFactionId() != null && getActiveChar().getFactionId().equals(((L2Attackable) target).getFactionId()))
+					if (me.getFactionId() != null && me.getFactionId().equals(((L2Attackable) target).getFactionId()))
 					{
 						return false;
 					}
@@ -391,7 +365,6 @@ public class L2AttackableAI extends L2CharacterAI implements Runnable
 		_attackTimeout = MAX_ATTACK_TIMEOUT + GameTimeController.getGameTicks();
 		
 		// self and buffs
-		
 		if (lastBuffTick + 30 < GameTimeController.getGameTicks())
 		{
 			for (L2Skill sk : _skillrender.getBuffSkills())
@@ -758,7 +731,7 @@ public class L2AttackableAI extends L2CharacterAI implements Runnable
 			}
 			catch (NullPointerException e)
 			{
-				_log.log(Level.WARNING, "L2AttackableAI: thinkAttack() faction call failed: " + e.getMessage(), e);
+				_log.warning(getClass().getSimpleName() + ": thinkAttack() faction call failed: " + e.getMessage());
 			}
 		}
 
@@ -1912,7 +1885,7 @@ public class L2AttackableAI extends L2CharacterAI implements Runnable
 		catch (NullPointerException e)
 		{
 			setIntention(AI_INTENTION_ACTIVE);
-			_log.log(Level.WARNING, this+ " - failed executing movementDisable(): "+e.getMessage(),e);
+			_log.warning(getClass().getSimpleName() + ": " + this + " - failed executing movementDisable(): " + e.getMessage());
 			return;
 		}
 	}
@@ -2422,7 +2395,7 @@ public class L2AttackableAI extends L2CharacterAI implements Runnable
 		}
 		catch(Exception e)
 		{
-			_log.log(Level.WARNING, this+" -  onEvtThink() failed: "+e.getMessage(), e);
+			_log.warning(getClass().getSimpleName() + ": " + this + " -  onEvtThink() failed: " + e.getMessage());
 		}
 		finally
 		{

+ 4 - 8
L2J_Server_BETA/java/com/l2jserver/gameserver/ai/L2ControllableMobAI.java

@@ -19,8 +19,6 @@ import static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_ATTACK;
 
 import java.util.Collection;
 import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
 
 import javolution.util.FastList;
 
@@ -46,8 +44,6 @@ import com.l2jserver.util.Rnd;
  */
 public class L2ControllableMobAI extends L2AttackableAI
 {
-	private static final Logger _log = Logger.getLogger(L2ControllableMobAI.class.getName());
-	
 	public static final int AI_IDLE = 1;
 	public static final int AI_NORMAL = 2;
 	public static final int AI_FORCEATTACK = 3;
@@ -155,7 +151,7 @@ public class L2ControllableMobAI extends L2AttackableAI
 		}
 		catch (NullPointerException e)
 		{
-			_log.log(Level.WARNING, "Encountered Null Value: " + e.getMessage(), e);
+			_log.warning(getClass().getSimpleName() + ": Encountered Null Value: " + e.getMessage());
 		}
 		
 		if (!_actor.isMuted())
@@ -218,7 +214,7 @@ public class L2ControllableMobAI extends L2AttackableAI
 		}
 		catch (NullPointerException e)
 		{
-			_log.log(Level.WARNING, "Encountered Null Value: " + e.getMessage(), e);
+			_log.warning(getClass().getSimpleName() + ": Encountered Null Value: " + e.getMessage());
 		}
 		
 		if (!_actor.isMuted() && (dist2 > ((range + 20) * (range + 20))))
@@ -271,7 +267,7 @@ public class L2ControllableMobAI extends L2AttackableAI
 		}
 		catch (NullPointerException e)
 		{
-			_log.log(Level.WARNING, "Encountered Null Value: " + e.getMessage(), e);
+			_log.warning(getClass().getSimpleName() + ": Encountered Null Value: " + e.getMessage());
 		}
 		
 		if (!_actor.isMuted() && (dist2 > ((range + 20) * (range + 20))))
@@ -359,7 +355,7 @@ public class L2ControllableMobAI extends L2AttackableAI
 			}
 			catch (NullPointerException e)
 			{
-				_log.log(Level.WARNING, "Encountered Null Value: " + e.getMessage(), e);
+				_log.warning(getClass().getSimpleName() + ": Encountered Null Value: " + e.getMessage());
 			}
 			
 			if (!_actor.isMuted() && (dist2 > ((range + 20) * (range + 20))))

+ 0 - 1
L2J_Server_BETA/java/com/l2jserver/gameserver/ai/L2DoorAI.java

@@ -27,7 +27,6 @@ import com.l2jserver.gameserver.model.skills.L2Skill;
  */
 public class L2DoorAI extends L2CharacterAI
 {
-	
 	public L2DoorAI(L2DoorInstance.AIAccessor accessor)
 	{
 		super(accessor);

+ 2 - 6
L2J_Server_BETA/java/com/l2jserver/gameserver/ai/L2FortSiegeGuardAI.java

@@ -19,7 +19,6 @@ import static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_ATTACK;
 import static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_IDLE;
 
 import java.util.concurrent.Future;
-import java.util.logging.Logger;
 
 import com.l2jserver.Config;
 import com.l2jserver.gameserver.GameTimeController;
@@ -48,9 +47,6 @@ import com.l2jserver.util.Rnd;
  */
 public class L2FortSiegeGuardAI extends L2CharacterAI implements Runnable
 {
-	
-	protected static final Logger _log1 = Logger.getLogger(L2FortSiegeGuardAI.class.getName());
-	
 	private static final int MAX_ATTACK_TIMEOUT = 300; // int ticks, i.e. 30 seconds
 	
 	/** The L2Attackable AI task executed every 1s (call onEvtThink method)*/
@@ -182,7 +178,7 @@ public class L2FortSiegeGuardAI extends L2CharacterAI implements Runnable
 	synchronized void changeIntention(CtrlIntention intention, Object arg0, Object arg1)
 	{
 		if (Config.DEBUG)
-			_log1.info("L2SiegeAI.changeIntention(" + intention + ", " + arg0 + ", " + arg1 + ")");
+			_log.warning(getClass().getSimpleName() + ": changeIntention(" + intention + ", " + arg0 + ", " + arg1 + ")");
 		
 		if (intention == AI_INTENTION_IDLE /*|| intention == AI_INTENTION_ACTIVE*/) // active becomes idle if only a summon is present
 		{
@@ -338,7 +334,7 @@ public class L2FortSiegeGuardAI extends L2CharacterAI implements Runnable
 	private void thinkAttack()
 	{
 		if (Config.DEBUG)
-			_log1.info("L2FortSiegeGuardAI.thinkAttack(); timeout=" + (_attackTimeout - GameTimeController.getGameTicks()));
+			_log.warning(getClass().getSimpleName() + ": thinkAttack(); timeout=" + (_attackTimeout - GameTimeController.getGameTicks()));
 		
 		if (_attackTimeout < GameTimeController.getGameTicks())
 		{

+ 2 - 2
L2J_Server_BETA/java/com/l2jserver/gameserver/ai/L2NpcWalkerAI.java

@@ -99,7 +99,7 @@ public class L2NpcWalkerAI extends L2CharacterAI implements Runnable
 	@Override
 	protected void onEvtArrivedBlocked(L2CharPosition blocked_at_pos)
 	{
-		_log.warning("NpcWalker ID: " + getActor().getNpcId() + ": Blocked at rote position [" + _currentPos + "], coords: " + blocked_at_pos.x + ", " + blocked_at_pos.y + ", " + blocked_at_pos.z + ". Teleporting to next point");
+		_log.warning(getClass().getSimpleName() + ": " + getActor().getNpcId() + ": Blocked at rote position [" + _currentPos + "], coords: " + blocked_at_pos.x + ", " + blocked_at_pos.y + ", " + blocked_at_pos.z + ". Teleporting to next point");
 		
 		int destinationX = _route.get(_currentPos).getMoveX();
 		int destinationY = _route.get(_currentPos).getMoveY();
@@ -133,7 +133,7 @@ public class L2NpcWalkerAI extends L2CharacterAI implements Runnable
 			{
 				delay = DEFAULT_MOVE_DELAY;
 				if (Config.DEVELOPER)
-					_log.warning("Wrong Delay Set in Npc Walker Functions = " + delay + " secs, using default delay: " + DEFAULT_MOVE_DELAY + " secs instead.");
+					_log.warning(getClass().getSimpleName() + ": Wrong Delay Set in Npc Walker Functions = " + delay + " secs, using default delay: " + DEFAULT_MOVE_DELAY + " secs instead.");
 			}
 			
 			_nextMoveTime = System.currentTimeMillis() + delay;

+ 1 - 1
L2J_Server_BETA/java/com/l2jserver/gameserver/ai/L2PlayerAI.java

@@ -252,7 +252,7 @@ public class L2PlayerAI extends L2PlayableAI
 	{
 		L2Character target = getCastTarget();
 		if (Config.DEBUG)
-			_log.warning("L2PlayerAI: thinkCast -> Start");
+			_log.warning(getClass().getSimpleName() + ": thinkCast -> Start");
 		
 		if (_skill.getTargetType() == L2TargetType.TARGET_GROUND && _actor instanceof L2PcInstance)
 		{

+ 2 - 5
L2J_Server_BETA/java/com/l2jserver/gameserver/ai/L2SiegeGuardAI.java

@@ -45,8 +45,6 @@ import com.l2jserver.util.Rnd;
  */
 public class L2SiegeGuardAI extends L2CharacterAI implements Runnable
 {
-	//protected static final Logger _log = Logger.getLogger(L2SiegeGuardAI.class.getName());
-	
 	private static final int MAX_ATTACK_TIMEOUT = 300; // int ticks, i.e. 30 seconds
 	
 	/** The L2Attackable AI task executed every 1s (call onEvtThink method)*/
@@ -171,7 +169,7 @@ public class L2SiegeGuardAI extends L2CharacterAI implements Runnable
 	synchronized void changeIntention(CtrlIntention intention, Object arg0, Object arg1)
 	{
 		if (Config.DEBUG)
-			_log.info("L2SiegeAI.changeIntention(" + intention + ", " + arg0 + ", " + arg1 + ")");
+			_log.info(getClass().getSimpleName() + ": changeIntention(" + intention + ", " + arg0 + ", " + arg1 + ")");
 		
 		if (intention == AI_INTENTION_IDLE /*|| intention == AI_INTENTION_ACTIVE*/) // active becomes idle if only a summon is present
 		{
@@ -321,7 +319,7 @@ public class L2SiegeGuardAI extends L2CharacterAI implements Runnable
 	private void thinkAttack()
 	{
 		if (Config.DEBUG)
-			_log.info("L2SiegeGuardAI.thinkAttack(); timeout=" + (_attackTimeout - GameTimeController.getGameTicks()));
+			_log.info(getClass().getSimpleName() + ": thinkAttack(); timeout=" + (_attackTimeout - GameTimeController.getGameTicks()));
 		
 		if (_attackTimeout < GameTimeController.getGameTicks())
 		{
@@ -483,7 +481,6 @@ public class L2SiegeGuardAI extends L2CharacterAI implements Runnable
 		}
 		catch (NullPointerException e)
 		{
-			//_log.warning("AttackableAI: Attack target is NULL.");
 			_actor.setTarget(null);
 			setIntention(AI_INTENTION_IDLE, null, null);
 			return;