ConditionLogicAnd.java 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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.skills.conditions;
  16. import com.l2jserver.gameserver.skills.Env;
  17. /**
  18. * @author mkizub
  19. *
  20. */
  21. public class ConditionLogicAnd extends Condition
  22. {
  23. private static Condition[] _emptyConditions = new Condition[0];
  24. public Condition[] conditions = _emptyConditions;
  25. public ConditionLogicAnd()
  26. {
  27. super();
  28. }
  29. /**
  30. *
  31. * @param condition
  32. */
  33. public void add(Condition condition)
  34. {
  35. if (condition == null)
  36. return;
  37. if (getListener() != null)
  38. condition.setListener(this);
  39. final int len = conditions.length;
  40. final Condition[] tmp = new Condition[len + 1];
  41. System.arraycopy(conditions, 0, tmp, 0, len);
  42. tmp[len] = condition;
  43. conditions = tmp;
  44. }
  45. /**
  46. *
  47. * @see com.l2jserver.gameserver.skills.conditions.Condition#setListener(com.l2jserver.gameserver.skills.conditions.ConditionListener)
  48. */
  49. @Override
  50. void setListener(ConditionListener listener)
  51. {
  52. if (listener != null)
  53. {
  54. for (Condition c : conditions)
  55. c.setListener(this);
  56. }
  57. else
  58. {
  59. for (Condition c : conditions)
  60. c.setListener(null);
  61. }
  62. super.setListener(listener);
  63. }
  64. /**
  65. *
  66. * @see com.l2jserver.gameserver.skills.conditions.Condition#testImpl(com.l2jserver.gameserver.skills.Env)
  67. */
  68. @Override
  69. public boolean testImpl(Env env)
  70. {
  71. for (Condition c : conditions)
  72. {
  73. if (!c.test(env))
  74. return false;
  75. }
  76. return true;
  77. }
  78. }