AiPlugingParameters.java 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 com.l2jserver.gameserver.ai2;
  16. import java.util.Set;
  17. import com.l2jserver.gameserver.datatables.NpcTable;
  18. import javolution.util.FastSet;
  19. /**
  20. *
  21. * @author -Wooden-
  22. */
  23. public class AiPlugingParameters
  24. {
  25. //here is order of priority
  26. private Set<String> _npcClassTypes;
  27. private Set<Class<?>> _npcL2jClasses;
  28. private Set<String> _aiTypes;
  29. private Set<Integer> _npcIDs;
  30. private boolean _converted;
  31. private AiPlugingParameters _but;
  32. public AiPlugingParameters(Set<String> npcClassTypes, Set<Class<?>> npcL2jClasses, Set<String> aiTypes, Set<Integer> npcIDs, AiPlugingParameters but)
  33. {
  34. _npcClassTypes = npcClassTypes;
  35. _npcL2jClasses = npcL2jClasses;
  36. _aiTypes = aiTypes;
  37. _npcIDs = npcIDs;
  38. _but = but;
  39. if (_npcIDs == null)
  40. _npcIDs = new FastSet<Integer>();
  41. }
  42. public void convertToIDs()
  43. {
  44. if (_but != null && !_but.isEmpty())
  45. _but.convertToIDs();
  46. if (_npcClassTypes != null)
  47. for (String classType : _npcClassTypes)
  48. {
  49. _npcIDs.addAll(NpcTable.getInstance().getAllNpcOfClassType(classType));
  50. }
  51. if (_npcL2jClasses != null)
  52. for (Class<?> l2jClass : _npcL2jClasses)
  53. {
  54. _npcIDs.addAll(NpcTable.getInstance().getAllNpcOfL2jClass(l2jClass));
  55. }
  56. if (_aiTypes != null)
  57. for (String aiType : _aiTypes)
  58. {
  59. _npcIDs.addAll(NpcTable.getInstance().getAllNpcOfAiType(aiType));
  60. }
  61. if (_but != null && !_but.isEmpty())
  62. removeIDs(_but.getIDs());
  63. _converted = true;
  64. }
  65. public boolean isEmpty()
  66. {
  67. return (_npcIDs.isEmpty() && _aiTypes.isEmpty() && _npcL2jClasses.isEmpty() && _npcClassTypes.isEmpty());
  68. }
  69. /**
  70. * If a AiPlugingParameters was converted to IDs its other parameter sets might not be accurate
  71. * @return true if AiPlugingParameters where converted to IDs
  72. */
  73. public boolean isConverted()
  74. {
  75. return _converted;
  76. }
  77. public void removeIDs(Set<Integer> ids)
  78. {
  79. _npcIDs.removeAll(ids);
  80. }
  81. public Set<Integer> getIDs()
  82. {
  83. return _npcIDs;
  84. }
  85. /**
  86. * @param id
  87. * @return
  88. */
  89. public boolean contains(int id)
  90. {
  91. if (!_converted)
  92. throw new IllegalStateException("Can not call 'contain' method on a non-converted AiPluginParameters");
  93. if (_but == null)
  94. return _npcIDs.contains(id);
  95. return _npcIDs.contains(id) && !_but.contains(id);
  96. }
  97. public boolean equals(AiPlugingParameters pparams)
  98. {
  99. if (!_converted)
  100. throw new IllegalStateException("Can not call 'equals' method on a non-converted AiPluginParameters");
  101. return (_npcIDs.containsAll(pparams.getIDs()) && pparams.getIDs().containsAll(_npcIDs));
  102. }
  103. }