ConditionSiegeZone.java 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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.instancemanager.CastleManager;
  17. import com.l2jserver.gameserver.instancemanager.FortManager;
  18. import com.l2jserver.gameserver.instancemanager.TerritoryWarManager;
  19. import com.l2jserver.gameserver.model.actor.L2Character;
  20. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  21. import com.l2jserver.gameserver.model.entity.Castle;
  22. import com.l2jserver.gameserver.model.entity.Fort;
  23. import com.l2jserver.gameserver.skills.Env;
  24. /**
  25. * The Class ConditionSiegeZone.
  26. *
  27. * @author Gigiikun
  28. */
  29. public final class ConditionSiegeZone extends Condition
  30. {
  31. // conditional values
  32. public final static int COND_NOT_ZONE = 0x0001;
  33. public final static int COND_CAST_ATTACK = 0x0002;
  34. public final static int COND_CAST_DEFEND = 0x0004;
  35. public final static int COND_CAST_NEUTRAL = 0x0008;
  36. public final static int COND_FORT_ATTACK = 0x0010;
  37. public final static int COND_FORT_DEFEND = 0x0020;
  38. public final static int COND_FORT_NEUTRAL = 0x0040;
  39. public final static int COND_TW_CHANNEL = 0x0080;
  40. public final static int COND_TW_PROGRESS = 0x0100;
  41. private final int _value;
  42. private final boolean _self;
  43. /**
  44. * Instantiates a new condition siege zone.
  45. *
  46. * @param value the value
  47. * @param self the self
  48. */
  49. public ConditionSiegeZone(int value, boolean self)
  50. {
  51. _value = value;
  52. _self = self;
  53. }
  54. /* (non-Javadoc)
  55. * @see com.l2jserver.gameserver.skills.conditions.Condition#testImpl(com.l2jserver.gameserver.skills.Env)
  56. */
  57. @Override
  58. public boolean testImpl(Env env)
  59. {
  60. L2Character target = _self ? env.player : env.target;
  61. Castle castle = CastleManager.getInstance().getCastle(target);
  62. Fort fort = FortManager.getInstance().getFort(target);
  63. if ((_value & COND_TW_PROGRESS) != 0 && !TerritoryWarManager.getInstance().isTWInProgress())
  64. return false;
  65. else if ((_value & COND_TW_CHANNEL) != 0 && !TerritoryWarManager.getInstance().isTWChannelOpen())
  66. return false;
  67. else if ((castle == null) && (fort == null))
  68. {
  69. if ((_value & COND_NOT_ZONE) != 0)
  70. return true;
  71. return false;
  72. }
  73. if (castle != null)
  74. return checkIfOk(target, castle, _value);
  75. return checkIfOk(target, fort, _value);
  76. }
  77. /**
  78. * Check if ok.
  79. *
  80. * @param activeChar the active char
  81. * @param castle the castle
  82. * @param value the value
  83. * @return true, if successful
  84. */
  85. public static boolean checkIfOk(L2Character activeChar, Castle castle, int value)
  86. {
  87. if (activeChar == null || !(activeChar instanceof L2PcInstance))
  88. return false;
  89. L2PcInstance player = (L2PcInstance)activeChar;
  90. if ((castle == null || castle.getCastleId() <= 0))
  91. {
  92. if ((value & COND_NOT_ZONE) != 0)
  93. return true;
  94. }
  95. else if (!castle.getZone().isActive())
  96. {
  97. if ((value & COND_NOT_ZONE) != 0)
  98. return true;
  99. }
  100. else if ((value & COND_CAST_ATTACK) != 0 && player.isRegisteredOnThisSiegeField(castle.getCastleId())
  101. && player.getSiegeState() == 1)
  102. return true;
  103. else if ((value & COND_CAST_DEFEND) != 0 && player.isRegisteredOnThisSiegeField(castle.getCastleId())
  104. && player.getSiegeState() == 2)
  105. return true;
  106. else if ((value & COND_CAST_NEUTRAL) != 0 && player.getSiegeState() == 0)
  107. return true;
  108. return false;
  109. }
  110. /**
  111. * Check if ok.
  112. *
  113. * @param activeChar the active char
  114. * @param fort the fort
  115. * @param value the value
  116. * @return true, if successful
  117. */
  118. public static boolean checkIfOk(L2Character activeChar, Fort fort, int value)
  119. {
  120. if (activeChar == null || !(activeChar instanceof L2PcInstance))
  121. return false;
  122. L2PcInstance player = (L2PcInstance)activeChar;
  123. if ((fort == null || fort.getFortId() <= 0))
  124. {
  125. if ((value & COND_NOT_ZONE) != 0)
  126. return true;
  127. }
  128. else if (!fort.getZone().isActive())
  129. {
  130. if ((value & COND_NOT_ZONE) != 0)
  131. return true;
  132. }
  133. else if ((value & COND_FORT_ATTACK) != 0 && player.isRegisteredOnThisSiegeField(fort.getFortId())
  134. && player.getSiegeState() == 1)
  135. return true;
  136. else if ((value & COND_FORT_DEFEND) != 0 && player.isRegisteredOnThisSiegeField(fort.getFortId())
  137. && player.getSiegeState() == 2)
  138. return true;
  139. else if ((value & COND_FORT_NEUTRAL) != 0 && player.getSiegeState() == 0)
  140. return true;
  141. return false;
  142. }
  143. }