ConditionSiegeZone.java 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. * @author Gigiikun
  26. */
  27. public final class ConditionSiegeZone extends Condition
  28. {
  29. // conditional values
  30. public final static int COND_NOT_ZONE = 0x0001;
  31. public final static int COND_CAST_ATTACK = 0x0002;
  32. public final static int COND_CAST_DEFEND = 0x0004;
  33. public final static int COND_CAST_NEUTRAL = 0x0008;
  34. public final static int COND_FORT_ATTACK = 0x0010;
  35. public final static int COND_FORT_DEFEND = 0x0020;
  36. public final static int COND_FORT_NEUTRAL = 0x0040;
  37. public final static int COND_TW_CHANNEL = 0x0080;
  38. public final static int COND_TW_PROGRESS = 0x0100;
  39. private final int _value;
  40. private final boolean _self;
  41. /**
  42. *
  43. */
  44. public ConditionSiegeZone(int value, boolean self)
  45. {
  46. _value = value;
  47. _self = self;
  48. }
  49. @Override
  50. public boolean testImpl(Env env)
  51. {
  52. L2Character target = _self ? env.player : env.target;
  53. Castle castle = CastleManager.getInstance().getCastle(target);
  54. Fort fort = FortManager.getInstance().getFort(target);
  55. if ((_value & COND_TW_PROGRESS) != 0 && !TerritoryWarManager.getInstance().isTWInProgress())
  56. return false;
  57. else if ((_value & COND_TW_CHANNEL) != 0 && !TerritoryWarManager.getInstance().isTWChannelOpen())
  58. return false;
  59. else if ((castle == null) && (fort == null))
  60. {
  61. if ((_value & COND_NOT_ZONE) != 0)
  62. return true;
  63. else
  64. return false;
  65. }
  66. if (castle != null)
  67. return checkIfOk(target, castle, _value);
  68. else
  69. return checkIfOk(target, fort, _value);
  70. }
  71. public static boolean checkIfOk(L2Character activeChar, Castle castle, int value)
  72. {
  73. if (activeChar == null || !(activeChar instanceof L2PcInstance))
  74. return false;
  75. L2PcInstance player = (L2PcInstance)activeChar;
  76. if ((castle == null || castle.getCastleId() <= 0))
  77. {
  78. if ((value & COND_NOT_ZONE) != 0)
  79. return true;
  80. }
  81. else if (!castle.getZone().isActive())
  82. {
  83. if ((value & COND_NOT_ZONE) != 0)
  84. return true;
  85. }
  86. else if ((value & COND_CAST_ATTACK) != 0 && player.isRegisteredOnThisSiegeField(castle.getCastleId())
  87. && player.getSiegeState() == 1)
  88. return true;
  89. else if ((value & COND_CAST_DEFEND) != 0 && player.isRegisteredOnThisSiegeField(castle.getCastleId())
  90. && player.getSiegeState() == 2)
  91. return true;
  92. else if ((value & COND_CAST_NEUTRAL) != 0 && player.getSiegeState() == 0)
  93. return true;
  94. return false;
  95. }
  96. public static boolean checkIfOk(L2Character activeChar, Fort fort, int value)
  97. {
  98. if (activeChar == null || !(activeChar instanceof L2PcInstance))
  99. return false;
  100. L2PcInstance player = (L2PcInstance)activeChar;
  101. if ((fort == null || fort.getFortId() <= 0))
  102. {
  103. if ((value & COND_NOT_ZONE) != 0)
  104. return true;
  105. }
  106. else if (!fort.getZone().isActive())
  107. {
  108. if ((value & COND_NOT_ZONE) != 0)
  109. return true;
  110. }
  111. else if ((value & COND_FORT_ATTACK) != 0 && player.isRegisteredOnThisSiegeField(fort.getFortId())
  112. && player.getSiegeState() == 1)
  113. return true;
  114. else if ((value & COND_FORT_DEFEND) != 0 && player.isRegisteredOnThisSiegeField(fort.getFortId())
  115. && player.getSiegeState() == 2)
  116. return true;
  117. else if ((value & COND_FORT_NEUTRAL) != 0 && player.getSiegeState() == 0)
  118. return true;
  119. return false;
  120. }
  121. }