protected boolean maybeMoveToPosition(Point3D worldPosition, int offset) { if (worldPosition == null) { _log.warn("maybeMoveToPosition: worldPosition == NULL!"); return false; } if (offset < 0) return false; // skill radius -1 if (!_actor.isInsideRadius( worldPosition.getX(), worldPosition.getY(), offset + _actor.getTemplate().getCollisionRadius(), false)) { if (_actor.isMovementDisabled()) return true; if (getIntention() == CtrlIntention.AI_INTENTION_CAST) { if (getCurrentSkill().isShiftPressed()) { _actor.sendPacket(SystemMessageId.DIST_TOO_FAR_CASTING_STOPPED); _actor.sendPacket(ActionFailed.STATIC_PACKET); return true; } } if (!_actor.isRunning() && !(this instanceof L2PlayerAI) && !(this instanceof L2SummonAI)) _actor.setRunning(); stopFollow(); int x = _actor.getX(); int y = _actor.getY(); double dx = worldPosition.getX() - x; double dy = worldPosition.getY() - y; double dist = Math.sqrt(dx * dx + dy * dy); double sin = dy / dist; double cos = dx / dist; dist -= offset - 5; x += (int) (dist * cos); y += (int) (dist * sin); moveTo(x, y, worldPosition.getZ()); return true; } if (getFollowTarget() != null) stopFollow(); return false; }
/** * Manage the Cast Intention : Stop current Attack, Init the AI in order to cast and Launch Think * Event.<br> * <br> * <B><U> Actions</U> : </B><br> * <br> * <li>Set the AI cast target * <li>Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop * (broadcast) * <li>Cancel action client side by sending Server->Client packet ActionFailed to the L2Player * actor * <li>Set the AI skill used by INTENTION_CAST * <li>Set the Intention of this AI to AI_INTENTION_CAST * <li>Launch the Think Event <br> * <br> */ @Override protected void onIntentionCast(SkillUsageRequest request) { final L2Skill skill = request.getSkill(); if (getIntention() == AI_INTENTION_REST && skill.isMagic()) { clientActionFailed(); return; } // Stop actions client-side to cast the skill if (skill.getHitTime() > 50) { // Abort the attack of the L2Character and send Server->Client ActionFailed packet _actor.abortAttack(); // Cancel action client side by sending Server->Client packet ActionFailed to the L2Player // actor // no need for second ActionFailed packet, abortAttack() already sent it // clientActionFailed(); } final L2Object target = request.getSkill().getFirstOfTargetList(_actor); // Change the Intention of this AbstractAI to AI_INTENTION_CAST changeIntention(AI_INTENTION_CAST, request, target); final Point3D p = request.getSkillWorldPosition(); if (p != null) { // normally magicskilluse packet turns char client side but for these skills, it doesn't (even // with correct target) _actor.setHeading( Util.calculateHeadingFrom(_actor.getX(), _actor.getY(), p.getX(), p.getY())); _actor.broadcastPacket(new ValidateLocation(_actor)); } // Launch the Think Event notifyEvent(CtrlEvent.EVT_THINK, null); }