L2SummonAI.java 4.5 KB

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