L2SummonAI.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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_FOLLOW;
  17. import static net.sf.l2j.gameserver.ai.CtrlIntention.AI_INTENTION_IDLE;
  18. import net.sf.l2j.gameserver.model.L2Summon;
  19. import net.sf.l2j.gameserver.model.L2Character.AIAccessor;
  20. public class L2SummonAI extends L2CharacterAI
  21. {
  22. private boolean _thinking; // to prevent recursive thinking
  23. private boolean _startFollow = ((L2Summon) _actor).getFollowStatus();
  24. public L2SummonAI(AIAccessor accessor)
  25. {
  26. super(accessor);
  27. }
  28. @Override
  29. protected void onIntentionIdle()
  30. {
  31. stopFollow();
  32. _startFollow = false;
  33. onIntentionActive();
  34. }
  35. @Override
  36. protected void onIntentionActive()
  37. {
  38. L2Summon summon = (L2Summon) _actor;
  39. if (_startFollow)
  40. setIntention(AI_INTENTION_FOLLOW, summon.getOwner());
  41. else
  42. 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()))
  52. return;
  53. clientStopMoving(null);
  54. _accessor.doAttack(getAttackTarget());
  55. return;
  56. }
  57. private void thinkCast()
  58. {
  59. L2Summon summon = (L2Summon) _actor;
  60. if (checkTargetLost(getCastTarget()))
  61. {
  62. setCastTarget(null);
  63. return;
  64. }
  65. boolean val = _startFollow;
  66. if (maybeMoveToPawn(getCastTarget(), _actor.getMagicalAttackRange(_skill)))
  67. return;
  68. clientStopMoving(null);
  69. summon.setFollowStatus(false);
  70. setIntention(AI_INTENTION_IDLE);
  71. _startFollow = val;
  72. _accessor.doCast(_skill);
  73. return;
  74. }
  75. private void thinkPickUp()
  76. {
  77. if (_actor.isAllSkillsDisabled())
  78. return;
  79. if (checkTargetLost(getTarget()))
  80. return;
  81. if (maybeMoveToPawn(getTarget(), 36))
  82. return;
  83. setIntention(AI_INTENTION_IDLE);
  84. ((L2Summon.AIAccessor) _accessor).doPickupItem(getTarget());
  85. return;
  86. }
  87. private void thinkInteract()
  88. {
  89. if (_actor.isAllSkillsDisabled())
  90. return;
  91. if (checkTargetLost(getTarget()))
  92. return;
  93. if (maybeMoveToPawn(getTarget(), 36))
  94. return;
  95. setIntention(AI_INTENTION_IDLE);
  96. return;
  97. }
  98. @Override
  99. protected void onEvtThink()
  100. {
  101. if (_thinking || _actor.isAllSkillsDisabled())
  102. return;
  103. _thinking = true;
  104. try
  105. {
  106. switch (getIntention())
  107. {
  108. case AI_INTENTION_ATTACK:
  109. thinkAttack();
  110. break;
  111. case AI_INTENTION_CAST:
  112. thinkCast();
  113. break;
  114. case AI_INTENTION_PICK_UP:
  115. thinkPickUp();
  116. break;
  117. case AI_INTENTION_INTERACT:
  118. thinkInteract();
  119. break;
  120. }
  121. }
  122. finally
  123. {
  124. _thinking = false;
  125. }
  126. }
  127. @Override
  128. protected void onEvtFinishCasting()
  129. {
  130. ((L2Summon) _actor).setFollowStatus(_startFollow);
  131. }
  132. public void notifyFollowStatusChange()
  133. {
  134. _startFollow = !_startFollow;
  135. switch (getIntention())
  136. {
  137. case AI_INTENTION_ACTIVE:
  138. case AI_INTENTION_FOLLOW:
  139. case AI_INTENTION_IDLE:
  140. ((L2Summon) _actor).setFollowStatus(_startFollow);
  141. }
  142. }
  143. public void setStartFollowController(boolean val)
  144. {
  145. _startFollow = val;
  146. }
  147. }