ConditionPlayerCanTakeCastle.java 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright (C) 2004-2014 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.model.entity.Castle;
  22. import com.l2jserver.gameserver.model.stats.Env;
  23. import com.l2jserver.gameserver.network.SystemMessageId;
  24. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  25. import com.l2jserver.gameserver.util.Util;
  26. /**
  27. * Player Can Possess Holything condition implementation.
  28. * @author Adry_85
  29. */
  30. public class ConditionPlayerCanTakeCastle extends Condition
  31. {
  32. private final boolean _val;
  33. public ConditionPlayerCanTakeCastle(boolean val)
  34. {
  35. _val = val;
  36. }
  37. @Override
  38. public boolean testImpl(Env env)
  39. {
  40. boolean canTakeCastle = true;
  41. if ((env.getPlayer() == null) || env.getPlayer().isAlikeDead() || env.getPlayer().isCursedWeaponEquipped())
  42. {
  43. canTakeCastle = false;
  44. }
  45. else if ((env.getPlayer().getClan() == null) || (env.getPlayer().getClan().getLeaderId() != env.getPlayer().getObjectId()))
  46. {
  47. canTakeCastle = false;
  48. }
  49. Castle castle = CastleManager.getInstance().getCastle(env.getPlayer());
  50. SystemMessage sm;
  51. if ((castle == null) || (castle.getResidenceId() <= 0) || !castle.getSiege().getIsInProgress() || (castle.getSiege().getAttackerClan(env.getPlayer().getClan()) == null))
  52. {
  53. sm = SystemMessage.getSystemMessage(SystemMessageId.S1_CANNOT_BE_USED);
  54. sm.addSkillName(env.getSkill());
  55. env.getPlayer().sendPacket(sm);
  56. canTakeCastle = false;
  57. }
  58. else if (!castle.getArtefacts().contains(env.getTarget()))
  59. {
  60. env.getPlayer().sendPacket(SystemMessageId.INCORRECT_TARGET);
  61. canTakeCastle = false;
  62. }
  63. else if (!Util.checkIfInRange(200, env.getPlayer(), env.getTarget(), true))
  64. {
  65. env.getPlayer().sendPacket(SystemMessageId.DIST_TOO_FAR_CASTING_STOPPED);
  66. canTakeCastle = false;
  67. }
  68. return (_val == canTakeCastle);
  69. }
  70. }