123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- package net.sf.l2j.gameserver.ai;
- import static net.sf.l2j.gameserver.ai.CtrlIntention.AI_INTENTION_ATTACK;
- import static net.sf.l2j.gameserver.ai.CtrlIntention.AI_INTENTION_CAST;
- import static net.sf.l2j.gameserver.ai.CtrlIntention.AI_INTENTION_FOLLOW;
- import static net.sf.l2j.gameserver.ai.CtrlIntention.AI_INTENTION_IDLE;
- import static net.sf.l2j.gameserver.ai.CtrlIntention.AI_INTENTION_INTERACT;
- import static net.sf.l2j.gameserver.ai.CtrlIntention.AI_INTENTION_PICK_UP;
- import net.sf.l2j.gameserver.model.L2Summon;
- import net.sf.l2j.gameserver.model.L2Character.AIAccessor;
- public class L2SummonAI extends L2CharacterAI
- {
- private boolean _thinking;
- public L2SummonAI(AIAccessor accessor)
- {
- super(accessor);
- }
- @Override
- protected void onIntentionIdle()
- {
- stopFollow();
- onIntentionActive();
- }
- @Override
- protected void onIntentionActive()
- {
- L2Summon summon = (L2Summon) _actor;
- if (summon.getFollowStatus()) setIntention(AI_INTENTION_FOLLOW, summon.getOwner());
- else super.onIntentionActive();
- }
- private void thinkAttack()
- {
- if (checkTargetLostOrDead(getAttackTarget()))
- {
- setAttackTarget(null);
- return;
- }
- if (maybeMoveToPawn(getAttackTarget(), _actor.getPhysicalAttackRange())) return;
- clientStopMoving(null);
- _accessor.doAttack(getAttackTarget());
- return;
- }
- private void thinkCast()
- {
- L2Summon summon = (L2Summon) _actor;
- if (checkTargetLost(getCastTarget()))
- {
- setCastTarget(null);
- return;
- }
- if (maybeMoveToPawn(getCastTarget(), _actor.getMagicalAttackRange(_skill))) return;
- clientStopMoving(null);
- summon.setFollowStatus(false);
- setIntention(AI_INTENTION_IDLE);
- _accessor.doCast(_skill);
- return;
- }
- private void thinkPickUp()
- {
- if (_actor.isAllSkillsDisabled()) return;
- if (checkTargetLost(getTarget())) return;
- if (maybeMoveToPawn(getTarget(), 36)) return;
- setIntention(AI_INTENTION_IDLE);
- ((L2Summon.AIAccessor) _accessor).doPickupItem(getTarget());
- return;
- }
- private void thinkInteract()
- {
- if (_actor.isAllSkillsDisabled()) return;
- if (checkTargetLost(getTarget())) return;
- if (maybeMoveToPawn(getTarget(), 36)) return;
- setIntention(AI_INTENTION_IDLE);
- return;
- }
- @Override
- protected void onEvtThink()
- {
- if (_thinking || _actor.isAllSkillsDisabled()) 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;
- }
- }
- }
|