L2SkillSiegeFlag.java 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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.l2skills;
  16. import com.l2jserver.gameserver.datatables.NpcTable;
  17. import com.l2jserver.gameserver.idfactory.IdFactory;
  18. import com.l2jserver.gameserver.instancemanager.CastleManager;
  19. import com.l2jserver.gameserver.instancemanager.FortManager;
  20. import com.l2jserver.gameserver.instancemanager.FortSiegeManager;
  21. import com.l2jserver.gameserver.instancemanager.SiegeManager;
  22. import com.l2jserver.gameserver.model.L2Object;
  23. import com.l2jserver.gameserver.model.L2Skill;
  24. import com.l2jserver.gameserver.model.actor.L2Character;
  25. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  26. import com.l2jserver.gameserver.model.actor.instance.L2SiegeFlagInstance;
  27. import com.l2jserver.gameserver.model.entity.Castle;
  28. import com.l2jserver.gameserver.model.entity.Fort;
  29. import com.l2jserver.gameserver.templates.StatsSet;
  30. public class L2SkillSiegeFlag extends L2Skill
  31. {
  32. private final boolean _isAdvanced;
  33. public L2SkillSiegeFlag(StatsSet set)
  34. {
  35. super(set);
  36. _isAdvanced = set.getBool("isadvanced", false);
  37. }
  38. /**
  39. * @see com.l2jserver.gameserver.model.L2Skill#useSkill(com.l2jserver.gameserver.model.actor.L2Character, com.l2jserver.gameserver.model.L2Object[])
  40. */
  41. public void useSkill(L2Character activeChar, L2Object[] targets)
  42. {
  43. if (!(activeChar instanceof L2PcInstance))
  44. return;
  45. L2PcInstance player = (L2PcInstance) activeChar;
  46. if (player.getClan() == null || player.getClan().getLeaderId() != player.getObjectId())
  47. return;
  48. Castle castle = CastleManager.getInstance().getCastle(player);
  49. Fort fort = FortManager.getInstance().getFort(player);
  50. if ((castle == null) && (fort == null))
  51. return;
  52. if (castle != null)
  53. {
  54. if (!checkIfOkToPlaceFlag(player, castle, true))
  55. return;
  56. }
  57. else
  58. {
  59. if (!checkIfOkToPlaceFlag(player, fort, true))
  60. return;
  61. }
  62. try
  63. {
  64. // Spawn a new flag
  65. L2SiegeFlagInstance flag = new L2SiegeFlagInstance(player, IdFactory.getInstance().getNextId(), NpcTable.getInstance().getTemplate(35062), _isAdvanced);
  66. flag.setTitle(player.getClan().getName());
  67. flag.setCurrentHpMp(flag.getMaxHp(), flag.getMaxMp());
  68. flag.setHeading(player.getHeading());
  69. flag.spawnMe(player.getX(), player.getY(), player.getZ() + 50);
  70. if (castle != null)
  71. castle.getSiege().getFlag(player.getClan()).add(flag);
  72. else
  73. fort.getSiege().getFlag(player.getClan()).add(flag);
  74. }
  75. catch (Exception e)
  76. {
  77. player.sendMessage("Error placing flag:" + e);
  78. }
  79. }
  80. /**
  81. * Return true if character clan place a flag<BR><BR>
  82. *
  83. * @param activeChar The L2Character of the character placing the flag
  84. * @param isCheckOnly if false, it will send a notification to the player telling him
  85. * why it failed
  86. */
  87. public static boolean checkIfOkToPlaceFlag(L2Character activeChar, boolean isCheckOnly)
  88. {
  89. Castle castle = CastleManager.getInstance().getCastle(activeChar);
  90. Fort fort = FortManager.getInstance().getFort(activeChar);
  91. if ((castle == null) && (fort == null))
  92. return false;
  93. if (castle != null)
  94. return checkIfOkToPlaceFlag(activeChar, castle, isCheckOnly);
  95. else
  96. return checkIfOkToPlaceFlag(activeChar, fort, isCheckOnly);
  97. }
  98. /**
  99. *
  100. * @param activeChar
  101. * @param castle
  102. * @param isCheckOnly
  103. * @return
  104. */
  105. public static boolean checkIfOkToPlaceFlag(L2Character activeChar, Castle castle, boolean isCheckOnly)
  106. {
  107. if (!(activeChar instanceof L2PcInstance))
  108. return false;
  109. String text = "";
  110. L2PcInstance player = (L2PcInstance) activeChar;
  111. if (castle == null || castle.getCastleId() <= 0)
  112. text = "You must be on castle ground to place a flag.";
  113. else if (!castle.getSiege().getIsInProgress())
  114. text = "You can only place a flag during a siege.";
  115. else if (castle.getSiege().getAttackerClan(player.getClan()) == null)
  116. text = "You must be an attacker to place a flag.";
  117. else if (player.getClan() == null || !player.isClanLeader())
  118. text = "You must be a clan leader to place a flag.";
  119. else if (castle.getSiege().getAttackerClan(player.getClan()).getNumFlags() >= SiegeManager.getInstance().getFlagMaxCount())
  120. text = "You have already placed the maximum number of flags possible.";
  121. else if (player.isInsideZone(L2Character.ZONE_NOHQ))
  122. text = "You cannot place flag here.";
  123. else
  124. return true;
  125. if (!isCheckOnly)
  126. player.sendMessage(text);
  127. return false;
  128. }
  129. /**
  130. *
  131. * @param activeChar
  132. * @param fort
  133. * @param isCheckOnly
  134. * @return
  135. */
  136. public static boolean checkIfOkToPlaceFlag(L2Character activeChar, Fort fort, boolean isCheckOnly)
  137. {
  138. if (!(activeChar instanceof L2PcInstance))
  139. return false;
  140. String text = "";
  141. L2PcInstance player = (L2PcInstance) activeChar;
  142. if (fort == null || fort.getFortId() <= 0)
  143. text = "You must be on fort ground to place a flag.";
  144. else if (!fort.getSiege().getIsInProgress())
  145. text = "You can only place a flag during a siege.";
  146. else if (fort.getSiege().getAttackerClan(player.getClan()) == null)
  147. text = "You must be an attacker to place a flag.";
  148. else if (player.getClan() == null || !player.isClanLeader())
  149. text = "You must be a clan leader to place a flag.";
  150. else if (fort.getSiege().getAttackerClan(player.getClan()).getNumFlags() >= FortSiegeManager.getInstance().getFlagMaxCount())
  151. text = "You have already placed the maximum number of flags possible.";
  152. else if (player.isInsideZone(L2Character.ZONE_NOHQ))
  153. text = "You cannot place flag here.";
  154. else
  155. return true;
  156. if (!isCheckOnly)
  157. player.sendMessage(text);
  158. return false;
  159. }
  160. }