L2SummonAI.java 3.7 KB

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