ConditionSiegeZone.java 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. else
  72. return false;
  73. }
  74. if (castle != null)
  75. return checkIfOk(target, castle, _value);
  76. else
  77. return checkIfOk(target, fort, _value);
  78. }
  79. /**
  80. * Check if ok.
  81. *
  82. * @param activeChar the active char
  83. * @param castle the castle
  84. * @param value the value
  85. * @return true, if successful
  86. */
  87. public static boolean checkIfOk(L2Character activeChar, Castle castle, int value)
  88. {
  89. if (activeChar == null || !(activeChar instanceof L2PcInstance))
  90. return false;
  91. L2PcInstance player = (L2PcInstance)activeChar;
  92. if ((castle == null || castle.getCastleId() <= 0))
  93. {
  94. if ((value & COND_NOT_ZONE) != 0)
  95. return true;
  96. }
  97. else if (!castle.getZone().isActive())
  98. {
  99. if ((value & COND_NOT_ZONE) != 0)
  100. return true;
  101. }
  102. else if ((value & COND_CAST_ATTACK) != 0 && player.isRegisteredOnThisSiegeField(castle.getCastleId())
  103. && player.getSiegeState() == 1)
  104. return true;
  105. else if ((value & COND_CAST_DEFEND) != 0 && player.isRegisteredOnThisSiegeField(castle.getCastleId())
  106. && player.getSiegeState() == 2)
  107. return true;
  108. else if ((value & COND_CAST_NEUTRAL) != 0 && player.getSiegeState() == 0)
  109. return true;
  110. return false;
  111. }
  112. /**
  113. * Check if ok.
  114. *
  115. * @param activeChar the active char
  116. * @param fort the fort
  117. * @param value the value
  118. * @return true, if successful
  119. */
  120. public static boolean checkIfOk(L2Character activeChar, Fort fort, int value)
  121. {
  122. if (activeChar == null || !(activeChar instanceof L2PcInstance))
  123. return false;
  124. L2PcInstance player = (L2PcInstance)activeChar;
  125. if ((fort == null || fort.getFortId() <= 0))
  126. {
  127. if ((value & COND_NOT_ZONE) != 0)
  128. return true;
  129. }
  130. else if (!fort.getZone().isActive())
  131. {
  132. if ((value & COND_NOT_ZONE) != 0)
  133. return true;
  134. }
  135. else if ((value & COND_FORT_ATTACK) != 0 && player.isRegisteredOnThisSiegeField(fort.getFortId())
  136. && player.getSiegeState() == 1)
  137. return true;
  138. else if ((value & COND_FORT_DEFEND) != 0 && player.isRegisteredOnThisSiegeField(fort.getFortId())
  139. && player.getSiegeState() == 2)
  140. return true;
  141. else if ((value & COND_FORT_NEUTRAL) != 0 && player.getSiegeState() == 0)
  142. return true;
  143. return false;
  144. }
  145. }