This commit is contained in:
852
trunk/java/com/l2jserver/gameserver/ai/AbstractAI.java
Normal file
852
trunk/java/com/l2jserver/gameserver/ai/AbstractAI.java
Normal file
@ -0,0 +1,852 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2014 L2J Server
|
||||
*
|
||||
* This file is part of L2J Server.
|
||||
*
|
||||
* L2J Server is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* L2J Server is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.gameserver.ai;
|
||||
|
||||
import static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_ATTACK;
|
||||
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.Logger;
|
||||
|
||||
import com.l2jserver.gameserver.GameTimeController;
|
||||
import com.l2jserver.gameserver.ThreadPoolManager;
|
||||
import com.l2jserver.gameserver.model.L2Object;
|
||||
import com.l2jserver.gameserver.model.Location;
|
||||
import com.l2jserver.gameserver.model.actor.L2Character;
|
||||
import com.l2jserver.gameserver.model.actor.L2Summon;
|
||||
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jserver.gameserver.model.skills.Skill;
|
||||
import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
|
||||
import com.l2jserver.gameserver.network.serverpackets.AutoAttackStart;
|
||||
import com.l2jserver.gameserver.network.serverpackets.AutoAttackStop;
|
||||
import com.l2jserver.gameserver.network.serverpackets.Die;
|
||||
import com.l2jserver.gameserver.network.serverpackets.MoveToLocation;
|
||||
import com.l2jserver.gameserver.network.serverpackets.MoveToPawn;
|
||||
import com.l2jserver.gameserver.network.serverpackets.StopMove;
|
||||
import com.l2jserver.gameserver.network.serverpackets.StopRotation;
|
||||
import com.l2jserver.gameserver.taskmanager.AttackStanceTaskManager;
|
||||
|
||||
/**
|
||||
* Mother class of all objects AI in the world.<br>
|
||||
* AbastractAI :<br>
|
||||
* <li>L2CharacterAI</li>
|
||||
*/
|
||||
public abstract class AbstractAI implements Ctrl
|
||||
{
|
||||
protected final Logger _log = Logger.getLogger(getClass().getName());
|
||||
|
||||
private NextAction _nextAction;
|
||||
|
||||
/**
|
||||
* @return the _nextAction
|
||||
*/
|
||||
public NextAction getNextAction()
|
||||
{
|
||||
return _nextAction;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param nextAction the next action to set.
|
||||
*/
|
||||
public void setNextAction(NextAction nextAction)
|
||||
{
|
||||
_nextAction = nextAction;
|
||||
}
|
||||
|
||||
private class FollowTask implements Runnable
|
||||
{
|
||||
protected int _range = 70;
|
||||
|
||||
public FollowTask()
|
||||
{
|
||||
}
|
||||
|
||||
public FollowTask(int range)
|
||||
{
|
||||
_range = range;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_followTask == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
L2Character followTarget = _followTarget; // copy to prevent NPE
|
||||
if (followTarget == null)
|
||||
{
|
||||
if (_actor instanceof L2Summon)
|
||||
{
|
||||
((L2Summon) _actor).setFollowStatus(false);
|
||||
}
|
||||
setIntention(AI_INTENTION_IDLE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_actor.isInsideRadius(followTarget, _range, true, false))
|
||||
{
|
||||
if (!_actor.isInsideRadius(followTarget, 3000, true, false))
|
||||
{
|
||||
// if the target is too far (maybe also teleported)
|
||||
if (_actor instanceof L2Summon)
|
||||
{
|
||||
((L2Summon) _actor).setFollowStatus(false);
|
||||
}
|
||||
|
||||
setIntention(AI_INTENTION_IDLE);
|
||||
return;
|
||||
}
|
||||
|
||||
moveToPawn(followTarget, _range);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_log.warning(getClass().getSimpleName() + ": Error: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** The character that this AI manages */
|
||||
protected final L2Character _actor;
|
||||
|
||||
/** An accessor for private methods of the actor */
|
||||
protected final L2Character.AIAccessor _accessor;
|
||||
|
||||
/** Current long-term intention */
|
||||
protected CtrlIntention _intention = AI_INTENTION_IDLE;
|
||||
/** Current long-term intention parameter */
|
||||
protected Object _intentionArg0 = null;
|
||||
/** Current long-term intention parameter */
|
||||
protected Object _intentionArg1 = null;
|
||||
|
||||
/** Flags about client's state, in order to know which messages to send */
|
||||
protected volatile boolean _clientMoving;
|
||||
/** Flags about client's state, in order to know which messages to send */
|
||||
protected volatile boolean _clientAutoAttacking;
|
||||
/** Flags about client's state, in order to know which messages to send */
|
||||
protected int _clientMovingToPawnOffset;
|
||||
|
||||
/** Different targets this AI maintains */
|
||||
private L2Object _target;
|
||||
private L2Character _castTarget;
|
||||
protected L2Character _attackTarget;
|
||||
protected L2Character _followTarget;
|
||||
|
||||
/** The skill we are currently casting by INTENTION_CAST */
|
||||
Skill _skill;
|
||||
|
||||
/** Different internal state flags */
|
||||
private int _moveToPawnTimeout;
|
||||
|
||||
protected Future<?> _followTask = null;
|
||||
private static final int FOLLOW_INTERVAL = 1000;
|
||||
private static final int ATTACK_FOLLOW_INTERVAL = 500;
|
||||
|
||||
/**
|
||||
* Constructor of AbstractAI.
|
||||
* @param accessor The AI accessor of the L2Character
|
||||
*/
|
||||
protected AbstractAI(L2Character.AIAccessor accessor)
|
||||
{
|
||||
_accessor = accessor;
|
||||
|
||||
// Get the L2Character managed by this Accessor AI
|
||||
_actor = accessor.getActor();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the L2Character managed by this Accessor AI.
|
||||
*/
|
||||
@Override
|
||||
public L2Character getActor()
|
||||
{
|
||||
return _actor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the current Intention.
|
||||
*/
|
||||
@Override
|
||||
public CtrlIntention getIntention()
|
||||
{
|
||||
return _intention;
|
||||
}
|
||||
|
||||
protected void setCastTarget(L2Character target)
|
||||
{
|
||||
_castTarget = target;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the current cast target.
|
||||
*/
|
||||
public L2Character getCastTarget()
|
||||
{
|
||||
return _castTarget;
|
||||
}
|
||||
|
||||
protected void setAttackTarget(L2Character target)
|
||||
{
|
||||
_attackTarget = target;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return current attack target.
|
||||
*/
|
||||
@Override
|
||||
public L2Character getAttackTarget()
|
||||
{
|
||||
return _attackTarget;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Intention of this AbstractAI.<br>
|
||||
* <FONT COLOR=#FF0000><B> <U>Caution</U> : This method is USED by AI classes</B></FONT><B><U><br>
|
||||
* Overridden in </U> : </B><BR>
|
||||
* <B>L2AttackableAI</B> : Create an AI Task executed every 1s (if necessary)<BR>
|
||||
* <B>L2PlayerAI</B> : Stores the current AI intention parameters to later restore it if necessary.
|
||||
* @param intention The new Intention to set to the AI
|
||||
* @param arg0 The first parameter of the Intention
|
||||
* @param arg1 The second parameter of the Intention
|
||||
*/
|
||||
synchronized void changeIntention(CtrlIntention intention, Object arg0, Object arg1)
|
||||
{
|
||||
_intention = intention;
|
||||
_intentionArg0 = arg0;
|
||||
_intentionArg1 = arg1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Launch the L2CharacterAI onIntention method corresponding to the new Intention.<br>
|
||||
* <FONT COLOR=#FF0000><B> <U>Caution</U> : Stop the FOLLOW mode if necessary</B></FONT>
|
||||
* @param intention The new Intention to set to the AI
|
||||
*/
|
||||
@Override
|
||||
public final void setIntention(CtrlIntention intention)
|
||||
{
|
||||
setIntention(intention, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Launch the L2CharacterAI onIntention method corresponding to the new Intention.<br>
|
||||
* <FONT COLOR=#FF0000><B> <U>Caution</U> : Stop the FOLLOW mode if necessary</B></FONT>
|
||||
* @param intention The new Intention to set to the AI
|
||||
* @param arg0 The first parameter of the Intention (optional target)
|
||||
*/
|
||||
@Override
|
||||
public final void setIntention(CtrlIntention intention, Object arg0)
|
||||
{
|
||||
setIntention(intention, arg0, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void setIntention(CtrlIntention intention, Object arg0, Object arg1)
|
||||
{
|
||||
// Stop the follow mode if necessary
|
||||
if ((intention != AI_INTENTION_FOLLOW) && (intention != AI_INTENTION_ATTACK))
|
||||
{
|
||||
stopFollow();
|
||||
}
|
||||
|
||||
// Launch the onIntention method of the L2CharacterAI corresponding to the new Intention
|
||||
switch (intention)
|
||||
{
|
||||
case AI_INTENTION_IDLE:
|
||||
onIntentionIdle();
|
||||
break;
|
||||
case AI_INTENTION_ACTIVE:
|
||||
onIntentionActive();
|
||||
break;
|
||||
case AI_INTENTION_REST:
|
||||
onIntentionRest();
|
||||
break;
|
||||
case AI_INTENTION_ATTACK:
|
||||
onIntentionAttack((L2Character) arg0);
|
||||
break;
|
||||
case AI_INTENTION_CAST:
|
||||
onIntentionCast((Skill) arg0, (L2Object) arg1);
|
||||
break;
|
||||
case AI_INTENTION_MOVE_TO:
|
||||
onIntentionMoveTo((Location) arg0);
|
||||
break;
|
||||
case AI_INTENTION_FOLLOW:
|
||||
onIntentionFollow((L2Character) arg0);
|
||||
break;
|
||||
case AI_INTENTION_PICK_UP:
|
||||
onIntentionPickUp((L2Object) arg0);
|
||||
break;
|
||||
case AI_INTENTION_INTERACT:
|
||||
onIntentionInteract((L2Object) arg0);
|
||||
break;
|
||||
}
|
||||
|
||||
// If do move or follow intention drop next action.
|
||||
if ((_nextAction != null) && _nextAction.getIntentions().contains(intention))
|
||||
{
|
||||
_nextAction = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Launch the L2CharacterAI onEvt method corresponding to the Event.<br>
|
||||
* <FONT COLOR=#FF0000><B> <U>Caution</U> : The current general intention won't be change (ex : If the character attack and is stunned, he will attack again after the stunned period)</B></FONT>
|
||||
* @param evt The event whose the AI must be notified
|
||||
*/
|
||||
@Override
|
||||
public final void notifyEvent(CtrlEvent evt)
|
||||
{
|
||||
notifyEvent(evt, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Launch the L2CharacterAI onEvt method corresponding to the Event. <FONT COLOR=#FF0000><B> <U>Caution</U> : The current general intention won't be change (ex : If the character attack and is stunned, he will attack again after the stunned period)</B></FONT>
|
||||
* @param evt The event whose the AI must be notified
|
||||
* @param arg0 The first parameter of the Event (optional target)
|
||||
*/
|
||||
@Override
|
||||
public final void notifyEvent(CtrlEvent evt, Object arg0)
|
||||
{
|
||||
notifyEvent(evt, arg0, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Launch the L2CharacterAI onEvt method corresponding to the Event. <FONT COLOR=#FF0000><B> <U>Caution</U> : The current general intention won't be change (ex : If the character attack and is stunned, he will attack again after the stunned period)</B></FONT>
|
||||
* @param evt The event whose the AI must be notified
|
||||
* @param arg0 The first parameter of the Event (optional target)
|
||||
* @param arg1 The second parameter of the Event (optional target)
|
||||
*/
|
||||
@Override
|
||||
public final void notifyEvent(CtrlEvent evt, Object arg0, Object arg1)
|
||||
{
|
||||
if ((!_actor.isVisible() && !_actor.isTeleporting()) || !_actor.hasAI())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (evt)
|
||||
{
|
||||
case EVT_THINK:
|
||||
onEvtThink();
|
||||
break;
|
||||
case EVT_ATTACKED:
|
||||
onEvtAttacked((L2Character) arg0);
|
||||
break;
|
||||
case EVT_AGGRESSION:
|
||||
onEvtAggression((L2Character) arg0, ((Number) arg1).intValue());
|
||||
break;
|
||||
case EVT_STUNNED:
|
||||
onEvtStunned((L2Character) arg0);
|
||||
break;
|
||||
case EVT_PARALYZED:
|
||||
onEvtParalyzed((L2Character) arg0);
|
||||
break;
|
||||
case EVT_SLEEPING:
|
||||
onEvtSleeping((L2Character) arg0);
|
||||
break;
|
||||
case EVT_ROOTED:
|
||||
onEvtRooted((L2Character) arg0);
|
||||
break;
|
||||
case EVT_CONFUSED:
|
||||
onEvtConfused((L2Character) arg0);
|
||||
break;
|
||||
case EVT_MUTED:
|
||||
onEvtMuted((L2Character) arg0);
|
||||
break;
|
||||
case EVT_EVADED:
|
||||
onEvtEvaded((L2Character) arg0);
|
||||
break;
|
||||
case EVT_READY_TO_ACT:
|
||||
if (!_actor.isCastingNow() && !_actor.isCastingSimultaneouslyNow())
|
||||
{
|
||||
onEvtReadyToAct();
|
||||
}
|
||||
break;
|
||||
case EVT_USER_CMD:
|
||||
onEvtUserCmd(arg0, arg1);
|
||||
break;
|
||||
case EVT_ARRIVED:
|
||||
// happens e.g. from stopmove but we don't process it if we're casting
|
||||
if (!_actor.isCastingNow() && !_actor.isCastingSimultaneouslyNow())
|
||||
{
|
||||
onEvtArrived();
|
||||
}
|
||||
break;
|
||||
case EVT_ARRIVED_REVALIDATE:
|
||||
// this is disregarded if the char is not moving any more
|
||||
if (_actor.isMoving())
|
||||
{
|
||||
onEvtArrivedRevalidate();
|
||||
}
|
||||
break;
|
||||
case EVT_ARRIVED_BLOCKED:
|
||||
onEvtArrivedBlocked((Location) arg0);
|
||||
break;
|
||||
case EVT_FORGET_OBJECT:
|
||||
onEvtForgetObject((L2Object) arg0);
|
||||
break;
|
||||
case EVT_CANCEL:
|
||||
onEvtCancel();
|
||||
break;
|
||||
case EVT_DEAD:
|
||||
onEvtDead();
|
||||
break;
|
||||
case EVT_FAKE_DEATH:
|
||||
onEvtFakeDeath();
|
||||
break;
|
||||
case EVT_FINISH_CASTING:
|
||||
onEvtFinishCasting();
|
||||
break;
|
||||
}
|
||||
|
||||
// Do next action.
|
||||
if ((_nextAction != null) && _nextAction.getEvents().contains(evt))
|
||||
{
|
||||
_nextAction.doAction();
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void onIntentionIdle();
|
||||
|
||||
protected abstract void onIntentionActive();
|
||||
|
||||
protected abstract void onIntentionRest();
|
||||
|
||||
protected abstract void onIntentionAttack(L2Character target);
|
||||
|
||||
protected abstract void onIntentionCast(Skill skill, L2Object target);
|
||||
|
||||
protected abstract void onIntentionMoveTo(Location destination);
|
||||
|
||||
protected abstract void onIntentionFollow(L2Character target);
|
||||
|
||||
protected abstract void onIntentionPickUp(L2Object item);
|
||||
|
||||
protected abstract void onIntentionInteract(L2Object object);
|
||||
|
||||
protected abstract void onEvtThink();
|
||||
|
||||
protected abstract void onEvtAttacked(L2Character attacker);
|
||||
|
||||
protected abstract void onEvtAggression(L2Character target, int aggro);
|
||||
|
||||
protected abstract void onEvtStunned(L2Character attacker);
|
||||
|
||||
protected abstract void onEvtParalyzed(L2Character attacker);
|
||||
|
||||
protected abstract void onEvtSleeping(L2Character attacker);
|
||||
|
||||
protected abstract void onEvtRooted(L2Character attacker);
|
||||
|
||||
protected abstract void onEvtConfused(L2Character attacker);
|
||||
|
||||
protected abstract void onEvtMuted(L2Character attacker);
|
||||
|
||||
protected abstract void onEvtEvaded(L2Character attacker);
|
||||
|
||||
protected abstract void onEvtReadyToAct();
|
||||
|
||||
protected abstract void onEvtUserCmd(Object arg0, Object arg1);
|
||||
|
||||
protected abstract void onEvtArrived();
|
||||
|
||||
protected abstract void onEvtArrivedRevalidate();
|
||||
|
||||
protected abstract void onEvtArrivedBlocked(Location blocked_at_pos);
|
||||
|
||||
protected abstract void onEvtForgetObject(L2Object object);
|
||||
|
||||
protected abstract void onEvtCancel();
|
||||
|
||||
protected abstract void onEvtDead();
|
||||
|
||||
protected abstract void onEvtFakeDeath();
|
||||
|
||||
protected abstract void onEvtFinishCasting();
|
||||
|
||||
/**
|
||||
* Cancel action client side by sending Server->Client packet ActionFailed to the L2PcInstance actor. <FONT COLOR=#FF0000><B> <U>Caution</U> : Low level function, used by AI subclasses</B></FONT>
|
||||
*/
|
||||
protected void clientActionFailed()
|
||||
{
|
||||
if (_actor instanceof L2PcInstance)
|
||||
{
|
||||
_actor.sendPacket(ActionFailed.STATIC_PACKET);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the actor to Pawn server side AND client side by sending Server->Client packet MoveToPawn <I>(broadcast)</I>.<br>
|
||||
* <FONT COLOR=#FF0000><B> <U>Caution</U> : Low level function, used by AI subclasses</B></FONT>
|
||||
* @param pawn
|
||||
* @param offset
|
||||
*/
|
||||
protected void moveToPawn(L2Object pawn, int offset)
|
||||
{
|
||||
// Check if actor can move
|
||||
if (!_actor.isMovementDisabled())
|
||||
{
|
||||
if (offset < 10)
|
||||
{
|
||||
offset = 10;
|
||||
}
|
||||
|
||||
// prevent possible extra calls to this function (there is none?),
|
||||
// also don't send movetopawn packets too often
|
||||
boolean sendPacket = true;
|
||||
if (_clientMoving && (_target == pawn))
|
||||
{
|
||||
if (_clientMovingToPawnOffset == offset)
|
||||
{
|
||||
if (GameTimeController.getInstance().getGameTicks() < _moveToPawnTimeout)
|
||||
{
|
||||
return;
|
||||
}
|
||||
sendPacket = false;
|
||||
}
|
||||
else if (_actor.isOnGeodataPath())
|
||||
{
|
||||
// minimum time to calculate new route is 2 seconds
|
||||
if (GameTimeController.getInstance().getGameTicks() < (_moveToPawnTimeout + 10))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set AI movement data
|
||||
_clientMoving = true;
|
||||
_clientMovingToPawnOffset = offset;
|
||||
_target = pawn;
|
||||
_moveToPawnTimeout = GameTimeController.getInstance().getGameTicks();
|
||||
_moveToPawnTimeout += 1000 / GameTimeController.MILLIS_IN_TICK;
|
||||
|
||||
if ((pawn == null) || (_accessor == null))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Calculate movement data for a move to location action and add the actor to movingObjects of GameTimeController
|
||||
_accessor.moveTo(pawn.getX(), pawn.getY(), pawn.getZ(), offset);
|
||||
|
||||
if (!_actor.isMoving())
|
||||
{
|
||||
clientActionFailed();
|
||||
return;
|
||||
}
|
||||
|
||||
// Send a Server->Client packet MoveToPawn/CharMoveToLocation to the actor and all L2PcInstance in its _knownPlayers
|
||||
if (pawn instanceof L2Character)
|
||||
{
|
||||
if (_actor.isOnGeodataPath())
|
||||
{
|
||||
_actor.broadcastPacket(new MoveToLocation(_actor));
|
||||
_clientMovingToPawnOffset = 0;
|
||||
}
|
||||
else if (sendPacket)
|
||||
{
|
||||
_actor.broadcastPacket(new MoveToPawn(_actor, (L2Character) pawn, offset));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_actor.broadcastPacket(new MoveToLocation(_actor));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
clientActionFailed();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the actor to Location (x,y,z) server side AND client side by sending Server->Client packet CharMoveToLocation <I>(broadcast)</I>.<br>
|
||||
* <FONT COLOR=#FF0000><B> <U>Caution</U> : Low level function, used by AI subclasses</B></FONT>
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
*/
|
||||
protected void moveTo(int x, int y, int z)
|
||||
{
|
||||
// Chek if actor can move
|
||||
if (!_actor.isMovementDisabled())
|
||||
{
|
||||
// Set AI movement data
|
||||
_clientMoving = true;
|
||||
_clientMovingToPawnOffset = 0;
|
||||
|
||||
// Calculate movement data for a move to location action and add the actor to movingObjects of GameTimeController
|
||||
_accessor.moveTo(x, y, z);
|
||||
|
||||
// Send a Server->Client packet CharMoveToLocation to the actor and all L2PcInstance in its _knownPlayers
|
||||
_actor.broadcastPacket(new MoveToLocation(_actor));
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
clientActionFailed();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop the actor movement server side AND client side by sending Server->Client packet StopMove/StopRotation <I>(broadcast)</I>.<br>
|
||||
* <FONT COLOR=#FF0000><B> <U>Caution</U> : Low level function, used by AI subclasses</B></FONT>
|
||||
* @param loc
|
||||
*/
|
||||
protected void clientStopMoving(Location loc)
|
||||
{
|
||||
// Stop movement of the L2Character
|
||||
if (_actor.isMoving())
|
||||
{
|
||||
_accessor.stopMove(loc);
|
||||
}
|
||||
|
||||
_clientMovingToPawnOffset = 0;
|
||||
|
||||
if (_clientMoving || (loc != null))
|
||||
{
|
||||
_clientMoving = false;
|
||||
|
||||
// Send a Server->Client packet StopMove to the actor and all L2PcInstance in its _knownPlayers
|
||||
_actor.broadcastPacket(new StopMove(_actor));
|
||||
|
||||
if (loc != null)
|
||||
{
|
||||
// Send a Server->Client packet StopRotation to the actor and all L2PcInstance in its _knownPlayers
|
||||
_actor.broadcastPacket(new StopRotation(_actor.getObjectId(), loc.getHeading(), 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Client has already arrived to target, no need to force StopMove packet.
|
||||
*/
|
||||
protected void clientStoppedMoving()
|
||||
{
|
||||
if (_clientMovingToPawnOffset > 0) // movetoPawn needs to be stopped
|
||||
{
|
||||
_clientMovingToPawnOffset = 0;
|
||||
_actor.broadcastPacket(new StopMove(_actor));
|
||||
}
|
||||
_clientMoving = false;
|
||||
}
|
||||
|
||||
public boolean isAutoAttacking()
|
||||
{
|
||||
return _clientAutoAttacking;
|
||||
}
|
||||
|
||||
public void setAutoAttacking(boolean isAutoAttacking)
|
||||
{
|
||||
if (_actor instanceof L2Summon)
|
||||
{
|
||||
L2Summon summon = (L2Summon) _actor;
|
||||
if (summon.getOwner() != null)
|
||||
{
|
||||
summon.getOwner().getAI().setAutoAttacking(isAutoAttacking);
|
||||
}
|
||||
return;
|
||||
}
|
||||
_clientAutoAttacking = isAutoAttacking;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the actor Auto Attack client side by sending Server->Client packet AutoAttackStart <I>(broadcast)</I>.<br>
|
||||
* <FONT COLOR=#FF0000><B> <U>Caution</U> : Low level function, used by AI subclasses</B></FONT>
|
||||
*/
|
||||
public void clientStartAutoAttack()
|
||||
{
|
||||
if (_actor instanceof L2Summon)
|
||||
{
|
||||
L2Summon summon = (L2Summon) _actor;
|
||||
if (summon.getOwner() != null)
|
||||
{
|
||||
summon.getOwner().getAI().clientStartAutoAttack();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!isAutoAttacking())
|
||||
{
|
||||
if (_actor.isPlayer() && _actor.hasSummon())
|
||||
{
|
||||
_actor.getSummon().broadcastPacket(new AutoAttackStart(_actor.getSummon().getObjectId()));
|
||||
}
|
||||
// Send a Server->Client packet AutoAttackStart to the actor and all L2PcInstance in its _knownPlayers
|
||||
_actor.broadcastPacket(new AutoAttackStart(_actor.getObjectId()));
|
||||
setAutoAttacking(true);
|
||||
}
|
||||
AttackStanceTaskManager.getInstance().addAttackStanceTask(_actor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop <I>(broadcast)</I>.<br>
|
||||
* <FONT COLOR=#FF0000><B> <U>Caution</U> : Low level function, used by AI subclasses</B></FONT>
|
||||
*/
|
||||
public void clientStopAutoAttack()
|
||||
{
|
||||
if (_actor instanceof L2Summon)
|
||||
{
|
||||
L2Summon summon = (L2Summon) _actor;
|
||||
if (summon.getOwner() != null)
|
||||
{
|
||||
summon.getOwner().getAI().clientStopAutoAttack();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (_actor instanceof L2PcInstance)
|
||||
{
|
||||
if (!AttackStanceTaskManager.getInstance().hasAttackStanceTask(_actor) && isAutoAttacking())
|
||||
{
|
||||
AttackStanceTaskManager.getInstance().addAttackStanceTask(_actor);
|
||||
}
|
||||
}
|
||||
else if (isAutoAttacking())
|
||||
{
|
||||
_actor.broadcastPacket(new AutoAttackStop(_actor.getObjectId()));
|
||||
setAutoAttacking(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Kill the actor client side by sending Server->Client packet AutoAttackStop, StopMove/StopRotation, Die <I>(broadcast)</I>.<br>
|
||||
* <FONT COLOR=#FF0000><B> <U>Caution</U> : Low level function, used by AI subclasses</B></FONT>
|
||||
*/
|
||||
protected void clientNotifyDead()
|
||||
{
|
||||
// Send a Server->Client packet Die to the actor and all L2PcInstance in its _knownPlayers
|
||||
Die msg = new Die(_actor);
|
||||
_actor.broadcastPacket(msg);
|
||||
|
||||
// Init AI
|
||||
_intention = AI_INTENTION_IDLE;
|
||||
_target = null;
|
||||
_castTarget = null;
|
||||
_attackTarget = null;
|
||||
|
||||
// Cancel the follow task if necessary
|
||||
stopFollow();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the state of this actor client side by sending Server->Client packet MoveToPawn/CharMoveToLocation and AutoAttackStart to the L2PcInstance player.<br>
|
||||
* <FONT COLOR=#FF0000><B> <U>Caution</U> : Low level function, used by AI subclasses</B></FONT>
|
||||
* @param player The L2PcIstance to notify with state of this L2Character
|
||||
*/
|
||||
public void describeStateToPlayer(L2PcInstance player)
|
||||
{
|
||||
if (getActor().isVisibleFor(player))
|
||||
{
|
||||
if (_clientMoving)
|
||||
{
|
||||
if ((_clientMovingToPawnOffset != 0) && (_followTarget != null))
|
||||
{
|
||||
// Send a Server->Client packet MoveToPawn to the actor and all L2PcInstance in its _knownPlayers
|
||||
player.sendPacket(new MoveToPawn(_actor, _followTarget, _clientMovingToPawnOffset));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Send a Server->Client packet CharMoveToLocation to the actor and all L2PcInstance in its _knownPlayers
|
||||
player.sendPacket(new MoveToLocation(_actor));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and Launch an AI Follow Task to execute every 1s.
|
||||
* @param target The L2Character to follow
|
||||
*/
|
||||
public synchronized void startFollow(L2Character target)
|
||||
{
|
||||
if (_followTask != null)
|
||||
{
|
||||
_followTask.cancel(false);
|
||||
_followTask = null;
|
||||
}
|
||||
|
||||
// Create and Launch an AI Follow Task to execute every 1s
|
||||
_followTarget = target;
|
||||
_followTask = ThreadPoolManager.getInstance().scheduleAiAtFixedRate(new FollowTask(), 5, FOLLOW_INTERVAL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and Launch an AI Follow Task to execute every 0.5s, following at specified range.
|
||||
* @param target The L2Character to follow
|
||||
* @param range
|
||||
*/
|
||||
public synchronized void startFollow(L2Character target, int range)
|
||||
{
|
||||
if (_followTask != null)
|
||||
{
|
||||
_followTask.cancel(false);
|
||||
_followTask = null;
|
||||
}
|
||||
|
||||
_followTarget = target;
|
||||
_followTask = ThreadPoolManager.getInstance().scheduleAiAtFixedRate(new FollowTask(range), 5, ATTACK_FOLLOW_INTERVAL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop an AI Follow Task.
|
||||
*/
|
||||
public synchronized void stopFollow()
|
||||
{
|
||||
if (_followTask != null)
|
||||
{
|
||||
// Stop the Follow Task
|
||||
_followTask.cancel(false);
|
||||
_followTask = null;
|
||||
}
|
||||
_followTarget = null;
|
||||
}
|
||||
|
||||
protected L2Character getFollowTarget()
|
||||
{
|
||||
return _followTarget;
|
||||
}
|
||||
|
||||
protected L2Object getTarget()
|
||||
{
|
||||
return _target;
|
||||
}
|
||||
|
||||
protected void setTarget(L2Object target)
|
||||
{
|
||||
_target = target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop all Ai tasks and futures.
|
||||
*/
|
||||
public void stopAITask()
|
||||
{
|
||||
stopFollow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "Actor: " + _actor;
|
||||
}
|
||||
}
|
107
trunk/java/com/l2jserver/gameserver/ai/Ctrl.java
Normal file
107
trunk/java/com/l2jserver/gameserver/ai/Ctrl.java
Normal file
@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2014 L2J Server
|
||||
*
|
||||
* This file is part of L2J Server.
|
||||
*
|
||||
* L2J Server is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* L2J Server is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.gameserver.ai;
|
||||
|
||||
import com.l2jserver.gameserver.model.actor.L2Character;
|
||||
|
||||
/**
|
||||
* Interface of AI and client state.<br>
|
||||
* To correctly send messages to client we need it's state.<br>
|
||||
* For example, if we've sent 'StartAutoAttack' message, we need to send 'StopAutoAttack' message before any other action.<br>
|
||||
* Or if we've sent 'MoveToPawn', we need to send 'StopMove' when the movement of a character is canceled (by Root spell or any other reason).<br>
|
||||
* Thus, we need to know the state of client, i.e. which messages we've sent and how the client will show the scene.<br>
|
||||
* Close to this task is the task of AI.<br>
|
||||
* If a player's character is attacking a mob, his ATTACK may be interrupted by an event, that temporary disable attacking.<br>
|
||||
* But when the possibility to ATTACK will be enabled, the character must continue the ATTACK.<br>
|
||||
* For mobs it may be more complex, since we want them to decide when to use magic, or when to follow the player for physical combat, or when to escape, to help another mob, etc.<br>
|
||||
* This interface is hiding complexity of server<->client interaction and multiple states of a character.<br>
|
||||
* It allows to set a desired, simple "wish" of a character, and the implementation of this interface will take care about the rest.<br>
|
||||
* The goal of a character may be like "ATTACK", "random walk" and so on.<br>
|
||||
* To reach the goal implementation will split it into several small actions, several steps (possibly repeatable).<br>
|
||||
* Like "run to target" then "hit it", then if target is not dead - repeat.<br>
|
||||
* This flow of simpler steps may be interrupted by incoming events.<br>
|
||||
* Like a character's movement was disabled (by Root spell, for instance).<br>
|
||||
* Depending on character's ability AI may choose to wait, or to use magic ATTACK and so on.<br>
|
||||
* Additionally incoming events are compared with client's state of the character,<br>
|
||||
* and required network messages are sent to client's, i.e. if we have incoming event that character's movement was disabled, it causes changing if its behavior,<br>
|
||||
* and if client's state for the character is "moving" we send messages to clients to stop the avatar/mob.
|
||||
*/
|
||||
public interface Ctrl
|
||||
{
|
||||
|
||||
/**
|
||||
* Gets the actor.
|
||||
* @return the actor
|
||||
*/
|
||||
L2Character getActor();
|
||||
|
||||
/**
|
||||
* Gets the intention.
|
||||
* @return the intention
|
||||
*/
|
||||
CtrlIntention getIntention();
|
||||
|
||||
/**
|
||||
* Gets the attack target.
|
||||
* @return the attack target
|
||||
*/
|
||||
L2Character getAttackTarget();
|
||||
|
||||
/**
|
||||
* Set general state/intention for AI, with optional data.
|
||||
* @param intention the new intention
|
||||
*/
|
||||
void setIntention(CtrlIntention intention);
|
||||
|
||||
/**
|
||||
* Sets the intention.
|
||||
* @param intention the intention
|
||||
* @param arg0 the arg0
|
||||
*/
|
||||
void setIntention(CtrlIntention intention, Object arg0);
|
||||
|
||||
/**
|
||||
* Sets the intention.
|
||||
* @param intention the intention
|
||||
* @param arg0 the arg0
|
||||
* @param arg1 the arg1
|
||||
*/
|
||||
void setIntention(CtrlIntention intention, Object arg0, Object arg1);
|
||||
|
||||
/**
|
||||
* Event, that notifies about previous step result, or user command, that does not change current general intention.
|
||||
* @param evt the event
|
||||
*/
|
||||
void notifyEvent(CtrlEvent evt);
|
||||
|
||||
/**
|
||||
* Notify an event.
|
||||
* @param evt the event
|
||||
* @param arg0 the arg0
|
||||
*/
|
||||
void notifyEvent(CtrlEvent evt, Object arg0);
|
||||
|
||||
/**
|
||||
* Notify an event.
|
||||
* @param evt the event
|
||||
* @param arg0 the arg0
|
||||
* @param arg1 the arg1
|
||||
*/
|
||||
void notifyEvent(CtrlEvent evt, Object arg0, Object arg1);
|
||||
}
|
90
trunk/java/com/l2jserver/gameserver/ai/CtrlEvent.java
Normal file
90
trunk/java/com/l2jserver/gameserver/ai/CtrlEvent.java
Normal file
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2014 L2J Server
|
||||
*
|
||||
* This file is part of L2J Server.
|
||||
*
|
||||
* L2J Server is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* L2J Server is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.gameserver.ai;
|
||||
|
||||
/**
|
||||
* This class contains an enum of each possibles events that can happen on an AI character.
|
||||
*/
|
||||
public enum CtrlEvent
|
||||
{
|
||||
/**
|
||||
* Something has changed, usually a previous step has being completed or maybe was completed, the AI must thing on next action.
|
||||
*/
|
||||
EVT_THINK,
|
||||
/**
|
||||
* The actor was attacked. This event comes each time a physical or magical<br>
|
||||
* attack was done on the actor. NPC may start attack in response, or ignore<br>
|
||||
* this event if they already attack someone, or change target and so on.
|
||||
*/
|
||||
EVT_ATTACKED,
|
||||
/** Increase/decrease aggression towards a target, or reduce global aggression if target is null */
|
||||
EVT_AGGRESSION,
|
||||
/** Actor is in stun state */
|
||||
EVT_STUNNED,
|
||||
/** Actor is paralyzed or petrified */
|
||||
EVT_PARALYZED,
|
||||
/** Actor starts/stops sleeping */
|
||||
EVT_SLEEPING,
|
||||
/** Actor is in rooted state (cannot move) */
|
||||
EVT_ROOTED,
|
||||
/** Actor evaded hit **/
|
||||
EVT_EVADED,
|
||||
/**
|
||||
* An event that previous action was completed. The action may be an attempt to physically/magically hit an enemy, or an action that discarded attack attempt has finished.
|
||||
*/
|
||||
EVT_READY_TO_ACT,
|
||||
/**
|
||||
* User's command, like using a combat magic or changing weapon, etc. The command is not intended to change final goal
|
||||
*/
|
||||
EVT_USER_CMD,
|
||||
/**
|
||||
* The actor arrived to assigned location, or it's a time to modify movement destination (follow, interact, random move and others intentions).
|
||||
*/
|
||||
EVT_ARRIVED,
|
||||
/**
|
||||
* The actor arrived to an intermediate point, and needs to revalidate destination. This is sent when follow/move to pawn if destination is far away.
|
||||
*/
|
||||
EVT_ARRIVED_REVALIDATE,
|
||||
/** The actor cannot move anymore. */
|
||||
EVT_ARRIVED_BLOCKED,
|
||||
/** Forgets an object (if it's used as attack target, follow target and so on */
|
||||
EVT_FORGET_OBJECT,
|
||||
/**
|
||||
* Attempt to cancel current step execution, but not change the intention.<br>
|
||||
* For example, the actor was put into a stun, so it's current attack<br>
|
||||
* or movement has to be canceled. But after the stun state expired,<br>
|
||||
* the actor may try to attack again. Another usage for CANCEL is a user's<br>
|
||||
* attempt to cancel a cast/bow attack and so on.
|
||||
*/
|
||||
EVT_CANCEL,
|
||||
/** The character is dead */
|
||||
EVT_DEAD,
|
||||
/** The character looks like dead */
|
||||
EVT_FAKE_DEATH,
|
||||
/** The character attack anyone randomly **/
|
||||
EVT_CONFUSED,
|
||||
/** The character cannot cast spells anymore **/
|
||||
EVT_MUTED,
|
||||
/** The character flee in random directions **/
|
||||
EVT_AFRAID,
|
||||
/** The character finish casting **/
|
||||
EVT_FINISH_CASTING,
|
||||
/** The character betrayed its master */
|
||||
EVT_BETRAYED
|
||||
}
|
44
trunk/java/com/l2jserver/gameserver/ai/CtrlIntention.java
Normal file
44
trunk/java/com/l2jserver/gameserver/ai/CtrlIntention.java
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2014 L2J Server
|
||||
*
|
||||
* This file is part of L2J Server.
|
||||
*
|
||||
* L2J Server is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* L2J Server is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.gameserver.ai;
|
||||
|
||||
/**
|
||||
* Enumeration of generic intentions of an NPC/PC, an intention may require several steps to be completed.
|
||||
*/
|
||||
public enum CtrlIntention
|
||||
{
|
||||
/** Do nothing, disconnect AI of NPC if no players around */
|
||||
AI_INTENTION_IDLE,
|
||||
/** Alerted state without goal : scan attackable targets, random walk, etc */
|
||||
AI_INTENTION_ACTIVE,
|
||||
/** Rest (sit until attacked) */
|
||||
AI_INTENTION_REST,
|
||||
/** Attack target (cast combat magic, go to target, combat), may be ignored, if target is locked on another character or a peaceful zone and so on. */
|
||||
AI_INTENTION_ATTACK,
|
||||
/** Cast a spell, depending on the spell - may start or stop attacking */
|
||||
AI_INTENTION_CAST,
|
||||
/** Just move to another location */
|
||||
AI_INTENTION_MOVE_TO,
|
||||
/** Like move, but check target's movement and follow it */
|
||||
AI_INTENTION_FOLLOW,
|
||||
/** PickUp and item, (got to item, pickup it, become idle */
|
||||
AI_INTENTION_PICK_UP,
|
||||
/** Move to target, then interact */
|
||||
AI_INTENTION_INTERACT;
|
||||
}
|
77
trunk/java/com/l2jserver/gameserver/ai/L2AirShipAI.java
Normal file
77
trunk/java/com/l2jserver/gameserver/ai/L2AirShipAI.java
Normal file
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2014 L2J Server
|
||||
*
|
||||
* This file is part of L2J Server.
|
||||
*
|
||||
* L2J Server is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* L2J Server is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.gameserver.ai;
|
||||
|
||||
import com.l2jserver.gameserver.model.Location;
|
||||
import com.l2jserver.gameserver.model.actor.instance.L2AirShipInstance;
|
||||
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jserver.gameserver.network.serverpackets.ExMoveToLocationAirShip;
|
||||
import com.l2jserver.gameserver.network.serverpackets.ExStopMoveAirShip;
|
||||
|
||||
/**
|
||||
* @author DS
|
||||
*/
|
||||
public class L2AirShipAI extends L2VehicleAI
|
||||
{
|
||||
public L2AirShipAI(L2AirShipInstance.AIAccessor accessor)
|
||||
{
|
||||
super(accessor);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void moveTo(int x, int y, int z)
|
||||
{
|
||||
if (!_actor.isMovementDisabled())
|
||||
{
|
||||
_clientMoving = true;
|
||||
_accessor.moveTo(x, y, z);
|
||||
_actor.broadcastPacket(new ExMoveToLocationAirShip(getActor()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void clientStopMoving(Location loc)
|
||||
{
|
||||
if (_actor.isMoving())
|
||||
{
|
||||
_accessor.stopMove(loc);
|
||||
}
|
||||
|
||||
if (_clientMoving || (loc != null))
|
||||
{
|
||||
_clientMoving = false;
|
||||
_actor.broadcastPacket(new ExStopMoveAirShip(getActor()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeStateToPlayer(L2PcInstance player)
|
||||
{
|
||||
if (_clientMoving)
|
||||
{
|
||||
player.sendPacket(new ExMoveToLocationAirShip(getActor()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public L2AirShipInstance getActor()
|
||||
{
|
||||
return (L2AirShipInstance) _actor;
|
||||
}
|
||||
}
|
2691
trunk/java/com/l2jserver/gameserver/ai/L2AttackableAI.java
Normal file
2691
trunk/java/com/l2jserver/gameserver/ai/L2AttackableAI.java
Normal file
File diff suppressed because it is too large
Load Diff
84
trunk/java/com/l2jserver/gameserver/ai/L2BoatAI.java
Normal file
84
trunk/java/com/l2jserver/gameserver/ai/L2BoatAI.java
Normal file
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2014 L2J Server
|
||||
*
|
||||
* This file is part of L2J Server.
|
||||
*
|
||||
* L2J Server is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* L2J Server is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.gameserver.ai;
|
||||
|
||||
import com.l2jserver.gameserver.model.Location;
|
||||
import com.l2jserver.gameserver.model.actor.instance.L2BoatInstance;
|
||||
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jserver.gameserver.network.serverpackets.VehicleDeparture;
|
||||
import com.l2jserver.gameserver.network.serverpackets.VehicleInfo;
|
||||
import com.l2jserver.gameserver.network.serverpackets.VehicleStarted;
|
||||
|
||||
/**
|
||||
* @author DS
|
||||
*/
|
||||
public class L2BoatAI extends L2VehicleAI
|
||||
{
|
||||
public L2BoatAI(L2BoatInstance.AIAccessor accessor)
|
||||
{
|
||||
super(accessor);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void moveTo(int x, int y, int z)
|
||||
{
|
||||
if (!_actor.isMovementDisabled())
|
||||
{
|
||||
if (!_clientMoving)
|
||||
{
|
||||
_actor.broadcastPacket(new VehicleStarted(getActor(), 1));
|
||||
}
|
||||
|
||||
_clientMoving = true;
|
||||
_accessor.moveTo(x, y, z);
|
||||
_actor.broadcastPacket(new VehicleDeparture(getActor()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void clientStopMoving(Location loc)
|
||||
{
|
||||
if (_actor.isMoving())
|
||||
{
|
||||
_accessor.stopMove(loc);
|
||||
}
|
||||
|
||||
if (_clientMoving || (loc != null))
|
||||
{
|
||||
_clientMoving = false;
|
||||
_actor.broadcastPacket(new VehicleStarted(getActor(), 0));
|
||||
_actor.broadcastPacket(new VehicleInfo(getActor()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeStateToPlayer(L2PcInstance player)
|
||||
{
|
||||
if (_clientMoving)
|
||||
{
|
||||
player.sendPacket(new VehicleDeparture(getActor()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public L2BoatInstance getActor()
|
||||
{
|
||||
return (L2BoatInstance) _actor;
|
||||
}
|
||||
}
|
1635
trunk/java/com/l2jserver/gameserver/ai/L2CharacterAI.java
Normal file
1635
trunk/java/com/l2jserver/gameserver/ai/L2CharacterAI.java
Normal file
File diff suppressed because it is too large
Load Diff
583
trunk/java/com/l2jserver/gameserver/ai/L2ControllableMobAI.java
Normal file
583
trunk/java/com/l2jserver/gameserver/ai/L2ControllableMobAI.java
Normal file
@ -0,0 +1,583 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2014 L2J Server
|
||||
*
|
||||
* This file is part of L2J Server.
|
||||
*
|
||||
* L2J Server is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* L2J Server is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.gameserver.ai;
|
||||
|
||||
import static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_ACTIVE;
|
||||
import static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_ATTACK;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import javolution.util.FastList;
|
||||
|
||||
import com.l2jserver.gameserver.model.L2Object;
|
||||
import com.l2jserver.gameserver.model.MobGroup;
|
||||
import com.l2jserver.gameserver.model.MobGroupTable;
|
||||
import com.l2jserver.gameserver.model.actor.L2Attackable;
|
||||
import com.l2jserver.gameserver.model.actor.L2Character;
|
||||
import com.l2jserver.gameserver.model.actor.L2Character.AIAccessor;
|
||||
import com.l2jserver.gameserver.model.actor.L2Npc;
|
||||
import com.l2jserver.gameserver.model.actor.L2Playable;
|
||||
import com.l2jserver.gameserver.model.actor.instance.L2ControllableMobInstance;
|
||||
import com.l2jserver.gameserver.model.actor.instance.L2DoorInstance;
|
||||
import com.l2jserver.gameserver.model.actor.instance.L2NpcInstance;
|
||||
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jserver.gameserver.model.skills.Skill;
|
||||
import com.l2jserver.gameserver.util.Util;
|
||||
import com.l2jserver.util.Rnd;
|
||||
|
||||
/**
|
||||
* AI for controllable mobs
|
||||
* @author littlecrow
|
||||
*/
|
||||
public final class L2ControllableMobAI extends L2AttackableAI
|
||||
{
|
||||
public static final int AI_IDLE = 1;
|
||||
public static final int AI_NORMAL = 2;
|
||||
public static final int AI_FORCEATTACK = 3;
|
||||
public static final int AI_FOLLOW = 4;
|
||||
public static final int AI_CAST = 5;
|
||||
public static final int AI_ATTACK_GROUP = 6;
|
||||
|
||||
private int _alternateAI;
|
||||
|
||||
private boolean _isThinking; // to prevent thinking recursively
|
||||
private boolean _isNotMoving;
|
||||
|
||||
private L2Character _forcedTarget;
|
||||
private MobGroup _targetGroup;
|
||||
|
||||
protected void thinkFollow()
|
||||
{
|
||||
L2Attackable me = (L2Attackable) _actor;
|
||||
|
||||
if (!Util.checkIfInRange(MobGroupTable.FOLLOW_RANGE, me, getForcedTarget(), true))
|
||||
{
|
||||
int signX = (Rnd.nextInt(2) == 0) ? -1 : 1;
|
||||
int signY = (Rnd.nextInt(2) == 0) ? -1 : 1;
|
||||
int randX = Rnd.nextInt(MobGroupTable.FOLLOW_RANGE);
|
||||
int randY = Rnd.nextInt(MobGroupTable.FOLLOW_RANGE);
|
||||
|
||||
moveTo(getForcedTarget().getX() + (signX * randX), getForcedTarget().getY() + (signY * randY), getForcedTarget().getZ());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEvtThink()
|
||||
{
|
||||
if (isThinking())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
setThinking(true);
|
||||
|
||||
try
|
||||
{
|
||||
switch (getAlternateAI())
|
||||
{
|
||||
case AI_IDLE:
|
||||
if (getIntention() != CtrlIntention.AI_INTENTION_ACTIVE)
|
||||
{
|
||||
setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
|
||||
}
|
||||
break;
|
||||
case AI_FOLLOW:
|
||||
thinkFollow();
|
||||
break;
|
||||
case AI_CAST:
|
||||
thinkCast();
|
||||
break;
|
||||
case AI_FORCEATTACK:
|
||||
thinkForceAttack();
|
||||
break;
|
||||
case AI_ATTACK_GROUP:
|
||||
thinkAttackGroup();
|
||||
break;
|
||||
default:
|
||||
if (getIntention() == AI_INTENTION_ACTIVE)
|
||||
{
|
||||
thinkActive();
|
||||
}
|
||||
else if (getIntention() == AI_INTENTION_ATTACK)
|
||||
{
|
||||
thinkAttack();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
setThinking(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void thinkCast()
|
||||
{
|
||||
L2Attackable npc = (L2Attackable) _actor;
|
||||
if ((getAttackTarget() == null) || getAttackTarget().isAlikeDead())
|
||||
{
|
||||
setAttackTarget(findNextRndTarget());
|
||||
clientStopMoving(null);
|
||||
}
|
||||
|
||||
if (getAttackTarget() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
npc.setTarget(getAttackTarget());
|
||||
|
||||
if (!_actor.isMuted())
|
||||
{
|
||||
int max_range = 0;
|
||||
// check distant skills
|
||||
|
||||
for (Skill sk : _actor.getAllSkills())
|
||||
{
|
||||
if (Util.checkIfInRange(sk.getCastRange(), _actor, getAttackTarget(), true) && !_actor.isSkillDisabled(sk) && (_actor.getCurrentMp() > _actor.getStat().getMpConsume(sk)))
|
||||
{
|
||||
_accessor.doCast(sk);
|
||||
return;
|
||||
}
|
||||
|
||||
max_range = Math.max(max_range, sk.getCastRange());
|
||||
}
|
||||
|
||||
if (!isNotMoving())
|
||||
{
|
||||
moveToPawn(getAttackTarget(), max_range);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
protected void thinkAttackGroup()
|
||||
{
|
||||
L2Character target = getForcedTarget();
|
||||
if ((target == null) || target.isAlikeDead())
|
||||
{
|
||||
// try to get next group target
|
||||
setForcedTarget(findNextGroupTarget());
|
||||
clientStopMoving(null);
|
||||
}
|
||||
|
||||
if (target == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_actor.setTarget(target);
|
||||
// as a response, we put the target in a forcedattack mode
|
||||
L2ControllableMobInstance theTarget = (L2ControllableMobInstance) target;
|
||||
L2ControllableMobAI ctrlAi = (L2ControllableMobAI) theTarget.getAI();
|
||||
ctrlAi.forceAttack(_actor);
|
||||
|
||||
double dist2 = _actor.calculateDistance(target, false, true);
|
||||
int range = _actor.getPhysicalAttackRange() + _actor.getTemplate().getCollisionRadius() + target.getTemplate().getCollisionRadius();
|
||||
int max_range = range;
|
||||
|
||||
if (!_actor.isMuted() && (dist2 > ((range + 20) * (range + 20))))
|
||||
{
|
||||
// check distant skills
|
||||
for (Skill sk : _actor.getAllSkills())
|
||||
{
|
||||
int castRange = sk.getCastRange();
|
||||
|
||||
if (((castRange * castRange) >= dist2) && !_actor.isSkillDisabled(sk) && (_actor.getCurrentMp() > _actor.getStat().getMpConsume(sk)))
|
||||
{
|
||||
_accessor.doCast(sk);
|
||||
return;
|
||||
}
|
||||
|
||||
max_range = Math.max(max_range, castRange);
|
||||
}
|
||||
|
||||
if (!isNotMoving())
|
||||
{
|
||||
moveToPawn(target, range);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
_accessor.doAttack(target);
|
||||
}
|
||||
|
||||
protected void thinkForceAttack()
|
||||
{
|
||||
if ((getForcedTarget() == null) || getForcedTarget().isAlikeDead())
|
||||
{
|
||||
clientStopMoving(null);
|
||||
setIntention(AI_INTENTION_ACTIVE);
|
||||
setAlternateAI(AI_IDLE);
|
||||
}
|
||||
|
||||
_actor.setTarget(getForcedTarget());
|
||||
double dist2 = _actor.calculateDistance(getForcedTarget(), false, true);
|
||||
int range = _actor.getPhysicalAttackRange() + _actor.getTemplate().getCollisionRadius() + getForcedTarget().getTemplate().getCollisionRadius();
|
||||
int max_range = range;
|
||||
|
||||
if (!_actor.isMuted() && (dist2 > ((range + 20) * (range + 20))))
|
||||
{
|
||||
// check distant skills
|
||||
for (Skill sk : _actor.getAllSkills())
|
||||
{
|
||||
int castRange = sk.getCastRange();
|
||||
|
||||
if (((castRange * castRange) >= dist2) && !_actor.isSkillDisabled(sk) && (_actor.getCurrentMp() > _actor.getStat().getMpConsume(sk)))
|
||||
{
|
||||
_accessor.doCast(sk);
|
||||
return;
|
||||
}
|
||||
|
||||
max_range = Math.max(max_range, castRange);
|
||||
}
|
||||
|
||||
if (!isNotMoving())
|
||||
{
|
||||
moveToPawn(getForcedTarget(), _actor.getPhysicalAttackRange()/* range */);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
_accessor.doAttack(getForcedTarget());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void thinkAttack()
|
||||
{
|
||||
if ((getAttackTarget() == null) || getAttackTarget().isAlikeDead())
|
||||
{
|
||||
if (getAttackTarget() != null)
|
||||
{
|
||||
// stop hating
|
||||
L2Attackable npc = (L2Attackable) _actor;
|
||||
npc.stopHating(getAttackTarget());
|
||||
}
|
||||
|
||||
setIntention(AI_INTENTION_ACTIVE);
|
||||
}
|
||||
else
|
||||
{
|
||||
// notify aggression
|
||||
if (((L2Npc) _actor).getTemplate().getClans() != null)
|
||||
{
|
||||
Collection<L2Object> objs = _actor.getKnownList().getKnownObjects().values();
|
||||
for (L2Object obj : objs)
|
||||
{
|
||||
if (!(obj instanceof L2Npc))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
L2Npc npc = (L2Npc) obj;
|
||||
|
||||
if (!npc.isInMyClan((L2Npc) _actor))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (_actor.isInsideRadius(npc, npc.getTemplate().getClanHelpRange(), false, true) && (Math.abs(getAttackTarget().getZ() - npc.getZ()) < 200))
|
||||
{
|
||||
npc.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, getAttackTarget(), 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_actor.setTarget(getAttackTarget());
|
||||
double dist2 = _actor.calculateDistance(getAttackTarget(), false, true);
|
||||
int range = _actor.getPhysicalAttackRange() + _actor.getTemplate().getCollisionRadius() + getAttackTarget().getTemplate().getCollisionRadius();
|
||||
int max_range = range;
|
||||
|
||||
if (!_actor.isMuted() && (dist2 > ((range + 20) * (range + 20))))
|
||||
{
|
||||
// check distant skills
|
||||
for (Skill sk : _actor.getAllSkills())
|
||||
{
|
||||
int castRange = sk.getCastRange();
|
||||
|
||||
if (((castRange * castRange) >= dist2) && !_actor.isSkillDisabled(sk) && (_actor.getCurrentMp() > _actor.getStat().getMpConsume(sk)))
|
||||
{
|
||||
_accessor.doCast(sk);
|
||||
return;
|
||||
}
|
||||
|
||||
max_range = Math.max(max_range, castRange);
|
||||
}
|
||||
|
||||
moveToPawn(getAttackTarget(), range);
|
||||
return;
|
||||
}
|
||||
|
||||
// Force mobs to attack anybody if confused.
|
||||
L2Character hated;
|
||||
|
||||
if (_actor.isConfused())
|
||||
{
|
||||
hated = findNextRndTarget();
|
||||
}
|
||||
else
|
||||
{
|
||||
hated = getAttackTarget();
|
||||
}
|
||||
|
||||
if (hated == null)
|
||||
{
|
||||
setIntention(AI_INTENTION_ACTIVE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (hated != getAttackTarget())
|
||||
{
|
||||
setAttackTarget(hated);
|
||||
}
|
||||
|
||||
if (!_actor.isMuted() && (Rnd.nextInt(5) == 3))
|
||||
{
|
||||
for (Skill sk : _actor.getAllSkills())
|
||||
{
|
||||
int castRange = sk.getCastRange();
|
||||
|
||||
if (((castRange * castRange) >= dist2) && !_actor.isSkillDisabled(sk) && (_actor.getCurrentMp() < _actor.getStat().getMpConsume(sk)))
|
||||
{
|
||||
_accessor.doCast(sk);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_accessor.doAttack(getAttackTarget());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void thinkActive()
|
||||
{
|
||||
setAttackTarget(findNextRndTarget());
|
||||
L2Character hated;
|
||||
|
||||
if (_actor.isConfused())
|
||||
{
|
||||
hated = findNextRndTarget();
|
||||
}
|
||||
else
|
||||
{
|
||||
hated = getAttackTarget();
|
||||
}
|
||||
|
||||
if (hated != null)
|
||||
{
|
||||
_actor.setRunning();
|
||||
setIntention(CtrlIntention.AI_INTENTION_ATTACK, hated);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkAutoAttackCondition(L2Character target)
|
||||
{
|
||||
if ((target == null) || !(_actor instanceof L2Attackable))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
L2Attackable me = (L2Attackable) _actor;
|
||||
|
||||
if ((target instanceof L2NpcInstance) || (target instanceof L2DoorInstance))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (target.isAlikeDead() || !me.isInsideRadius(target, me.getAggroRange(), false, false) || (Math.abs(_actor.getZ() - target.getZ()) > 100))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if the target isn't invulnerable
|
||||
if (target.isInvul())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Spawn protection (only against mobs)
|
||||
if ((target instanceof L2PcInstance) && ((L2PcInstance) target).isSpawnProtected())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if the target is a L2Playable
|
||||
if (target.isPlayable())
|
||||
{
|
||||
// Check if the target isn't in silent move mode
|
||||
if (((L2Playable) target).isSilentMovingAffected())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (target instanceof L2Npc)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return me.isAggressive();
|
||||
}
|
||||
|
||||
private L2Character findNextRndTarget()
|
||||
{
|
||||
int aggroRange = ((L2Attackable) _actor).getAggroRange();
|
||||
L2Attackable npc = (L2Attackable) _actor;
|
||||
int npcX, npcY, targetX, targetY;
|
||||
double dy, dx;
|
||||
double dblAggroRange = aggroRange * aggroRange;
|
||||
|
||||
List<L2Character> potentialTarget = new FastList<>();
|
||||
|
||||
Collection<L2Object> objs = npc.getKnownList().getKnownObjects().values();
|
||||
for (L2Object obj : objs)
|
||||
{
|
||||
if (!(obj instanceof L2Character))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
npcX = npc.getX();
|
||||
npcY = npc.getY();
|
||||
targetX = obj.getX();
|
||||
targetY = obj.getY();
|
||||
|
||||
dx = npcX - targetX;
|
||||
dy = npcY - targetY;
|
||||
|
||||
if (((dx * dx) + (dy * dy)) > dblAggroRange)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
L2Character target = (L2Character) obj;
|
||||
|
||||
if (checkAutoAttackCondition(target))
|
||||
{
|
||||
potentialTarget.add(target);
|
||||
}
|
||||
}
|
||||
|
||||
if (potentialTarget.isEmpty())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// we choose a random target
|
||||
int choice = Rnd.nextInt(potentialTarget.size());
|
||||
L2Character target = potentialTarget.get(choice);
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
private L2ControllableMobInstance findNextGroupTarget()
|
||||
{
|
||||
return getGroupTarget().getRandomMob();
|
||||
}
|
||||
|
||||
public L2ControllableMobAI(AIAccessor accessor)
|
||||
{
|
||||
super(accessor);
|
||||
setAlternateAI(AI_IDLE);
|
||||
}
|
||||
|
||||
public int getAlternateAI()
|
||||
{
|
||||
return _alternateAI;
|
||||
}
|
||||
|
||||
public void setAlternateAI(int _alternateai)
|
||||
{
|
||||
_alternateAI = _alternateai;
|
||||
}
|
||||
|
||||
public void forceAttack(L2Character target)
|
||||
{
|
||||
setAlternateAI(AI_FORCEATTACK);
|
||||
setForcedTarget(target);
|
||||
}
|
||||
|
||||
public void forceAttackGroup(MobGroup group)
|
||||
{
|
||||
setForcedTarget(null);
|
||||
setGroupTarget(group);
|
||||
setAlternateAI(AI_ATTACK_GROUP);
|
||||
}
|
||||
|
||||
public void stop()
|
||||
{
|
||||
setAlternateAI(AI_IDLE);
|
||||
clientStopMoving(null);
|
||||
}
|
||||
|
||||
public void move(int x, int y, int z)
|
||||
{
|
||||
moveTo(x, y, z);
|
||||
}
|
||||
|
||||
public void follow(L2Character target)
|
||||
{
|
||||
setAlternateAI(AI_FOLLOW);
|
||||
setForcedTarget(target);
|
||||
}
|
||||
|
||||
public boolean isThinking()
|
||||
{
|
||||
return _isThinking;
|
||||
}
|
||||
|
||||
public boolean isNotMoving()
|
||||
{
|
||||
return _isNotMoving;
|
||||
}
|
||||
|
||||
public void setNotMoving(boolean isNotMoving)
|
||||
{
|
||||
_isNotMoving = isNotMoving;
|
||||
}
|
||||
|
||||
public void setThinking(boolean isThinking)
|
||||
{
|
||||
_isThinking = isThinking;
|
||||
}
|
||||
|
||||
private L2Character getForcedTarget()
|
||||
{
|
||||
return _forcedTarget;
|
||||
}
|
||||
|
||||
private MobGroup getGroupTarget()
|
||||
{
|
||||
return _targetGroup;
|
||||
}
|
||||
|
||||
private void setForcedTarget(L2Character forcedTarget)
|
||||
{
|
||||
_forcedTarget = forcedTarget;
|
||||
}
|
||||
|
||||
private void setGroupTarget(MobGroup targetGroup)
|
||||
{
|
||||
_targetGroup = targetGroup;
|
||||
}
|
||||
}
|
181
trunk/java/com/l2jserver/gameserver/ai/L2DoorAI.java
Normal file
181
trunk/java/com/l2jserver/gameserver/ai/L2DoorAI.java
Normal file
@ -0,0 +1,181 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2014 L2J Server
|
||||
*
|
||||
* This file is part of L2J Server.
|
||||
*
|
||||
* L2J Server is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* L2J Server is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.gameserver.ai;
|
||||
|
||||
import com.l2jserver.gameserver.ThreadPoolManager;
|
||||
import com.l2jserver.gameserver.model.L2Object;
|
||||
import com.l2jserver.gameserver.model.Location;
|
||||
import com.l2jserver.gameserver.model.actor.L2Character;
|
||||
import com.l2jserver.gameserver.model.actor.instance.L2DefenderInstance;
|
||||
import com.l2jserver.gameserver.model.actor.instance.L2DoorInstance;
|
||||
import com.l2jserver.gameserver.model.skills.Skill;
|
||||
|
||||
/**
|
||||
* @author mkizub
|
||||
*/
|
||||
public class L2DoorAI extends L2CharacterAI
|
||||
{
|
||||
public L2DoorAI(L2DoorInstance.AIAccessor accessor)
|
||||
{
|
||||
super(accessor);
|
||||
}
|
||||
|
||||
// rather stupid AI... well, it's for doors :D
|
||||
@Override
|
||||
protected void onIntentionIdle()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onIntentionActive()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onIntentionRest()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onIntentionAttack(L2Character target)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onIntentionCast(Skill skill, L2Object target)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onIntentionMoveTo(Location destination)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onIntentionFollow(L2Character target)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onIntentionPickUp(L2Object item)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onIntentionInteract(L2Object object)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEvtThink()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEvtAttacked(L2Character attacker)
|
||||
{
|
||||
L2DoorInstance me = (L2DoorInstance) _actor;
|
||||
ThreadPoolManager.getInstance().executeGeneral(new onEventAttackedDoorTask(me, attacker));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEvtAggression(L2Character target, int aggro)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEvtStunned(L2Character attacker)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEvtSleeping(L2Character attacker)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEvtRooted(L2Character attacker)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEvtReadyToAct()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEvtUserCmd(Object arg0, Object arg1)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEvtArrived()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEvtArrivedRevalidate()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEvtArrivedBlocked(Location blocked_at_loc)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEvtForgetObject(L2Object object)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEvtCancel()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEvtDead()
|
||||
{
|
||||
}
|
||||
|
||||
private class onEventAttackedDoorTask implements Runnable
|
||||
{
|
||||
private final L2DoorInstance _door;
|
||||
private final L2Character _attacker;
|
||||
|
||||
public onEventAttackedDoorTask(L2DoorInstance door, L2Character attacker)
|
||||
{
|
||||
_door = door;
|
||||
_attacker = attacker;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
for (L2DefenderInstance guard : _door.getKnownDefenders())
|
||||
{
|
||||
if (_actor.isInsideRadius(guard, guard.getTemplate().getClanHelpRange(), false, true) && (Math.abs(_attacker.getZ() - guard.getZ()) < 200))
|
||||
{
|
||||
guard.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, _attacker, 15);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
969
trunk/java/com/l2jserver/gameserver/ai/L2FortSiegeGuardAI.java
Normal file
969
trunk/java/com/l2jserver/gameserver/ai/L2FortSiegeGuardAI.java
Normal file
@ -0,0 +1,969 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2014 L2J Server
|
||||
*
|
||||
* This file is part of L2J Server.
|
||||
*
|
||||
* L2J Server is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* L2J Server is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.gameserver.ai;
|
||||
|
||||
import static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_ACTIVE;
|
||||
import static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_ATTACK;
|
||||
import static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_IDLE;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import com.l2jserver.Config;
|
||||
import com.l2jserver.gameserver.GameTimeController;
|
||||
import com.l2jserver.gameserver.GeoData;
|
||||
import com.l2jserver.gameserver.ThreadPoolManager;
|
||||
import com.l2jserver.gameserver.model.L2Object;
|
||||
import com.l2jserver.gameserver.model.actor.L2Attackable;
|
||||
import com.l2jserver.gameserver.model.actor.L2Character;
|
||||
import com.l2jserver.gameserver.model.actor.L2Npc;
|
||||
import com.l2jserver.gameserver.model.actor.L2Playable;
|
||||
import com.l2jserver.gameserver.model.actor.L2Summon;
|
||||
import com.l2jserver.gameserver.model.actor.instance.L2DefenderInstance;
|
||||
import com.l2jserver.gameserver.model.actor.instance.L2DoorInstance;
|
||||
import com.l2jserver.gameserver.model.actor.instance.L2FortCommanderInstance;
|
||||
import com.l2jserver.gameserver.model.actor.instance.L2NpcInstance;
|
||||
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jserver.gameserver.model.effects.L2EffectType;
|
||||
import com.l2jserver.gameserver.model.skills.Skill;
|
||||
import com.l2jserver.gameserver.util.Util;
|
||||
import com.l2jserver.util.Rnd;
|
||||
|
||||
/**
|
||||
* This class manages AI of L2Attackable.
|
||||
*/
|
||||
public class L2FortSiegeGuardAI extends L2CharacterAI implements Runnable
|
||||
{
|
||||
private static final int MAX_ATTACK_TIMEOUT = 300; // int ticks, i.e. 30 seconds
|
||||
|
||||
/** The L2Attackable AI task executed every 1s (call onEvtThink method) */
|
||||
private Future<?> _aiTask;
|
||||
|
||||
/** For attack AI, analysis of mob and its targets */
|
||||
private final SelfAnalysis _selfAnalysis = new SelfAnalysis();
|
||||
|
||||
/** The delay after which the attacked is stopped */
|
||||
private int _attackTimeout;
|
||||
|
||||
/** 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
|
||||
|
||||
private final int _attackRange;
|
||||
|
||||
/**
|
||||
* Constructor of L2AttackableAI.
|
||||
* @param accessor The AI accessor of the L2Character
|
||||
*/
|
||||
public L2FortSiegeGuardAI(L2Character.AIAccessor accessor)
|
||||
{
|
||||
super(accessor);
|
||||
_selfAnalysis.init();
|
||||
_attackTimeout = Integer.MAX_VALUE;
|
||||
_globalAggro = -10; // 10 seconds timeout of ATTACK after respawn
|
||||
_attackRange = _actor.getPhysicalAttackRange();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
// Launch actions corresponding to the Event Think
|
||||
onEvtThink();
|
||||
}
|
||||
|
||||
/**
|
||||
* <B><U> Actor is a L2GuardInstance</U> :</B>
|
||||
* <ul>
|
||||
* <li>The target isn't a Folk or a Door</li>
|
||||
* <li>The target isn't dead, isn't invulnerable, isn't in silent moving mode AND too far (>100)</li>
|
||||
* <li>The target is in the actor Aggro range and is at the same height</li>
|
||||
* <li>The L2PcInstance target has karma (=PK)</li>
|
||||
* <li>The L2MonsterInstance target is aggressive</li>
|
||||
* </ul>
|
||||
* <B><U> Actor is a L2SiegeGuardInstance</U> :</B>
|
||||
* <ul>
|
||||
* <li>The target isn't a Folk or a Door</li>
|
||||
* <li>The target isn't dead, isn't invulnerable, isn't in silent moving mode AND too far (>100)</li>
|
||||
* <li>The target is in the actor Aggro range and is at the same height</li>
|
||||
* <li>A siege is in progress</li>
|
||||
* <li>The L2PcInstance target isn't a Defender</li>
|
||||
* </ul>
|
||||
* <B><U> Actor is a L2FriendlyMobInstance</U> :</B>
|
||||
* <ul>
|
||||
* <li>The target isn't a Folk, a Door or another L2NpcInstance</li>
|
||||
* <li>The target isn't dead, isn't invulnerable, isn't in silent moving mode AND too far (>100)</li>
|
||||
* <li>The target is in the actor Aggro range and is at the same height</li>
|
||||
* <li>The L2PcInstance target has karma (=PK)</li>
|
||||
* </ul>
|
||||
* <B><U> Actor is a L2MonsterInstance</U> :</B>
|
||||
* <ul>
|
||||
* <li>The target isn't a Folk, a Door or another L2NpcInstance</li>
|
||||
* <li>The target isn't dead, isn't invulnerable, isn't in silent moving mode AND too far (>100)</li>
|
||||
* <li>The target is in the actor Aggro range and is at the same height</li>
|
||||
* <li>The actor is Aggressive</li>
|
||||
* </ul>
|
||||
* @param target The targeted L2Object
|
||||
* @return True if the target is autoattackable (depends on the actor type).
|
||||
*/
|
||||
private boolean autoAttackCondition(L2Character target)
|
||||
{
|
||||
// Check if the target isn't another guard, folk or a door
|
||||
if ((target == null) || (target instanceof L2DefenderInstance) || (target instanceof L2NpcInstance) || (target instanceof L2DoorInstance) || target.isAlikeDead() || (target instanceof L2FortCommanderInstance) || (target instanceof L2Playable))
|
||||
{
|
||||
L2PcInstance player = null;
|
||||
if (target instanceof L2PcInstance)
|
||||
{
|
||||
player = ((L2PcInstance) target);
|
||||
}
|
||||
else if (target instanceof L2Summon)
|
||||
{
|
||||
player = ((L2Summon) target).getOwner();
|
||||
}
|
||||
if ((player == null) || ((player.getClan() != null) && (player.getClan().getFortId() == ((L2Npc) _actor).getFort().getResidenceId())))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the target isn't invulnerable
|
||||
if ((target != null) && target.isInvul())
|
||||
{
|
||||
// However EffectInvincible requires to check GMs specially
|
||||
if ((target instanceof L2PcInstance) && target.isGM())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ((target instanceof L2Summon) && ((L2Summon) target).getOwner().isGM())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Get the owner if the target is a summon
|
||||
if (target instanceof L2Summon)
|
||||
{
|
||||
L2PcInstance owner = ((L2Summon) target).getOwner();
|
||||
if (_actor.isInsideRadius(owner, 1000, true, false))
|
||||
{
|
||||
target = owner;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the target is a L2PcInstance
|
||||
if (target instanceof L2Playable)
|
||||
{
|
||||
// Check if the target isn't in silent move mode AND too far (>100)
|
||||
if (((L2Playable) target).isSilentMovingAffected() && !_actor.isInsideRadius(target, 250, false, false))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Los Check Here
|
||||
return (_actor.isAutoAttackable(target) && GeoData.getInstance().canSeeTarget(_actor, target));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Intention of this L2CharacterAI and create an AI Task executed every 1s (call onEvtThink method) for this L2Attackable.<br>
|
||||
* <FONT COLOR=#FF0000><B> <U>Caution</U> : If actor _knowPlayer isn't EMPTY, AI_INTENTION_IDLE will be change in AI_INTENTION_ACTIVE</B></FONT>
|
||||
* @param intention The new Intention to set to the AI
|
||||
* @param arg0 The first parameter of the Intention
|
||||
* @param arg1 The second parameter of the Intention
|
||||
*/
|
||||
@Override
|
||||
synchronized void changeIntention(CtrlIntention intention, Object arg0, Object arg1)
|
||||
{
|
||||
if (Config.DEBUG)
|
||||
{
|
||||
_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
|
||||
{
|
||||
// Check if actor is not dead
|
||||
if (!_actor.isAlikeDead())
|
||||
{
|
||||
L2Attackable npc = (L2Attackable) _actor;
|
||||
|
||||
// If its _knownPlayer isn't empty set the Intention to AI_INTENTION_ACTIVE
|
||||
if (!npc.getKnownList().getKnownPlayers().isEmpty())
|
||||
{
|
||||
intention = AI_INTENTION_ACTIVE;
|
||||
}
|
||||
else
|
||||
{
|
||||
intention = AI_INTENTION_IDLE;
|
||||
}
|
||||
}
|
||||
|
||||
if (intention == AI_INTENTION_IDLE)
|
||||
{
|
||||
// Set the Intention of this L2AttackableAI to AI_INTENTION_IDLE
|
||||
super.changeIntention(AI_INTENTION_IDLE, null, null);
|
||||
|
||||
// Stop AI task and detach AI from NPC
|
||||
if (_aiTask != null)
|
||||
{
|
||||
_aiTask.cancel(true);
|
||||
_aiTask = null;
|
||||
}
|
||||
|
||||
// Cancel the AI
|
||||
_accessor.detachAI();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Set the Intention of this L2AttackableAI to intention
|
||||
super.changeIntention(intention, arg0, arg1);
|
||||
|
||||
// If not idle - create an AI task (schedule onEvtThink repeatedly)
|
||||
if (_aiTask == null)
|
||||
{
|
||||
_aiTask = ThreadPoolManager.getInstance().scheduleAiAtFixedRate(this, 1000, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage the Attack Intention : Stop current Attack (if necessary), Calculate attack timeout, Start a new Attack and Launch Think Event.
|
||||
* @param target The L2Character to attack
|
||||
*/
|
||||
@Override
|
||||
protected void onIntentionAttack(L2Character target)
|
||||
{
|
||||
// Calculate the attack timeout
|
||||
_attackTimeout = MAX_ATTACK_TIMEOUT + GameTimeController.getInstance().getGameTicks();
|
||||
|
||||
// Manage the Attack Intention : Stop current Attack (if necessary), Start a new Attack and Launch Think Event
|
||||
// if (_actor.getTarget() != null)
|
||||
super.onIntentionAttack(target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage AI standard thinks of a L2Attackable (called by onEvtThink).<br>
|
||||
* <B><U> Actions</U> :</B>
|
||||
* <ul>
|
||||
* <li>Update every 1s the _globalAggro counter to come close to 0</li>
|
||||
* <li>If the actor is Aggressive and can attack, add all autoAttackable L2Character in its Aggro Range to its _aggroList, chose a target and order to attack it</li>
|
||||
* <li>If the actor can't attack, order to it to return to its home location</li>
|
||||
* </ul>
|
||||
*/
|
||||
private void thinkActive()
|
||||
{
|
||||
L2Attackable npc = (L2Attackable) _actor;
|
||||
|
||||
// Update every 1s the _globalAggro counter to come close to 0
|
||||
if (_globalAggro != 0)
|
||||
{
|
||||
if (_globalAggro < 0)
|
||||
{
|
||||
_globalAggro++;
|
||||
}
|
||||
else
|
||||
{
|
||||
_globalAggro--;
|
||||
}
|
||||
}
|
||||
|
||||
// Add all autoAttackable L2Character in L2Attackable Aggro Range to its _aggroList with 0 damage and 1 hate
|
||||
// A L2Attackable isn't aggressive during 10s after its spawn because _globalAggro is set to -10
|
||||
if (_globalAggro >= 0)
|
||||
{
|
||||
for (L2Character target : npc.getKnownList().getKnownCharactersInRadius(_attackRange))
|
||||
{
|
||||
if (target == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (autoAttackCondition(target)) // check aggression
|
||||
{
|
||||
// Get the hate level of the L2Attackable against this L2Character target contained in _aggroList
|
||||
int hating = npc.getHating(target);
|
||||
|
||||
// Add the attacker to the L2Attackable _aggroList with 0 damage and 1 hate
|
||||
if (hating == 0)
|
||||
{
|
||||
npc.addDamageHate(target, 0, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Chose a target from its aggroList
|
||||
L2Character hated;
|
||||
if (_actor.isConfused())
|
||||
{
|
||||
hated = getAttackTarget(); // Force mobs to attack anybody if confused
|
||||
}
|
||||
else
|
||||
{
|
||||
hated = npc.getMostHated();
|
||||
// _mostHatedAnalysis.Update(hated);
|
||||
}
|
||||
|
||||
// Order to the L2Attackable to attack the target
|
||||
if (hated != null)
|
||||
{
|
||||
// Get the hate level of the L2Attackable against this L2Character target contained in _aggroList
|
||||
int aggro = npc.getHating(hated);
|
||||
|
||||
if ((aggro + _globalAggro) > 0)
|
||||
{
|
||||
// Set the L2Character movement type to run and send Server->Client packet ChangeMoveType to all others L2PcInstance
|
||||
if (!_actor.isRunning())
|
||||
{
|
||||
_actor.setRunning();
|
||||
}
|
||||
|
||||
// Set the AI Intention to AI_INTENTION_ATTACK
|
||||
setIntention(CtrlIntention.AI_INTENTION_ATTACK, hated, null);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
// Order to the L2SiegeGuardInstance to return to its home location because there's no target to attack
|
||||
if (_actor.getWalkSpeed() >= 0)
|
||||
{
|
||||
if (_actor instanceof L2DefenderInstance)
|
||||
{
|
||||
((L2DefenderInstance) _actor).returnHome();
|
||||
}
|
||||
else
|
||||
{
|
||||
((L2FortCommanderInstance) _actor).returnHome();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage AI attack thinks of a L2Attackable (called by onEvtThink).<br>
|
||||
* <B><U> Actions</U> :</B>
|
||||
* <ul>
|
||||
* <li>Update the attack timeout if actor is running</li>
|
||||
* <li>If target is dead or timeout is expired, stop this attack and set the Intention to AI_INTENTION_ACTIVE</li>
|
||||
* <li>Call all L2Object of its Faction inside the Faction Range</li>
|
||||
* <li>Chose a target and order to attack it with magic skill or physical attack</li>
|
||||
* </ul>
|
||||
* TODO: Manage casting rules to healer mobs (like Ant Nurses)
|
||||
*/
|
||||
private void thinkAttack()
|
||||
{
|
||||
if (Config.DEBUG)
|
||||
{
|
||||
_log.warning(getClass().getSimpleName() + ": thinkAttack(); timeout=" + (_attackTimeout - GameTimeController.getInstance().getGameTicks()));
|
||||
}
|
||||
|
||||
if (_attackTimeout < GameTimeController.getInstance().getGameTicks())
|
||||
{
|
||||
// Check if the actor is running
|
||||
if (_actor.isRunning())
|
||||
{
|
||||
// Set the actor movement type to walk and send Server->Client packet ChangeMoveType to all others L2PcInstance
|
||||
_actor.setWalking();
|
||||
|
||||
// Calculate a new attack timeout
|
||||
_attackTimeout = MAX_ATTACK_TIMEOUT + GameTimeController.getInstance().getGameTicks();
|
||||
}
|
||||
}
|
||||
|
||||
L2Character attackTarget = getAttackTarget();
|
||||
// Check if target is dead or if timeout is expired to stop this attack
|
||||
if ((attackTarget == null) || attackTarget.isAlikeDead() || (_attackTimeout < GameTimeController.getInstance().getGameTicks()))
|
||||
{
|
||||
// Stop hating this target after the attack timeout or if target is dead
|
||||
if (attackTarget != null)
|
||||
{
|
||||
L2Attackable npc = (L2Attackable) _actor;
|
||||
npc.stopHating(attackTarget);
|
||||
}
|
||||
|
||||
// Cancel target and timeout
|
||||
_attackTimeout = Integer.MAX_VALUE;
|
||||
setAttackTarget(null);
|
||||
|
||||
// Set the AI Intention to AI_INTENTION_ACTIVE
|
||||
setIntention(AI_INTENTION_ACTIVE, null, null);
|
||||
|
||||
_actor.setWalking();
|
||||
return;
|
||||
}
|
||||
|
||||
factionNotifyAndSupport();
|
||||
attackPrepare();
|
||||
}
|
||||
|
||||
private final void factionNotifyAndSupport()
|
||||
{
|
||||
L2Character target = getAttackTarget();
|
||||
// Call all L2Object of its Faction inside the Faction Range
|
||||
if ((((L2Npc) _actor).getTemplate().getClans() == null) || (target == null))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (target.isInvul())
|
||||
{
|
||||
return; // speeding it up for siege guards
|
||||
}
|
||||
|
||||
// Go through all L2Character that belong to its faction
|
||||
// for (L2Character cha : _actor.getKnownList().getKnownCharactersInRadius(((L2NpcInstance) _actor).getFactionRange()+_actor.getTemplate().collisionRadius))
|
||||
for (L2Character cha : _actor.getKnownList().getKnownCharactersInRadius(1000))
|
||||
{
|
||||
if (cha == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!(cha instanceof L2Npc))
|
||||
{
|
||||
if (_selfAnalysis.hasHealOrResurrect && (cha instanceof L2PcInstance) && ((L2Npc) _actor).getFort().getSiege().checkIsDefender(((L2PcInstance) cha).getClan()))
|
||||
{
|
||||
// heal friends
|
||||
if (!_actor.isAttackingDisabled() && (cha.getCurrentHp() < (cha.getMaxHp() * 0.6)) && (_actor.getCurrentHp() > (_actor.getMaxHp() / 2)) && (_actor.getCurrentMp() > (_actor.getMaxMp() / 2)) && cha.isInCombat())
|
||||
{
|
||||
for (Skill sk : _selfAnalysis.healSkills)
|
||||
{
|
||||
if (_actor.getCurrentMp() < sk.getMpConsume())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (_actor.isSkillDisabled(sk))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!Util.checkIfInRange(sk.getCastRange(), _actor, cha, true))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int chance = 5;
|
||||
if (chance >= Rnd.get(100))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!GeoData.getInstance().canSeeTarget(_actor, cha))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
L2Object OldTarget = _actor.getTarget();
|
||||
_actor.setTarget(cha);
|
||||
clientStopMoving(null);
|
||||
_accessor.doCast(sk);
|
||||
_actor.setTarget(OldTarget);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
L2Npc npc = (L2Npc) cha;
|
||||
|
||||
if (!npc.isInMyClan((L2Npc) _actor))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (npc.getAI() != null) // TODO: possibly check not needed
|
||||
{
|
||||
if (!npc.isDead() && (Math.abs(target.getZ() - npc.getZ()) < 600)
|
||||
// && _actor.getAttackByList().contains(getAttackTarget())
|
||||
&& ((npc.getAI()._intention == CtrlIntention.AI_INTENTION_IDLE) || (npc.getAI()._intention == CtrlIntention.AI_INTENTION_ACTIVE))
|
||||
// limiting aggro for siege guards
|
||||
&& target.isInsideRadius(npc, 1500, true, false) && GeoData.getInstance().canSeeTarget(npc, target))
|
||||
{
|
||||
// Notify the L2Object AI with EVT_AGGRESSION
|
||||
npc.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, getAttackTarget(), 1);
|
||||
return;
|
||||
}
|
||||
// heal friends
|
||||
if (_selfAnalysis.hasHealOrResurrect && !_actor.isAttackingDisabled() && (npc.getCurrentHp() < (npc.getMaxHp() * 0.6)) && (_actor.getCurrentHp() > (_actor.getMaxHp() / 2)) && (_actor.getCurrentMp() > (_actor.getMaxMp() / 2)) && npc.isInCombat())
|
||||
{
|
||||
for (Skill sk : _selfAnalysis.healSkills)
|
||||
{
|
||||
if (_actor.getCurrentMp() < sk.getMpConsume())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (_actor.isSkillDisabled(sk))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!Util.checkIfInRange(sk.getCastRange(), _actor, npc, true))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int chance = 4;
|
||||
if (chance >= Rnd.get(100))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!GeoData.getInstance().canSeeTarget(_actor, npc))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
L2Object OldTarget = _actor.getTarget();
|
||||
_actor.setTarget(npc);
|
||||
clientStopMoving(null);
|
||||
_accessor.doCast(sk);
|
||||
_actor.setTarget(OldTarget);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void attackPrepare()
|
||||
{
|
||||
// Get all information needed to choose between physical or magical attack
|
||||
Collection<Skill> skills = null;
|
||||
double dist_2 = 0;
|
||||
int range = 0;
|
||||
L2DefenderInstance sGuard;
|
||||
if (_actor instanceof L2FortCommanderInstance)
|
||||
{
|
||||
sGuard = (L2FortCommanderInstance) _actor;
|
||||
}
|
||||
else
|
||||
{
|
||||
sGuard = (L2DefenderInstance) _actor;
|
||||
}
|
||||
L2Character attackTarget = getAttackTarget();
|
||||
|
||||
try
|
||||
{
|
||||
_actor.setTarget(attackTarget);
|
||||
skills = _actor.getAllSkills();
|
||||
dist_2 = _actor.calculateDistance(attackTarget, false, true);
|
||||
range = _actor.getPhysicalAttackRange() + _actor.getTemplate().getCollisionRadius() + attackTarget.getTemplate().getCollisionRadius();
|
||||
if (attackTarget.isMoving())
|
||||
{
|
||||
range += 50;
|
||||
}
|
||||
}
|
||||
catch (NullPointerException e)
|
||||
{
|
||||
// _log.warning("AttackableAI: Attack target is NULL.");
|
||||
_actor.setTarget(null);
|
||||
setIntention(AI_INTENTION_IDLE, null, null);
|
||||
return;
|
||||
}
|
||||
|
||||
// never attack defenders
|
||||
if ((attackTarget instanceof L2PcInstance) && sGuard.getFort().getSiege().checkIsDefender(((L2PcInstance) attackTarget).getClan()))
|
||||
{
|
||||
// Cancel the target
|
||||
sGuard.stopHating(attackTarget);
|
||||
_actor.setTarget(null);
|
||||
setIntention(AI_INTENTION_IDLE, null, null);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!GeoData.getInstance().canSeeTarget(_actor, attackTarget))
|
||||
{
|
||||
// Siege guards differ from normal mobs currently:
|
||||
// If target cannot seen, don't attack any more
|
||||
sGuard.stopHating(attackTarget);
|
||||
_actor.setTarget(null);
|
||||
setIntention(AI_INTENTION_IDLE, null, null);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if the actor isn't muted and if it is far from target
|
||||
if (!_actor.isMuted() && (dist_2 > (range * range)))
|
||||
{
|
||||
// check for long ranged skills and heal/buff skills
|
||||
for (Skill sk : skills)
|
||||
{
|
||||
int castRange = sk.getCastRange();
|
||||
|
||||
if ((dist_2 <= (castRange * castRange)) && (castRange > 70) && !_actor.isSkillDisabled(sk) && (_actor.getCurrentMp() >= _actor.getStat().getMpConsume(sk)) && !sk.isPassive())
|
||||
{
|
||||
|
||||
L2Object OldTarget = _actor.getTarget();
|
||||
if ((sk.isContinuous() && !sk.isDebuff()) || (sk.hasEffectType(L2EffectType.HEAL)))
|
||||
{
|
||||
boolean useSkillSelf = true;
|
||||
if ((sk.hasEffectType(L2EffectType.HEAL)) && (_actor.getCurrentHp() > (int) (_actor.getMaxHp() / 1.5)))
|
||||
{
|
||||
useSkillSelf = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if ((sk.isContinuous() && !sk.isDebuff()) && _actor.isAffectedBySkill(sk.getId()))
|
||||
{
|
||||
useSkillSelf = false;
|
||||
}
|
||||
|
||||
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.getSpawn().getX();
|
||||
double homeY = attackTarget.getY() - sGuard.getSpawn().getY();
|
||||
|
||||
// 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
|
||||
{
|
||||
if (_selfAnalysis.isMage)
|
||||
{
|
||||
range = _selfAnalysis.maxCastRange - 50;
|
||||
}
|
||||
if (_actor.getWalkSpeed() <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (attackTarget.isMoving())
|
||||
{
|
||||
moveToPawn(attackTarget, range - 70);
|
||||
}
|
||||
else
|
||||
{
|
||||
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 * range)))
|
||||
{
|
||||
// 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
|
||||
{
|
||||
if (_selfAnalysis.isMage)
|
||||
{
|
||||
range = _selfAnalysis.maxCastRange - 50;
|
||||
}
|
||||
if (_actor.getWalkSpeed() <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (attackTarget.isMoving())
|
||||
{
|
||||
moveToPawn(attackTarget, range - 70);
|
||||
}
|
||||
else
|
||||
{
|
||||
moveToPawn(attackTarget, range);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Else, if this is close enough to attack
|
||||
else if (dist_2 <= (range * range))
|
||||
{
|
||||
// Force mobs to attack 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.getInstance().getGameTicks();
|
||||
|
||||
// check for close combat skills && heal/buff skills
|
||||
if (!_actor.isMuted() && (Rnd.nextInt(100) <= 5))
|
||||
{
|
||||
for (Skill sk : skills)
|
||||
{
|
||||
int castRange = sk.getCastRange();
|
||||
|
||||
if (((castRange * castRange) >= dist_2) && !sk.isPassive() && (_actor.getCurrentMp() >= _actor.getStat().getMpConsume(sk)) && !_actor.isSkillDisabled(sk))
|
||||
{
|
||||
L2Object OldTarget = _actor.getTarget();
|
||||
if ((sk.isContinuous() && !sk.isDebuff()) || (sk.hasEffectType(L2EffectType.HEAL)))
|
||||
{
|
||||
boolean useSkillSelf = true;
|
||||
if ((sk.hasEffectType(L2EffectType.HEAL)) && (_actor.getCurrentHp() > (int) (_actor.getMaxHp() / 1.5)))
|
||||
{
|
||||
useSkillSelf = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if ((sk.isContinuous() && !sk.isDebuff()) && _actor.isAffectedBySkill(sk.getId()))
|
||||
{
|
||||
useSkillSelf = false;
|
||||
}
|
||||
|
||||
if (useSkillSelf)
|
||||
{
|
||||
_actor.setTarget(_actor);
|
||||
}
|
||||
}
|
||||
|
||||
clientStopMoving(null);
|
||||
_accessor.doCast(sk);
|
||||
_actor.setTarget(OldTarget);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Finally, do the physical attack itself
|
||||
_accessor.doAttack(attackTarget);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage AI thinking actions of a L2Attackable.
|
||||
*/
|
||||
@Override
|
||||
protected void onEvtThink()
|
||||
{
|
||||
// if(getIntention() != AI_INTENTION_IDLE && (!_actor.isVisible() || !_actor.hasAI() || !_actor.isKnownPlayers()))
|
||||
// setIntention(AI_INTENTION_IDLE);
|
||||
|
||||
// Check if the actor can't use skills and if a thinking action isn't already in progress
|
||||
if (_thinking || _actor.isCastingNow() || _actor.isAllSkillsDisabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Start thinking action
|
||||
_thinking = true;
|
||||
|
||||
try
|
||||
{
|
||||
// Manage AI thinks of a L2Attackable
|
||||
if (getIntention() == AI_INTENTION_ACTIVE)
|
||||
{
|
||||
thinkActive();
|
||||
}
|
||||
else if (getIntention() == AI_INTENTION_ATTACK)
|
||||
{
|
||||
thinkAttack();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Stop thinking action
|
||||
_thinking = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Launch actions corresponding to the Event Attacked.<br>
|
||||
* <B><U> Actions</U> :</B>
|
||||
* <ul>
|
||||
* <li>Init the attack : Calculate the attack timeout, Set the _globalAggro to 0, Add the attacker to the actor _aggroList</li>
|
||||
* <li>Set the L2Character movement type to run and send Server->Client packet ChangeMoveType to all others L2PcInstance</li>
|
||||
* <li>Set the Intention to AI_INTENTION_ATTACK</li>
|
||||
* </ul>
|
||||
* @param attacker The L2Character that attacks the actor
|
||||
*/
|
||||
@Override
|
||||
protected void onEvtAttacked(L2Character attacker)
|
||||
{
|
||||
// Calculate the attack timeout
|
||||
_attackTimeout = MAX_ATTACK_TIMEOUT + GameTimeController.getInstance().getGameTicks();
|
||||
|
||||
// Set the _globalAggro to 0 to permit attack even just after spawn
|
||||
if (_globalAggro < 0)
|
||||
{
|
||||
_globalAggro = 0;
|
||||
}
|
||||
|
||||
// Add the attacker to the _aggroList of the actor
|
||||
((L2Attackable) _actor).addDamageHate(attacker, 0, 1);
|
||||
|
||||
// Set the L2Character movement type to run and send Server->Client packet ChangeMoveType to all others L2PcInstance
|
||||
if (!_actor.isRunning())
|
||||
{
|
||||
_actor.setRunning();
|
||||
}
|
||||
|
||||
// Set the Intention to AI_INTENTION_ATTACK
|
||||
if (getIntention() != AI_INTENTION_ATTACK)
|
||||
{
|
||||
setIntention(CtrlIntention.AI_INTENTION_ATTACK, attacker, null);
|
||||
}
|
||||
|
||||
super.onEvtAttacked(attacker);
|
||||
}
|
||||
|
||||
/**
|
||||
* Launch actions corresponding to the Event Aggression.<br>
|
||||
* <B><U> Actions</U> :</B>
|
||||
* <ul>
|
||||
* <li>Add the target to the actor _aggroList or update hate if already present</li>
|
||||
* <li>Set the actor Intention to AI_INTENTION_ATTACK (if actor is L2GuardInstance check if it isn't too far from its home location)</li>
|
||||
* </ul>
|
||||
* @param aggro The value of hate to add to the actor against the target
|
||||
*/
|
||||
@Override
|
||||
protected void onEvtAggression(L2Character target, int aggro)
|
||||
{
|
||||
if (_actor == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
L2Attackable me = (L2Attackable) _actor;
|
||||
|
||||
if (target != null)
|
||||
{
|
||||
// Add the target to the actor _aggroList or update hate if already present
|
||||
me.addDamageHate(target, 0, aggro);
|
||||
|
||||
// Get the hate of the actor against the target
|
||||
aggro = me.getHating(target);
|
||||
|
||||
if (aggro <= 0)
|
||||
{
|
||||
if (me.getMostHated() == null)
|
||||
{
|
||||
_globalAggro = -25;
|
||||
me.clearAggroList();
|
||||
setIntention(AI_INTENTION_IDLE, null, null);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Set the actor AI Intention to AI_INTENTION_ATTACK
|
||||
if (getIntention() != CtrlIntention.AI_INTENTION_ATTACK)
|
||||
{
|
||||
// Set the L2Character movement type to run and send Server->Client packet ChangeMoveType to all others L2PcInstance
|
||||
if (!_actor.isRunning())
|
||||
{
|
||||
_actor.setRunning();
|
||||
}
|
||||
|
||||
L2DefenderInstance sGuard;
|
||||
if (_actor instanceof L2FortCommanderInstance)
|
||||
{
|
||||
sGuard = (L2FortCommanderInstance) _actor;
|
||||
}
|
||||
else
|
||||
{
|
||||
sGuard = (L2DefenderInstance) _actor;
|
||||
}
|
||||
double homeX = target.getX() - sGuard.getSpawn().getX();
|
||||
double homeY = target.getY() - sGuard.getSpawn().getY();
|
||||
|
||||
// Check if the L2SiegeGuardInstance is not too far from its home location
|
||||
if (((homeX * homeX) + (homeY * homeY)) < 3240000)
|
||||
{
|
||||
setIntention(CtrlIntention.AI_INTENTION_ATTACK, target, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// currently only for setting lower general aggro
|
||||
if (aggro >= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
L2Character mostHated = me.getMostHated();
|
||||
if (mostHated == null)
|
||||
{
|
||||
_globalAggro = -25;
|
||||
return;
|
||||
}
|
||||
|
||||
for (L2Character aggroed : me.getAggroList().keySet())
|
||||
{
|
||||
me.addDamageHate(aggroed, 0, aggro);
|
||||
}
|
||||
|
||||
aggro = me.getHating(mostHated);
|
||||
if (aggro <= 0)
|
||||
{
|
||||
_globalAggro = -25;
|
||||
me.clearAggroList();
|
||||
setIntention(AI_INTENTION_IDLE, null, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopAITask()
|
||||
{
|
||||
if (_aiTask != null)
|
||||
{
|
||||
_aiTask.cancel(false);
|
||||
_aiTask = null;
|
||||
}
|
||||
_accessor.detachAI();
|
||||
super.stopAITask();
|
||||
}
|
||||
}
|
121
trunk/java/com/l2jserver/gameserver/ai/L2PlayableAI.java
Normal file
121
trunk/java/com/l2jserver/gameserver/ai/L2PlayableAI.java
Normal file
@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2014 L2J Server
|
||||
*
|
||||
* This file is part of L2J Server.
|
||||
*
|
||||
* L2J Server is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* L2J Server is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.gameserver.ai;
|
||||
|
||||
import com.l2jserver.gameserver.model.L2Object;
|
||||
import com.l2jserver.gameserver.model.actor.L2Character;
|
||||
import com.l2jserver.gameserver.model.actor.L2Character.AIAccessor;
|
||||
import com.l2jserver.gameserver.model.actor.L2Playable;
|
||||
import com.l2jserver.gameserver.model.skills.Skill;
|
||||
import com.l2jserver.gameserver.model.zone.ZoneId;
|
||||
import com.l2jserver.gameserver.network.SystemMessageId;
|
||||
|
||||
/**
|
||||
* This class manages AI of L2Playable.<br>
|
||||
* L2PlayableAI : <li>L2SummonAI</li> <li>L2PlayerAI</li>
|
||||
* @author JIV
|
||||
*/
|
||||
public abstract class L2PlayableAI extends L2CharacterAI
|
||||
{
|
||||
/**
|
||||
* @param accessor
|
||||
*/
|
||||
public L2PlayableAI(AIAccessor accessor)
|
||||
{
|
||||
super(accessor);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onIntentionAttack(L2Character target)
|
||||
{
|
||||
if (target instanceof L2Playable)
|
||||
{
|
||||
if (target.getActingPlayer().isProtectionBlessingAffected() && ((_actor.getActingPlayer().getLevel() - target.getActingPlayer().getLevel()) >= 10) && (_actor.getActingPlayer().getKarma() > 0) && !(target.isInsideZone(ZoneId.PVP)))
|
||||
{
|
||||
// If attacker have karma and have level >= 10 than his target and target have
|
||||
// Newbie Protection Buff,
|
||||
_actor.getActingPlayer().sendPacket(SystemMessageId.THAT_IS_AN_INCORRECT_TARGET);
|
||||
clientActionFailed();
|
||||
return;
|
||||
}
|
||||
|
||||
if (_actor.getActingPlayer().isProtectionBlessingAffected() && ((target.getActingPlayer().getLevel() - _actor.getActingPlayer().getLevel()) >= 10) && (target.getActingPlayer().getKarma() > 0) && !(target.isInsideZone(ZoneId.PVP)))
|
||||
{
|
||||
// If target have karma and have level >= 10 than his target and actor have
|
||||
// Newbie Protection Buff,
|
||||
_actor.getActingPlayer().sendPacket(SystemMessageId.THAT_IS_AN_INCORRECT_TARGET);
|
||||
clientActionFailed();
|
||||
return;
|
||||
}
|
||||
|
||||
if (target.getActingPlayer().isCursedWeaponEquipped() && (_actor.getActingPlayer().getLevel() <= 20))
|
||||
{
|
||||
_actor.getActingPlayer().sendPacket(SystemMessageId.THAT_IS_AN_INCORRECT_TARGET);
|
||||
clientActionFailed();
|
||||
return;
|
||||
}
|
||||
|
||||
if (_actor.getActingPlayer().isCursedWeaponEquipped() && (target.getActingPlayer().getLevel() <= 20))
|
||||
{
|
||||
_actor.getActingPlayer().sendPacket(SystemMessageId.THAT_IS_AN_INCORRECT_TARGET);
|
||||
clientActionFailed();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
super.onIntentionAttack(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onIntentionCast(Skill skill, L2Object target)
|
||||
{
|
||||
if ((target instanceof L2Playable) && skill.isBad())
|
||||
{
|
||||
if (target.getActingPlayer().isProtectionBlessingAffected() && ((_actor.getActingPlayer().getLevel() - target.getActingPlayer().getLevel()) >= 10) && (_actor.getActingPlayer().getKarma() > 0) && !target.isInsideZone(ZoneId.PVP))
|
||||
{
|
||||
// If attacker have karma and have level >= 10 than his target and target have
|
||||
// Newbie Protection Buff,
|
||||
_actor.getActingPlayer().sendPacket(SystemMessageId.THAT_IS_AN_INCORRECT_TARGET);
|
||||
clientActionFailed();
|
||||
_actor.setIsCastingNow(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_actor.getActingPlayer().isProtectionBlessingAffected() && ((target.getActingPlayer().getLevel() - _actor.getActingPlayer().getLevel()) >= 10) && (target.getActingPlayer().getKarma() > 0) && !target.isInsideZone(ZoneId.PVP))
|
||||
{
|
||||
// If target have karma and have level >= 10 than his target and actor have
|
||||
// Newbie Protection Buff,
|
||||
_actor.getActingPlayer().sendPacket(SystemMessageId.THAT_IS_AN_INCORRECT_TARGET);
|
||||
clientActionFailed();
|
||||
_actor.setIsCastingNow(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (target.getActingPlayer().isCursedWeaponEquipped() && ((_actor.getActingPlayer().getLevel() <= 20) || (target.getActingPlayer().getLevel() <= 20)))
|
||||
{
|
||||
_actor.getActingPlayer().sendPacket(SystemMessageId.THAT_IS_AN_INCORRECT_TARGET);
|
||||
clientActionFailed();
|
||||
_actor.setIsCastingNow(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
super.onIntentionCast(skill, target);
|
||||
}
|
||||
|
||||
}
|
358
trunk/java/com/l2jserver/gameserver/ai/L2PlayerAI.java
Normal file
358
trunk/java/com/l2jserver/gameserver/ai/L2PlayerAI.java
Normal file
@ -0,0 +1,358 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2014 L2J Server
|
||||
*
|
||||
* This file is part of L2J Server.
|
||||
*
|
||||
* L2J Server is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* L2J Server is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.gameserver.ai;
|
||||
|
||||
import static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_ATTACK;
|
||||
import static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_CAST;
|
||||
import static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_IDLE;
|
||||
import static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_INTERACT;
|
||||
import static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_MOVE_TO;
|
||||
import static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_PICK_UP;
|
||||
import static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_REST;
|
||||
|
||||
import com.l2jserver.gameserver.model.L2Object;
|
||||
import com.l2jserver.gameserver.model.Location;
|
||||
import com.l2jserver.gameserver.model.actor.L2Character;
|
||||
import com.l2jserver.gameserver.model.actor.L2Character.AIAccessor;
|
||||
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jserver.gameserver.model.actor.instance.L2StaticObjectInstance;
|
||||
import com.l2jserver.gameserver.model.skills.Skill;
|
||||
import com.l2jserver.gameserver.model.skills.targets.L2TargetType;
|
||||
|
||||
public class L2PlayerAI extends L2PlayableAI
|
||||
{
|
||||
private boolean _thinking; // to prevent recursive thinking
|
||||
|
||||
IntentionCommand _nextIntention = null;
|
||||
|
||||
public L2PlayerAI(AIAccessor accessor)
|
||||
{
|
||||
super(accessor);
|
||||
}
|
||||
|
||||
void saveNextIntention(CtrlIntention intention, Object arg0, Object arg1)
|
||||
{
|
||||
_nextIntention = new IntentionCommand(intention, arg0, arg1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntentionCommand getNextIntention()
|
||||
{
|
||||
return _nextIntention;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the current Intention for this L2PlayerAI if necessary and calls changeIntention in AbstractAI.
|
||||
* @param intention The new Intention to set to the AI
|
||||
* @param arg0 The first parameter of the Intention
|
||||
* @param arg1 The second parameter of the Intention
|
||||
*/
|
||||
@Override
|
||||
protected synchronized void changeIntention(CtrlIntention intention, Object arg0, Object arg1)
|
||||
{
|
||||
// do nothing unless CAST intention
|
||||
// however, forget interrupted actions when starting to use an offensive skill
|
||||
if ((intention != AI_INTENTION_CAST) || ((arg0 != null) && ((Skill) arg0).isBad()))
|
||||
{
|
||||
_nextIntention = null;
|
||||
super.changeIntention(intention, arg0, arg1);
|
||||
return;
|
||||
}
|
||||
|
||||
// do nothing if next intention is same as current one.
|
||||
if ((intention == _intention) && (arg0 == _intentionArg0) && (arg1 == _intentionArg1))
|
||||
{
|
||||
super.changeIntention(intention, arg0, arg1);
|
||||
return;
|
||||
}
|
||||
|
||||
// save current intention so it can be used after cast
|
||||
saveNextIntention(_intention, _intentionArg0, _intentionArg1);
|
||||
super.changeIntention(intention, arg0, arg1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Launch actions corresponding to the Event ReadyToAct.<br>
|
||||
* <B><U> Actions</U> :</B>
|
||||
* <ul>
|
||||
* <li>Launch actions corresponding to the Event Think</li>
|
||||
* </ul>
|
||||
*/
|
||||
@Override
|
||||
protected void onEvtReadyToAct()
|
||||
{
|
||||
// Launch actions corresponding to the Event Think
|
||||
if (_nextIntention != null)
|
||||
{
|
||||
setIntention(_nextIntention._crtlIntention, _nextIntention._arg0, _nextIntention._arg1);
|
||||
_nextIntention = null;
|
||||
}
|
||||
super.onEvtReadyToAct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Launch actions corresponding to the Event Cancel.<br>
|
||||
* <B><U> Actions</U> :</B>
|
||||
* <ul>
|
||||
* <li>Stop an AI Follow Task</li>
|
||||
* <li>Launch actions corresponding to the Event Think</li>
|
||||
* </ul>
|
||||
*/
|
||||
@Override
|
||||
protected void onEvtCancel()
|
||||
{
|
||||
_nextIntention = null;
|
||||
super.onEvtCancel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Finalize the casting of a skill. This method overrides L2CharacterAI method.<br>
|
||||
* <B>What it does:</B><br>
|
||||
* Check if actual intention is set to CAST and, if so, retrieves latest intention before the actual CAST and set it as the current intention for the player.
|
||||
*/
|
||||
@Override
|
||||
protected void onEvtFinishCasting()
|
||||
{
|
||||
if (getIntention() == AI_INTENTION_CAST)
|
||||
{
|
||||
// run interrupted or next intention
|
||||
|
||||
IntentionCommand nextIntention = _nextIntention;
|
||||
if (nextIntention != null)
|
||||
{
|
||||
if (nextIntention._crtlIntention != AI_INTENTION_CAST) // previous state shouldn't be casting
|
||||
{
|
||||
setIntention(nextIntention._crtlIntention, nextIntention._arg0, nextIntention._arg1);
|
||||
}
|
||||
else
|
||||
{
|
||||
setIntention(AI_INTENTION_IDLE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// set intention to idle if skill doesn't change intention.
|
||||
setIntention(AI_INTENTION_IDLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onIntentionRest()
|
||||
{
|
||||
if (getIntention() != AI_INTENTION_REST)
|
||||
{
|
||||
changeIntention(AI_INTENTION_REST, null, null);
|
||||
setTarget(null);
|
||||
if (getAttackTarget() != null)
|
||||
{
|
||||
setAttackTarget(null);
|
||||
}
|
||||
clientStopMoving(null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onIntentionActive()
|
||||
{
|
||||
setIntention(AI_INTENTION_IDLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage the Move To Intention : Stop current Attack and Launch a Move to Location Task.<br>
|
||||
* <B><U> Actions</U> : </B>
|
||||
* <ul>
|
||||
* <li>Stop the actor auto-attack server side AND client side by sending Server->Client packet AutoAttackStop (broadcast)</li>
|
||||
* <li>Set the Intention of this AI to AI_INTENTION_MOVE_TO</li>
|
||||
* <li>Move the actor to Location (x,y,z) server side AND client side by sending Server->Client packet CharMoveToLocation (broadcast)</li>
|
||||
* </ul>
|
||||
*/
|
||||
@Override
|
||||
protected void onIntentionMoveTo(Location loc)
|
||||
{
|
||||
if (getIntention() == AI_INTENTION_REST)
|
||||
{
|
||||
// Cancel action client side by sending Server->Client packet ActionFailed to the L2PcInstance actor
|
||||
clientActionFailed();
|
||||
return;
|
||||
}
|
||||
|
||||
if (_actor.isAllSkillsDisabled() || _actor.isCastingNow() || _actor.isAttackingNow())
|
||||
{
|
||||
clientActionFailed();
|
||||
saveNextIntention(AI_INTENTION_MOVE_TO, loc, null);
|
||||
return;
|
||||
}
|
||||
|
||||
// Set the Intention of this AbstractAI to AI_INTENTION_MOVE_TO
|
||||
changeIntention(AI_INTENTION_MOVE_TO, loc, null);
|
||||
|
||||
// Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
|
||||
clientStopAutoAttack();
|
||||
|
||||
// Abort the attack of the L2Character and send Server->Client ActionFailed packet
|
||||
_actor.abortAttack();
|
||||
|
||||
// Move the actor to Location (x,y,z) server side AND client side by sending Server->Client packet CharMoveToLocation (broadcast)
|
||||
moveTo(loc.getX(), loc.getY(), loc.getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void clientNotifyDead()
|
||||
{
|
||||
_clientMovingToPawnOffset = 0;
|
||||
_clientMoving = false;
|
||||
|
||||
super.clientNotifyDead();
|
||||
}
|
||||
|
||||
private void thinkAttack()
|
||||
{
|
||||
L2Character target = getAttackTarget();
|
||||
if (target == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (checkTargetLostOrDead(target))
|
||||
{
|
||||
// Notify the target
|
||||
setAttackTarget(null);
|
||||
return;
|
||||
}
|
||||
if (maybeMoveToPawn(target, _actor.getPhysicalAttackRange()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_accessor.doAttack(target);
|
||||
}
|
||||
|
||||
private void thinkCast()
|
||||
{
|
||||
L2Character target = getCastTarget();
|
||||
if ((_skill.getTargetType() == L2TargetType.GROUND) && (_actor instanceof L2PcInstance))
|
||||
{
|
||||
if (maybeMoveToPosition(((L2PcInstance) _actor).getCurrentSkillWorldPosition(), _actor.getMagicalAttackRange(_skill)))
|
||||
{
|
||||
_actor.setIsCastingNow(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (checkTargetLost(target))
|
||||
{
|
||||
if (_skill.isBad() && (getAttackTarget() != null))
|
||||
{
|
||||
// Notify the target
|
||||
setCastTarget(null);
|
||||
}
|
||||
_actor.setIsCastingNow(false);
|
||||
return;
|
||||
}
|
||||
if ((target != null) && maybeMoveToPawn(target, _actor.getMagicalAttackRange(_skill)))
|
||||
{
|
||||
_actor.setIsCastingNow(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ((_skill.getHitTime() > 50) && !_skill.isSimultaneousCast())
|
||||
{
|
||||
clientStopMoving(null);
|
||||
}
|
||||
|
||||
_accessor.doCast(_skill);
|
||||
}
|
||||
|
||||
private void thinkPickUp()
|
||||
{
|
||||
if (_actor.isAllSkillsDisabled() || _actor.isCastingNow())
|
||||
{
|
||||
return;
|
||||
}
|
||||
L2Object target = getTarget();
|
||||
if (checkTargetLost(target))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (maybeMoveToPawn(target, 36))
|
||||
{
|
||||
return;
|
||||
}
|
||||
setIntention(AI_INTENTION_IDLE);
|
||||
((L2PcInstance.AIAccessor) _accessor).doPickupItem(target);
|
||||
}
|
||||
|
||||
private void thinkInteract()
|
||||
{
|
||||
if (_actor.isAllSkillsDisabled() || _actor.isCastingNow())
|
||||
{
|
||||
return;
|
||||
}
|
||||
L2Object target = getTarget();
|
||||
if (checkTargetLost(target))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (maybeMoveToPawn(target, 36))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!(target instanceof L2StaticObjectInstance))
|
||||
{
|
||||
((L2PcInstance.AIAccessor) _accessor).doInteract((L2Character) target);
|
||||
}
|
||||
setIntention(AI_INTENTION_IDLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEvtThink()
|
||||
{
|
||||
if (_thinking && (getIntention() != AI_INTENTION_CAST))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_thinking = true;
|
||||
try
|
||||
{
|
||||
if (getIntention() == AI_INTENTION_ATTACK)
|
||||
{
|
||||
thinkAttack();
|
||||
}
|
||||
else if (getIntention() == AI_INTENTION_CAST)
|
||||
{
|
||||
thinkCast();
|
||||
}
|
||||
else if (getIntention() == AI_INTENTION_PICK_UP)
|
||||
{
|
||||
thinkPickUp();
|
||||
}
|
||||
else if (getIntention() == AI_INTENTION_INTERACT)
|
||||
{
|
||||
thinkInteract();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_thinking = false;
|
||||
}
|
||||
}
|
||||
}
|
51
trunk/java/com/l2jserver/gameserver/ai/L2ShuttleAI.java
Normal file
51
trunk/java/com/l2jserver/gameserver/ai/L2ShuttleAI.java
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2014 L2J Server
|
||||
*
|
||||
* This file is part of L2J Server.
|
||||
*
|
||||
* L2J Server is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* L2J Server is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.gameserver.ai;
|
||||
|
||||
import com.l2jserver.gameserver.model.actor.instance.L2AirShipInstance;
|
||||
import com.l2jserver.gameserver.model.actor.instance.L2ShuttleInstance;
|
||||
import com.l2jserver.gameserver.network.serverpackets.shuttle.ExShuttleMove;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class L2ShuttleAI extends L2VehicleAI
|
||||
{
|
||||
public L2ShuttleAI(L2AirShipInstance.AIAccessor accessor)
|
||||
{
|
||||
super(accessor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveTo(int x, int y, int z)
|
||||
{
|
||||
if (!_actor.isMovementDisabled())
|
||||
{
|
||||
_clientMoving = true;
|
||||
_accessor.moveTo(x, y, z);
|
||||
_actor.broadcastPacket(new ExShuttleMove(getActor(), x, y, z));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public L2ShuttleInstance getActor()
|
||||
{
|
||||
return (L2ShuttleInstance) _actor;
|
||||
}
|
||||
}
|
933
trunk/java/com/l2jserver/gameserver/ai/L2SiegeGuardAI.java
Normal file
933
trunk/java/com/l2jserver/gameserver/ai/L2SiegeGuardAI.java
Normal file
@ -0,0 +1,933 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2014 L2J Server
|
||||
*
|
||||
* This file is part of L2J Server.
|
||||
*
|
||||
* L2J Server is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* L2J Server is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.gameserver.ai;
|
||||
|
||||
import static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_ACTIVE;
|
||||
import static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_ATTACK;
|
||||
import static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_IDLE;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import com.l2jserver.Config;
|
||||
import com.l2jserver.gameserver.GameTimeController;
|
||||
import com.l2jserver.gameserver.GeoData;
|
||||
import com.l2jserver.gameserver.ThreadPoolManager;
|
||||
import com.l2jserver.gameserver.model.L2Object;
|
||||
import com.l2jserver.gameserver.model.actor.L2Attackable;
|
||||
import com.l2jserver.gameserver.model.actor.L2Character;
|
||||
import com.l2jserver.gameserver.model.actor.L2Npc;
|
||||
import com.l2jserver.gameserver.model.actor.L2Playable;
|
||||
import com.l2jserver.gameserver.model.actor.L2Summon;
|
||||
import com.l2jserver.gameserver.model.actor.instance.L2DefenderInstance;
|
||||
import com.l2jserver.gameserver.model.actor.instance.L2DoorInstance;
|
||||
import com.l2jserver.gameserver.model.actor.instance.L2NpcInstance;
|
||||
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jserver.gameserver.model.effects.L2EffectType;
|
||||
import com.l2jserver.gameserver.model.skills.Skill;
|
||||
import com.l2jserver.gameserver.util.Util;
|
||||
import com.l2jserver.util.Rnd;
|
||||
|
||||
/**
|
||||
* This class manages AI of L2Attackable.
|
||||
*/
|
||||
public class L2SiegeGuardAI extends L2CharacterAI implements Runnable
|
||||
{
|
||||
private static final int MAX_ATTACK_TIMEOUT = 300; // int ticks, i.e. 30 seconds
|
||||
|
||||
/** The L2Attackable AI task executed every 1s (call onEvtThink method) */
|
||||
private Future<?> _aiTask;
|
||||
|
||||
/** For attack AI, analysis of mob and its targets */
|
||||
private final SelfAnalysis _selfAnalysis = new SelfAnalysis();
|
||||
// private TargetAnalysis _mostHatedAnalysis = new TargetAnalysis();
|
||||
|
||||
/** The delay after which the attacked is stopped */
|
||||
private int _attackTimeout;
|
||||
|
||||
/** 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
|
||||
|
||||
private final int _attackRange;
|
||||
|
||||
/**
|
||||
* Constructor of L2AttackableAI.
|
||||
* @param accessor The AI accessor of the L2Character
|
||||
*/
|
||||
public L2SiegeGuardAI(L2Character.AIAccessor accessor)
|
||||
{
|
||||
super(accessor);
|
||||
_selfAnalysis.init();
|
||||
_attackTimeout = Integer.MAX_VALUE;
|
||||
_globalAggro = -10; // 10 seconds timeout of ATTACK after respawn
|
||||
_attackRange = _actor.getPhysicalAttackRange();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
// Launch actions corresponding to the Event Think
|
||||
onEvtThink();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* <B><U> Actor is a L2GuardInstance</U> :</B>
|
||||
* <ul>
|
||||
* <li>The target isn't a Folk or a Door</li>
|
||||
* <li>The target isn't dead, isn't invulnerable, isn't in silent moving mode AND too far (>100)</li>
|
||||
* <li>The target is in the actor Aggro range and is at the same height</li>
|
||||
* <li>The L2PcInstance target has karma (=PK)</li>
|
||||
* <li>The L2MonsterInstance target is aggressive</li>
|
||||
* </ul>
|
||||
* <B><U> Actor is a L2SiegeGuardInstance</U> :</B>
|
||||
* <ul>
|
||||
* <li>The target isn't a Folk or a Door</li>
|
||||
* <li>The target isn't dead, isn't invulnerable, isn't in silent moving mode AND too far (>100)</li>
|
||||
* <li>The target is in the actor Aggro range and is at the same height</li>
|
||||
* <li>A siege is in progress</li>
|
||||
* <li>The L2PcInstance target isn't a Defender</li>
|
||||
* </ul>
|
||||
* <B><U> Actor is a L2FriendlyMobInstance</U> :</B>
|
||||
* <ul>
|
||||
* <li>The target isn't a Folk, a Door or another L2NpcInstance</li>
|
||||
* <li>The target isn't dead, isn't invulnerable, isn't in silent moving mode AND too far (>100)</li>
|
||||
* <li>The target is in the actor Aggro range and is at the same height</li>
|
||||
* <li>The L2PcInstance target has karma (=PK)</li>
|
||||
* </ul>
|
||||
* <B><U> Actor is a L2MonsterInstance</U> :</B>
|
||||
* <ul>
|
||||
* <li>The target isn't a Folk, a Door or another L2NpcInstance</li>
|
||||
* <li>The target isn't dead, isn't invulnerable, isn't in silent moving mode AND too far (>100)</li>
|
||||
* <li>The target is in the actor Aggro range and is at the same height</li>
|
||||
* <li>The actor is Aggressive</li>
|
||||
* </ul>
|
||||
* @param target The targeted L2Object
|
||||
* @return True if the target is autoattackable (depends on the actor type).
|
||||
*/
|
||||
protected boolean autoAttackCondition(L2Character target)
|
||||
{
|
||||
// Check if the target isn't another guard, folk or a door
|
||||
if ((target == null) || (target instanceof L2DefenderInstance) || (target instanceof L2NpcInstance) || (target instanceof L2DoorInstance) || target.isAlikeDead())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if the target isn't invulnerable
|
||||
if (target.isInvul())
|
||||
{
|
||||
// However EffectInvincible requires to check GMs specially
|
||||
if ((target instanceof L2PcInstance) && target.isGM())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ((target instanceof L2Summon) && ((L2Summon) target).getOwner().isGM())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Get the owner if the target is a summon
|
||||
if (target instanceof L2Summon)
|
||||
{
|
||||
L2PcInstance owner = ((L2Summon) target).getOwner();
|
||||
if (_actor.isInsideRadius(owner, 1000, true, false))
|
||||
{
|
||||
target = owner;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the target is a L2PcInstance
|
||||
if (target instanceof L2Playable)
|
||||
{
|
||||
// Check if the target isn't in silent move mode AND too far (>100)
|
||||
if (((L2Playable) target).isSilentMovingAffected() && !_actor.isInsideRadius(target, 250, false, false))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Los Check Here
|
||||
return (_actor.isAutoAttackable(target) && GeoData.getInstance().canSeeTarget(_actor, target));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Intention of this L2CharacterAI and create an AI Task executed every 1s (call onEvtThink method) for this L2Attackable.<br>
|
||||
* <FONT COLOR=#FF0000><B> <U>Caution</U> : If actor _knowPlayer isn't EMPTY, AI_INTENTION_IDLE will be change in AI_INTENTION_ACTIVE</B></FONT>
|
||||
* @param intention The new Intention to set to the AI
|
||||
* @param arg0 The first parameter of the Intention
|
||||
* @param arg1 The second parameter of the Intention
|
||||
*/
|
||||
@Override
|
||||
synchronized void changeIntention(CtrlIntention intention, Object arg0, Object arg1)
|
||||
{
|
||||
if (Config.DEBUG)
|
||||
{
|
||||
_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
|
||||
{
|
||||
// Check if actor is not dead
|
||||
if (!_actor.isAlikeDead())
|
||||
{
|
||||
L2Attackable npc = (L2Attackable) _actor;
|
||||
|
||||
// If its _knownPlayer isn't empty set the Intention to AI_INTENTION_ACTIVE
|
||||
if (!npc.getKnownList().getKnownPlayers().isEmpty())
|
||||
{
|
||||
intention = AI_INTENTION_ACTIVE;
|
||||
}
|
||||
else
|
||||
{
|
||||
intention = AI_INTENTION_IDLE;
|
||||
}
|
||||
}
|
||||
|
||||
if (intention == AI_INTENTION_IDLE)
|
||||
{
|
||||
// Set the Intention of this L2AttackableAI to AI_INTENTION_IDLE
|
||||
super.changeIntention(AI_INTENTION_IDLE, null, null);
|
||||
|
||||
// Stop AI task and detach AI from NPC
|
||||
if (_aiTask != null)
|
||||
{
|
||||
_aiTask.cancel(true);
|
||||
_aiTask = null;
|
||||
}
|
||||
|
||||
// Cancel the AI
|
||||
_accessor.detachAI();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Set the Intention of this L2AttackableAI to intention
|
||||
super.changeIntention(intention, arg0, arg1);
|
||||
|
||||
// If not idle - create an AI task (schedule onEvtThink repeatedly)
|
||||
if (_aiTask == null)
|
||||
{
|
||||
_aiTask = ThreadPoolManager.getInstance().scheduleAiAtFixedRate(this, 1000, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage the Attack Intention : Stop current Attack (if necessary), Calculate attack timeout, Start a new Attack and Launch Think Event.
|
||||
* @param target The L2Character to attack
|
||||
*/
|
||||
@Override
|
||||
protected void onIntentionAttack(L2Character target)
|
||||
{
|
||||
// Calculate the attack timeout
|
||||
_attackTimeout = MAX_ATTACK_TIMEOUT + GameTimeController.getInstance().getGameTicks();
|
||||
|
||||
// Manage the Attack Intention : Stop current Attack (if necessary), Start a new Attack and Launch Think Event
|
||||
// if (_actor.getTarget() != null)
|
||||
super.onIntentionAttack(target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage AI standard thinks of a L2Attackable (called by onEvtThink).<br>
|
||||
* <B><U> Actions</U> :</B>
|
||||
* <ul>
|
||||
* <li>Update every 1s the _globalAggro counter to come close to 0</li>
|
||||
* <li>If the actor is Aggressive and can attack, add all autoAttackable L2Character in its Aggro Range to its _aggroList, chose a target and order to attack it</li>
|
||||
* <li>If the actor can't attack, order to it to return to its home location</li>
|
||||
* </ul>
|
||||
*/
|
||||
private void thinkActive()
|
||||
{
|
||||
L2Attackable npc = (L2Attackable) _actor;
|
||||
|
||||
// Update every 1s the _globalAggro counter to come close to 0
|
||||
if (_globalAggro != 0)
|
||||
{
|
||||
if (_globalAggro < 0)
|
||||
{
|
||||
_globalAggro++;
|
||||
}
|
||||
else
|
||||
{
|
||||
_globalAggro--;
|
||||
}
|
||||
}
|
||||
|
||||
// Add all autoAttackable L2Character in L2Attackable Aggro Range to its _aggroList with 0 damage and 1 hate
|
||||
// A L2Attackable isn't aggressive during 10s after its spawn because _globalAggro is set to -10
|
||||
if (_globalAggro >= 0)
|
||||
{
|
||||
for (L2Character target : npc.getKnownList().getKnownCharactersInRadius(_attackRange))
|
||||
{
|
||||
if (target == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (autoAttackCondition(target)) // check aggression
|
||||
{
|
||||
// Get the hate level of the L2Attackable against this L2Character target contained in _aggroList
|
||||
int hating = npc.getHating(target);
|
||||
|
||||
// Add the attacker to the L2Attackable _aggroList with 0 damage and 1 hate
|
||||
if (hating == 0)
|
||||
{
|
||||
npc.addDamageHate(target, 0, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Chose a target from its aggroList
|
||||
L2Character hated;
|
||||
if (_actor.isConfused())
|
||||
{
|
||||
hated = getAttackTarget(); // Force mobs to attack anybody if confused
|
||||
}
|
||||
else
|
||||
{
|
||||
hated = npc.getMostHated();
|
||||
// _mostHatedAnalysis.Update(hated);
|
||||
}
|
||||
|
||||
// Order to the L2Attackable to attack the target
|
||||
if (hated != null)
|
||||
{
|
||||
// Get the hate level of the L2Attackable against this L2Character target contained in _aggroList
|
||||
int aggro = npc.getHating(hated);
|
||||
|
||||
if ((aggro + _globalAggro) > 0)
|
||||
{
|
||||
// Set the L2Character movement type to run and send Server->Client packet ChangeMoveType to all others L2PcInstance
|
||||
if (!_actor.isRunning())
|
||||
{
|
||||
_actor.setRunning();
|
||||
}
|
||||
|
||||
// Set the AI Intention to AI_INTENTION_ATTACK
|
||||
setIntention(CtrlIntention.AI_INTENTION_ATTACK, hated, null);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
// Order to the L2DefenderInstance to return to its home location because there's no target to attack
|
||||
((L2DefenderInstance) _actor).returnHome();
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage AI attack thinks of a L2Attackable (called by onEvtThink).<br>
|
||||
* <B><U> Actions</U> :</B>
|
||||
* <ul>
|
||||
* <li>Update the attack timeout if actor is running</li>
|
||||
* <li>If target is dead or timeout is expired, stop this attack and set the Intention to AI_INTENTION_ACTIVE</li>
|
||||
* <li>Call all L2Object of its Faction inside the Faction Range</li>
|
||||
* <li>Chose a target and order to attack it with magic skill or physical attack</li>
|
||||
* </ul>
|
||||
* TODO: Manage casting rules to healer mobs (like Ant Nurses)
|
||||
*/
|
||||
private void thinkAttack()
|
||||
{
|
||||
if (Config.DEBUG)
|
||||
{
|
||||
_log.info(getClass().getSimpleName() + ": thinkAttack(); timeout=" + (_attackTimeout - GameTimeController.getInstance().getGameTicks()));
|
||||
}
|
||||
|
||||
if (_attackTimeout < GameTimeController.getInstance().getGameTicks())
|
||||
{
|
||||
// Check if the actor is running
|
||||
if (_actor.isRunning())
|
||||
{
|
||||
// Set the actor movement type to walk and send Server->Client packet ChangeMoveType to all others L2PcInstance
|
||||
_actor.setWalking();
|
||||
|
||||
// Calculate a new attack timeout
|
||||
_attackTimeout = MAX_ATTACK_TIMEOUT + GameTimeController.getInstance().getGameTicks();
|
||||
}
|
||||
}
|
||||
|
||||
L2Character attackTarget = getAttackTarget();
|
||||
// Check if target is dead or if timeout is expired to stop this attack
|
||||
if ((attackTarget == null) || attackTarget.isAlikeDead() || (_attackTimeout < GameTimeController.getInstance().getGameTicks()))
|
||||
{
|
||||
// Stop hating this target after the attack timeout or if target is dead
|
||||
if (attackTarget != null)
|
||||
{
|
||||
L2Attackable npc = (L2Attackable) _actor;
|
||||
npc.stopHating(attackTarget);
|
||||
}
|
||||
|
||||
// Cancel target and timeout
|
||||
_attackTimeout = Integer.MAX_VALUE;
|
||||
setAttackTarget(null);
|
||||
|
||||
// Set the AI Intention to AI_INTENTION_ACTIVE
|
||||
setIntention(AI_INTENTION_ACTIVE, null, null);
|
||||
|
||||
_actor.setWalking();
|
||||
return;
|
||||
}
|
||||
|
||||
factionNotifyAndSupport();
|
||||
attackPrepare();
|
||||
}
|
||||
|
||||
private final void factionNotifyAndSupport()
|
||||
{
|
||||
L2Character target = getAttackTarget();
|
||||
// Call all L2Object of its Faction inside the Faction Range
|
||||
if ((((L2Npc) _actor).getTemplate().getClans() == null) || (target == null))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (target.isInvul())
|
||||
{
|
||||
return; // speeding it up for siege guards
|
||||
}
|
||||
|
||||
// Go through all L2Character that belong to its faction
|
||||
// for (L2Character cha : _actor.getKnownList().getKnownCharactersInRadius(((L2NpcInstance) _actor).getFactionRange()+_actor.getTemplate().collisionRadius))
|
||||
for (L2Character cha : _actor.getKnownList().getKnownCharactersInRadius(1000))
|
||||
{
|
||||
if (cha == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!(cha instanceof L2Npc))
|
||||
{
|
||||
if (_selfAnalysis.hasHealOrResurrect && (cha instanceof L2PcInstance) && (((L2Npc) _actor).getCastle().getSiege().checkIsDefender(((L2PcInstance) cha).getClan())))
|
||||
{
|
||||
// heal friends
|
||||
if (!_actor.isAttackingDisabled() && (cha.getCurrentHp() < (cha.getMaxHp() * 0.6)) && (_actor.getCurrentHp() > (_actor.getMaxHp() / 2)) && (_actor.getCurrentMp() > (_actor.getMaxMp() / 2)) && cha.isInCombat())
|
||||
{
|
||||
for (Skill sk : _selfAnalysis.healSkills)
|
||||
{
|
||||
if (_actor.getCurrentMp() < sk.getMpConsume())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (_actor.isSkillDisabled(sk))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!Util.checkIfInRange(sk.getCastRange(), _actor, cha, true))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int chance = 5;
|
||||
if (chance >= Rnd.get(100))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!GeoData.getInstance().canSeeTarget(_actor, cha))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
L2Object OldTarget = _actor.getTarget();
|
||||
_actor.setTarget(cha);
|
||||
clientStopMoving(null);
|
||||
_accessor.doCast(sk);
|
||||
_actor.setTarget(OldTarget);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
L2Npc npc = (L2Npc) cha;
|
||||
|
||||
if (!npc.isInMyClan((L2Npc) _actor))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (npc.getAI() != null) // TODO: possibly check not needed
|
||||
{
|
||||
if (!npc.isDead() && (Math.abs(target.getZ() - npc.getZ()) < 600)
|
||||
// && _actor.getAttackByList().contains(getAttackTarget())
|
||||
&& ((npc.getAI()._intention == CtrlIntention.AI_INTENTION_IDLE) || (npc.getAI()._intention == CtrlIntention.AI_INTENTION_ACTIVE))
|
||||
// limiting aggro for siege guards
|
||||
&& target.isInsideRadius(npc, 1500, true, false) && GeoData.getInstance().canSeeTarget(npc, target))
|
||||
{
|
||||
// Notify the L2Object AI with EVT_AGGRESSION
|
||||
npc.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, getAttackTarget(), 1);
|
||||
return;
|
||||
}
|
||||
// heal friends
|
||||
if (_selfAnalysis.hasHealOrResurrect && !_actor.isAttackingDisabled() && (npc.getCurrentHp() < (npc.getMaxHp() * 0.6)) && (_actor.getCurrentHp() > (_actor.getMaxHp() / 2)) && (_actor.getCurrentMp() > (_actor.getMaxMp() / 2)) && npc.isInCombat())
|
||||
{
|
||||
for (Skill sk : _selfAnalysis.healSkills)
|
||||
{
|
||||
if (_actor.getCurrentMp() < sk.getMpConsume())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (_actor.isSkillDisabled(sk))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!Util.checkIfInRange(sk.getCastRange(), _actor, npc, true))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int chance = 4;
|
||||
if (chance >= Rnd.get(100))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!GeoData.getInstance().canSeeTarget(_actor, npc))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
L2Object OldTarget = _actor.getTarget();
|
||||
_actor.setTarget(npc);
|
||||
clientStopMoving(null);
|
||||
_accessor.doCast(sk);
|
||||
_actor.setTarget(OldTarget);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void attackPrepare()
|
||||
{
|
||||
// Get all information needed to choose between physical or magical attack
|
||||
Collection<Skill> skills = null;
|
||||
double dist_2 = 0;
|
||||
int range = 0;
|
||||
L2DefenderInstance sGuard = (L2DefenderInstance) _actor;
|
||||
L2Character attackTarget = getAttackTarget();
|
||||
|
||||
try
|
||||
{
|
||||
_actor.setTarget(attackTarget);
|
||||
skills = _actor.getAllSkills();
|
||||
dist_2 = _actor.calculateDistance(attackTarget, false, true);
|
||||
range = _actor.getPhysicalAttackRange() + _actor.getTemplate().getCollisionRadius() + attackTarget.getTemplate().getCollisionRadius();
|
||||
if (attackTarget.isMoving())
|
||||
{
|
||||
range += 50;
|
||||
}
|
||||
}
|
||||
catch (NullPointerException e)
|
||||
{
|
||||
_actor.setTarget(null);
|
||||
setIntention(AI_INTENTION_IDLE, null, null);
|
||||
return;
|
||||
}
|
||||
|
||||
// never attack defenders
|
||||
if (attackTarget instanceof L2PcInstance)
|
||||
{
|
||||
if ((sGuard.getConquerableHall() == null) && sGuard.getCastle().getSiege().checkIsDefender(((L2PcInstance) attackTarget).getClan()))
|
||||
{
|
||||
// Cancel the target
|
||||
sGuard.stopHating(attackTarget);
|
||||
_actor.setTarget(null);
|
||||
setIntention(AI_INTENTION_IDLE, null, null);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!GeoData.getInstance().canSeeTarget(_actor, attackTarget))
|
||||
{
|
||||
// Siege guards differ from normal mobs currently:
|
||||
// If target cannot seen, don't attack any more
|
||||
sGuard.stopHating(attackTarget);
|
||||
_actor.setTarget(null);
|
||||
setIntention(AI_INTENTION_IDLE, null, null);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if the actor isn't muted and if it is far from target
|
||||
if (!_actor.isMuted() && (dist_2 > (range * range)))
|
||||
{
|
||||
// check for long ranged skills and heal/buff skills
|
||||
for (Skill sk : skills)
|
||||
{
|
||||
int castRange = sk.getCastRange();
|
||||
|
||||
if ((dist_2 <= (castRange * castRange)) && (castRange > 70) && !_actor.isSkillDisabled(sk) && (_actor.getCurrentMp() >= _actor.getStat().getMpConsume(sk)) && !sk.isPassive())
|
||||
{
|
||||
|
||||
L2Object OldTarget = _actor.getTarget();
|
||||
if ((sk.isContinuous() && !sk.isDebuff()) || (sk.hasEffectType(L2EffectType.HEAL)))
|
||||
{
|
||||
boolean useSkillSelf = true;
|
||||
if ((sk.hasEffectType(L2EffectType.HEAL)) && (_actor.getCurrentHp() > (int) (_actor.getMaxHp() / 1.5)))
|
||||
{
|
||||
useSkillSelf = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if ((sk.isContinuous() && !sk.isDebuff()) && _actor.isAffectedBySkill(sk.getId()))
|
||||
{
|
||||
useSkillSelf = false;
|
||||
}
|
||||
|
||||
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.getSpawn().getX();
|
||||
double homeY = attackTarget.getY() - sGuard.getSpawn().getY();
|
||||
|
||||
// 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
|
||||
{
|
||||
if (_selfAnalysis.isHealer)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (_selfAnalysis.isMage)
|
||||
{
|
||||
range = _selfAnalysis.maxCastRange - 50;
|
||||
}
|
||||
if (attackTarget.isMoving())
|
||||
{
|
||||
moveToPawn(attackTarget, range - 70);
|
||||
}
|
||||
else
|
||||
{
|
||||
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 * range)) && !_selfAnalysis.isHealer)
|
||||
{
|
||||
// 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
|
||||
{
|
||||
if (_selfAnalysis.isMage)
|
||||
{
|
||||
range = _selfAnalysis.maxCastRange - 50;
|
||||
}
|
||||
if (attackTarget.isMoving())
|
||||
{
|
||||
moveToPawn(attackTarget, range - 70);
|
||||
}
|
||||
else
|
||||
{
|
||||
moveToPawn(attackTarget, range);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Else, if this is close enough to attack
|
||||
else if (dist_2 <= (range * range))
|
||||
{
|
||||
// Force mobs to attack 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.getInstance().getGameTicks();
|
||||
|
||||
// check for close combat skills && heal/buff skills
|
||||
if (!_actor.isMuted() && (Rnd.nextInt(100) <= 5))
|
||||
{
|
||||
for (Skill sk : skills)
|
||||
{
|
||||
int castRange = sk.getCastRange();
|
||||
|
||||
if (((castRange * castRange) >= dist_2) && !sk.isPassive() && (_actor.getCurrentMp() >= _actor.getStat().getMpConsume(sk)) && !_actor.isSkillDisabled(sk))
|
||||
{
|
||||
L2Object OldTarget = _actor.getTarget();
|
||||
if ((sk.isContinuous() && !sk.isDebuff()) || (sk.hasEffectType(L2EffectType.HEAL)))
|
||||
{
|
||||
boolean useSkillSelf = true;
|
||||
if ((sk.hasEffectType(L2EffectType.HEAL)) && (_actor.getCurrentHp() > (int) (_actor.getMaxHp() / 1.5)))
|
||||
{
|
||||
useSkillSelf = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if ((sk.isContinuous() && !sk.isDebuff()) && _actor.isAffectedBySkill(sk.getId()))
|
||||
{
|
||||
useSkillSelf = false;
|
||||
}
|
||||
|
||||
if (useSkillSelf)
|
||||
{
|
||||
_actor.setTarget(_actor);
|
||||
}
|
||||
}
|
||||
|
||||
clientStopMoving(null);
|
||||
_accessor.doCast(sk);
|
||||
_actor.setTarget(OldTarget);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Finally, do the physical attack itself
|
||||
if (!_selfAnalysis.isHealer)
|
||||
{
|
||||
_accessor.doAttack(attackTarget);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage AI thinking actions of a L2Attackable.
|
||||
*/
|
||||
@Override
|
||||
protected void onEvtThink()
|
||||
{
|
||||
// if(getIntention() != AI_INTENTION_IDLE && (!_actor.isVisible() || !_actor.hasAI() || !_actor.isKnownPlayers()))
|
||||
// setIntention(AI_INTENTION_IDLE);
|
||||
|
||||
// Check if the thinking action is already in progress
|
||||
if (_thinking || _actor.isCastingNow() || _actor.isAllSkillsDisabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Start thinking action
|
||||
_thinking = true;
|
||||
|
||||
try
|
||||
{
|
||||
// Manage AI thinks of a L2Attackable
|
||||
if (getIntention() == AI_INTENTION_ACTIVE)
|
||||
{
|
||||
thinkActive();
|
||||
}
|
||||
else if (getIntention() == AI_INTENTION_ATTACK)
|
||||
{
|
||||
thinkAttack();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Stop thinking action
|
||||
_thinking = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Launch actions corresponding to the Event Attacked.<br>
|
||||
* <B><U> Actions</U> :</B>
|
||||
* <ul>
|
||||
* <li>Init the attack : Calculate the attack timeout, Set the _globalAggro to 0, Add the attacker to the actor _aggroList</li>
|
||||
* <li>Set the L2Character movement type to run and send Server->Client packet ChangeMoveType to all others L2PcInstance</li>
|
||||
* <li>Set the Intention to AI_INTENTION_ATTACK</li>
|
||||
* </ul>
|
||||
* @param attacker The L2Character that attacks the actor
|
||||
*/
|
||||
@Override
|
||||
protected void onEvtAttacked(L2Character attacker)
|
||||
{
|
||||
// Calculate the attack timeout
|
||||
_attackTimeout = MAX_ATTACK_TIMEOUT + GameTimeController.getInstance().getGameTicks();
|
||||
|
||||
// Set the _globalAggro to 0 to permit attack even just after spawn
|
||||
if (_globalAggro < 0)
|
||||
{
|
||||
_globalAggro = 0;
|
||||
}
|
||||
|
||||
// Add the attacker to the _aggroList of the actor
|
||||
((L2Attackable) _actor).addDamageHate(attacker, 0, 1);
|
||||
|
||||
// Set the L2Character movement type to run and send Server->Client packet ChangeMoveType to all others L2PcInstance
|
||||
if (!_actor.isRunning())
|
||||
{
|
||||
_actor.setRunning();
|
||||
}
|
||||
|
||||
// Set the Intention to AI_INTENTION_ATTACK
|
||||
if (getIntention() != AI_INTENTION_ATTACK)
|
||||
{
|
||||
setIntention(CtrlIntention.AI_INTENTION_ATTACK, attacker, null);
|
||||
}
|
||||
|
||||
super.onEvtAttacked(attacker);
|
||||
}
|
||||
|
||||
/**
|
||||
* Launch actions corresponding to the Event Aggression.<br>
|
||||
* <B><U> Actions</U> :</B>
|
||||
* <ul>
|
||||
* <li>Add the target to the actor _aggroList or update hate if already present</li>
|
||||
* <li>Set the actor Intention to AI_INTENTION_ATTACK (if actor is L2GuardInstance check if it isn't too far from its home location)</li>
|
||||
* </ul>
|
||||
* @param aggro The value of hate to add to the actor against the target
|
||||
*/
|
||||
@Override
|
||||
protected void onEvtAggression(L2Character target, int aggro)
|
||||
{
|
||||
if (_actor == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
L2Attackable me = (L2Attackable) _actor;
|
||||
|
||||
if (target != null)
|
||||
{
|
||||
// Add the target to the actor _aggroList or update hate if already present
|
||||
me.addDamageHate(target, 0, aggro);
|
||||
|
||||
// Get the hate of the actor against the target
|
||||
aggro = me.getHating(target);
|
||||
|
||||
if (aggro <= 0)
|
||||
{
|
||||
if (me.getMostHated() == null)
|
||||
{
|
||||
_globalAggro = -25;
|
||||
me.clearAggroList();
|
||||
setIntention(AI_INTENTION_IDLE, null, null);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Set the actor AI Intention to AI_INTENTION_ATTACK
|
||||
if (getIntention() != CtrlIntention.AI_INTENTION_ATTACK)
|
||||
{
|
||||
// Set the L2Character movement type to run and send Server->Client packet ChangeMoveType to all others L2PcInstance
|
||||
if (!_actor.isRunning())
|
||||
{
|
||||
_actor.setRunning();
|
||||
}
|
||||
|
||||
L2DefenderInstance sGuard = (L2DefenderInstance) _actor;
|
||||
double homeX = target.getX() - sGuard.getSpawn().getX();
|
||||
double homeY = target.getY() - sGuard.getSpawn().getY();
|
||||
|
||||
// Check if the L2SiegeGuardInstance is not too far from its home location
|
||||
if (((homeX * homeX) + (homeY * homeY)) < 3240000)
|
||||
{
|
||||
setIntention(CtrlIntention.AI_INTENTION_ATTACK, target, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// currently only for setting lower general aggro
|
||||
if (aggro >= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
L2Character mostHated = me.getMostHated();
|
||||
if (mostHated == null)
|
||||
{
|
||||
_globalAggro = -25;
|
||||
return;
|
||||
}
|
||||
|
||||
for (L2Character aggroed : me.getAggroList().keySet())
|
||||
{
|
||||
me.addDamageHate(aggroed, 0, aggro);
|
||||
}
|
||||
|
||||
aggro = me.getHating(mostHated);
|
||||
if (aggro <= 0)
|
||||
{
|
||||
_globalAggro = -25;
|
||||
me.clearAggroList();
|
||||
setIntention(AI_INTENTION_IDLE, null, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopAITask()
|
||||
{
|
||||
if (_aiTask != null)
|
||||
{
|
||||
_aiTask.cancel(false);
|
||||
_aiTask = null;
|
||||
}
|
||||
_accessor.detachAI();
|
||||
super.stopAITask();
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2014 L2J Server
|
||||
*
|
||||
* This file is part of L2J Server.
|
||||
*
|
||||
* L2J Server is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* L2J Server is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.gameserver.ai;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.l2jserver.gameserver.model.actor.L2Character;
|
||||
import com.l2jserver.gameserver.model.actor.L2Character.AIAccessor;
|
||||
|
||||
/**
|
||||
* @author BiggBoss
|
||||
*/
|
||||
public final class L2SpecialSiegeGuardAI extends L2SiegeGuardAI
|
||||
{
|
||||
private final ArrayList<Integer> _allied;
|
||||
|
||||
/**
|
||||
* @param accessor
|
||||
*/
|
||||
public L2SpecialSiegeGuardAI(AIAccessor accessor)
|
||||
{
|
||||
super(accessor);
|
||||
_allied = new ArrayList<>();
|
||||
}
|
||||
|
||||
public ArrayList<Integer> getAlly()
|
||||
{
|
||||
return _allied;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean autoAttackCondition(L2Character target)
|
||||
{
|
||||
if (_allied.contains(target.getObjectId()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return super.autoAttackCondition(target);
|
||||
}
|
||||
}
|
303
trunk/java/com/l2jserver/gameserver/ai/L2SummonAI.java
Normal file
303
trunk/java/com/l2jserver/gameserver/ai/L2SummonAI.java
Normal file
@ -0,0 +1,303 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2014 L2J Server
|
||||
*
|
||||
* This file is part of L2J Server.
|
||||
*
|
||||
* L2J Server is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* L2J Server is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.gameserver.ai;
|
||||
|
||||
import static com.l2jserver.gameserver.ai.CtrlIntention.AI_INTENTION_ATTACK;
|
||||
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 com.l2jserver.Config;
|
||||
import com.l2jserver.gameserver.GeoData;
|
||||
import com.l2jserver.gameserver.ThreadPoolManager;
|
||||
import com.l2jserver.gameserver.model.L2Object;
|
||||
import com.l2jserver.gameserver.model.actor.L2Character;
|
||||
import com.l2jserver.gameserver.model.actor.L2Character.AIAccessor;
|
||||
import com.l2jserver.gameserver.model.actor.L2Summon;
|
||||
import com.l2jserver.gameserver.model.skills.Skill;
|
||||
import com.l2jserver.util.Rnd;
|
||||
|
||||
public class L2SummonAI extends L2PlayableAI implements Runnable
|
||||
{
|
||||
private static final int AVOID_RADIUS = 70;
|
||||
|
||||
private volatile boolean _thinking; // to prevent recursive thinking
|
||||
private volatile boolean _startFollow = ((L2Summon) _actor).getFollowStatus();
|
||||
private L2Character _lastAttack = null;
|
||||
|
||||
private volatile boolean _startAvoid = false;
|
||||
private Future<?> _avoidTask = null;
|
||||
|
||||
public L2SummonAI(AIAccessor accessor)
|
||||
{
|
||||
super(accessor);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onIntentionIdle()
|
||||
{
|
||||
stopFollow();
|
||||
_startFollow = false;
|
||||
onIntentionActive();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onIntentionActive()
|
||||
{
|
||||
L2Summon summon = (L2Summon) _actor;
|
||||
if (_startFollow)
|
||||
{
|
||||
setIntention(AI_INTENTION_FOLLOW, summon.getOwner());
|
||||
}
|
||||
else
|
||||
{
|
||||
super.onIntentionActive();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized void changeIntention(CtrlIntention intention, Object arg0, Object arg1)
|
||||
{
|
||||
switch (intention)
|
||||
{
|
||||
case AI_INTENTION_ACTIVE:
|
||||
case AI_INTENTION_FOLLOW:
|
||||
startAvoidTask();
|
||||
break;
|
||||
default:
|
||||
stopAvoidTask();
|
||||
}
|
||||
|
||||
super.changeIntention(intention, arg0, arg1);
|
||||
}
|
||||
|
||||
private void thinkAttack()
|
||||
{
|
||||
if (checkTargetLostOrDead(getAttackTarget()))
|
||||
{
|
||||
setAttackTarget(null);
|
||||
return;
|
||||
}
|
||||
if (maybeMoveToPawn(getAttackTarget(), _actor.getPhysicalAttackRange()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
clientStopMoving(null);
|
||||
_accessor.doAttack(getAttackTarget());
|
||||
}
|
||||
|
||||
private void thinkCast()
|
||||
{
|
||||
L2Summon summon = (L2Summon) _actor;
|
||||
if (checkTargetLost(getCastTarget()))
|
||||
{
|
||||
setCastTarget(null);
|
||||
return;
|
||||
}
|
||||
boolean val = _startFollow;
|
||||
if (maybeMoveToPawn(getCastTarget(), _actor.getMagicalAttackRange(_skill)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
clientStopMoving(null);
|
||||
summon.setFollowStatus(false);
|
||||
setIntention(AI_INTENTION_IDLE);
|
||||
_startFollow = val;
|
||||
_accessor.doCast(_skill);
|
||||
}
|
||||
|
||||
private void thinkPickUp()
|
||||
{
|
||||
if (checkTargetLost(getTarget()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (maybeMoveToPawn(getTarget(), 36))
|
||||
{
|
||||
return;
|
||||
}
|
||||
setIntention(AI_INTENTION_IDLE);
|
||||
((L2Summon.AIAccessor) _accessor).doPickupItem(getTarget());
|
||||
}
|
||||
|
||||
private void thinkInteract()
|
||||
{
|
||||
if (checkTargetLost(getTarget()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (maybeMoveToPawn(getTarget(), 36))
|
||||
{
|
||||
return;
|
||||
}
|
||||
setIntention(AI_INTENTION_IDLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEvtThink()
|
||||
{
|
||||
if (_thinking || _actor.isCastingNow() || _actor.isAllSkillsDisabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
_thinking = true;
|
||||
try
|
||||
{
|
||||
switch (getIntention())
|
||||
{
|
||||
case AI_INTENTION_ATTACK:
|
||||
thinkAttack();
|
||||
break;
|
||||
case AI_INTENTION_CAST:
|
||||
thinkCast();
|
||||
break;
|
||||
case AI_INTENTION_PICK_UP:
|
||||
thinkPickUp();
|
||||
break;
|
||||
case AI_INTENTION_INTERACT:
|
||||
thinkInteract();
|
||||
break;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_thinking = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEvtFinishCasting()
|
||||
{
|
||||
if (_lastAttack == null)
|
||||
{
|
||||
((L2Summon) _actor).setFollowStatus(_startFollow);
|
||||
}
|
||||
else
|
||||
{
|
||||
setIntention(CtrlIntention.AI_INTENTION_ATTACK, _lastAttack);
|
||||
_lastAttack = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEvtAttacked(L2Character attacker)
|
||||
{
|
||||
super.onEvtAttacked(attacker);
|
||||
|
||||
avoidAttack(attacker);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEvtEvaded(L2Character attacker)
|
||||
{
|
||||
super.onEvtEvaded(attacker);
|
||||
|
||||
avoidAttack(attacker);
|
||||
}
|
||||
|
||||
private void avoidAttack(L2Character attacker)
|
||||
{
|
||||
// trying to avoid if summon near owner
|
||||
if ((((L2Summon) _actor).getOwner() != null) && (((L2Summon) _actor).getOwner() != attacker) && ((L2Summon) _actor).getOwner().isInsideRadius(_actor, 2 * AVOID_RADIUS, true, false))
|
||||
{
|
||||
_startAvoid = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (_startAvoid)
|
||||
{
|
||||
_startAvoid = false;
|
||||
|
||||
if (!_clientMoving && !_actor.isDead() && !_actor.isMovementDisabled())
|
||||
{
|
||||
final int ownerX = ((L2Summon) _actor).getOwner().getX();
|
||||
final int ownerY = ((L2Summon) _actor).getOwner().getY();
|
||||
final double angle = Math.toRadians(Rnd.get(-90, 90)) + Math.atan2(ownerY - _actor.getY(), ownerX - _actor.getX());
|
||||
|
||||
final int targetX = ownerX + (int) (AVOID_RADIUS * Math.cos(angle));
|
||||
final int targetY = ownerY + (int) (AVOID_RADIUS * Math.sin(angle));
|
||||
if ((Config.GEODATA == 0) || GeoData.getInstance().canMove(_actor.getX(), _actor.getY(), _actor.getZ(), targetX, targetY, _actor.getZ(), _actor.getInstanceId()))
|
||||
{
|
||||
moveTo(targetX, targetY, _actor.getZ());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void notifyFollowStatusChange()
|
||||
{
|
||||
_startFollow = !_startFollow;
|
||||
switch (getIntention())
|
||||
{
|
||||
case AI_INTENTION_ACTIVE:
|
||||
case AI_INTENTION_FOLLOW:
|
||||
case AI_INTENTION_IDLE:
|
||||
case AI_INTENTION_MOVE_TO:
|
||||
case AI_INTENTION_PICK_UP:
|
||||
((L2Summon) _actor).setFollowStatus(_startFollow);
|
||||
}
|
||||
}
|
||||
|
||||
public void setStartFollowController(boolean val)
|
||||
{
|
||||
_startFollow = val;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onIntentionCast(Skill skill, L2Object target)
|
||||
{
|
||||
if (getIntention() == AI_INTENTION_ATTACK)
|
||||
{
|
||||
_lastAttack = getAttackTarget();
|
||||
}
|
||||
else
|
||||
{
|
||||
_lastAttack = null;
|
||||
}
|
||||
super.onIntentionCast(skill, target);
|
||||
}
|
||||
|
||||
private void startAvoidTask()
|
||||
{
|
||||
if (_avoidTask == null)
|
||||
{
|
||||
_avoidTask = ThreadPoolManager.getInstance().scheduleAiAtFixedRate(this, 100, 100);
|
||||
}
|
||||
}
|
||||
|
||||
private void stopAvoidTask()
|
||||
{
|
||||
if (_avoidTask != null)
|
||||
{
|
||||
_avoidTask.cancel(false);
|
||||
_avoidTask = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopAITask()
|
||||
{
|
||||
stopAvoidTask();
|
||||
super.stopAITask();
|
||||
}
|
||||
}
|
129
trunk/java/com/l2jserver/gameserver/ai/L2VehicleAI.java
Normal file
129
trunk/java/com/l2jserver/gameserver/ai/L2VehicleAI.java
Normal file
@ -0,0 +1,129 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2014 L2J Server
|
||||
*
|
||||
* This file is part of L2J Server.
|
||||
*
|
||||
* L2J Server is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* L2J Server is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.gameserver.ai;
|
||||
|
||||
import com.l2jserver.gameserver.model.L2Object;
|
||||
import com.l2jserver.gameserver.model.actor.L2Character;
|
||||
import com.l2jserver.gameserver.model.actor.L2Vehicle;
|
||||
import com.l2jserver.gameserver.model.skills.Skill;
|
||||
|
||||
/**
|
||||
* @author DS
|
||||
*/
|
||||
public abstract class L2VehicleAI extends L2CharacterAI
|
||||
{
|
||||
/**
|
||||
* Simple AI for vehicles
|
||||
* @param accessor
|
||||
*/
|
||||
public L2VehicleAI(L2Vehicle.AIAccessor accessor)
|
||||
{
|
||||
super(accessor);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onIntentionAttack(L2Character target)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onIntentionCast(Skill skill, L2Object target)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onIntentionFollow(L2Character target)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onIntentionPickUp(L2Object item)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onIntentionInteract(L2Object object)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEvtAttacked(L2Character attacker)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEvtAggression(L2Character target, int aggro)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEvtStunned(L2Character attacker)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEvtSleeping(L2Character attacker)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEvtRooted(L2Character attacker)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEvtForgetObject(L2Object object)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEvtCancel()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEvtDead()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEvtFakeDeath()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEvtFinishCasting()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void clientActionFailed()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void moveToPawn(L2Object pawn, int offset)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void clientStoppedMoving()
|
||||
{
|
||||
}
|
||||
}
|
206
trunk/java/com/l2jserver/gameserver/ai/NextAction.java
Normal file
206
trunk/java/com/l2jserver/gameserver/ai/NextAction.java
Normal file
@ -0,0 +1,206 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2014 L2J Server
|
||||
*
|
||||
* This file is part of L2J Server.
|
||||
*
|
||||
* L2J Server is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* L2J Server is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.gameserver.ai;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Class for AI action after some event.<br>
|
||||
* Has 2 array list for "work" and "break".
|
||||
* @author Yaroslav
|
||||
*/
|
||||
public class NextAction
|
||||
{
|
||||
public interface NextActionCallback
|
||||
{
|
||||
public void doWork();
|
||||
}
|
||||
|
||||
private ArrayList<CtrlEvent> _events;
|
||||
private ArrayList<CtrlIntention> _intentions;
|
||||
private NextActionCallback _callback;
|
||||
|
||||
/**
|
||||
* Main constructor.
|
||||
* @param events
|
||||
* @param intentions
|
||||
* @param callback
|
||||
*/
|
||||
public NextAction(ArrayList<CtrlEvent> events, ArrayList<CtrlIntention> intentions, NextActionCallback callback)
|
||||
{
|
||||
_events = events;
|
||||
_intentions = intentions;
|
||||
setCallback(callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Single constructor.
|
||||
* @param event
|
||||
* @param intention
|
||||
* @param callback
|
||||
*/
|
||||
public NextAction(CtrlEvent event, CtrlIntention intention, NextActionCallback callback)
|
||||
{
|
||||
if (_events == null)
|
||||
{
|
||||
_events = new ArrayList<>();
|
||||
}
|
||||
|
||||
if (_intentions == null)
|
||||
{
|
||||
_intentions = new ArrayList<>();
|
||||
}
|
||||
|
||||
if (event != null)
|
||||
{
|
||||
_events.add(event);
|
||||
}
|
||||
|
||||
if (intention != null)
|
||||
{
|
||||
_intentions.add(intention);
|
||||
}
|
||||
setCallback(callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Do action.
|
||||
*/
|
||||
public void doAction()
|
||||
{
|
||||
if (_callback != null)
|
||||
{
|
||||
_callback.doWork();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the _event
|
||||
*/
|
||||
public ArrayList<CtrlEvent> getEvents()
|
||||
{
|
||||
// If null return empty list.
|
||||
if (_events == null)
|
||||
{
|
||||
_events = new ArrayList<>();
|
||||
}
|
||||
return _events;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param event the event to set.
|
||||
*/
|
||||
public void setEvents(ArrayList<CtrlEvent> event)
|
||||
{
|
||||
_events = event;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param event
|
||||
*/
|
||||
public void addEvent(CtrlEvent event)
|
||||
{
|
||||
if (_events == null)
|
||||
{
|
||||
_events = new ArrayList<>();
|
||||
}
|
||||
|
||||
if (event != null)
|
||||
{
|
||||
_events.add(event);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param event
|
||||
*/
|
||||
public void removeEvent(CtrlEvent event)
|
||||
{
|
||||
if (_events == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_events.remove(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the _callback
|
||||
*/
|
||||
public NextActionCallback getCallback()
|
||||
{
|
||||
return _callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callback the callback to set.
|
||||
*/
|
||||
public void setCallback(NextActionCallback callback)
|
||||
{
|
||||
_callback = callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the _intentions
|
||||
*/
|
||||
public ArrayList<CtrlIntention> getIntentions()
|
||||
{
|
||||
// If null return empty list.
|
||||
if (_intentions == null)
|
||||
{
|
||||
_intentions = new ArrayList<>();
|
||||
}
|
||||
return _intentions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param intentions the intention to set.
|
||||
*/
|
||||
public void setIntentions(ArrayList<CtrlIntention> intentions)
|
||||
{
|
||||
_intentions = intentions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param intention
|
||||
*/
|
||||
public void addIntention(CtrlIntention intention)
|
||||
{
|
||||
if (_intentions == null)
|
||||
{
|
||||
_intentions = new ArrayList<>();
|
||||
}
|
||||
|
||||
if (intention != null)
|
||||
{
|
||||
_intentions.add(intention);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param intention
|
||||
*/
|
||||
public void removeIntention(CtrlIntention intention)
|
||||
{
|
||||
if (_intentions == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_intentions.remove(intention);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user