Ctrl.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 com.l2jserver.gameserver.model.actor.L2Character;
  17. /**
  18. * Interface of AI and client state.
  19. *
  20. * To correctly send messages to client we need it's state.
  21. * For example, if we've sent 'StartAutoAttack' message, we need to
  22. * send 'StopAutoAttack' message before any other action. Or
  23. * if we've sent 'MoveToPawn', we need to send 'StopMove' when
  24. * the movement of a character is canceled (by Root spell or
  25. * any other reason). Thus, we need to know the state of
  26. * client, i.e. which messages we've sent and how the client
  27. * will show the scene.
  28. *
  29. * Close to this task is the task of AI.
  30. * If a player's character is attacking a mob, his ATTACK may be
  31. * interrupted by an event, that temporary disable attacking.
  32. * But when the possibility to ATTACK will be enabled, the
  33. * character must continue the ATTACK. For mobs it may be
  34. * more complex, since we want them to decide when to use magic,
  35. * or when to follow the player for physical combat, or when to escape,
  36. * to help another mob, etc.
  37. *
  38. * This interface is hiding complexity of server<->client
  39. * interaction and multiple states of a character. It allows to
  40. * set a desired, simple "wish" of a character, and the implementation
  41. * of this interface will take care about the rest.
  42. * The goal of a character may be like "ATTACK", "random walk" and so on.
  43. * To reach the goal implementation will split it into several small
  44. * actions, several steps (possibly repeatable). Like "run to target"
  45. * then "hit it", then if target is not dead - repeat.
  46. * This flow of simpler steps may be interrupted by incoming events.
  47. * Like a character's movement was disabled (by Root spell, for instance).
  48. * Depending on character's ability AI may choose to wait, or to use
  49. * magic ATTACK and so on.
  50. * Additionally incoming events are compared with client's state
  51. * of the character, and required network messages are sent to
  52. * client's, i.e. if we have incoming event that character's movement
  53. * was disabled, it causes changing if its behavior, and if client's
  54. * state for the character is "moving" we send messages to clients
  55. * to stop the avatar/mob.
  56. */
  57. public interface Ctrl
  58. {
  59. /**
  60. * Gets the actor.
  61. * @return the actor
  62. */
  63. L2Character getActor();
  64. /**
  65. * Gets the intention.
  66. * @return the intention
  67. */
  68. CtrlIntention getIntention();
  69. /**
  70. * Gets the attack target.
  71. * @return the attack target
  72. */
  73. L2Character getAttackTarget();
  74. /**
  75. * Set general state/intention for AI, with optional data.
  76. * @param intention the new intention
  77. */
  78. void setIntention(CtrlIntention intention);
  79. /**
  80. * Sets the intention.
  81. * @param intention the intention
  82. * @param arg0 the arg0
  83. */
  84. void setIntention(CtrlIntention intention, Object arg0);
  85. /**
  86. * Sets the intention.
  87. * @param intention the intention
  88. * @param arg0 the arg0
  89. * @param arg1 the arg1
  90. */
  91. void setIntention(CtrlIntention intention, Object arg0, Object arg1);
  92. /**
  93. * Event, that notifies about previous step result, or user command, that does not change current general intention.
  94. * @param evt the event
  95. */
  96. void notifyEvent(CtrlEvent evt);
  97. /**
  98. * Notify an event.
  99. * @param evt the event
  100. * @param arg0 the arg0
  101. */
  102. void notifyEvent(CtrlEvent evt, Object arg0);
  103. /**
  104. * Notify an event.
  105. * @param evt the event
  106. * @param arg0 the arg0
  107. * @param arg1 the arg1
  108. */
  109. void notifyEvent(CtrlEvent evt, Object arg0, Object arg1);
  110. }