ConditionLogicAnd.java 2.1 KB

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