ConditionSiegeZone.java 5.2 KB

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