}
}
}
// Force mobs to attack anybody if confused
L2Character hated;
if (_actor.isConfused()) hated = getAttackTarget();
else hated = ((L2Attackable) _actor).getMostHated();
if (hated == null)
{
setIntention(AI_INTENTION_ACTIVE);
return;
}
if (hated != getAttackTarget())
{
setAttackTarget(hated);
}
// We should calculate new distance cuz mob can have changed the target
dist2 = _actor.getPlanDistanceSq(hated.getX(), hated.getY());
if (hated.isMoving()) range += 50;
// Check if the actor isn't far from target
if (dist2 > range*range)
{
// check for long ranged skills and heal/buff skills
if (!_actor.isMuted() &&
(!Config.ALT_GAME_MOB_ATTACK_AI || (_actor instanceof L2MonsterInstance && Rnd.nextInt(100) <= 5))
)
for (L2Skill sk : skills)
{
int castRange = sk.getCastRange();
if (((sk.getSkillType() == L2Skill.SkillType.BUFF || sk.getSkillType() == L2Skill.SkillType.HEAL) || (dist2 >= castRange * castRange / 9.0)
&& (dist2 <= castRange * castRange) && (castRange > 70))
&& !_actor.isSkillDisabled(sk.getId())
&& _actor.getCurrentMp() >= _actor.getStat().getMpConsume(sk)
&& !sk.isPassive()
&& Rnd.nextInt(100) <= 5)
{
L2Object OldTarget = _actor.getTarget();
if (sk.getSkillType() == L2Skill.SkillType.BUFF
|| sk.getSkillType() == L2Skill.SkillType.HEAL)
{
boolean useSkillSelf = true;
if (sk.getSkillType() == L2Skill.SkillType.HEAL
&& _actor.getCurrentHp() > (int) (_actor.getMaxHp() / 1.5))
{
useSkillSelf = false;
break;
}
if (sk.getSkillType() == L2Skill.SkillType.BUFF)
{
L2Effect[] effects = _actor.getAllEffects();
for (int i = 0; effects != null && i < effects.length; i++)
{
L2Effect effect = effects[i];
if (effect.getSkill() == sk)
{
useSkillSelf = false;
break;
}
}
}
if (useSkillSelf) _actor.setTarget(_actor);
}
clientStopMoving(null);
_accessor.doCast(sk);
_actor.setTarget(OldTarget);
return;
}
}
// Move the actor to Pawn server side AND client side by sending Server->Client packet MoveToPawn (broadcast)
if (hated.isMoving()) range -= 100; if (range < 5) range = 5;
moveToPawn(getAttackTarget(), range);
}
// Else, if this is close enough to attack
else
{