ConditionSiegeZone.java 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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.model.actor.L2Character;
  19. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  20. import com.l2jserver.gameserver.model.entity.Castle;
  21. import com.l2jserver.gameserver.model.entity.Fort;
  22. import com.l2jserver.gameserver.skills.Env;
  23. /**
  24. * @author Gigiikun
  25. */
  26. public final class ConditionSiegeZone extends Condition
  27. {
  28. // conditional values
  29. public final static int COND_NOT_ZONE = 0x0001;
  30. public final static int COND_CAST_ATTACK = 0x0002;
  31. public final static int COND_CAST_DEFEND = 0x0004;
  32. public final static int COND_CAST_NEUTRAL = 0x0008;
  33. public final static int COND_FORT_ATTACK = 0x0010;
  34. public final static int COND_FORT_DEFEND = 0x0020;
  35. public final static int COND_FORT_NEUTRAL = 0x0040;
  36. private final int _value;
  37. private final boolean _self;
  38. /**
  39. *
  40. */
  41. public ConditionSiegeZone(int value, boolean self)
  42. {
  43. _value = value;
  44. _self = self;
  45. }
  46. @Override
  47. public boolean testImpl(Env env)
  48. {
  49. L2Character target = _self ? env.player : env.target;
  50. Castle castle = CastleManager.getInstance().getCastle(target);
  51. Fort fort = FortManager.getInstance().getFort(target);
  52. if ((castle == null) && (fort == null))
  53. {
  54. if ((_value & COND_NOT_ZONE) != 0)
  55. return true;
  56. else
  57. return false;
  58. }
  59. if (castle != null)
  60. return checkIfOk(target, castle, _value);
  61. else
  62. return checkIfOk(target, fort, _value);
  63. }
  64. public static boolean checkIfOk(L2Character activeChar, Castle castle, int value)
  65. {
  66. if (activeChar == null || !(activeChar instanceof L2PcInstance))
  67. return false;
  68. L2PcInstance player = (L2PcInstance)activeChar;
  69. if ((castle == null || castle.getCastleId() <= 0))
  70. {
  71. if ((value & COND_NOT_ZONE) != 0)
  72. return true;
  73. }
  74. else if (!castle.getSiege().getIsInProgress())
  75. {
  76. if ((value & COND_NOT_ZONE) != 0)
  77. return true;
  78. }
  79. else if ((castle.getSiege().getAttackerClan(player.getClan()) != null) && (value & COND_CAST_ATTACK) != 0)
  80. return true;
  81. else if ((castle.getSiege().getDefenderClan(player.getClan()) != null) && (value & COND_CAST_DEFEND) != 0)
  82. return true;
  83. else if ((castle.getSiege().getAttackerClan(player.getClan()) == null) && (castle.getSiege().getDefenderClan(player.getClan()) == null) && (value & COND_CAST_NEUTRAL) != 0)
  84. return true;
  85. return false;
  86. }
  87. public static boolean checkIfOk(L2Character activeChar, Fort fort, int value)
  88. {
  89. if (activeChar == null || !(activeChar instanceof L2PcInstance))
  90. return false;
  91. L2PcInstance player = (L2PcInstance)activeChar;
  92. if ((fort == null || fort.getFortId() <= 0))
  93. {
  94. if ((value & COND_NOT_ZONE) != 0)
  95. return true;
  96. }
  97. else if (!fort.getSiege().getIsInProgress())
  98. {
  99. if ((value & COND_NOT_ZONE) != 0)
  100. return true;
  101. }
  102. else if ((fort.getSiege().getAttackerClan(player.getClan()) != null) && (value & COND_FORT_ATTACK) != 0)
  103. return true;
  104. else if ((fort.getOwnerClan() == player.getClan()) && (value & COND_FORT_DEFEND) != 0)
  105. return true;
  106. else if ((fort.getSiege().getAttackerClan(player.getClan()) == null) && (fort.getOwnerClan() != player.getClan()) && (value & COND_FORT_NEUTRAL) != 0)
  107. return true;
  108. return false;
  109. }
  110. }