Ctrl.java 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License as published by
  4. * the Free Software Foundation; either version 2, or (at your option)
  5. * any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program; if not, write to the Free Software
  14. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  15. * 02111-1307, USA.
  16. *
  17. * http://www.gnu.org/copyleft/gpl.html
  18. */
  19. package net.sf.l2j.gameserver.ai;
  20. import net.sf.l2j.gameserver.model.L2Character;
  21. /**
  22. * Interface of AI and client state.
  23. *
  24. * To correctly send messages to client we need it's state.
  25. * For example, if we've sent 'StartAutoAttack' message, we need to
  26. * send 'StopAutoAttack' message before any other action. Or
  27. * if we've sent 'MoveToPawn', we need to send 'StopMove' when
  28. * the movement of a character is canceled (by Root spell or
  29. * any other reason). Thus, we need to know the state of
  30. * client, i.e. which messages we've sent and how the client
  31. * will show the scene.
  32. *
  33. * Close to this task is the task of AI.
  34. * If a player's character is attacking a mob, his ATTACK may be
  35. * iterrupted by an event, that temporary disable attacking.
  36. * But when the possibility to ATTACK will be enabled, the
  37. * character must continue the ATTACK. For mobs it may be
  38. * more complex, since we want them to decide when to use magic,
  39. * or when to follow the player for physical combat, or when to escape,
  40. * to help another mob, etc.
  41. *
  42. * This interface is hiding complexity of server<->client
  43. * interaction and multiple states of a character. It allows to
  44. * set a desired, simple "wish" of a character, and the implementation
  45. * of this interface will take care about the rest.
  46. * The goal of a character may be like "ATTACK", "random walk" and so on.
  47. * To reach the goal inplementation will split it into several small
  48. * actions, several steps (possibly repeatable). Like "run to target"
  49. * then "hit it", then if target is not dead - repeat.
  50. * This flow of simplier steps may be interrupted by incoming events.
  51. * Like a character's movement was disabled (by Root spell, for instance).
  52. * Depending on character's ability AI may choose to wait, or to use
  53. * magic ATTACK and so on.
  54. * Additionally incoming events are compared with client's state
  55. * of the character, and required network messages are sent to
  56. * client's, i.e. if we have incoming event that character's movement
  57. * was disabled, it causes changing if its behavour, and if client's
  58. * state for the character is "moving" we send messages to clients
  59. * to stop the avatar/mob.
  60. *
  61. */
  62. public interface Ctrl {
  63. /** the character this AI serves */
  64. L2Character getActor();
  65. /** get current intention */
  66. CtrlIntention getIntention();
  67. /** get current ATTACK target */
  68. L2Character getAttackTarget();
  69. /** Set general state/intention for AI, with optional data */
  70. void setIntention(CtrlIntention intention);
  71. void setIntention(CtrlIntention intention, Object arg0);
  72. void setIntention(CtrlIntention intention, Object arg0, Object arg1);
  73. /** Event, that notifies about previous step result, or user command,
  74. * that does not change current general intention */
  75. void notifyEvent(CtrlEvent evt);
  76. void notifyEvent(CtrlEvent evt, Object arg0);
  77. void notifyEvent(CtrlEvent evt, Object arg0, Object arg1);
  78. }