Index: D:/Proyectos/Eclipse Workspace/L2_GameServer/java/net/sf/l2j/gameserver/model/L2Character.java =================================================================== --- D:/Proyectos/Eclipse Workspace/L2_GameServer/java/net/sf/l2j/gameserver/model/L2Character.java (revision 1674) +++ D:/Proyectos/Eclipse Workspace/L2_GameServer/java/net/sf/l2j/gameserver/model/L2Character.java (working copy) @@ -4660,6 +4660,12 @@ // Disable all skills during the casting time and create a task EnableAllSkills with Medium priority to enable all skills at the end of the cating time disableAllSkills(); ClientScheduler.getInstance().scheduleMed(new EnableAllSkills(skill), skillTime); + + if (_skillCast != null) + { + _skillCast.cancel(true); + _skillCast = null; + } // Create a task MagicUseTask with Medium priority to launch the MagicSkill at the end of the casting time _skillCast = ClientScheduler.getInstance().scheduleMed(new MagicUseTask(targets, skill), skillTime); @@ -5615,7 +5621,7 @@ return false; } - public void setAttacked(boolean isAttacked) + public synchronized void setAttacked(boolean isAttacked) { if (Config.DEBUG && isAttacked != _isAttacked) { @@ -5640,7 +5646,7 @@ { if(GameTimeController.getGameTicks() - _lastAttackChange > 15 * GameTimeController.TICKS_PER_SECOND) { - _isAttacked = false; + synchronized(this){ _isAttacked = false; } if (Config.DEBUG) { _log.fine("Unlocked isAttacked state"); Index: D:/Proyectos/Eclipse Workspace/L2_GameServer/java/net/sf/l2j/gameserver/ai/L2AttackableAI.java =================================================================== --- D:/Proyectos/Eclipse Workspace/L2_GameServer/java/net/sf/l2j/gameserver/ai/L2AttackableAI.java (revision 1674) +++ D:/Proyectos/Eclipse Workspace/L2_GameServer/java/net/sf/l2j/gameserver/ai/L2AttackableAI.java (working copy) @@ -343,7 +343,7 @@ // Chose a target from its aggroList L2Character hated; if (_actor.isConfused()) - hated = _attack_target; // Force mobs to attak anybody if confused + hated = getAttackTarget(); // Force mobs to attak anybody if confused else hated = npc.getMostHated(); @@ -462,23 +462,23 @@ // Check if target is dead or if timeout is expired to stop this attack - if ( _attack_target == null || - _attack_target.isAlikeDead() || + if ( getAttackTarget() == null || + getAttackTarget().isAlikeDead() || _attack_timeout < GameTimeController.getGameTicks() ) { // Stop hating this target after the attack timeout or if target is dead - if (_attack_target != null) + if (getAttackTarget() != null) { L2Attackable npc = (L2Attackable)_actor; - int hate = npc.getHating(_attack_target); + int hate = npc.getHating(getAttackTarget()); if (hate > 0) - npc.addDamageHate(_attack_target, 0, -hate); + npc.addDamageHate(getAttackTarget(), 0, -hate); } // Cancel target and timeout _attack_timeout = Integer.MAX_VALUE; - _attack_target = null; + setAttackTarget(null); //clientStopAutoAttack(); // Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast) @@ -502,15 +502,15 @@ { L2NpcInstance npc = (L2NpcInstance)obj; - if (npc == null || _attack_target == null || faction_id != npc.getFactionId()) + if (npc == null || getAttackTarget() == null || faction_id != npc.getFactionId()) continue; // Check if the L2Object is inside the Faction Range of the actor if (_actor.getDistance(npc.getX(), npc.getY()) < npc.getFactionRange() - && Math.abs(_attack_target.getZ()-npc.getZ()) < 600 && npc.getAI() != null && _actor.isAttacked()) + && Math.abs(getAttackTarget().getZ()-npc.getZ()) < 600 && npc.getAI() != null && _actor.isAttacked()) { // Notify the L2Object AI with EVT_AGGRESSION - npc.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, _attack_target, 1); + npc.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, getAttackTarget(), 1); } } } @@ -524,9 +524,9 @@ try { - _actor.setTarget(_attack_target); + _actor.setTarget(getAttackTarget()); skills = _actor.getAllSkills(); - dist = _actor.getDistance(_attack_target.getX(), _attack_target.getY()); + dist = _actor.getDistance(getAttackTarget().getX(), getAttackTarget().getY()); range = _actor.getPhysicalAttackRange(); } catch (NullPointerException e) @@ -576,7 +576,7 @@ // Move the actor to Pawn server side AND client side by sending Server->Client packet MoveToPawn (broadcast) - moveToPawn(_attack_target, range); + moveToPawn(getAttackTarget(), range); return; @@ -584,7 +584,7 @@ // Else, if the actor is muted and far from target, just "move to pawn" else if (_actor.isMuted() && dist > range+20) { - moveToPawn(_attack_target, range); + moveToPawn(getAttackTarget(), range); return; } // Else, if this is close enough to attack @@ -593,7 +593,7 @@ // Force mobs to attak anybody if confused L2Character hated; if (_actor.isConfused()) - hated = _attack_target; + hated = getAttackTarget(); else hated =((L2Attackable)_actor).getMostHated(); @@ -602,8 +602,8 @@ setIntention(AI_INTENTION_ACTIVE); return; } - if (hated != _attack_target) - _attack_target = hated; + if (hated != getAttackTarget()) + setAttackTarget(hated); _attack_timeout = MAX_ATTACK_TIMEOUT + GameTimeController.getGameTicks(); @@ -645,7 +645,7 @@ } // Finally, do the physical attack itself - _accessor.doAttack(_attack_target); + _accessor.doAttack(getAttackTarget()); } } @@ -712,7 +712,7 @@ { setIntention(CtrlIntention.AI_INTENTION_ATTACK, attacker); } - else if(((L2Attackable)_actor).getMostHated() != _attack_target) + else if(((L2Attackable)_actor).getMostHated() != getAttackTarget()) { setIntention(CtrlIntention.AI_INTENTION_ATTACK, attacker); } Index: D:/Proyectos/Eclipse Workspace/L2_GameServer/java/net/sf/l2j/gameserver/ai/L2CharacterAI.java =================================================================== --- D:/Proyectos/Eclipse Workspace/L2_GameServer/java/net/sf/l2j/gameserver/ai/L2CharacterAI.java (revision 1674) +++ D:/Proyectos/Eclipse Workspace/L2_GameServer/java/net/sf/l2j/gameserver/ai/L2CharacterAI.java (working copy) @@ -76,21 +76,21 @@ protected void onIntentionIdle() { //If attaking or casting, notify the target - if (getIntention() == AI_INTENTION_ATTACK && _attack_target!= null) + if (getIntention() == AI_INTENTION_ATTACK && getAttackTarget()!= null) { - _attack_target.setAttacked(false); + getAttackTarget().setAttacked(false); } - if (getIntention() == AI_INTENTION_CAST && _cast_target != null) + if (getIntention() == AI_INTENTION_CAST && getCastTarget() != null) { - _cast_target.setAttacked(false); + getCastTarget().setAttacked(false); } // Set the AI Intention to AI_INTENTION_IDLE changeIntention(AI_INTENTION_IDLE, null, null); // Init cast and attack target - _cast_target = null; - _attack_target = null; + setCastTarget(null); + setAttackTarget(null); // Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast) clientStopAutoAttack(); @@ -121,21 +121,21 @@ if (getIntention() != AI_INTENTION_ACTIVE) { //If attaking or casting, notify the target - if (getIntention() == AI_INTENTION_ATTACK && _attack_target!= null) + if (getIntention() == AI_INTENTION_ATTACK && getAttackTarget()!= null) { - _attack_target.setAttacked(false); + getAttackTarget().setAttacked(false); } - if (getIntention() == AI_INTENTION_CAST && _cast_target != null) + if (getIntention() == AI_INTENTION_CAST && getCastTarget() != null) { - _cast_target.setAttacked(false); + getCastTarget().setAttacked(false); } // Set the AI Intention to AI_INTENTION_ACTIVE changeIntention(AI_INTENTION_ACTIVE, null, null); // Init cast and attack target - _cast_target = null; - _attack_target = null; + setCastTarget(null); + setAttackTarget(null); // Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast) clientStopAutoAttack(); @@ -158,13 +158,13 @@ protected void onIntentionRest() { //If attaking or casting, notify the target - if (getIntention() == AI_INTENTION_ATTACK && _attack_target!= null) + if (getIntention() == AI_INTENTION_ATTACK && getAttackTarget()!= null) { - _attack_target.setAttacked(false); + getAttackTarget().setAttacked(false); } - if (getIntention() == AI_INTENTION_CAST && _cast_target != null) + if (getIntention() == AI_INTENTION_CAST && getCastTarget() != null) { - _cast_target.setAttacked(false); + getCastTarget().setAttacked(false); } // Set the AI Intention to AI_INTENTION_IDLE setIntention(AI_INTENTION_IDLE); @@ -211,13 +211,13 @@ if (getIntention() == AI_INTENTION_ATTACK) { // Check if the AI already targets the L2Character - if (_attack_target != target) + if (getAttackTarget() != target) { // Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast) clientStopAutoAttack(); // Set the AI attack target (change target) - _attack_target = target; + setAttackTarget(target); // Notify the target target.setAttacked(true); @@ -241,7 +241,7 @@ changeIntention(AI_INTENTION_ATTACK, target, null); // Set the AI attack target - _attack_target = target; + setAttackTarget(target); //Notify the target if (target != null) @@ -300,7 +300,7 @@ } // Set the AI cast target - _cast_target = (L2Character)target; + setCastTarget((L2Character)target); // Stop actions client-side to cast the skill if (skill.getSkillTime() > 50) @@ -323,14 +323,14 @@ // Set the AI skill used by INTENTION_CAST _skill = skill; - if(skill.isOffensive() && _cast_target != null) + if(skill.isOffensive() && getCastTarget() != null) { - if (skill.getTargetType() == SkillTargetType.TARGET_AURA && _cast_target.getObjectId() == _actor.getObjectId()) + if (skill.getTargetType() == SkillTargetType.TARGET_AURA && getCastTarget().getObjectId() == _actor.getObjectId()) { } else - //Notify the target - _cast_target.setAttacked(true); + //Notify the target + getCastTarget().setAttacked(true); } /* @@ -372,13 +372,13 @@ } //If attaking or casting, notify the target - if (getIntention() == AI_INTENTION_ATTACK && _attack_target!= null) + if (getIntention() == AI_INTENTION_ATTACK && getAttackTarget()!= null) { - _attack_target.setAttacked(false); + getAttackTarget().setAttacked(false); } - if (getIntention() == AI_INTENTION_CAST && _cast_target != null) + if (getIntention() == AI_INTENTION_CAST && getCastTarget() != null) { - _cast_target.setAttacked(false); + getCastTarget().setAttacked(false); } // Set the Intention of this AbstractAI to AI_INTENTION_MOVE_TO @@ -422,13 +422,13 @@ } //If attaking or casting, notify the target - if (getIntention() == AI_INTENTION_ATTACK && _attack_target!= null) + if (getIntention() == AI_INTENTION_ATTACK && getAttackTarget()!= null) { - _attack_target.setAttacked(false); + getAttackTarget().setAttacked(false); } - if (getIntention() == AI_INTENTION_CAST && _cast_target != null) + if (getIntention() == AI_INTENTION_CAST && getCastTarget() != null) { - _cast_target.setAttacked(false); + getCastTarget().setAttacked(false); } // Set the Intention of this AbstractAI to AI_INTENTION_FOLLOW @@ -468,13 +468,13 @@ } //If attaking or casting, notify the target - if (getIntention() == AI_INTENTION_ATTACK && _attack_target!= null) + if (getIntention() == AI_INTENTION_ATTACK && getAttackTarget()!= null) { - _attack_target.setAttacked(false); + getAttackTarget().setAttacked(false); } - if (getIntention() == AI_INTENTION_CAST && _cast_target != null) + if (getIntention() == AI_INTENTION_CAST && getCastTarget() != null) { - _cast_target.setAttacked(false); + getCastTarget().setAttacked(false); } // Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast) @@ -484,7 +484,7 @@ changeIntention(AI_INTENTION_PICK_UP, object, null); // Set the AI pick up target - _target = object; + setTarget(object); // Move the actor to Pawn server side AND client side by sending Server->Client packet MoveToPawn (broadcast) moveToPawn(object, 20); @@ -524,20 +524,20 @@ clientStopAutoAttack(); //If attaking or casting, notify the target - if (getIntention() == AI_INTENTION_ATTACK && _attack_target!= null) + if (getIntention() == AI_INTENTION_ATTACK && getAttackTarget()!= null) { - _attack_target.setAttacked(false); + getAttackTarget().setAttacked(false); } - if (getIntention() == AI_INTENTION_CAST && _cast_target != null) + if (getIntention() == AI_INTENTION_CAST && getCastTarget() != null) { - _cast_target.setAttacked(false); + getCastTarget().setAttacked(false); } // Set the Intention of this AbstractAI to AI_INTENTION_INTERACT changeIntention(AI_INTENTION_INTERACT, object, null); // Set the AI interact target - _target = object; + setTarget(object); // Move the actor to Pawn server side AND client side by sending Server->Client packet MoveToPawn (broadcast) moveToPawn(object, 60); @@ -587,13 +587,13 @@ clientStopAutoAttack(); //If attaking or casting, notify the target - if (getIntention() == AI_INTENTION_ATTACK && _attack_target!= null) + if (getIntention() == AI_INTENTION_ATTACK && getAttackTarget()!= null) { - _attack_target.setAttacked(false); + getAttackTarget().setAttacked(false); } - if (getIntention() == AI_INTENTION_CAST && _cast_target != null) + if (getIntention() == AI_INTENTION_CAST && getCastTarget() != null) { - _cast_target.setAttacked(false); + getCastTarget().setAttacked(false); } // Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast) @@ -627,13 +627,13 @@ clientStopAutoAttack(); //If attaking or casting, notify the target - if (getIntention() == AI_INTENTION_ATTACK && _attack_target!= null) + if (getIntention() == AI_INTENTION_ATTACK && getAttackTarget()!= null) { - _attack_target.setAttacked(false); + getAttackTarget().setAttacked(false); } - if (getIntention() == AI_INTENTION_CAST && _cast_target != null) + if (getIntention() == AI_INTENTION_CAST && getCastTarget() != null) { - _cast_target.setAttacked(false); + getCastTarget().setAttacked(false); } // Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast) @@ -807,9 +807,9 @@ protected void onEvtForgetObject(L2Object object) { // If the object was targeted and the Intention was AI_INTENTION_INTERACT or AI_INTENTION_PICK_UP, set the Intention to AI_INTENTION_ACTIVE - if (_target == object) + if (getTarget() == object) { - _target = null; + setTarget(null); if (getIntention() == AI_INTENTION_INTERACT) setIntention(AI_INTENTION_ACTIVE); @@ -818,36 +818,36 @@ } // Check if the object was targeted to attack - if (_attack_target == object) + if (getAttackTarget() == object) { // Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast) clientStopAutoAttack(); //Notify the attack target - _attack_target.setAttacked(false); + getAttackTarget().setAttacked(false); // Cancel attack target - _attack_target = null; + setAttackTarget(null); // Set the Intention of this AbstractAI to AI_INTENTION_ACTIVE setIntention(AI_INTENTION_ACTIVE); } // Check if the object was targeted to cast - if (_cast_target == object) + if (getCastTarget() == object) { //Notify the cast target - _cast_target.setAttacked(false); + getCastTarget().setAttacked(false); // Cancel cast target - _cast_target = null; + setCastTarget(null); // Set the Intention of this AbstractAI to AI_INTENTION_ACTIVE setIntention(AI_INTENTION_ACTIVE); } // Check if the object was targeted to follow - if (_follow_target == object) + if (getFollowTarget() == object) { // Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast) clientStopMoving(null); @@ -863,9 +863,9 @@ if (_actor == object) { // Cancel AI target - _target = null; - _attack_target = null; - _cast_target = null; + setTarget(null); + setAttackTarget(null); + setCastTarget(null); // Stop an AI Follow Task stopFollow(); @@ -913,13 +913,13 @@ _actor.setAttacked(false); - if (getIntention() == AI_INTENTION_ATTACK && _attack_target!= null) + if (getIntention() == AI_INTENTION_ATTACK && getAttackTarget()!= null) { - _attack_target.setAttacked(false); + getAttackTarget().setAttacked(false); } - if (getIntention() == AI_INTENTION_CAST && _cast_target != null) + if (getIntention() == AI_INTENTION_CAST && getCastTarget() != null) { - _cast_target.setAttacked(false); + getCastTarget().setAttacked(false); } // Kill the actor client side by sending Server->Client packet AutoAttackStop, StopMove/StopRotation, Die (broadcast) @@ -941,13 +941,13 @@ _actor.setAttacked(false); - if (getIntention() == AI_INTENTION_ATTACK && _attack_target!= null) + if (getIntention() == AI_INTENTION_ATTACK && getAttackTarget()!= null) { - _attack_target.setAttacked(false); + getAttackTarget().setAttacked(false); } - if (getIntention() == AI_INTENTION_CAST && _cast_target != null) + if (getIntention() == AI_INTENTION_CAST && getCastTarget() != null) { - _cast_target.setAttacked(false); + getCastTarget().setAttacked(false); } // Stop the actor auto-attack and send Server->Client packet AutoAttackStop (broadcast) @@ -958,9 +958,9 @@ // Init AI _intention = AI_INTENTION_IDLE; - _target = null; - _cast_target = null; - _attack_target = null; + setTarget(null); + setCastTarget(null); + setAttackTarget(null); } /** @@ -1007,7 +1007,7 @@ _log.warning("L2CharacterAI: maybeMoveToPawn -> moving to catch target. Casting stopped"); */ - if (_follow_target != null) + if (getFollowTarget() != null) return true; // If not running, set the L2Character movement type to run and send Server->Client packet ChangeMoveType to all others L2PcInstance @@ -1034,7 +1034,7 @@ return true; } - if (_follow_target != null) + if (getFollowTarget() != null) stopFollow(); // Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast) @@ -1069,13 +1069,13 @@ clientStopAutoAttack(); // If attaking or casting, notify the target - if (getIntention() == AI_INTENTION_ATTACK && _attack_target!= null) + if (getIntention() == AI_INTENTION_ATTACK && getAttackTarget()!= null) { - _attack_target.setAttacked(false); + getAttackTarget().setAttacked(false); } - if (getIntention() == AI_INTENTION_CAST && _cast_target != null) + if (getIntention() == AI_INTENTION_CAST && getCastTarget() != null) { - _cast_target.setAttacked(false); + getCastTarget().setAttacked(false); } // Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast) @@ -1120,13 +1120,13 @@ clientStopAutoAttack(); //If attaking or casting, notify the target - if (getIntention() == AI_INTENTION_ATTACK && _attack_target!= null) + if (getIntention() == AI_INTENTION_ATTACK && getAttackTarget()!= null) { - _attack_target.setAttacked(false); + getAttackTarget().setAttacked(false); } - if (getIntention() == AI_INTENTION_CAST && _cast_target != null) + if (getIntention() == AI_INTENTION_CAST && getCastTarget() != null) { - _cast_target.setAttacked(false); + getCastTarget().setAttacked(false); } // Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast) Index: D:/Proyectos/Eclipse Workspace/L2_GameServer/java/net/sf/l2j/gameserver/ai/L2PlayerAI.java =================================================================== --- D:/Proyectos/Eclipse Workspace/L2_GameServer/java/net/sf/l2j/gameserver/ai/L2PlayerAI.java (revision 1674) +++ D:/Proyectos/Eclipse Workspace/L2_GameServer/java/net/sf/l2j/gameserver/ai/L2PlayerAI.java (working copy) @@ -137,11 +137,11 @@ if (getIntention() != AI_INTENTION_REST) { changeIntention(AI_INTENTION_REST, null, null); - _target = null; - if(_attack_target != null) + setTarget(null); + if(getAttackTarget() != null) { - _attack_target.setAttacked(false); - _attack_target = null; + getAttackTarget().setAttacked(false); + setAttackTarget(null); } clientStopAutoAttack(); clientStopMoving(null); @@ -155,26 +155,26 @@ } private void thinkAttack() { - if (checkTargetLostOrDead(_attack_target)) + if (checkTargetLostOrDead(getAttackTarget())) { - if(_attack_target != null) + if(getAttackTarget() != null) { // Notify the target - _attack_target.setAttacked(false); - _attack_target = null; + getAttackTarget().setAttacked(false); + setAttackTarget(null); } return; } - if (maybeMoveToPawn(_attack_target, _actor.getPhysicalAttackRange())) + if (maybeMoveToPawn(getAttackTarget(), _actor.getPhysicalAttackRange())) return; //clientStopMoving(null); - if(_attack_target != null) + if(getAttackTarget() != null) { //Notify the target - _attack_target.setAttacked(true); + getAttackTarget().setAttacked(true); } clientStartAutoAttack(); - _accessor.doAttack(_attack_target); + _accessor.doAttack(getAttackTarget()); return; } @@ -185,13 +185,13 @@ _log.warning("L2PlayerAI: thinkCast -> Start"); */ - if (checkTargetLost(_cast_target)) + if (checkTargetLost(getAttackTarget())) { - if(_skill.isOffensive() && _cast_target != null) + if(_skill.isOffensive() && getAttackTarget() != null) { //Notify the target - _cast_target.setAttacked(false); - _cast_target = null; + getAttackTarget().setAttacked(false); + setAttackTarget(null); } return; } @@ -201,7 +201,7 @@ _log.warning("L2PlayerAI: thinkCast -> valid target: " + _cast_target); */ - if (maybeMoveToPawn(_cast_target, _actor.getMagicalAttackRange(_skill))) + if (maybeMoveToPawn(getCastTarget(), _actor.getMagicalAttackRange(_skill))) return; /* @@ -212,10 +212,10 @@ // - Saves current _cast_target; // - Stops the moving client/server side; // - Retrieves old _cast_target; - L2Character castTarget = _cast_target; + L2Character castTarget = getCastTarget(); if (_skill.getSkillTime() > 50) clientStopMoving(null); - _cast_target = castTarget; + setCastTarget(castTarget); /* if (Config.DEBUG) @@ -225,13 +225,13 @@ L2Object oldTarget = _actor.getTarget(); if (oldTarget != null) { - if (_cast_target != null) - _actor.setTarget(_cast_target); + if (getCastTarget() != null) + _actor.setTarget(getCastTarget()); - if(_skill.isOffensive() && _cast_target != null) + if(_skill.isOffensive() && getCastTarget() != null) { //Notify the target - _cast_target.setAttacked(true); + getCastTarget().setAttacked(true); } _accessor.doCast(_skill); _actor.setTarget(oldTarget); @@ -245,23 +245,23 @@ private void thinkPickUp() { if (_actor.isAllSkillsDisabled()) return; - if (checkTargetLost(_target)) + if (checkTargetLost(getTarget())) return; - if (maybeMoveToPawn(_target, 36)) + if (maybeMoveToPawn(getTarget(), 36)) return; setIntention(AI_INTENTION_IDLE); - ((L2PcInstance.AIAccessor)_accessor).doPickupItem(_target); + ((L2PcInstance.AIAccessor)_accessor).doPickupItem(getTarget()); return; } private void thinkInteract() { if (_actor.isAllSkillsDisabled()) return; - if (checkTargetLost(_target)) + if (checkTargetLost(getTarget())) return; - if (maybeMoveToPawn(_target, 36)) + if (maybeMoveToPawn(getTarget(), 36)) return; - ((L2PcInstance.AIAccessor)_accessor).doInteract((L2Character)_target); + ((L2PcInstance.AIAccessor)_accessor).doInteract((L2Character)getTarget()); setIntention(AI_INTENTION_IDLE); return; } Index: D:/Proyectos/Eclipse Workspace/L2_GameServer/java/net/sf/l2j/gameserver/ai/L2ControllableMobAI.java =================================================================== --- D:/Proyectos/Eclipse Workspace/L2_GameServer/java/net/sf/l2j/gameserver/ai/L2ControllableMobAI.java (revision 1674) +++ D:/Proyectos/Eclipse Workspace/L2_GameServer/java/net/sf/l2j/gameserver/ai/L2ControllableMobAI.java (working copy) @@ -99,15 +99,15 @@ protected void thinkCast() { L2Attackable npc = (L2Attackable) _actor; - if (_attack_target==null || _attack_target.isAlikeDead()) { - _attack_target = findNextRndTarget(); + if (getAttackTarget() ==null || getAttackTarget().isAlikeDead()) { + setAttackTarget(findNextRndTarget()); clientStopMoving(null); } - if (_attack_target==null) { + if (getAttackTarget()==null) { return; } - npc.setTarget(_attack_target); + npc.setTarget(getAttackTarget()); L2Skill[] skills = null; @@ -115,7 +115,7 @@ try { skills = _actor.getAllSkills(); - dist = _actor.getDistance(_attack_target.getX(), _attack_target.getY()); + dist = _actor.getDistance(getAttackTarget().getX(), getAttackTarget().getY()); } catch (NullPointerException e) { _log.warning("Encountered Null Value."); e.printStackTrace(); @@ -134,7 +134,7 @@ max_range = Math.max(max_range, sk.getCastRange()); } if (!no_move) - moveToPawn(_attack_target, max_range); + moveToPawn(getAttackTarget(), max_range); return; } @@ -236,15 +236,15 @@ protected void thinkAttack() { - if (_attack_target == null || _attack_target.isAlikeDead()) { - if (_attack_target != null) { + if (getAttackTarget() == null || getAttackTarget().isAlikeDead()) { + if (getAttackTarget() != null) { // stop hating L2Attackable npc = (L2Attackable) _actor; - int hate = npc.getHating(_attack_target); + int hate = npc.getHating(getAttackTarget()); if (hate > 0) - npc.addDamageHate(_attack_target, 0, -hate); + npc.addDamageHate(getAttackTarget(), 0, -hate); } - _attack_target = null; + setAttackTarget(null); // clientStopAutoAttack(); clientStopMoving(null); setIntention(AI_INTENTION_ACTIVE); @@ -259,9 +259,9 @@ continue; if (_actor.getDistance(npc.getX(), npc.getY()) < npc .getFactionRange() - && Math.abs(_attack_target.getZ() - npc.getZ()) < 200) { + && Math.abs(getAttackTarget().getZ() - npc.getZ()) < 200) { npc.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, - _attack_target, 1); + getAttackTarget(), 1); } } } @@ -273,9 +273,9 @@ int max_range = 0; try { - _actor.setTarget(_attack_target); + _actor.setTarget(getAttackTarget()); skills = _actor.getAllSkills(); - dist = _actor.getDistance(_attack_target.getX(), _attack_target + dist = _actor.getDistance(getAttackTarget().getX(), getAttackTarget() .getY()); range = _actor.getPhysicalAttackRange(); max_range = range; @@ -295,13 +295,13 @@ } max_range = Math.max(max_range, sk.getCastRange()); } - moveToPawn(_attack_target, range); + moveToPawn(getAttackTarget(), range); return; } // Force mobs to attak anybody if confused L2Character hated; if (_actor.isConfused()) - hated = _attack_target; + hated = getAttackTarget(); else hated = findNextRndTarget(); @@ -310,8 +310,8 @@ return; } - if (hated != _attack_target) - _attack_target = hated; + if (hated != getAttackTarget()) + setAttackTarget(hated); if (!_actor.isMuted() && skills.length > 0 && _rnd.nextInt(5) == 3) { for (L2Skill sk : skills) { if (sk.getCastRange() >= dist @@ -322,20 +322,20 @@ } } } - _accessor.doAttack(_attack_target); + _accessor.doAttack(getAttackTarget()); } } private void thinkActive() { - _attack_target = findNextRndTarget(); + setAttackTarget(findNextRndTarget()); // Force mobs to attak anybody if confused L2Character hated; if (_actor.isConfused()) - hated = _attack_target; + hated = getAttackTarget(); else - hated = _attack_target; + hated = getAttackTarget(); if (hated != null) { _actor.setRunning(); setIntention(CtrlIntention.AI_INTENTION_ATTACK, hated); Index: D:/Proyectos/Eclipse Workspace/L2_GameServer/java/net/sf/l2j/gameserver/ai/L2SummonAI.java =================================================================== --- D:/Proyectos/Eclipse Workspace/L2_GameServer/java/net/sf/l2j/gameserver/ai/L2SummonAI.java (revision 1674) +++ D:/Proyectos/Eclipse Workspace/L2_GameServer/java/net/sf/l2j/gameserver/ai/L2SummonAI.java (working copy) @@ -50,29 +50,29 @@ } private void thinkAttack() { - if (checkTargetLostOrDead(_attack_target)) + if (checkTargetLostOrDead(getAttackTarget())) { - _attack_target = null; + setAttackTarget(null); return; } stopFollow(); - if (maybeMoveToPawn(_attack_target, _actor.getPhysicalAttackRange())) + if (maybeMoveToPawn(getAttackTarget(), _actor.getPhysicalAttackRange())) return; clientStopMoving(null); clientStartAutoAttack(); - _accessor.doAttack(_attack_target); + _accessor.doAttack(getAttackTarget()); return; } private void thinkCast() { L2Summon summon = (L2Summon)_actor; - if (checkTargetLost(_cast_target)) + if (checkTargetLost(getCastTarget())) { - _cast_target = null; + setCastTarget(null); return; } stopFollow(); - if (maybeMoveToPawn(_cast_target, _actor.getMagicalAttackRange(_skill))) + if (maybeMoveToPawn(getCastTarget(), _actor.getMagicalAttackRange(_skill))) return; clientStopMoving(null); summon.setFollowStatus(false); @@ -84,21 +84,21 @@ private void thinkPickUp() { if (_actor.isAllSkillsDisabled()) return; - if (checkTargetLost(_target)) + if (checkTargetLost(getTarget())) return; - if (maybeMoveToPawn(_target, 36)) + if (maybeMoveToPawn(getTarget(), 36)) return; setIntention(AI_INTENTION_IDLE); - ((L2Summon.AIAccessor)_accessor).doPickupItem(_target); + ((L2Summon.AIAccessor)_accessor).doPickupItem(getTarget()); return; } private void thinkInteract() { if (_actor.isAllSkillsDisabled()) return; - if (checkTargetLost(_target)) + if (checkTargetLost(getTarget())) return; - if (maybeMoveToPawn(_target, 36)) + if (maybeMoveToPawn(getTarget(), 36)) return; setIntention(AI_INTENTION_IDLE); return; Index: D:/Proyectos/Eclipse Workspace/L2_GameServer/java/net/sf/l2j/gameserver/ai/L2SiegeGuardAI.java =================================================================== --- D:/Proyectos/Eclipse Workspace/L2_GameServer/java/net/sf/l2j/gameserver/ai/L2SiegeGuardAI.java (revision 1674) +++ D:/Proyectos/Eclipse Workspace/L2_GameServer/java/net/sf/l2j/gameserver/ai/L2SiegeGuardAI.java (working copy) @@ -291,7 +291,7 @@ // Chose a target from its aggroList L2Character hated; if (_actor.isConfused()) - hated = _attack_target; // Force mobs to attak anybody if confused + hated = getAttackTarget(); // Force mobs to attak anybody if confused else hated = npc.getMostHated(); @@ -352,23 +352,23 @@ // Check if target is dead or if timeout is expired to stop this attack - if ( _attack_target == null || - _attack_target.isAlikeDead() || + if ( getAttackTarget() == null || + getAttackTarget().isAlikeDead() || _attack_timeout < GameTimeController.getGameTicks() ) { // Stop hating this target after the attack timeout or if target is dead - if (_attack_target != null) + if (getAttackTarget() != null) { L2Attackable npc = (L2Attackable)_actor; - int hate = npc.getHating(_attack_target); + int hate = npc.getHating(getAttackTarget()); if (hate > 0) - npc.addDamageHate(_attack_target, 0, -hate); + npc.addDamageHate(getAttackTarget(), 0, -hate); } // Cancel target and timeout _attack_timeout = Integer.MAX_VALUE; - _attack_target = null; + setAttackTarget(null); //clientStopAutoAttack(); // Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation (broadcast) @@ -397,10 +397,10 @@ // Check if the L2Object is inside the Faction Range of the actor if (_actor.getDistance(npc.getX(), npc.getY()) < npc.getFactionRange() - && Math.abs(_attack_target.getZ()-npc.getZ()) < 600 && npc.getAI() != null) + && Math.abs(getAttackTarget().getZ()-npc.getZ()) < 600 && npc.getAI() != null) { // Notify the L2Object AI with EVT_AGGRESSION - npc.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, _attack_target, 1); + npc.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, getAttackTarget(), 1); } } } @@ -414,9 +414,9 @@ try { - _actor.setTarget(_attack_target); + _actor.setTarget(getAttackTarget()); skills = _actor.getAllSkills(); - dist = _actor.getDistance(_attack_target.getX(), _attack_target.getY()); + dist = _actor.getDistance(getAttackTarget().getX(), getAttackTarget().getY()); range = _actor.getPhysicalAttackRange(); } catch (NullPointerException e) @@ -465,33 +465,33 @@ } // Check if the L2SiegeGuardInstance is attacking, knows the target and can't run - if (!(_actor.isAttackingNow()) &&(_actor.getRunSpeed() == 0)&&(_actor.knowsObject(_attack_target))) + if (!(_actor.isAttackingNow()) &&(_actor.getRunSpeed() == 0)&&(_actor.knowsObject(getAttackTarget()))) { // Cancel the target - _actor.removeKnownObject(_attack_target); + _actor.removeKnownObject(getAttackTarget()); _actor.setTarget(null); } else { L2SiegeGuardInstance sGuard = (L2SiegeGuardInstance)_actor; - double dx = _actor.getX() - _attack_target.getX(); - double dy = _actor.getY() - _attack_target.getY(); - double homeX = _attack_target.getX() - sGuard.getHomeX(); - double homeY = _attack_target.getY() - sGuard.getHomeY(); + double dx = _actor.getX() - getAttackTarget().getX(); + double dy = _actor.getY() - getAttackTarget().getY(); + double homeX = getAttackTarget().getX() - sGuard.getHomeX(); + double homeY = getAttackTarget().getY() - sGuard.getHomeY(); // Check if the L2SiegeGuardInstance isn't too far from it's home location if (( dx*dx+dy*dy > 100*100 )&& - (homeX*homeX+homeY*homeY > 1200*1200)&&(_actor.knowsObject(_attack_target))) + (homeX*homeX+homeY*homeY > 1200*1200)&&(_actor.knowsObject(getAttackTarget()))) { // Cancel the target - _actor.removeKnownObject(_attack_target); + _actor.removeKnownObject(getAttackTarget()); _actor.setTarget(null); setIntention(AI_INTENTION_IDLE); } else { // Move the actor to Pawn server side AND client side by sending Server->Client packet MoveToPawn (broadcast) - moveToPawn(_attack_target, range); + moveToPawn(getAttackTarget(), range); } } @@ -501,7 +501,7 @@ // Else, if the actor is muted and far from target, just "move to pawn" else if (_actor.isMuted() && dist > range+20) { - moveToPawn(_attack_target, range); + moveToPawn(getAttackTarget(), range); return; } // Else, if this is close enough to attack @@ -510,7 +510,7 @@ // Force mobs to attak anybody if confused L2Character hated; if (_actor.isConfused()) - hated = _attack_target; + hated = getAttackTarget(); else hated =((L2Attackable)_actor).getMostHated(); @@ -519,8 +519,8 @@ setIntention(AI_INTENTION_ACTIVE); return; } - if (hated != _attack_target) - _attack_target = hated; + if (hated != getAttackTarget()) + setAttackTarget(hated); _attack_timeout = MAX_ATTACK_TIMEOUT + GameTimeController.getGameTicks(); @@ -562,7 +562,7 @@ } // Finally, do the physical attack itself - _accessor.doAttack(_attack_target); + _accessor.doAttack(getAttackTarget()); } } Index: D:/Proyectos/Eclipse Workspace/L2_GameServer/java/net/sf/l2j/gameserver/ai/L2DoorAI.java =================================================================== --- D:/Proyectos/Eclipse Workspace/L2_GameServer/java/net/sf/l2j/gameserver/ai/L2DoorAI.java (revision 1674) +++ D:/Proyectos/Eclipse Workspace/L2_GameServer/java/net/sf/l2j/gameserver/ai/L2DoorAI.java (working copy) @@ -66,9 +66,9 @@ if (!(npc instanceof L2SiegeGuardInstance) ) continue; if (_actor.getDistance(npc.getX(), npc.getY()) < npc.getFactionRange() - && Math.abs(_attack_target.getZ()-npc.getZ()) < 200) + && Math.abs(getAttackTarget().getZ()-npc.getZ()) < 200) { - npc.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, _attack_target, 1); + npc.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, getAttackTarget(), 1); } } } Index: D:/Proyectos/Eclipse Workspace/L2_GameServer/java/net/sf/l2j/gameserver/ai/AbstractAI.java =================================================================== --- D:/Proyectos/Eclipse Workspace/L2_GameServer/java/net/sf/l2j/gameserver/ai/AbstractAI.java (revision 1674) +++ D:/Proyectos/Eclipse Workspace/L2_GameServer/java/net/sf/l2j/gameserver/ai/AbstractAI.java (working copy) @@ -102,10 +102,10 @@ private int _client_moving_to_pawn_offset; /** Different targets this AI maintains */ - L2Object _target; - L2Character _cast_target; - L2Character _attack_target; - L2Character _follow_target; + private L2Object _target; + private L2Character _cast_target; + private L2Character _attack_target; + private L2Character _follow_target; /** The skill we are curently casting by INTENTION_CAST */ L2Skill _skill; @@ -148,6 +148,12 @@ return _intention; } + + protected synchronized void setCastTarget(L2Character target) + { + _cast_target = target; + } + /** * Return the current cast target.

*/ @@ -156,6 +162,11 @@ return _cast_target; } + protected synchronized void setAttackTarget(L2Character target) + { + _attack_target = target; + } + /** * Return current attack target.

*/ @@ -178,7 +189,7 @@ * @param arg1 The second parameter of the Intention * */ - void changeIntention(CtrlIntention intention, Object arg0, Object arg1) + synchronized void changeIntention(CtrlIntention intention, Object arg0, Object arg1) { /* if (Config.DEBUG) @@ -593,15 +604,18 @@ */ protected void clientStartAutoAttack() { - // Check if the actor is not already in auto attack mode - if (!_client_auto_attacking) - { - _client_auto_attacking = true; - - // Send a Server->Client packet AutoAttackStart to the actor and all L2PcInstance in its _knownPlayers - AutoAttackStart msg = new AutoAttackStart(_actor.getObjectId()); - _actor.broadcastPacket(msg); - } + synchronized(this) + { + // Check if the actor is not already in auto attack mode + if (_client_auto_attacking) + return; + + _client_auto_attacking = true; + } + + // Send a Server->Client packet AutoAttackStart to the actor and all L2PcInstance in its _knownPlayers + AutoAttackStart msg = new AutoAttackStart(_actor.getObjectId()); + _actor.broadcastPacket(msg); } @@ -613,14 +627,18 @@ */ protected void clientStopAutoAttack() { - if (_client_auto_attacking) - { - _client_auto_attacking = false; + synchronized(this) + { + if (!_client_auto_attacking) + { + return; + } + _client_auto_attacking = false; + } - // Send a Server->Client packet AutoAttackStop to the actor and all L2PcInstance in its _knownPlayers - AutoAttackStop msg = new AutoAttackStop(_actor.getObjectId()); - _actor.broadcastPacket(msg); - } + // Send a Server->Client packet AutoAttackStop to the actor and all L2PcInstance in its _knownPlayers + AutoAttackStop msg = new AutoAttackStop(_actor.getObjectId()); + _actor.broadcastPacket(msg); } @@ -694,9 +712,14 @@ */ public synchronized void startFollow(L2Character target) { + if (_follow_task != null) + { + _follow_task.cancel(false); + _follow_task = null; + } + + // Create and Launch an AI Follow Task to execute every 1s _follow_target = target; - - // Create and Launch an AI Follow Task to execute every 1s _follow_task = ClientScheduler.getInstance().scheduleMedAtFixedRate(new FollowTask(), 5, FOLLOW_INTERVAL); } @@ -731,5 +754,20 @@ } _follow_target = null; } + + protected L2Character getFollowTarget() + { + return _follow_target; + } + + protected L2Object getTarget() + { + return _target; + } + + protected synchronized void setTarget(L2Object target) + { + _target = target; + } }