Ctrl.java 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 net.sf.l2j.gameserver.model.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. * iterrupted 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 inplementation 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 simplier 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 behavour, and if client's
  54. * state for the character is "moving" we send messages to clients
  55. * to stop the avatar/mob.
  56. *
  57. */
  58. public interface Ctrl {
  59. /** the character this AI serves */
  60. L2Character getActor();
  61. /** get current intention */
  62. CtrlIntention getIntention();
  63. /** get current ATTACK target */
  64. L2Character getAttackTarget();
  65. /** Set general state/intention for AI, with optional data */
  66. void setIntention(CtrlIntention intention);
  67. void setIntention(CtrlIntention intention, Object arg0);
  68. void setIntention(CtrlIntention intention, Object arg0, Object arg1);
  69. /** Event, that notifies about previous step result, or user command,
  70. * that does not change current general intention */
  71. void notifyEvent(CtrlEvent evt);
  72. void notifyEvent(CtrlEvent evt, Object arg0);
  73. void notifyEvent(CtrlEvent evt, Object arg0, Object arg1);
  74. }