L2SummonAI.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License as published by
  4. * the Free Software Foundation; either version 2, or (at your option)
  5. * any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program; if not, write to the Free Software
  14. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  15. * 02111-1307, USA.
  16. *
  17. * http://www.gnu.org/copyleft/gpl.html
  18. */
  19. package net.sf.l2j.gameserver.ai;
  20. import static net.sf.l2j.gameserver.ai.CtrlIntention.AI_INTENTION_ATTACK;
  21. import static net.sf.l2j.gameserver.ai.CtrlIntention.AI_INTENTION_CAST;
  22. import static net.sf.l2j.gameserver.ai.CtrlIntention.AI_INTENTION_FOLLOW;
  23. import static net.sf.l2j.gameserver.ai.CtrlIntention.AI_INTENTION_IDLE;
  24. import static net.sf.l2j.gameserver.ai.CtrlIntention.AI_INTENTION_INTERACT;
  25. import static net.sf.l2j.gameserver.ai.CtrlIntention.AI_INTENTION_PICK_UP;
  26. import net.sf.l2j.gameserver.model.L2Summon;
  27. import net.sf.l2j.gameserver.model.L2Character.AIAccessor;
  28. public class L2SummonAI extends L2CharacterAI
  29. {
  30. private boolean _thinking; // to prevent recursive thinking
  31. public L2SummonAI(AIAccessor accessor)
  32. {
  33. super(accessor);
  34. }
  35. @Override
  36. protected void onIntentionIdle()
  37. {
  38. stopFollow();
  39. onIntentionActive();
  40. }
  41. @Override
  42. protected void onIntentionActive()
  43. {
  44. L2Summon summon = (L2Summon) _actor;
  45. if (summon.getFollowStatus()) setIntention(AI_INTENTION_FOLLOW, summon.getOwner());
  46. else super.onIntentionActive();
  47. }
  48. private void thinkAttack()
  49. {
  50. if (checkTargetLostOrDead(getAttackTarget()))
  51. {
  52. setAttackTarget(null);
  53. return;
  54. }
  55. if (maybeMoveToPawn(getAttackTarget(), _actor.getPhysicalAttackRange())) return;
  56. clientStopMoving(null);
  57. _accessor.doAttack(getAttackTarget());
  58. return;
  59. }
  60. private void thinkCast()
  61. {
  62. L2Summon summon = (L2Summon) _actor;
  63. if (checkTargetLost(getCastTarget()))
  64. {
  65. setCastTarget(null);
  66. return;
  67. }
  68. if (maybeMoveToPawn(getCastTarget(), _actor.getMagicalAttackRange(_skill))) return;
  69. clientStopMoving(null);
  70. summon.setFollowStatus(false);
  71. setIntention(AI_INTENTION_IDLE);
  72. _accessor.doCast(_skill);
  73. return;
  74. }
  75. private void thinkPickUp()
  76. {
  77. if (_actor.isAllSkillsDisabled()) return;
  78. if (checkTargetLost(getTarget())) return;
  79. if (maybeMoveToPawn(getTarget(), 36)) return;
  80. setIntention(AI_INTENTION_IDLE);
  81. ((L2Summon.AIAccessor) _accessor).doPickupItem(getTarget());
  82. return;
  83. }
  84. private void thinkInteract()
  85. {
  86. if (_actor.isAllSkillsDisabled()) return;
  87. if (checkTargetLost(getTarget())) return;
  88. if (maybeMoveToPawn(getTarget(), 36)) return;
  89. setIntention(AI_INTENTION_IDLE);
  90. return;
  91. }
  92. @Override
  93. protected void onEvtThink()
  94. {
  95. if (_thinking || _actor.isAllSkillsDisabled()) return;
  96. _thinking = true;
  97. try
  98. {
  99. if (getIntention() == AI_INTENTION_ATTACK) thinkAttack();
  100. else if (getIntention() == AI_INTENTION_CAST) thinkCast();
  101. else if (getIntention() == AI_INTENTION_PICK_UP) thinkPickUp();
  102. else if (getIntention() == AI_INTENTION_INTERACT) thinkInteract();
  103. }
  104. finally
  105. {
  106. _thinking = false;
  107. }
  108. }
  109. }