Ctrl.java 4.2 KB

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