NextAction.java 3.8 KB

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