NextAction.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /*
  2. * Copyright (C) 2004-2013 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 java.util.ArrayList;
  21. /**
  22. * Class for AI action after some event.<br>
  23. * Has 2 array list for "work" and "break".
  24. * @author Yaroslav
  25. */
  26. public class NextAction
  27. {
  28. public interface NextActionCallback
  29. {
  30. public void doWork();
  31. }
  32. private ArrayList<CtrlEvent> _events;
  33. private ArrayList<CtrlIntention> _intentions;
  34. private NextActionCallback _callback;
  35. /**
  36. * Main constructor.
  37. * @param events
  38. * @param intentions
  39. * @param callback
  40. */
  41. public NextAction(ArrayList<CtrlEvent> events, ArrayList<CtrlIntention> intentions, NextActionCallback callback)
  42. {
  43. _events = events;
  44. _intentions = intentions;
  45. setCallback(callback);
  46. }
  47. /**
  48. * Single constructor.
  49. * @param event
  50. * @param intention
  51. * @param callback
  52. */
  53. public NextAction(CtrlEvent event, CtrlIntention intention, NextActionCallback callback)
  54. {
  55. if (_events == null)
  56. {
  57. _events = new ArrayList<>();
  58. }
  59. if (_intentions == null)
  60. {
  61. _intentions = new ArrayList<>();
  62. }
  63. if (event != null)
  64. {
  65. _events.add(event);
  66. }
  67. if (intention != null)
  68. {
  69. _intentions.add(intention);
  70. }
  71. setCallback(callback);
  72. }
  73. /**
  74. * Do action.
  75. */
  76. public void doAction()
  77. {
  78. if (_callback != null)
  79. {
  80. _callback.doWork();
  81. }
  82. }
  83. /**
  84. * @return the _event
  85. */
  86. public ArrayList<CtrlEvent> getEvents()
  87. {
  88. // If null return empty list.
  89. if (_events == null)
  90. {
  91. _events = new ArrayList<>();
  92. }
  93. return _events;
  94. }
  95. /**
  96. * @param event the event to set.
  97. */
  98. public void setEvents(ArrayList<CtrlEvent> event)
  99. {
  100. _events = event;
  101. }
  102. /**
  103. * @param event
  104. */
  105. public void addEvent(CtrlEvent event)
  106. {
  107. if (_events == null)
  108. {
  109. _events = new ArrayList<>();
  110. }
  111. if (event != null)
  112. {
  113. _events.add(event);
  114. }
  115. }
  116. /**
  117. * @param event
  118. */
  119. public void removeEvent(CtrlEvent event)
  120. {
  121. if (_events == null)
  122. {
  123. return;
  124. }
  125. _events.remove(event);
  126. }
  127. /**
  128. * @return the _callback
  129. */
  130. public NextActionCallback getCallback()
  131. {
  132. return _callback;
  133. }
  134. /**
  135. * @param callback the callback to set.
  136. */
  137. public void setCallback(NextActionCallback callback)
  138. {
  139. _callback = callback;
  140. }
  141. /**
  142. * @return the _intentions
  143. */
  144. public ArrayList<CtrlIntention> getIntentions()
  145. {
  146. // If null return empty list.
  147. if (_intentions == null)
  148. {
  149. _intentions = new ArrayList<>();
  150. }
  151. return _intentions;
  152. }
  153. /**
  154. * @param intentions the intention to set.
  155. */
  156. public void setIntentions(ArrayList<CtrlIntention> intentions)
  157. {
  158. _intentions = intentions;
  159. }
  160. /**
  161. * @param intention
  162. */
  163. public void addIntention(CtrlIntention intention)
  164. {
  165. if (_intentions == null)
  166. {
  167. _intentions = new ArrayList<>();
  168. }
  169. if (intention != null)
  170. {
  171. _intentions.add(intention);
  172. }
  173. }
  174. /**
  175. * @param intention
  176. */
  177. public void removeIntention(CtrlIntention intention)
  178. {
  179. if (_intentions == null)
  180. {
  181. return;
  182. }
  183. _intentions.remove(intention);
  184. }
  185. }