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;
}
}
// Check if the L2SiegeGuardInstance is attacking, knows the target and can't run
if (!(_actor.isAttackingNow()) && (_actor.getRunSpeed() == 0)
&& (_actor.getKnownList().knowsObject(_attackTarget)))
{
// Cancel the target
_actor.getKnownList().removeKnownObject(_attackTarget);
_actor.setTarget(null);
setIntention(AI_INTENTION_IDLE, null, null);
}
else
{
double dx = _actor.getX() - _attackTarget.getX();
double dy = _actor.getY() - _attackTarget.getY();
double dz = _actor.getZ() - _attackTarget.getZ();
double homeX = _attackTarget.getX() - sGuard.getHomeX();
double homeY = _attackTarget.getY() - sGuard.getHomeY();
// Check if the L2SiegeGuardInstance isn't too far from it's home location
if ((dx * dx + dy * dy > 10000) && (homeX * homeX + homeY * homeY > 3240000) // 1800 * 1800
&& (_actor.getKnownList().knowsObject(_attackTarget)))
{
// Cancel the target
_actor.getKnownList().removeKnownObject(_attackTarget);
_actor.setTarget(null);
setIntention(AI_INTENTION_IDLE, null, null);
}
else // Move the actor to Pawn server side AND client side by sending Server->Client packet MoveToPawn (broadcast)
{
// Temporary hack for preventing guards jumping off towers,
// before replacing this with effective geodata checks and AI modification
if(dz*dz < 170*170) // normally 130 if guard z coordinates correct
moveToPawn(_attackTarget, range);
}
}
return;
}
// Else, if the actor is muted and far from target, just "move to pawn"
else if (_actor.isMuted() && dist_2 > (range + 20) * (range + 20))
{
// Temporary hack for preventing guards jumping off towers,
// before replacing this with effective geodata checks and AI modification
double dz = _actor.getZ() - _attackTarget.getZ();
if(dz*dz < 170*170) // normally 130 if guard z coordinates correct
moveToPawn(_attackTarget, range);
return;
}
// Else, if this is close enough to attack
else if (dist_2 <= (range + 20) * (range + 20))
{
// Force mobs to attak anybody if confused
L2Character hated = null;
if (_actor.isConfused()) hated = _attackTarget;
else hated = ((L2Attackable) _actor).getMostHated();
if (hated == null)
{
setIntention(AI_INTENTION_ACTIVE, null, null);
return;
}
if (hated != _attackTarget) _attackTarget = hated;
_attackTimeout = MAX_ATTACK_TIMEOUT + GameTimeController.getGameTicks();
// check for close combat skills && heal/buff skills
if (!_actor.isMuted() && Rnd.nextInt(100) <= 5)
{
for (L2Skill sk : skills)
{
int castRange = sk.getCastRange();
if (castRange * castRange >= dist_2 && castRange <= 70 && !sk.isPassive()
&& _actor.getCurrentMp() >= _actor.getStat().getMpConsume(sk)
&& !_actor.isSkillDisabled(sk.getId()))
{
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;
}
}