TakeCastle.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 net.sf.l2j.gameserver.handler.skillhandlers;
  16. import net.sf.l2j.gameserver.handler.ISkillHandler;
  17. import net.sf.l2j.gameserver.instancemanager.CastleManager;
  18. import net.sf.l2j.gameserver.model.L2Character;
  19. import net.sf.l2j.gameserver.model.L2Object;
  20. import net.sf.l2j.gameserver.model.L2Skill;
  21. import net.sf.l2j.gameserver.model.actor.instance.L2ArtefactInstance;
  22. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  23. import net.sf.l2j.gameserver.model.entity.Castle;
  24. import net.sf.l2j.gameserver.templates.L2SkillType;
  25. import net.sf.l2j.gameserver.util.Util;
  26. /**
  27. * @author _drunk_
  28. *
  29. */
  30. public class TakeCastle implements ISkillHandler
  31. {
  32. private static final L2SkillType[] SKILL_IDS =
  33. {
  34. L2SkillType.TAKECASTLE
  35. };
  36. /**
  37. *
  38. * @see net.sf.l2j.gameserver.handler.ISkillHandler#useSkill(net.sf.l2j.gameserver.model.L2Character, net.sf.l2j.gameserver.model.L2Skill, net.sf.l2j.gameserver.model.L2Object[])
  39. */
  40. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  41. {
  42. if (!(activeChar instanceof L2PcInstance))
  43. return;
  44. L2PcInstance player = (L2PcInstance) activeChar;
  45. if (player.getClan() == null || player.getClan().getLeaderId() != player.getObjectId())
  46. return;
  47. Castle castle = CastleManager.getInstance().getCastle(player);
  48. if (castle == null || !checkIfOkToCastSealOfRule(player, castle, true))
  49. return;
  50. try
  51. {
  52. if (targets[0] instanceof L2ArtefactInstance)
  53. castle.Engrave(player.getClan(), targets[0].getObjectId());
  54. }
  55. catch (Exception e)
  56. {
  57. }
  58. }
  59. /**
  60. *
  61. * @see net.sf.l2j.gameserver.handler.ISkillHandler#getSkillIds()
  62. */
  63. public L2SkillType[] getSkillIds()
  64. {
  65. return SKILL_IDS;
  66. }
  67. /**
  68. * Return true if character clan place a flag<BR><BR>
  69. *
  70. * @param activeChar The L2Character of the character placing the flag
  71. *
  72. */
  73. public static boolean checkIfOkToCastSealOfRule(L2Character activeChar, boolean isCheckOnly)
  74. {
  75. return checkIfOkToCastSealOfRule(activeChar, CastleManager.getInstance().getCastle(activeChar), isCheckOnly);
  76. }
  77. /**
  78. *
  79. * @param activeChar
  80. * @param castle
  81. * @param isCheckOnly
  82. * @return
  83. */
  84. public static boolean checkIfOkToCastSealOfRule(L2Character activeChar, Castle castle, boolean isCheckOnly)
  85. {
  86. if (!(activeChar instanceof L2PcInstance))
  87. return false;
  88. String text = "";
  89. L2PcInstance player = (L2PcInstance) activeChar;
  90. if (castle == null || castle.getCastleId() <= 0)
  91. text = "You must be on castle ground to use this skill";
  92. else if (!(player.getTarget() instanceof L2ArtefactInstance))
  93. text = "You can only use this skill on an artifact";
  94. else if (!castle.getSiege().getIsInProgress())
  95. text = "You can only use this skill during a siege.";
  96. else if (!Util.checkIfInRange(200, player, player.getTarget(), true))
  97. text = "You are not in range of the artifact.";
  98. else if (castle.getSiege().getAttackerClan(player.getClan()) == null)
  99. text = "You must be an attacker to use this skill";
  100. else
  101. {
  102. if (!isCheckOnly)
  103. castle.getSiege().announceToPlayer("Clan " + player.getClan().getName() + " has begun to engrave the ruler.", true);
  104. return true;
  105. }
  106. if (!isCheckOnly)
  107. player.sendMessage(text);
  108. return false;
  109. }
  110. }